def post(self, status="1"): data = json.loads(self.request.body.decode('utf-8')) billing_plan = BillingPlan.find(data['id']) if status == "1": if billing_plan.activate(): msg = "Billing Plan activated successfully" print(msg) else: msg = billing_plan.error print(msg) else: billing_plan_update_attributes = [{ "op": "replace", "path": "/", "value": { "state": "INACTIVE" } }] if billing_plan.replace(billing_plan_update_attributes): msg = "Billing Plan inactivated successfully" print(msg) else: msg = billing_plan.error print(msg) self.write({'response': msg})
def active_plan(self, plan_id): try: billing_plan = BillingPlan.find(plan_id) if billing_plan.activate(): return billing_plan.state else: raise Exception(billing_plan.error['message']) except ResourceNotFound as error: raise Exception("Billing Plan Not Found")
def activate(): """Merchant activates plan after creation """ if session.get('logged_in') and session.get('merchant'): billing_plan = BillingPlan.find(request.args.get('id', '')) if billing_plan.activate(): print("Billing Plan [%s] activated successfully" % (billing_plan.id)) else: print(billing_plan.error) return redirect(url_for('admin')) else: return redirect(url_for('login'))
def activate(): """Merchant activates plan after creation """ if session.get('logged_in') and session.get('merchant'): billing_plan_update_attributes = [ { "op": "replace", "path": "/", "value": { "state": "ACTIVE" } } ] billing_plan = BillingPlan.find(request.args.get('id', '')) if billing_plan.replace(billing_plan_update_attributes): billing_plan = BillingPlan.find(request.args.get('id', '')) else: print(billing_plan.error) return redirect(url_for('admin')) else: return redirect(url_for('login'))
def delete_plan(self, plan_id): try: billing_plan = BillingPlan.find(plan_id) billing_plan_update_attributes = [{ "op": "replace", "path": "/", "value": { "state": "DELETED" } }] if billing_plan.replace(billing_plan_update_attributes): return billing_plan else: raise Exception(billing_plan.error) except ResourceNotFound as error: raise Exception("Billing Plan Not Found")
def activate_plan(): """ Function to activate plan """ try: if current_user.user_type != 'admin': flash('You are not allowed to access this page', 'danger') return redirect(url_for('userbp.dashboard')) configure_paypal() pid = request.args.get('id', '') billing_plan = BillingPlan.find(pid) if billing_plan.activate(): subplan = Subscription.by_planid(pid) subplan.status = True db.session.commit() else: errorlog.error('Plan activate Error', details=str(billing_plan.error)) return redirect(url_for('paymentbp.subscriptions')) except Exception as err: errorlog.error('Plan activate Error', details=str(err)) return render_template('error.html', message="Error!")
def activate_plan(): billing_plan = BillingPlan.find('P-3NF352338H658800LZS4KMVY') if billing_plan.activate(): return "Billing Plan [%s] activated successfully" % billing_plan.id else: return billing_plan.error
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 activate_plan(plan_id): billing_plan = BillingPlan.find(plan_id) if not billing_plan.activate(): raise RuntimeError(billing_plan.error) return billing_plan
from paypalrestsdk import BillingPlan, ResourceNotFound import logging logging.basicConfig(level=logging.INFO) try: billing_plan = BillingPlan.find("P-0NJ10521L3680291SOAQIVT") print( ("Got Billing Plan Details for Billing Plan[%s]" % (billing_plan.id))) if billing_plan.activate(): billing_plan = BillingPlan.find("P-0NJ10521L3680291SOAQIVT") print(("Billing Plan [%s] state changed to [%s]" % (billing_plan.id, billing_plan.state))) else: print((billing_plan.error)) except ResourceNotFound as error: print("Billing Plan Not Found")
def find_billing_plan(self, billing_plan_id): billing_plan = BillingPlan.find(billing_plan_id) return billing_plan
from paypalrestsdk import BillingPlan, ResourceNotFound import logging logging.basicConfig(level=logging.INFO) try: billing_plan = BillingPlan.find("P-0NJ10521L3680291SOAQIVT") print("Got Billing Plan Details for Billing Plan[%s]" % (billing_plan.id)) except ResourceNotFound as error: print("Billing Plan Not Found")
def delete_plan(plan_id): p = BillingPlan.find(plan_id, api=api) p.replace([{"op": "replace", "path": "/", "value": {"state": "DELETED"}}])
def get_plan(self, plan_id): try: billing_plan = BillingPlan.find(plan_id) return billing_plan except ResourceNotFound as error: print("Billing Plan Not Found")