我在阅读https://developer.paypal.com/docs/api/后稍微误解了Paypal流程事件.我想将快速结账和信用卡付款整合到我的网站.我正在使用Flask
并且paypalrestsdk
没有任何Flask扩展.
以下是我的应用摘录:
@app.route('/', methods=['GET']) def index(): # Page with but form, price/quantity/name values # are stored in hidden fields, "Buy now" acts as submit return render_template('index.html') @app.route('/payment/paypal', methods=['POST']) def payment_paypal(): # Here I am creating dict with required params payment_template = { 'intent': 'sale', 'payer': {'payment_method': 'paypal'}, 'redirect_urls': { 'return_url': url_for('payment_paypal_execute'), 'cancel_url': url_for('payment_paypal_error') }, ...... } payment = paypalrestsdk.Payment(payment) if payment.create(): print('Payment "{}" created successfully'.format(payment.id)) for link in payment.links: if link.method == "REDIRECT": redirect_url = str(link.href) print('Redirect for approval: {}'.format(redirect_url)) return redirect(redirect_urls) @app.route('/payment/paypal/execute', methods=['GET']) def payment_paypal_execute(): payer_id = request.args.get('payerId') payment_id = request.args.get('paymentId') token = request.args.get('token') pending_payment = PayPalPayment.query.filter_by(token=token).filter_by(state='created').first_or_404() try: payment = paypalrestsdk.Payment.find(pending_payment.payment_id) except paypalrestsdk.exceptions.ResourceNotFound as ex: print('Paypal resource not found: {}'.format(ex)) abort(404) if payment.execute({"payer_id": payer_id}): pending_payment.state = payment.state pending_payment.updated_at = datetime.strptime(payment.update_time, "%Y-%m-%dT%H:%M:%SZ") db.session.commit() return render_template('payment/success.html', payment_id=payment.id, state=payment.state) return render_template('payment/error.html', payment_error=payment.error, step='Finallizing payment')
单击payment
成功创建的按钮(使用状态created
)用户重定向到批准页面后,它工作正常.在那里,他点击"确认"......当我指定return_url时,我从未返回到我的应用程序,事件!即,应用程序永远不会被告知买方批准付款,并且应该在我自己的数据库中进行更新,并且应该向该人发送新的许可证.
问题:
我无法找到定义一些回调的方法pyhtonrestsdk
.怎么做?
即使我添加回调(我尝试使用纯Javascript按钮代码嵌入Express Checkout),data-callback
我的应用程序也没有被调用.我怀疑因为远程服务器无法调用http://127.0.0.1/payment/paypal/success
用户可以在点击"确认"后立即关闭带有PayPal确认的窗口,这样我就无法信任它稍后以某种方式执行的浏览器重定向.
最后,我怀疑我不明白PayPal工作流程,但我无法在开发人员门户网站上找到有关它的更多信息.