Creating G Suite subscription - google-reseller-api

While creating a subscription for customer using "G Suite Reseller API" POST https://www.googleapis.com/apps/reseller/v1/customers/customerId/subscriptions
can we specify :
plan.planName as "ANNUAL_MONTHLY_PAY", and renewalSettings.renewalType as "AUTO_RENEW_YEARLY_PAY"
or the renewalType should be "AUTO_RENEW_MONTHLY_PAY" if planName is "ANNUAL_MONTHLY_PAY" ?
currently I do not have test reseller account hence not tested yet.
Thanks

I think so as GSuite Reseller API has this list of available plans:
ANNUAL_MONTHLY_PAY — Annual commitment with monthly payments (more info)
ANNUAL_YEARLY_PAY — Annual commitment with one yearly payment (more info)
FLEXIBLE — Non-commitment plan with monthly payments (more info)
TRIAL — Free trial plan
Trial length is variable up to 30 days max
Gmail daily sending limit set to 500 messages per user
FREE — Free plan only for Cloud Identity Free Edition subscriptions
And for renewalSettings.renewalType these are the accepted values:
"AUTO_RENEW_MONTHLY_PAY": At the end of an annual commitment plan's interval, automatically renew the subscription's plan with the same number of user licenses.
"AUTO_RENEW_YEARLY_PAY": At the end of an annual commitment plan's interval, automatically renew the subscription's plan with the same number of user licenses.
"CANCEL": At the end of an annual commitment plan's interval, the customer's account is suspended. For a 30-day free trial, if a payment plan is not set up for a trial subscription and at the end of the trial, the trial subscription is cancelled.
"RENEW_CURRENT_USERS_MONTHLY_PAY": At the end of an annual commitment plan's interval, renew the subscription's plan but use the total number of current active user licenses.
"RENEW_CURRENT_USERS_YEARLY_PAY": At the end of an annual commitment plan's interval, renew the subscription's plan but use the total number of current active user licenses.
"SWITCH_TO_PAY_AS_YOU_GO": At the end of an annual commitment plan's interval, change the annual commitment plan to a flexible plan.
As long as the values/property was mentioned in the docs, it can be used.

If the plan.planName is ANNUAL_MONTHLY_PAY, the .renewalType must be AUTO_RENEW_MONTHLY_PAY (As this is for Annual Plans with monthly payments)
If the plan.planName is ANNUAL_YEARLY_PAY, the .renwalType must be AUTO_RENEW_YEARLY_PAY (As this of for the Annual Plan with yearly payments)

Related

Grab specific HEADERS off JSON file extracted

