def execute(): """Customer redirected to this endpoint by PayPal after payment approval """ if session.get('logged_in') and session.get('customer'): payment_token = request.args.get('token', '') billing_agreement_response = BillingAgreement.execute(payment_token) return redirect(url_for('agreement_details', id=billing_agreement_response.id)) else: return redirect(url_for('login'))
def execute(): """Customer redirected to this endpoint by PayPal after payment approval """ if session.get('logged_in') and session.get('customer'): payment_token = request.args.get('token', '') billing_agreement_response = BillingAgreement.execute(payment_token) return redirect(url_for('agreement_details', id=billing_agreement_response.id)) else: return redirect(url_for('login'))
def get(self): from flask import request, redirect from paypalrestsdk import BillingAgreement token = request.args.get('token') billing_agreement_response = BillingAgreement.execute(token) print("BillingAgreement[%s] executed successfully" % (billing_agreement_response.id)) return redirect('http://localhost:4200/paypal_redirect?done={}&type={}&id={}'.format( 1, 'premium', billing_agreement_response.id ))
def execute(): """ Function to execute plan after redirecting from paypal site after customer agreement """ try: configure_paypal() payment_token = request.args.get('token', '') billing_agreement_response = BillingAgreement.execute(payment_token) plans = Subscription.get_all() action = url_for('userbp.dashboard') billing_action = url_for('paymentbp.billing') if 'id' in billing_agreement_response: pdobj = PaymentDetail( amount=plans.subscription_price, subscription_id=plans.id, payment_status='Success', payment_date=func.now(), billing_aggrement_id=billing_agreement_response.id, payment_token=payment_token, payment_mode='paypal') db.session.add(pdobj) db.session.commit() user_id = current_user.id if 'app_user_id' in session: user_id = session['app_user_id'] session.pop('app_user_id') action = url_for('userbp.dashboard', userid=user_id) billing_action = url_for('paymentbp.billing', userid=user_id) pobj = Payment(user_id=user_id, payment_detail_id=pdobj.id, created_at=func.now(), updated_at=func.now()) db.session.add(pobj) get_user = User.by_id(int(user_id)) get_user.payment_status = True db.session.commit() flash(PLAN_EXECUTED, 'success') return redirect(action) else: flash(PLAN_EXECUTED_ERROR, 'danger') return redirect(billing_action) except Exception as err: errorlog.error('Subscribe Error', details=str(err)) return render_template('error.html', message="Error!")
def execute_agreement(): payment_token = request.args.get('token', '') billing_agreement_response = BillingAgreement.execute(payment_token) return (url_for('agreement_details', id=billing_agreement_response.id)) return 'execute'
"payment_method": "paypal" }, "shipping_address": { "line1": "StayBr111idge Suites", "line2": "Cro12ok Street", "city": "San Jose", "state": "CA", "postal_code": "95112", "country_code": "US" } }) # After creating the agreement, redirect user to the url provided in links array # entry with method field set to REDIRECT if billing_agreement.create(): print("Billing Agreement created successfully") for link in billing_agreement.links: if link.rel == "approval_url": approval_url = link.href print("For approving billing agreement, redirect user to\n [%s]" % (approval_url)) else: print(billing_agreement.error) # After user approves the agreement, call execute with the payment token appended to # the redirect url to execute the billing agreement. # https://github.paypal.com/pages/lkutch/paypal-developer-docs/api/#execute-an-agreement billing_agreement_response = BillingAgreement.execute(payment_token) print("BillingAgreement[%s] executed successfully" % (billing_agreement_response.id))
def execute_billing_agreement(self, payment_token): billing_agreement_response = BillingAgreement.execute(payment_token) print(billing_agreement_response) print(billing_agreement_response.id) return billing_agreement_response
def subscribe(payment_id, user_id=None, ccform=None): """ Function to create billing agreement using credit card and paypal """ try: configure_paypal() user_detail = current_user if user_id is not None: user_detail = User.by_id(user_id) session['app_user_id'] = user_id if ccform is not None: exp_detail = ccform.expiry_date.data.split('/') exp_month = exp_detail[0] if exp_detail[0] else 0 exp_year = exp_detail[1] if exp_detail[1] else 0 payer_info = { "payer": { "payment_method": "credit_card", "funding_instruments": [{ "credit_card": { "type": str(ccform.type.data), "number": str(ccform.card_number.data), "expire_month": str(exp_month), "expire_year": str(exp_year), "cvv2": str(ccform.cvv.data), "first_name": str(ccform.first_name.data), "last_name": str(ccform.last_name.data), "billing_address": { "line1": str(current_user.address1), "line2": str(current_user.address2), "city": str(current_user.city), "state": str(current_user.state), "postal_code": str(current_user.zipcode), "country_code": "US" } }, }] } } else: payer_info = { "payer": { "payment_method": "paypal", "funding_option_id": user_detail.id, "payer_info": { "email": user_detail.email, "first_name": user_detail.first_name, "last_name": user_detail.last_name, } } } plan = Subscription.by_planid(payment_id) billing_agreement = BillingAgreement({ "name": plan.subscription_name, "description": "Agreement for the recurring payment for the plan " + plan.subscription_name + ". The cost of this plan is $" + str('%.2f' % plan.subscription_price) + " /month.", "start_date": (datetime.now() + timedelta(hours=1)).strftime('%Y-%m-%dT%H:%M:%SZ'), "plan": { "id": str(payment_id) }, "payer": payer_info['payer'], }) if billing_agreement.create(): if ccform is not None: billing_agreement_response = BillingAgreement.execute( billing_agreement.id) return save_credit_card_response(billing_agreement, payment_id) for link in billing_agreement.links: if link.rel == "approval_url": approval_url = link.href return approval_url return False else: errorlog.error('Subscribe Error', details=str(billing_agreement.error)) flash(SUBSCRIPTION_ERROR, 'danger') return False except Exception as err: errorlog.error('Subscribe Error', details=str(err)) flash(SUBSCRIPTION_ERROR, 'danger') return redirect(url_for('paymentbp.billing'))
"payment_method": "paypal" }, "shipping_address": { "line1": "StayBr111idge Suites", "line2": "Cro12ok Street", "city": "San Jose", "state": "CA", "postal_code": "95112", "country_code": "US" } }) # After creating the agreement, redirect user to the url provided in links array # entry with method field set to REDIRECT if billing_agreement.create(): print("Billing Agreement created successfully") for link in billing_agreement.links: if link.rel == "approval_url": approval_url = link.href print( "For approving billing agreement, redirect user to\n [%s]" % (approval_url)) else: print(billing_agreement.error) # After user approves the agreement, call execute with the payment token appended to # the redirect url to execute the billing agreement. # https://github.paypal.com/pages/lkutch/paypal-developer-docs/api/#execute-an-agreement billing_agreement_response = BillingAgreement.execute(payment_token) print("BillingAgreement[%s] executed successfully" % (billing_agreement_response.id))
def post(self): data = json.loads(self.request.body.decode('utf-8')) payment_token = data['token'] billing_agreement_response = BillingAgreement.execute(payment_token) self.write({'response': billing_agreement_response.id})