#ali-raza_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1319666356320469043
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ali-raza_api, 22 hours ago, 52 messages
- ali-raza_code, 1 day ago, 24 messages
- ali-raza_code, 1 day ago, 47 messages
Can you share the req_xxx ID for the error you describe here:
The payment method ID generated from front-end doesn't work on the first attempt
Also we generally don't recommend using createPaymentMethod unless required in your integration. You should instead just use the Elements instance to confirm the generated intent, which handles the PM creation: https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=elements#complete-payment
Frist time fail
id: 'pm_1QY6bHCuC33ZJzbkfcoqThhS',
object: 'payment_method',
First time fail error message:
error: StripeInvalidRequestError: No such source: 'pm_1QY6e1CuC33ZJzbkQRy0CcuS'
Second time using same pm_id
id: 'pm_1QY6e1CuC33ZJzbkQRy0CcuS',
object: 'payment_method',
I am able to purchase subscription.
why is that so? It doesn't work on first time but on second attempt it wroks
I have to follow this UI. Client wants in-app
Well the error is because you're trying to set a Payment Method object (pm_xxx) to a field that expects a src_xxx object (default_source)
what src_xxx ??
customer id ?
backend code where I attach the card to customer in stripe
const stripeCustomer = await attachPaymentMethodFn({
customerId,
paymentMethodId,
stripe,
});
export const attachPaymentMethodFn = async ({
customerId,
paymentMethodId,
stripe,
}: {
customerId: string;
paymentMethodId: string;
stripe: Stripe;
}): Promise<Stripe.Customer> => {
try {
// Retrieve all payment methods attached to the customer
const paymentMethods = await stripe.paymentMethods.list({
customer: customerId,
type: 'card',
});
console.log('๐ ~ paymentMethods:', paymentMethods);
// Check if the provided payment method is already attached
const isAlreadyAttached = paymentMethods.data.some(
(method) => method.id === paymentMethodId,
);
if (isAlreadyAttached) {
// If the payment method is already attached, just update the default
return stripe.customers.update(customerId, {
invoice_settings: { default_payment_method: paymentMethodId },
});
}
// If not attached, attach the payment method
await stripe.paymentMethods.attach(paymentMethodId, {
customer: customerId,
});
// Set it as the default payment method
return stripe.customers.update(customerId, {
invoice_settings: { default_payment_method: paymentMethodId },
default_source: paymentMethodId,
});
} catch (error) {
console.error('Failed to attach or update payment method:', error);
throwHttpException(
'Failed to attach payment method',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
};
The ID of a Source object, legacy API. You should just not set that parameter, invoice_settings[default_payment_method] is what you need
I should remove default source?
return stripe.customers.update(customerId, {
invoice_settings: { default_payment_method: paymentMethodId },
default_source: paymentMethodId,
});
Is this what you are saying?
Yes, remove the default_source param
Wait, let me try again then
Thanks
It workd
@restive yarrow can you tell me is there any way to delete my stripe account? like the main account!
From here, is there any way?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Thanks @restive yarrow โค๏ธ