【问题标题】:Python - PayPal recurring Payments - Agreement Details are not shownPython - PayPal 定期付款 - 未显示协议详细信息
【发布时间】:2018-09-05 13:04:08
【问题描述】:

在我的 python 项目中,我必须实施 paypal 定期付款。 我已经安装了 paypal sdk 并创建了一个文件来创建一个 PayPal 支付页面,如下所示:

import paypalrestsdk
from paypalrestsdk import BillingPlan
from paypalrestsdk import BillingAgreement
from paypalrestsdk import Payment
import webbrowser
from urllib import parse

paypalrestsdk.configure({
    'mode': 'sandbox',  # sandbox or live
    'client_id': <my app client id>,
    'client_secret': <my app secret>})


def create_bill():
    billing_plan = BillingPlan({
        "name": "Plan with Regular and Trial Payment Definitions",
        "description": "Plan with regular and trial payment definitions.",
        "type": "INFINITE",
        "payment_definitions": [
            {
                "name": "Regular payment definition",
                "type": "REGULAR",
                "frequency": "MONTH",
                "frequency_interval": "1",
                "amount": {
                    "value": "100",
                    "currency": "USD"
                },
                "cycles": "0",
                "charge_models": [
                    {
                        "type": "SHIPPING",
                        "amount": {
                            "value": "10",
                            "currency": "USD"
                    }
                },
                {
                    "type": "TAX",
                    "amount": {
                        "value": "12",
                        "currency": "USD"
                    }
                }
            ]
        },
        {
            "name": "Trial payment definition",
            "type": "TRIAL",
            "frequency": "WEEK",
            "frequency_interval": "5",
            "amount": {
                "value": "9.19",
                "currency": "USD"
            },
            "cycles": "2",
            "charge_models": [
                {
                    "type": "SHIPPING",
                    "amount": {
                        "value": "1",
                        "currency": "USD"
                    }
                },
                {
                    "type": "TAX",
                    "amount": {
                        "value": "2",
                        "currency": "USD"
                    }
                }
            ]
        }
    ],
    "merchant_preferences": {
        "setup_fee": {
            "value": "1",
            "currency": "USD"
        },
        "return_url": "https://example.com",
        "cancel_url": "https://example.com/cancel",
        "auto_bill_amount": "YES",
        "initial_fail_amount_action": "CONTINUE",
        "max_fail_attempts": "0"
    }
})

# Create billing plan
if billing_plan.create():
    print("Billing Plan [%s] created successfully" % billing_plan.id)

    # Activate billing plan
    if billing_plan.activate():
        billing_plan = BillingPlan.find(billing_plan.id)
        print("Billing Plan [%s] state changed to %s" % (billing_plan.id, billing_plan.state))
        return billing_plan
    else:
        print(billing_plan.error)
else:
    print(billing_plan.error)


def create_agreement(ret_bil):

    billing_agreement = BillingAgreement({
        "name": "Fast Speed Agreement",
        "description": "Agreement for Fast Speed Plan",
        "start_date": "2018-03-29T00:37:04Z",
        "plan": {
            "id": str(ret_bil.id)
        },
        "payer": {
            "payment_method": "paypal"
        },
        "shipping_address": {
            "line1": "StayBr111idge Suites",
            "line2": "Cro12ok Street",
            "city": "San Jose",
            "state": "CA",
            "postal_code": "95112",
            "country_code": "US"
        }
    })

    if billing_agreement.create():
        # Extract redirect url
        for link in billing_agreement.links:
            if link.method == "REDIRECT":
                # Capture redirect url
                redirect_url = str(link.href)
                # REDIRECT USER TO redirect_url
                webbrowser.open(redirect_url)

    else:
        print(billing_agreement.error)


if __name__ == "__main__":
    create_agreement(create_bill())

但是当我运行上面的代码时,Paypal 以协议描述开始,但我看不到 BilingPlan 中定义的项目详细信息和描述(我希望看到有关项目、试用期、金额、重复周期等的详细信息)

我的代码有问题吗?这是我第一次在我的项目中使用 Paypal;我是否正确编写了代码来实现定期付款?

提前致谢

【问题讨论】:

    标签: python django paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:

    PayPal 不会显示重复周期、金额和服务详情。 您必须在您的网站页面上显示并继续使用 PayPal。

    【讨论】:

    • 我注意到它显示了预先批准的imgur.com/a/Sp7JdVC ?这是什么意思,我怎么知道它是否向客户收费。是否有额外的步骤来确保向客户收费?谢谢。 @桑达尔
    猜你喜欢
    • 2014-07-03
    • 2014-02-23
    • 2018-04-05
    • 2011-12-01
    • 2015-07-22
    • 2016-01-03
    • 2017-02-16
    • 2018-08-30
    • 2016-06-28
    相关资源
    最近更新 更多