def init_plans(): from paypalrestsdk import BillingPlan pro_plan = BillingPlan({ "name": "Pro subscription plan", "description": "Gives you private researches, ability to scrape Play store and many other features", "type": "INFINITE", "payment_definitions": [{ "name": "Pro Plan", "type": "REGULAR", "frequency_interval": "1", "frequency": "MONTH", "amount": { "currency": "USD", "value": "1" } }], "merchant_preferences": { "auto_bill_amount": "yes", "cancel_url": "http://localhost:5080/payment/pro/cancel", "initial_fail_amount_action": "continue", "max_fail_attempts": "0", "return_url": "http://localhost:5080/payment/pro/execute", "setup_fee": { "currency": "USD", "value": "1" } } }) if pro_plan.create(): print("Billing Plan [%s] created successfully (pro)" % pro_plan.id) if pro_plan.activate(): pro_plan = BillingPlan.find(pro_plan.id) print("Billing Plan [%s] state changed to %s (pro)" % (pro_plan.id, pro_plan.state)) app.config['PRO'] = pro_plan.id else: print(pro_plan.error) else: print(pro_plan.error) premium_plan = BillingPlan({ "name": "Premium subscription plan", "description": "Subscription which lets you work without any limitations", "type": "INFINITE", "payment_definitions": [{ "name": "Pro Plan", "type": "REGULAR", "frequency_interval": "1", "frequency": "MONTH", "amount": { "currency": "USD", "value": "2" } }], "merchant_preferences": { "auto_bill_amount": "yes", "cancel_url": "http://localhost:5080/payment/premium/cancel", "initial_fail_amount_action": "continue", "max_fail_attempts": "0", "return_url": "http://localhost:5080/payment/premium/execute", "setup_fee": { "currency": "USD", "value": "1" } } }) if premium_plan.create(): print("Billing Plan [%s] created successfully (premium)" % premium_plan.id) if premium_plan.activate(): premium_plan = BillingPlan.find(premium_plan.id) print("Billing Plan [%s] state changed to %s (premium)" % (premium_plan.id, premium_plan.state)) app.config['PREMIUM'] = premium_plan.id else: print(premium_plan.error) else: print(premium_plan.error)
def create_billing_plan(self, return_url, cancel_url, item_price, num_cycles, frequency): plan = { "description": "Basic Plan subscription", "merchant_preferences": { "auto_bill_amount": "yes", "cancel_url": cancel_url, "initial_fail_amount_action": "continue", "max_fail_attempts": "2", "return_url": return_url, # to be charged immediately # replacement for TRIAL PERIOD "setup_fee": { "currency": "USD", "value": "1.00" } }, "name": "Basic Plan subscription", "payment_definitions": [ { "type": "REGULAR", "frequency": frequency, "frequency_interval": "1", "cycles": str(num_cycles), "amount": { "currency": "USD", "value": str(item_price) }, "name": "Succeeding Month Recurring Payments", "charge_models": [ { "type": "TAX", "amount": { "currency": "USD", "value": "0.00" } }, { "type": "SHIPPING", "amount": { "currency": "USD", "value": "0.00" } } ], }, #{ # "type": "TRIAL", # "frequency": "Day", # "frequency_interval": "2", # "cycles": str(1), # "amount": { # "currency": "USD", # "value": str(1) # }, # "name": "First Month Prorated Payment", # "charge_models": [ # { # "type": "TAX", # "amount": { # "currency": "USD", # "value": "0.00" # } # }, # { # "type": "SHIPPING", # "amount": { # "currency": "USD", # "value": "0.00" # } # } # ], #}, ], "type": "FIXED" } billing_plan = BillingPlan(plan) if billing_plan.create(): #print("Billing Plan {} creation successful!".format(billing_plan.id)) if billing_plan.activate(): #print("Billing Plan {} activation successful {}".format(billing_plan.id, billing_plan.state)) pass else: print("Billing Plan activation failed! {}".format(billing_plan.error)) else: print("Billing Plan creation failed!".format(billing_plan.error)) return billing_plan.id