简体   繁体   English

Python-PayPal定期付款-协议明细未显示

[英]Python - PayPal recurring Payments - Agreement Details are not shown

In my python project I have to implement paypal recurring payments. 在我的python项目中,我必须实现Paypal定期付款。 I have installed the paypal sdk and created a file to create a PayPal payment page, like this: 我已经安装了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())

But when I run the code above, Paypal starts with agreement description but I can't see the item details and description defined in the BilingPlan (I expected to see the detail about items, trial period, amount, recurrence etc) 但是,当我运行上面的代码时,Paypal从协议描述开始,但是我看不到BilingPlan中定义的项目详细信息和描述(我希望看到有关项目,试用期,金额,重复发生的详细信息)

在此处输入图片说明

Is there something wrong in my code? 我的代码有问题吗? This is the first time I implement Paypal in my project; 这是我第一次在项目中实施Paypal。 have I written my code correctly to implement recurrent payments? 我是否正确编写了代码以实现经常性付款?

So many Thanks in advance 非常感谢

PayPal will not show the recurring period, amount and service details. PayPal将不会显示重复周期,金额和服务详细信息。 You have to show that in your website's page and proceed to PayPal. 您必须在您的网站页面上显示该内容,然后转到PayPal。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM