【问题标题】:getting No such PaymentMethod: error message when trying to attach paymentMethodId to customerId尝试将 paymentMethodId 附加到 customerId 时出现 No such PaymentMethod: 错误消息
【发布时间】:2020-05-29 23:38:37
【问题描述】:

stripe 新手,但文档看起来很前卫,但现在库存的东西非常简陋,我可以看到在 stripe 控制台中创建的客户,与产品和价格相同,但是当我尝试附加从 cardElement 检索的付款方式时,并将其发送到服务器我收到 paymentMethod 无效的消息。我正在关注此页面中的条带文档 https://stripe.com/docs/billing/subscriptions/fixed-price#create-customer

在javascript中我有:

    const payload = await stripe.createPaymentMethod({
        type: 'card',
        card: elements.getElement(CardElement),
        billing_details: billingDetails,
    });

这会返回一个带有 id 的 paymentMethod 对象

 paymentMethod.id be like pm_1GoHU32eZvKYloXXXXXXX

在服务器端:

await stripe.paymentMethods.attach(paymentMethodId, {
    customer: customerId,
});

但我得到一个像下面这样的异常

StripeInvalidRequestError: No such PaymentMethod: pm_1GoHU32eZvKYloXXXXXXX
at Function.generate (/root/coco/node_modules/stripe/lib/Error.js:39:16)
at IncomingMessage.<anonymous> 
(/root/coco/node_modules/stripe/lib/StripeResource.js:175:33)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at IncomingMessage.EventEmitter.emit (domain.js:485:12)
at endReadableNT (_stream_readable.js:1225:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
type: 'StripeInvalidRequestError',
raw: {
code: 'resource_missing',
doc_url: 'https://stripe.com/docs/error-codes/resource-missing',
message: 'No such PaymentMethod: pm_1GoHU32eZvKYlo2CYLA3SCaX',

【问题讨论】:

  • 我也遇到了这个错误你找到解决办法了吗?

标签: stripe-payments


【解决方案1】:

好的,想通了。我从条带示例中复制并粘贴,条带通常很适合用您的密钥替换他们的文档示例,但此文档(发布在问题中)使用的是示例可发布密钥!

【讨论】:

  • 您是否在文档页面上登录了 Stripe?一旦你这样做了,它就会使用你的 API 密钥 :)
  • 我很确定我已登录,我正在查看仪表板中的产品和价格以及客户 ID,但我看到该文档实际上使用了登录键 - 奇怪 :)跨度>
【解决方案2】:

这是基本的,但我遇到了同样的问题。 当我使用我的公钥时解决了它

【讨论】:

  • 用支持信息和代码改进你的答案。
【解决方案3】:

我使用的是 stripe connect,并正在 Connect 帐户上创建付款资料。然后在检索时我没有正确传递条带帐户。一旦我这样做了,付款方式就被正确检索了。这是我使用的代码。可能会帮助某人

//retrieve account
$stripe = new \Stripe\StripeClient({platform api key});
$payment_method = $stripe->paymentMethods->retrieve(
  {payment method id from payment_intent},
  [],
  ['stripe_account' => {stripe connect account id}]
);

【讨论】:

    猜你喜欢
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2018-06-28
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    相关资源
    最近更新 更多