用烧瓶获取PayPal服务器端订阅
我想拥有一个简单的解决方案来在烧瓶应用程序中付款后获得订阅ID。
PayPal仅为客户端提供此代码:
<div id="paypal-button-container-P-REF"></div>
<script src="https://www.paypal.com/sdk/js?client-id=REF_ID=subscription" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'P-REF',
quantity: 1 // The quantity of the product for a subscription
});
},
onApprove: function(data, actions) {
alert(data.subscriptionID); // You can add optional success message for the subscriber here
actions.redirect('/thankyou', _external=True);
}
}).render('#paypal-button-container-REF'); // Renders the PayPal button
</script>
在服务器端,它应该是这样的:
@app.route('/upgrade',methods = ['POST','GET'])
@login_required
def upgrade():
global user, user_email,user_category
print(request.method )
if request.method == 'POST':
subscriptionID = request.args.get('subscriptionID')
print(subscriptionID)
if subscriptionID == None:
flash('Payment error, please try again.','error')
else:
flash('Payment successful, thanks!','success')
insert_payment(subscriptionID,user.id,'best_plan')#Add payment id to DB
update_user_subscription(user.id,'best_plan')#Update user plan
return render_template('upgrade.html', u_email=user_email, u_category = user_category)
但是我需要使用POST方法检索订阅方法以将其保存在数据库中。
客户群方法未发送帖子信息。
烧瓶和JS可以轻松地做到这一点吗?我不明白任何电子市场只能与客户端代码一起使用。
请注意,PayPal中有关服务器端的代码主要用于经典订单支付,而不是订阅。
I'd like to have a simple solution to get the subscription ID after a payment approval in a Flask app.
Paypal provides this code only for client side:
<div id="paypal-button-container-P-REF"></div>
<script src="https://www.paypal.com/sdk/js?client-id=REF_ID=subscription" data-sdk-integration-source="button-factory"></script>
<script>
paypal.Buttons({
style: {
shape: 'pill',
color: 'gold',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'P-REF',
quantity: 1 // The quantity of the product for a subscription
});
},
onApprove: function(data, actions) {
alert(data.subscriptionID); // You can add optional success message for the subscriber here
actions.redirect('/thankyou', _external=True);
}
}).render('#paypal-button-container-REF'); // Renders the PayPal button
</script>
In server side, it should be something like:
@app.route('/upgrade',methods = ['POST','GET'])
@login_required
def upgrade():
global user, user_email,user_category
print(request.method )
if request.method == 'POST':
subscriptionID = request.args.get('subscriptionID')
print(subscriptionID)
if subscriptionID == None:
flash('Payment error, please try again.','error')
else:
flash('Payment successful, thanks!','success')
insert_payment(subscriptionID,user.id,'best_plan')#Add payment id to DB
update_user_subscription(user.id,'best_plan')#Update user plan
return render_template('upgrade.html', u_email=user_email, u_category = user_category)
But I need to retrieve the subscriptionID with a post method to save it in a database.
The client base method doesn't send back post information.
Any idea to do it easily with flask and JS? I don't understand how any e-market could work only with a client side code.
Note that the code available about server side in Paypal is mainly for classic order payment, not subscriptions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
订阅 a>事件。这样,您将收到订阅每笔付款的通知,而不仅仅是第一个付款。
Subscribe to a webhook for the PAYMENT.SALE.COMPLETED event. This way you will get notifications for every payment on the subscription, not just the first one.