我无法使用Python设置Flask的计费周期

2024-06-06 04:32:10 发布

您现在位置:Python中文网/ 问答频道 /正文

对于正常的支付,我使用的是一个通过RESTAPI进行的修复。我现在正在尝试创建计费周期,但无论我做什么,都会出现错误。有人能帮我把它放在烧瓶上吗

基本上我想做以下几点:

  • 用户单击“立即加入”按钮,就会显示一个页面(已经完成)
  • 在那个页面上,我通常会有两个贝宝按钮
  • 使用订阅/计划API,我理解这是不可能的。我怎么能那样做呢。 我希望用户单击JS中的按钮,触发对我的服务器的请求,处理付款,在DB上注册用户,然后刷新页面,以便他们可以登录到仪表板。如果是一次性付款,我会这么做。我怎样才能用计划做到这一点

这是我到目前为止写的:

@app.route('/payment')
def payment():
    redirect(create_billing_agreement())

# HELPERS
def create_billing_agreement():
    billing_agreement = BillingAgreement({
        "name": 'Stocked Lab Subscription Agreement',
        'description': "Agreement for Stocked Lab Subscription Plan",
        'start_date': datetime.datetime.now().replace(microsecond=0).isoformat(),
        "plan": {'id': create_billing_plan()}})
    if billing_agreement.create():
        for link in billing_agreement.links:
            if link.method == "REDIRECT":
                redirect_url = str(link.href)
                return redirect_url
    else:
        print(billing_agreement.error)

def create_billing_plan():
    plan = BillingPlan({
        "name": 'Stocked Lab Subscription',
        'description': 'The base subscription for Stocked Lab',
        "type": 'INFINITE',
        "payment_definitions": [{
            "name": "Standard Plan",
            "type": "REGULAR",
            "frequency_interval": "1",
            "frequency": "MONTH",
            "cycles": '0',
            "amount": {
                "currency": "USD",
                "value": "15"
            }
        }],
        "merchant_preferences": {
            "auto_bill_amount": "yes",
            "cancel_url": "http://localhost:5000/cancel_subscription",
            "initial_fail_amount_action": "continue",
            "max_fail_attempts": "1",
            "return_url": "http://localhost:5000/",
            "currency": "USD",
            "value": '0'
        }
    })
    if plan.create():
        print(f'Billing Plan [{plan.id}] created successfully')
        if plan.activate():
            plan = BillingPlan.find(plan.id)
            print(f"Billing Plan [{plan.id}] state changed to {plan.state}")
            return plan.id
        else:
            print(plan.error)
    else:
        print(plan.error)

谢谢你的帮助


Tags: 用户idurlifcreateagreementlab页面