def payment(): ''' takes in item description and price of the rental transaction ''' data = request.get_json() itemDescription = data['itemDescription'] price = data['price'] # TODO retrieve payment details payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:7400/payment/execute", "cancel_url": "http://localhost:7400" }, "transactions": [{ "item_list": { "items": [{ "name": itemDescription, "sku": "12345", "price": price, "currency": "SGD", "quantity": 1 }] }, "amount": { "total": price, "currency": "SGD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print('Payment success!') else: print(payment.error) return jsonify({'paymentID': payment.id})
def donate_post(): donation_amount = request.form.get('amount') if not donation_amount: abort(402) donation_amount = "{0:.2f}".format(float(donation_amount)) payer = {"payment_method": "paypal"} items = [{ "name": "TitanEmbeds Donation", "price": donation_amount, "currency": "USD", "quantity": "1" }] amount = {"total": donation_amount, "currency": "USD"} description = "Donate and support TitanEmbeds development." redirect_urls = { "return_url": url_for('user.donate_confirm', success="true", _external=True), "cancel_url": url_for('index', _external=True) } payment = paypalrestsdk.Payment( { "intent": "sale", "payer": payer, "redirect_urls": redirect_urls, "transactions": [{ "item_list": { "items": items }, "amount": amount, "description": description }] }, api=get_paypal_api()) if payment.create(): for link in payment.links: if link['method'] == "REDIRECT": return redirect(link["href"]) return redirect(url_for('index'))
def checkout_prepare(self, request, cart): self.init_api() kwargs = {} if request.resolver_match and 'cart_namespace' in request.resolver_match.kwargs: kwargs['cart_namespace'] = request.resolver_match.kwargs[ 'cart_namespace'] payment = paypalrestsdk.Payment({ 'intent': 'sale', 'payer': { "payment_method": "paypal", }, "redirect_urls": { "return_url": build_absolute_uri(request.event, 'plugins:paypal:return', kwargs=kwargs), "cancel_url": build_absolute_uri(request.event, 'plugins:paypal:abort', kwargs=kwargs), }, "transactions": [{ "item_list": { "items": [{ "name": __('Order for %s') % str(request.event), "quantity": 1, "price": str(cart['total']), "currency": request.event.currency }] }, "amount": { "currency": request.event.currency, "total": str(cart['total']) }, "description": __('Event tickets for {event}').format( event=request.event.name) }] }) request.session['payment_paypal_order'] = None return self._create_payment(request, payment)
def payment(): user = session['username'] premuser = PremiumCustomer(user) db.session.add(premuser) db.session.commit() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:5000/payment/execute", "cancel_url": "http://localhost:5000/" }, "transactions": [{ "item_list": { "items": [{ "name": "testitem", "sku": "12345", "price": "10.00", "currency": "AUD", "quantity": 1 }] }, "amount": { "total": "10.00", "currency": "AUD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print('Payment success!') else: return render_template('/error.html', message=payment.error) #print(payment.error) updateuser = PremiumCustomer.query.filter_by(username=user).first() updateuser.paymentid = payment.id db.session.commit() return jsonify({'paymentID': payment.id})
def paypal_checkout(id): listing = Listing.query.get_or_404(id) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://pennpy.com/paypal_review", "cancel_url": "http://pennpy.com/" }, "transactions": [{ "item_list": { "items": [{ "name": listing.name, "sku": listing.category, "price": listing.price, "currency": "USD", "quantity": 1 }] }, "amount": { "total": listing.price, "currency": "USD" }, "description": listing.description }] }) if payment.create(): print("Payment created successfully") else: print(payment.error) for link in payment.links: if link.rel == "approval_url": approval_url = link.href # print("Redirect for approval: %s" % (approval_url)) return redirect(approval_url)
def pay(request, order): """ Create the payment and redirect to PayPal or back to the order with an error message """ payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": request.build_absolute_uri().split('?')[0] + '?status=success', "cancel_url": request.build_absolute_uri().split('?')[0] + '?status=failed', }, "transactions": [ { "amount": { "total": str(PayOrderByPaypal.get_paypal_price(order)), "currency": CURRENCY[1], }, "description": _("Payment for {event} with variable symbol: {vs}".format( event=order.event, vs=order.variable_symbol)) }, ] }) if payment.create(): request.session['paypal_payment_id'] = payment['id'] try: return redirect(PayOrderByPaypal.get_paypal_url(payment)) except Exception as e: logger.error(str(e)) logger.error( "Payment for order(pk={order}) couldn't be created! Error: {err}". format(order=order.pk, err=payment.error)) messages.error(request, _('Something went wrong, try again later.')) return redirect('konfera_payments:payment_options', order_uuid=str(order.uuid))
def api_payment(): if request.method == 'POST': print('request data is', request.data) amt_details = request.get_json(force=True) print('amt_details is', amt_details, 'type is', type(amt_details)) amt = amt_details['inputamt'] int_amt = int(amt) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "https://api.bewigged38.hasura-app.io/api/execute", "cancel_url": "https://api.bewigged38.hasura-app.io" }, "transactions": [{ "item_list": { "items": [{ "name": "item1", "sku": "12345", "price": int_amt, "currency": "INR", "quantity": 1 }] }, "amount": { "total": int_amt, "currency": "INR" }, "description": "This is the payment transaction description" }] }) if payment.create(): print('Payment success') else: print(payment.error) print('PaymentID created is', payment.id) return jsonify({'paymentID': payment.id})
def charge_cc(self): payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "credit_card", "funding_instruments": [{ "credit_card_token": { "credit_card_id": self.ppid } }] }, "transactions": [{ "amount": { "total": self.type.monthly_cost, "currency": "USD" }, "description": "Recurring monthly subscription from repunch.com." }] }) if payment.create(): invoice = Invoice() invoice.account = Account.objects.filter(subscription=self).get() invoice.charge_date = datetime.datetime.now() invoice.response_code = payment.id invoice.status = payment.state if invoice.status == 'approved': invoice.trans_id = payment.transactions[0].related_resources[ 0].sale.id invoice.save() return invoice else: print("Error while creating payment:") raise Exception(payment.error) return None
def paypal_create(request): payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "item_list": { "items": [{ "name": 'Usuario Premium', "price": 1, "currency": "USD", "quantity": 1 }] }, "amount": { "total": 1, "currency": "USD" }, "description": 'Usuario Premium' }] }) redirect_url = "/" if payment.create(): # Store payment id in user session request.session['payment_id'] = payment.id # Redirect the user to given approval url for link in payment.links: if link.method == "REDIRECT": redirect_url = link.href return redirect(redirect_url) else: return redirect('/error/')
def create_payment(order, return_url, cancel_url, payee_email=None): """ Create payment for an order :param order: Order to create payment for. :param return_url: return url for the payment. :param cancel_url: cancel_url for the payment. :param payee_email: email of the payee. Default to event paypal email if not set :return: request_id or the error message along with an indicator. """ payee_email = payee_email or order.event.paypal_email if not payee_email: raise ConflictError( {'pointer': ''}, "Payments through Paypal hasn't been configured for the billing", ) PayPalPaymentsManager.configure_paypal() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "amount": { "total": float(round_money(order.amount)), "currency": order.event.payment_currency, }, "payee": { "email": payee_email }, }], }) if payment.create(): return True, payment.id return False, payment.error
def create_payment(): #create a new order paypal_items = [] paypal_item = {} for item in session['cart']: paypal_item = { "name": item['name'], "sku": item['id'], "price": item['unit_cost'], "currency": "USD", "quantity": item['quantity'] } paypal_items.append(paypal_item) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost/success", #change these routes "cancel_url": "http://localhost/place_order" }, #change these routes "transactions": [{ "item_list": { "items": paypal_items }, #change quantities to match what's in the cart "amount": { "total": session['cart_total'], "currency": "USD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print('payment success') else: print(payment.error) return jsonify({'paymentID': payment.id})
def checkout(): donation_amount = request.form.get('amount') if not donation_amount: return redirect(url_for('index')) donation_amount = "{0:.2f}".format(float(donation_amount)) payer = {"payment_method": "paypal"} items = [{ "name": "Mee6 Contribution", "price": donation_amount, "currency": "EUR", "quantity": "1" }] amount = {"total": donation_amount, "currency": "EUR"} description = "Contribute to the Mee6 Bot project!" redirect_urls = { "return_url": "http://" + DOMAIN + url_for('checkout_confirm') + "?success=true", "cancel_url": "http://" + DOMAIN + url_for('index') } payment = paypalrestsdk.Payment({ "intent": "sale", "payer": payer, "redirect_urls": redirect_urls, "transactions": [{ "item_list": { "items": items }, "amount": amount, "description": description }] }) if payment.create(): for link in payment.links: if link['method'] == "REDIRECT": return redirect(link["href"]) return redirect(url_for('index'))
def topUp(card, amount, cvv): payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "credit_card", "funding_instruments": [{ "credit_card": { "type": card[5], "number": card[1], "expire_month": card[2], "expire_year": card[3], "cvv2": cvv, "first_name": card[4], "last_name": card[6] } }] }, "transactions": [{ "item_list": { "items": [{ "name": "Funds Top Up", "sku": "Funds Top Up", "price": amount, "currency": "EUR", "quantity": 1 }] }, "amount": { "total": amount, "currency": "EUR" }, "description": "Fund Top Up for ClickNWin" }] }) if payment.create(): return True else: return False
def pay(): print('Chegou /pay') payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:3000/success", "cancel_url": "http://localhost:3000/cancel" }, "transactions": [{ "item_list": { "items": [{ "name": "Service Instance", "sku": "001", "price": "5.00", "currency": "USD", "quantity": 1 }] }, "amount": { "total": "5.00", "currency": "USD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print("Payment created successfully") for link in payment.links: if link.rel == "approval_url": # Convert to str to avoid Google App Engine Unicode issue # https://github.com/paypal/rest-api-sdk-python/pull/58 approval_url = str(link.href) print("Redirect for approval: %s" % (approval_url)) else: print(payment.error)
def payment_prepare(self, request, payment_obj): self.init_api() payment = paypalrestsdk.Payment({ 'intent': 'sale', 'payer': { "payment_method": "paypal", }, "redirect_urls": { "return_url": build_absolute_uri(request.event, 'plugins:paypal:return'), "cancel_url": build_absolute_uri(request.event, 'plugins:paypal:abort'), }, "transactions": [{ "item_list": { "items": [{ "name": __('Order {slug}-{code}').format( slug=self.event.slug.upper(), code=payment_obj.order.code), "quantity": 1, "price": self.format_price(payment_obj.amount), "currency": payment_obj.order.event.currency }] }, "amount": { "currency": request.event.currency, "total": self.format_price(payment_obj.amount) }, "description": __('Order {order} for {event}').format( event=request.event.name, order=payment_obj.order.code) }] }) request.session['payment_paypal_order'] = payment_obj.order.pk request.session['payment_paypal_payment'] = payment_obj.pk return self._create_payment(request, payment)
def create_payment(order, return_url, cancel_url): """ Create payment for an order :param order: Order to create payment for. :param return_url: return url for the payment. :param cancel_url: cancel_url for the payment. :return: request_id or the error message along with an indicator. """ if (not order.event.paypal_email) or order.event.paypal_email == '': raise ConflictException( {'pointer': ''}, "Payments through Paypal hasn't been configured for the event", ) PayPalPaymentsManager.configure_paypal() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "amount": { "total": int(order.amount), "currency": order.event.payment_currency, }, "payee": { "email": order.event.paypal_email }, }], }) if payment.create(): return True, payment.id else: return False, payment.error
def create_payment(self, name, price, total): # Se configura la App con las credenciales y el modo de operativa paypalrestsdk.configure({ "mode": self.modo, "client_id": self.client_id, "client_secret": self.client_secret, }) # Se crea el objeto de Pago payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal", }, "redirect_urls": { "return_url": self.return_url, "cancel_url": self.cancel_url, }, "transactions": [{ "item_list": { "items": [{ "name": name, "sku": "item", "price": price, "currency": "EUR", "quantity": 1, }] }, "amount": { "total": total, "currency": "EUR", }, "description": "This is the payment transaction description." }] }) # Se devuelve el objeto de pago creado y configurado configurado payment.create() return payment
def process_payment(self): print("order total: ",self.order.total.amount) print("paypal order is: ",self.order.to_paypal_transaction_items_list()) self.payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": self.open_invoice(), "transactions": [{ "item_list": self.order.to_paypal_transaction_items_list(), "amount": { "total": str(self.total), "currency": "GBP" }, "description": "Payment To GlueDot Candles" }] }) self.status = "Creating Payment URL" self.ds_transaction["status"] = self.status dsc.put(self.ds_transaction) if self.payment.create(): print("Payment created successfully") self.status = "Payment Created Successfully" self.ds_transaction["status"] = self.status dsc.put(self.ds_transaction) for link in self.payment.links: if link.method == "REDIRECT": # Capture redirect url redirect_url = str(link.href) #send this link to the front end else: print(self.payment.error) self.status_code = 2 self.ds_transaction["status_code"] = self.status_code self.status = "Payment URL Served" self.ds_transaction["status"] = self.status dsc.put(self.ds_transaction) return {"transaction_url":redirect_url,"transaction_id":str(self.ds_transaction.key.id)}
def process_payment(patientID, bookingID): details = Payment.query.filter_by(patientID=patientID, bookingID=bookingID).first() if details: payment_amount = details.total_price print(payment_amount) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:3000/payment/execute", "cancel_url": "http://localhost:3000/" }, "transactions": [{ "item_list": { "items": [{ "name": "Medical Bill", "sku": "12345", "price": payment_amount, "currency": "SGD", "quantity": 1 }] }, "amount": { "total": payment_amount, "currency": "SGD" }, "description": "Medical prescription bill." }] }) if payment.create(): print('Payment created!') else: print(payment.error) return jsonify({'paymentID': payment.id})
def create_payment(price, num_of_credits): """ Creates a Paypal payment object for the amount of 'price' price: int num_of_credits: int """ description = "Purchase of " + str(num_of_credits) + " Credits from TapeFlip.app" paypalrestsdk.configure({ "mode": app.config["PAYPAL_MODE"], # sandbox or live "client_id": app.config["PAYPAL_CLIENT_ID"], "client_secret": app.config["PAYPAL_CLIENT_SECRET"]}) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal"}, "redirect_urls": { "return_url": url_for('bp_users.profile'), "cancel_url": url_for('bp_users.profile')}, "transactions": [{ "item_list": { "items": [{ "name": "Credit Purchase", "price": price, "currency": "USD", "quantity": 1}]}, "amount": { "total": price, "currency": "USD"}, "description": description}]}) if payment.create(): print("Payment created successfully") else: print(payment.error) return jsonify({"paymentID":payment.id})
def payment(): global tprice print(tprice) print("HI") payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:3000/payment/execute", "cancel_url": "http://localhost:3000/" }, "transactions": [{ "item_list": { "items": [{ "name": "testitem", "sku": "12345", "price": tprice, "currency": "USD", "quantity": 1 }] }, "amount": { "total": tprice, "currency": "USD" }, "description": "This is the payment transaction description." }] }) if payment.create(): flash('Payment success!') else: flash(payment.error) return jsonify({'paymentID': payment.id})
def test_issue_credit(self): """ Tests issuing credit/refund with Paypal processor """ refund = self.create_refund(self.processor_name) order = refund.order basket = order.basket amount = refund.total_credit_excl_tax currency = refund.currency source = order.sources.first() transaction_id = 'PAY-REFUND-1' paypal_refund = paypalrestsdk.Refund({'id': transaction_id}) payment = paypalrestsdk.Payment({ 'transactions': [ Resource({ 'related_resources': [ Resource( {'sale': paypalrestsdk.Sale({'id': 'PAY-SALE-1'})}) ] }) ] }) with mock.patch.object(paypalrestsdk.Payment, 'find', return_value=payment): with mock.patch.object(paypalrestsdk.Sale, 'refund', return_value=paypal_refund): actual_transaction_id = self.processor.issue_credit( order.number, order.basket, source.reference, amount, currency) self.assertEqual(actual_transaction_id, transaction_id) # Verify PaymentProcessorResponse created self.assert_processor_response_recorded(self.processor.NAME, transaction_id, {'id': transaction_id}, basket)
def createpayment(payment_amount): global access_token api = paypalrestsdk.set_config( mode="sandbox", # sandbox or live client_id= "AUkSDlXcL3qKVW8Yq45p4jlOjsDCBRGxCBHpATn4t8H0Ka8Q02DxkUxvdmVz-MazblfTjvCMd-5cC-EM", client_secret= "EE7coF-C74aXMGEpm8hY-46yoXlr04oRGjVjk50vqVm83AoheJTzWwxdx1EmGGTDlLoiQtJnkVYtNUgD" ) access_token = api.get_access_token() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:5000/executepaymentrequest", "cancel_url": "http://localhost:5000/checkoutpage" }, "transactions": [{ "amount": { "total": payment_amount, "currency": "USD" }, "description": "creating a payment of " + str(payment_amount) }] }) payment_response = payment.create() if payment_response == True: return "payment created. <p>payment: " + str( payment) + "</p>Payment amount: " + str( payment_amount) + "<p>Payment redirect_url: " + str( payment['links'][1]["href"] ) + "</p>" + "<p>access token = " + str(access_token) + "</p>" if payment_response == False: return "payment not created"
def pruchase_plugin(): resp = send_get_request({'plugin_id': request.form['pluginID']}, 'plugin/get') if(resp.status_code != 200): abort(resp.status_code) plugin_obj = lambda : None plugin_json = resp.json() plugin_obj.name = plugin_json['name'] plugin_obj.price = plugin_json['price'] payment = paypal.Payment({ "intent": "sale", "payer": { "payment_method": "paypal"}, "redirect_urls": { "return_url": "http://localhost:3000/payment/execute", "cancel_url": "http://localhost:3000/"}, "transactions": [{ "item_list": { "items": [{ "name": plugin_obj.name, "sku": "item", "price": str(plugin_obj.price), "currency": "USD", "quantity": 1}]}, "amount": { "total": str(plugin_obj.price), "currency": "USD"}, "description": "It will take one minute after completed transaction for the rank to be given to you" } ] }) payment.create() return jsonify({'paymentID': payment.id })
def payment(student_id): student = db.session.query(Student.id, Student.name, Bill.total_bill).join(Bill).\ filter(Student.id == student_id).first() student_name = student.name student_bill = student.total_bill payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://localhost:3000/payment/execute", "cancel_url": "http://localhost:3000/" }, "transactions": [{ "item_list": { "items": [{ "name": student_name + " Tuition Payment", "sku": "12345", "price": student_bill, "currency": "USD", "quantity": 1 }] }, "amount": { "total": student_bill, "currency": "USD" }, "description": "This is the payment transaction description." }] }) if payment.create(): print('Payment success!') else: print(payment.error) return jsonify({'paymentID': payment.id})
def create_payment(amount, return_url, cancel_url, org=ORGANIZATION_NAME): """Creates a PayPal payment with the necessary information & app experience profile ID.""" try: payment = paypalrestsdk.Payment({ "intent": "sale", "experience_profile_id": "XP-3YAL-A7TU-M7ZW-AMTU", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "item_list": { "items": [{ "name": "תרומה", "price": amount, "currency": "ILS", "quantity": 1 }] }, "amount": { "total": amount, "currency": "ILS" }, "description": f"תרומה ל{org}" }] }) if payment.create(): return payment else: raise RuntimeError except (paypalrestsdk.exceptions.UnauthorizedAccess, paypalrestsdk.exceptions.MissingConfig): raise ConnectionError
def payment(): payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": "http://127.0.0.1:5000/payment/execute", "cancel_url": "http://127.0.0.1:5000/" }, "transactions": [{ "item_list": { "items": [{ "name": "diagnosis", "sku": "11111", "price": "16.97", "currency": "EUR", "quantity": 1 }] }, "amount": { "total": "16.97", "currency": "EUR" }, "description": "This is the payment transaction description." }] }) if payment.create(): print('Payment success!') else: print("here") print(payment.error) return jsonify({'paymentID': payment.id})
def create_payment(): access_token() return_url = "http://localhost:5002/payment/execute" cancel_url = "http://localhost/esd-project/Refurban/" try: data = request.get_json(force=True) except Exception as e: print(e) amount = data['amount'] purchase_details = json.dumps(data['purchase_details']) corrid = str(uuid.uuid4()) sendPurchase(purchase_details, corrid) payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": cancel_url }, "transactions": [{ "amount": amount, "description": corrid }] }) if payment.create(): for link in payment.links: if link.rel == "approval_url": approval_url = str(link.href) return jsonify({"approval_url": approval_url}), 201 else: return jsonify({"message": payment.error}), 400
def create_payment(price, return_url): configure_paypal() payment = paypalrestsdk.Payment({ "intent": "sale", "payer": { "payment_method": "paypal" }, "redirect_urls": { "return_url": return_url, "cancel_url": return_url }, "transactions": [{ "item_list": { "items": [{ "name": "pitchforkContribution", "sku": "item", "price": str(price), "currency": "USD", "quantity": 1 }] }, "amount": { "total": str(price), "currency": "USD" }, "description": "This is your contribution to your groups total bill." }] }) if payment.create(): print("Payment created successfully") return payment.id else: print(payment.error) return None
def charge_wallet(transaction, customer_id=None, correlation_id=None, intent="authorize"): """Charge a customer who formerly consented to future payments from paypal wallet. """ payment = paypalrestsdk.Payment({ "intent": intent, "payer": { "payment_method": "paypal" }, "transactions": [{ "amount": { "total": transaction["amount"]["total"], "currency": transaction["amount"]["currency"] }, "description": transaction["description"] }] }) refresh_token = get_stored_refresh_token(customer_id) if not refresh_token: return False, "Customer has not granted consent as no refresh token has been found for customer. Authorization code needed to get new refresh token." if payment.create(refresh_token, correlation_id): print("Payment %s created successfully" % (payment.id)) if payment['intent'] == "authorize": authorization_id = payment['transactions'][0]['related_resources'][ 0]['authorization']['id'] print("Payment %s authorized. Authorization id is %s" % (payment.id, authorization_id)) return True, "Charged customer " + customer_id + " " + transaction[ "amount"]["total"] else: return False, "Error while creating payment:" + str(payment.error)