Python - PayPal 定期付款 - 未显示协议(protocol)详细信息

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

在我的 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 以协议(protocol)描述开始,但我看不到 BilingPlan 中定义的项目详细信息和描述(我希望看到有关项目、试用期、金额、重复等的详细信息)

enter image description here

我的代码有问题吗?这是我第一次在项目中实现 Paypal;我是否正确编写了代码以实现经常性付款?

非常感谢

最佳答案

PayPal 不会显示循环周期、金额和服务详情。 您必须在您的网站页面中显示该信息并继续使用 PayPal。

关于Python - PayPal 定期付款 - 未显示协议(protocol)详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49507498/

相关文章:

python - 定时测验 : How to consider internet interruptions?

PayPal 快速结账状态 PaymentActionInProgress

python - 使用 Python 中的 PyChart 库以 (%) 形式显示饼图的数据

HTTP 请求 header 的 Python 正则表达式

Python Tkinter : Listbox mouse enter event for a specific entry

paypal - Reg - Card present 支付网关集成

wordpress - 在 WooCommerce 中使用 PayPal 时出错

python - 在 PySpark 中计算加权平均值

PHP/Django/Rails/Flex 混合演示 - 需要项目创意

python - Django 不呈现第二个应用程序 HTML