API = https://fulfillment.paytm.com/v2/issues?is_cst=1&is_bank=0&parent_issue_id=24000001
While I place a GET request I get the below HTML format data :- Can anyone please help me understand, how do I grab specific headers like - "issue_text" from the below data with its values
'{"reasonObjs":[{"id":24000012,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"My order is pending for a long time","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":0,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":22,"meta_data":{"our_suggestion":{"id":399855,"issue_id":24000012,"key":"our_suggestion","value":"This may happen because we are awaiting confirmation on payment from your bank. No worries! We are checking with your bank on regular intervals to know the status of your transaction. Please wait for sometime before placing another order as orders once initiated cannot be cancelled.","file":""}},"display_text":"My order is pending for a long time"},{"id":24000012,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"My order is pending for a long time","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":0,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":22,"meta_data":{"our_suggestion":{"id":399855,"issue_id":24000012,"key":"our_suggestion","value":"This may happen because we are awaiting confirmation on payment from your bank. No worries! We are checking with your bank on regular intervals to know the status of your transaction. Please wait for sometime before placing another order as orders once initiated cannot be cancelled.","file":""}},"display_text":"My order is pending for a long time"},{"id":24000012,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"My order is pending for a long time","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":0,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":22,"meta_data":{"our_suggestion":{"id":399855,"issue_id":24000012,"key":"our_suggestion","value":"This may happen because we are awaiting confirmation on payment from your bank. No worries! We are checking with your bank on regular intervals to know the status of your transaction. Please wait for sometime before placing another order as orders once initiated cannot be cancelled.","file":""}},"display_text":"My order is pending for a long time"},{"id":24000012,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"My order is pending for a long time","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":0,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":22,"meta_data":{"our_suggestion":{"id":399855,"issue_id":24000012,"key":"our_suggestion","value":"This may happen because we are awaiting confirmation on payment from your bank. No worries! We are checking with your bank on regular intervals to know the status of your transaction. Please wait for sometime before placing another order as orders once initiated cannot be cancelled.","file":""}},"display_text":"My order is pending for a long time"},{"id":24000012,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"My order is pending for a long time","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":0,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":22,"meta_data":{"our_suggestion":{"id":399855,"issue_id":24000012,"key":"our_suggestion","value":"This may happen because we are awaiting confirmation on payment from your bank. No worries! We are checking with your bank on regular intervals to know the status of your transaction. Please wait for sometime before placing another order as orders once initiated cannot be cancelled.","file":""}},"display_text":"My order is pending for a long time"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000013,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I am unable to cancel my order","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":0,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":131,"category_id":null,"order_state":7,"meta_data":{"our_suggestion":{"id":399856,"issue_id":24000013,"key":"our_suggestion","value":"The orders for Paytm First membership, once initiated, cannot be cancelled. However, the Paytm First members will enjoy a wide range of exclusive benefits from leading partner brands for the entire year. This includes Zomato Gold membership, Gaana annual membership, Annual Sony Liv subscription, OYO Wizard, Blue membership, GOQii Plus annual membership, ViU Premium, The Man Company (offers worth Rs 2400 on products), Ombre Lane (offers worth Rs 6000 on women formals), Eros Now annual membership, Uber (benefits up to Rs 6000) and many more exciting partner offers worth more than Rs. 12,000.","file":""},"deeplink":{"id":400319,"issue_id":24000013,"key":"deeplink","value":"Click here to view all the benefits of Paytm First membership#https://paytm.com/offer/weex/paytm_first-test.php","file":""}},"display_text":"I am unable to cancel my order"},{"id":24000035,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"I cannot find invoice for purchase of membership","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":null,"category_id":null,"order_state":null,"meta_data":{"our_suggestion":{"id":399857,"issue_id":24000035,"key":"our_suggestion","value":"To download the invoice, please go the My Orders section and choose the order. Click on Invoice icon to download","file":""}},"display_text":"I cannot find invoice for purchase of membership"},{"id":24000036,"parent_issue_id":24000001,"replacement_allowed":0,"cancellation_allowed":0,"raise_ticket_allowed":1,"return_allowed":0,"is_active":1,"is_admin_user":0,"is_merchant_user":0,"is_customer_user":1,"is_paytm_owner":1,"is_fc_owner":0,"is_merchant_owner":0,"message":"","comments":"","issue_text":"How do I check the validity of my Paytm First Membership?","out_of_stock":0,"is_replaced_order":0,"icon":"","level":3,"order_flag":1,"faq_link":null,"is_call_allowed":0,"is_email_allowed":1,"priority":null,"is_bank":0,"is_version":0,"is_seller_user":0,"vertical_id":null,"category_id":null,"order_state":null,"meta_data":{"our_suggestion":{"id":399858,"issue_id":24000036,"key":"our_suggestion","value":"Paytm First Membership is valid for a period of 1 year from the date of purchase. To check the validity of your Paytm First Membership, go the \'Profile\' section of the Paytm app (menu on extreme top left) and click on Paytm First, to view the validity mentioned on the top","file":""}},"display_text":"How do I check the validity of my Paytm First Membership?"}]}'
If you're using Requests, you can use the json() method on the response object, like so:
import requests
url = r"https://fulfillment.paytm.com/v2/issues?is_cst=1&is_bank=0&parent_issue_id=24000001"
response = requests.get(url)
json_dict = response.json()
for item in json_dict["reasonObjs"]:
issue_text = item["issue_text"] # or item.get("issue_text", "*no issue text*")
print(issue_text)
Output:
My order is pending for a long time
My order is pending for a long time
My order is pending for a long time
My order is pending for a long time
My order is pending for a long time
I am unable to cancel my order
I am unable to cancel my order
I am unable to cancel my order
I am unable to cancel my order
I am unable to cancel my order
I am unable to cancel my order
I cannot find invoice for purchase of membership
How do I check the validity of my Paytm First Membership?
You could also use the json module:
import json
json_dict = json.loads(response.text)

How I must save money transaction in mysql tables

I have wallet and business concepts in my project and it's possible to transfer money between wallet and business and between businesses.
I have a table for wallet transactions and if I have a money transfer from the wallet to business or business to wallet, I'll save it in the wallet_transactions table.
Also I have a table for business transactions and if I have a money transfer between businesses I'll save it in the business_transactions table.
Now I need to fetch all of the transactions regarding to a business and display them descending in a table with pagination
Must I save a money transform from the wallet to business or business to wallet in the business_transactions table or I must use the join?

MS Access SQL Query to Populate Combo Box List of Values

