[英]How to get paypal smart payment button response to Flask
I am trying to setup a Paypal payment in my Flask project.我正在尝试在我的 Flask 项目中设置 Paypal 付款。 I am copying the smart payment button code from Paypal and pasted in my template.
我正在从 Paypal 复制智能支付按钮代码并粘贴到我的模板中。 The payment process worked buy response details is in the javascript.
javascript 中的付款流程有效购买响应详细信息。 How can I get the response back to my Flask app so that I can confirm the payment?
我如何才能将响应返回给我的 Flask 应用程序,以便我可以确认付款?
This is in my template:这是在我的模板中:
<div id="paypal-button-container"></div>
<script src="https://www.paypal.com/sdk/js?client-id=fake¤cy=USD" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
//method: 'POST',
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '10'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
// window.write('Transaction completed by ' + details.payer.name.given_name + '!');
console.log("success");
return details;
})
}
}).render('#paypal-button-container');
</script>
And app code:和应用程序代码:
@app.route('/upgrade/<username>', methods=['GET','POST'])
@login_required
def upgrade(username):
user = User.query.filter_by(username=username).first()
result = request.get_json()
flash(result)
return render_template('upgrade.html', user=user)
Empty dict is returned by the flash message. flash 消息返回空字典。
Flask is a server framework, so you should be using the following frontend UI: https://developer.paypal.com/demo/checkout/#/pattern/server Flask 是一个服务器框架,因此您应该使用以下前端 UI: https://developer.paypal.com/demo/checkout/#/patternserver/
And paring it with two corresponding routes on your server, one for 'Set Up Transaction' and one for 'Capture Transaction', documented here: https://developer.paypal.com/docs/checkout/reference/server-integration/并将其与服务器上的两条相应路由配对,一条用于“设置事务”,一条用于“捕获事务”,记录在此: https://developer.paypal.com/docs/checkout/reference/server-integration/
You can use the Checkout-Python-SDK within those calls.您可以在这些调用中使用 Checkout-Python-SDK。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.