【问题标题】:Python Stripe Payment GatewayPython 条纹支付网关
【发布时间】:2020-10-14 15:28:48
【问题描述】:

我正在尝试通过 Python 对卡进行收费。 但是,我无法让它工作。 根据文档,我可以使用测试条卡 https://stripe.com/docs/testing

但是,当使用其中一张测试卡时,我遇到了错误

stripe.error.InvalidRequestError: Request req_y3tPpc4nHFd7Pi: No such token: 4242424242424242

请告诉我如何测试。我没有带卡或余额的条带帐户。

stripe.api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"

a = stripe.Charge.create(
  amount=2000,
  currency="usd",
  source="4242424242424242",
  description="My First Test Charge (created for API docs)",
)

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    正确的语法是[1]:

        # `source` is obtained with Stripe.js; see https://stripe.com/docs/payments/accept-a-payment-charges#web-create-token
        stripe.Charge.create(
          amount=2000,
          currency="eur",
          source="tok_visa",  # <-- The tokenized card information not a CC number
          description="My First Test Charge (created for API docs)",
        )
    

    您需要使用 Stripe.js 使用 createToken() 标记卡信息。 [2]

    话虽如此,推荐的集成路径是使用 PaymentIntents 而不是 Tokens and Charges。 [3]

    希望有帮助!

    [1]https://stripe.com/docs/api/charges/create?lang=python

    [2]https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement

    [3]https://stripe.com/docs/payments/accept-a-payment#web

    【讨论】:

    • 非常感谢,createToken python helper 有效。
    猜你喜欢
    • 2021-10-08
    • 2022-08-19
    • 1970-01-01
    • 2021-01-13
    • 2016-03-29
    • 2017-09-14
    • 2021-08-02
    • 2020-12-30
    • 1970-01-01
    相关资源
    最近更新 更多