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

时间:2018-03-27 08:05:43

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

enter image description here

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

非常感谢提前

1 个答案:

答案 0 :(得分:1)

PayPal不会显示经常性的期限,金额和服务详情。 您必须在您网站的页面中显示该信息并继续使用PayPal。