简体   繁体   English

Braintree 中的付款方式令牌无效

[英]Payment method token is invalid in Braintree

I want to test it on the side of the functionality of the subscription payment gateway Braintree - for my application using Django (python).我想在订阅支付网关 Braintree 的功能方面测试它 - 对于我使用 Django (python) 的应用程序。

Your code I have only one py file.你的代码我只有一个 py 文件。 (without front-end). (没有前端)。 When I want to create a subscription I get an error:当我想创建订阅时,出现错误:

<ErrorResult 'Payment method token is invalid.' at 7f101d301390>

How can I get token payment method?我如何获得代币支付方式?

Here is all my code:这是我的所有代码:

import braintree

braintree.Configuration.configure(braintree.Environment.Sandbox,
                                  merchant_id="myMechrantId",
                                  public_key="myPublicKey",
                                  private_key="myPrivateKey")

client_token = braintree.ClientToken.generate()

client = braintree.Customer.create({
    "first_name": 'Mike',
    "last_name": "Smith",
    "company": "Braintree",
    "email": "jen@example.com",
    "phone": "312.555.1234",
    "fax": "614.555.5678",
    "website": "www.example.com"
})

result = braintree.Subscription.create({
    "payment_method_token": "the_token",
    "plan_id": "Here is my plan ID"
})

I work at Braintree.我在布伦特里工作。 Please get in touch with our support team if you have more questions.如果您有更多问题,请与我们的支持团队联系

In general, one of the main benefits of a service like Braintree is that you never have to handle credit card numbers, so you're better off following the Braintree recurring billing guide instead, which will better match a real integration with Braintree.一般来说,像 Braintree 这样的服务的主要好处之一是您永远不必处理信用卡号,因此您最好遵循 Braintree 定期计费指南,这将更好地匹配与 Braintree 的真正集成。

That said, if you do want to test it without a front-end, you can test it like this:也就是说,如果你想在没有前端的情况下测试它,你可以这样测试:

result = braintree.Customer.create({
    "credit_card": {
        "number": "4111111111111111",
        "expiration_date": "12/16"
    }
})

result = braintree.Subscription.create({
    "payment_method_token": result.customer.credit_cards[0].token,
    "plan_id": "my_plan_id"
})

It's late but I got stuck on this problem recently, this is the solution that helped me很晚了,但我最近遇到了这个问题,这是帮助我的解决方案

customer_create_result = gateway.customer.create({
        "first_name": user.first_name,
        "last_name": user.middle_name + '' + user.last_name,
        "payment_method_nonce": payment_method_nonce
    })
subscription_create_result = gateway.subscription.create({
        "payment_method_token":
        customer_create_result.customer.payment_methods[0].token,
        "plan_id": braintree_plan_id
    })

where payment_method_nonce can be obtained from payload.nonce on payment button click and braintree_plan_id is the id for the plan you create in braintree control panel其中payment_method_nonce可以从付款按钮点击braintree_plan_id payload.nonce获得对你在布伦特里控制面板中创建计划的ID

here is the braintree reference that helped me https://developer.paypal.com/braintree/docs/guides/customers#create-with-payment-method这是帮助我的脑树参考https://developer.paypal.com/braintree/docs/guides/customers#create-with-payment-method

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

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