Reputation: 5557
I'm following this example to clone a payment method: https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
const paymentMethod = await stripe.paymentMethods.create(
{
customer: card.customer,
payment_method: card.id,
},
{
stripeAccount: vendorAcc,
}
);
This returns:
{
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'
}
However, when I next try to run:
const paymentMethod2 = await stripe.paymentMethods.retrieve(
paymentMethod.id
);
or
const paymentMethodAttached = await stripe.paymentMethods.attach(
paymentMethod.id,
{ customer: card.customer }
I get the error:
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
}
);
UPDATE:
I am now running:
const paymentMethodAttached = await stripe.paymentMethods.attach(
paymentMethod.id,
{
customer: card.customer,
},
{
stripeAccount: vendorAcc,
}
);
This throws the error:
No such customer: 'cus_...'
When I run
const paymentMethod2 = await stripe.paymentMethods.retrieve(
paymentMethod.id,
{
stripeAccount: vendorAcc,
}
);
this returns successfully, with:
{
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: 2024,
fingerprint: '...',
funding: 'credit',
generated_from: null,
last4: '4242',
networks: { available: [Array], preferred: null },
three_d_secure_usage: { supported: true },
wallet: null
},
created: 1616158821,
customer: null,
livemode: false,
metadata: {},
type: 'card'
}
Upvotes: 1
Views: 3471
Reputation: 8747
“No such...” errors are usually caused by either a mismatch in API keys (e.g. using a mixture of your test plus live keys) or by trying to access objects that exist on a different account (e.g. trying to perform an operation from your platform account on an object that was created on a connected account).
In this case it's the second one: your retrieve or attach calls don't include the Stripe-Account header, so they're looking on the wrong Stripe Account.
Update: Also the Customer must exist on the Connected Account, which it likely doesn't given your 'no such Customer' error.
Upvotes: 3