I have a database that schedules teachers to deliver lectures that range from 15 minutes to 4 hours long. Many of these lectures take place simultaneously. Some lectures require multiple teachers to deliver due to complexity of the subject. These lectures cover topics that are categorized in one of ten areas of specialization. We have ten teams whose members are experts in one of the ten areas of specialization. Each team is responsible for delivering the lectures that are associated with their area of specialization.
Teachers are assigned to a team based on their chosen area of specialization and expertise. Teachers must pass a certification course in order to be allowed to teach in an associated area of specialization.
Some teachers have multiple certifications and as a result can be scheduled to deliver lectures that are not the responsibility of the team to which they are assigned. However, they only fill in in this capacity if all teachers from the team with responsibility for the lecture in question are busy and no one else can be assigned the lecture.
Teachers earn sick and vacation time and they can use this time as needed. In addition, teachers are from time to time required to participate in professional development events or attend meetings. Therefore, they are not always available to deliver lectures.
My task has been to develop a process where teachers can be scheduled to deliver lectures based on their certifications, team membership, and availability.
I have the following tables:
 Instructor lecture assignments (which instructors have been assigned to which lecture)
 Lecture schedule (name, date, start time, end time, certifications required for each lecture)
 Teacher not available (teacher name, date unavailable, start time unavailable, end time of unavailability)
 Teacher teams (names of teacher teams)
 Teachers (first, middle, last name of each teacher)
 Teacher certifications (name of each certification that can be earned by each teacher)
 Teacher certification conferrals (which teachers have earned which certifications and on what date)
 Teacher team assignments (which teachers are on which team)
The issue that I am trying to resolve is how to structure a query that will display, for each lecture, the teachers that are CURRENTLY certified to deliver that lecture, a member of the team that is responsible for that lecture, NOT unavailable due to professional development nor being assigned to deliver another simultaneously occurring lecture.
Can someone help me to understand how to structure this needed query, please?
Thank you in advance.
What you have to do is take it one step at a time. Forget:
"for each lecture, the teachers that are CURRENTLY certified to deliver that lecture, a member of the team that is responsible for that lecture, NOT unavailable due to professional development nor being assigned to deliver another simultaneously occurring lecture."
Start with:
List all teachers
List all teacher certifications with their start and/or end dates. Your wording does not make it clear if by "currently" you mean "has not expired" which is what the assumption is reading the word currently, or "has already earned it" which is what your description of your data indicates, or both.
Filter the above with the certification required by each lecture
Filer by each reason for unavailability
One step at a time, you can't solve the problem in one go. It is ok if you take a wrong turn or end up with some extra queries that are unneeded, you can clean up when the goal has been reached.

Money expiration tracking

I am working with money expiration tracking problem at the moment (originally it is not money, but I have used it as a more convenient example).
An user can earn money from a platform for some mysterious reason and spent them for buying stuff (products, gifts etc.).
I am looking an algorithm (SQL query best case) to find a current balance of an user balance.
The events of spending and earning money are stored different database (MySQL) tables (let's say user_earned and user_spent). So in normal case, I would simply count user totals from user_earned and subtract spent money (total of user_spent).
BUT! There is a condition, that earned user money expires in 2 years if they are not used.
That means, if user have not used his money or used just a part of it, they will expire. If an user uses his money, they are used from the oldest not expired money record, so the balance (bonus) could be calculated in user's favor.
These are 5 scenarios with events in time, to have a better understanding on the case:
Both tables (user_earned and user_spent) have timestamps for date tracking.
I did something similar in one of my projects.
Looks like you need an additional table spends_covering with columns
spend_id, earhed_id, sum
So for each spends record you need to insert one or many rows into the spends_covering to mark 'used' money.
Then balance would be just sum of not used where date is less than 2 years.
select sum(sub.earned_sum-sub.spent_sum) as balance
from
(select e.sum as earned_sum, sum(sc.sum) as spent_sum
from earned e
left join spends_covering sc on e.earhed_id=sc.earhed_id
where e.date BETWEEN ...
group by e.earhed_id
having earned_sum > spent_sum) sub
It may be worth it to have two tables -- one (or more) with all the historical details, one with just the current balances for each 'user'. Be sure to use transactions to keep the two in sync.

PayPal - How to refuse payments below a certain threshold?

I am selling a high volume product that costs a minimal amount per piece. ($0.001 USD each to be exact).
I allow my customers to purchase a one time amount of product or a recurring payment amount of product at their desired choice of USD per payment.
How can I limit my customers to only spending $10 USD or more per payment through PayPal? They limit it at $10,000 USD, can I limit it at $10 USD?
Right now, I am not processing payments of less than $10 USD, and recommending that customers do not, but it is still possible to make them.
The problem arises when a customer purchases $1 worth of product and paypal takes 40 odd percent of that payment due to per-payment fees.
I do not believe PayPal offers a setting for minimum allowed payment. This is something you would need to handle on the server side. It would be easy enough to do. Just don't display the "Pay with PayPal" button unless the order total is $10 or more.