I am trying to setup a Paypal payment in my Flask project. I am copying the smart payment button code from Paypal and pasted in my template. The payment process worked buy response details is in the javascript. How can I get the response back to my Flask app so that I can confirm the payment?
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.
Flask is a server framework, so you should be using the following frontend UI: https://developer.paypal.com/demo/checkout/#/pattern/server
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/
You can use the Checkout-Python-SDK within those calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.