智能支付按钮为 IPN 传递自定义变量 [英] Smart Payment Buttons passing custom variable for IPN

查看:59
本文介绍了智能支付按钮为 IPN 传递自定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有两个用于按月订阅的 Smart 按钮(运行良好).我成功收到 IPN 响应,其中支付信息已准备好添加到数据库中.但是我需要通过 IPN 响应获取我的应用程序的 UserID.

如何使用智能支付按钮传递自定义变量,以便将其传递给 IPN(如果可能,用于购买交易和退款/取消交易?)

这是我的智能按钮代码:

<script src="https://www.paypal.com/sdk/js?client-id=[ID]...></script><脚本>贝宝.按钮({风格:{颜色:蓝色",形状:矩形",标签:贝宝",标语:假},创建订阅:函数(数据,动作){返回 actions.subscription.create({'plan_id': 'P-02S33....'});},onApprove:函数(数据,动作){alert('您已成功创建订阅企业' + data.subscriptionID);}}).render('#paypal_button');

解决方案

我使用了 Paypal IPN 和客户完成支付时的重定向响应.

当客户完成支付时,它会调用JS函数onApprove.如果需要,我使用此函数从我的应用程序中收集 data.subscriptionID 与用户 ID 和其他信息.然后我将这些信息发送到我的数据库中(我的情况下,paypal SubscriptionID 和我的 UserID).

然后我等待贝宝 IPN 调用我的路线之一.IPN 会发送很多有关付款的信息.其中之一是我之前存储的 SubscriptionID.所以我只需要使用我拥有的匹配订阅 ID 更新我的数据库条目.

为了更安全,如果 Subscription_ID 与我的数据库中的任何条目都不匹配(如果 IPN 在客户端之前触发,或者如果客户端关闭,我的客户端调用和 IPN 调用都将创建一个新的数据库条目在给客户打电话之前,我的网站页面).

I have two Smart button on my website for a monthly subscription (working well). I successfully receive the IPN response with the payment information ready to be added to the Database. But I need to get the UserID of my application with the IPN response.

How can I pass custom variable with my Smart payment button so it can be passed to the IPN (for buying transaction and refund/cancellation ones if possible?)

Here is my Smart button code :

<div id="paypal_button"></div>

<script src="https://www.paypal.com/sdk/js?client-id=[ID]...></script>

<script>
paypal.Buttons({
    style:{
        color:"blue",
        shape:"rect",
        label:"paypal",
        tagline:false
    },
    createSubscription: function(data, actions) {
        return actions.subscription.create({'plan_id': 'P-02S33....'});
    },
    onApprove: function(data, actions) {
        alert('You have successfully created subscription ENTERPRISE' + data.subscriptionID);
    }
}).render('#paypal_button');
</script>

解决方案

I used a mix between the Paypal IPN and the Client redirection response when he finished the payment.

When the client finish his payment, It will call the JS function onApprove. I use this function to gather the data.subscriptionID with the UserID and other information from my application if needed. I then send thoses information inside my Database (The paypal SubscriptionID and my UserID for my case).

I then wait for the paypal IPN to call one of my routes. The IPN will sent a lot of information about the payment. One of them is the SubscriptionID i stored earlier. So I just need to update my Database entry with the matching SubscriptionID I have.

For more security, both of my Client Call and the IPN Call will create a new DB entry if the Subscription_ID is not matching any entry in my Database (in case of the IPN is triggered before the Client, or if the client closed my Website page before making the client Call).

这篇关于智能支付按钮为 IPN 传递自定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