没有这种付款方式 - 克隆付款方式 Stripe Connect

时间:2021-03-19 01:57:30

标签: javascript node.js stripe-payments

我正在按照此示例克隆付款方式:https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods

self

返回:

const paymentMethod = await stripe.paymentMethods.create(
    {
        customer: card.customer,
        payment_method: card.id,
    },
    {
        stripeAccount: vendorAcc,
    }
);

但是,当我下次尝试运行时:

{
  id: 'pm_....',
  object: 'payment_method',
  billing_details: {
    address: {
      city: null,
      country: null,
      line1: null,
      line2: null,
      postal_code: null,
      state: null
    },
    email: '...',
    name: '...',
    phone: null
  },
  card: {
    brand: 'visa',
    checks: {
      address_line1_check: null,
      address_postal_code_check: null,
      cvc_check: 'pass'
    },
    country: 'US',
    exp_month: 3,
    exp_year: ...,
    fingerprint: 'c...',
    funding: 'credit',
    generated_from: null,
    last4: '4242',
    networks: { available: [Array], preferred: null },
    three_d_secure_usage: { supported: true },
    wallet: null
  },
  created: 1616118576,
  customer: null,
  livemode: false,
  metadata: {},
  type: 'card'
}

const paymentMethod2 = await stripe.paymentMethods.retrieve(
     paymentMethod.id
);

我收到错误:

const paymentMethodAttached = await stripe.paymentMethods.attach(
    paymentMethod.id,
    { customer: card.customer }

更新

我现在正在跑步:

    StripeInvalidRequestError: No such PaymentMethod: 'pm_...'
    ...
    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_...'",
    param: 'payment_method',
    type: 'invalid_request_error',
    headers: {
      server: 'nginx',
      date: 'Fri, 19 Mar 2021 01:49:37 GMT',
      'content-type': 'application/json',
      'content-length': '262',
      connection: 'keep-alive',
      'access-control-allow-credentials': 'true',
      'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
      'access-control-max-age': '300',
      'cache-control': 'no-cache, no-store',
      'request-id': 'req_...',
      'stripe-version': '2020-03-02',
      'x-stripe-c-cost': '12',
      'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
    },
    statusCode: 404,
    requestId: 'req_...'
  },
  rawType: 'invalid_request_error',
  code: 'resource_missing',
  doc_url: 'https://stripe.com/docs/error-codes/resource-missing',
  param: 'payment_method',
  detail: undefined,
  headers: {
    server: 'nginx',
    date: 'Fri, 19 Mar 2021 01:49:37 GMT',
    'content-type': 'application/json',
    'content-length': '262',
    connection: 'keep-alive',
    'access-control-allow-credentials': 'true',
    'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
    'access-control-max-age': '300',
    'cache-control': 'no-cache, no-store',
    'request-id': 'req_...',
    'stripe-version': '2020-03-02',
    'x-stripe-c-cost': '12',
    'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
  },
  requestId: 'req_...',
  statusCode: 404,
  charge: undefined,
  decline_code: undefined,
  payment_intent: undefined,
  payment_method: undefined,
  payment_method_type: undefined,
  setup_intent: undefined,
  source: undefined
}

    );

这会引发错误:

没有这样的客户:'cus_...'

当我跑步时

const paymentMethodAttached = await stripe.paymentMethods.attach( 
      paymentMethod.id,
      {
          customer: card.customer,
      },
      {
          stripeAccount: vendorAcc,
      }
);

这成功返回,带有:

const paymentMethod2 = await stripe.paymentMethods.retrieve(
      paymentMethod.id,
      {
         stripeAccount: vendorAcc,
      }
);
   

1 个答案:

答案 0 :(得分:1)

“No such...”错误通常是由 API 密钥不匹配(例如,混合使用测试密钥和实时密钥)或尝试访问不同帐户上存在的对象(例如尝试执行从您的平台帐户对在已连接帐户上创建的对象进行的操作)。

在这种情况下,它是第二个:您的检索或附加调用不include the Stripe-Account header,因此他们正在查找错误的 Stripe 帐户。

更新:此外,该客户必须存在于关联帐户中,这可能不会出现您的“没有此类客户”错误。