#ali-raza_code

1 messages ยท Page 1 of 1 (latest)

cerulean briarBOT
#

๐Ÿ‘‹ 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.

restive yarrow
#

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

loud bolt
#

yes

#

Failed attempt

req_3YDgyL4Lwq33nO

restive yarrow
loud bolt
#

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

restive yarrow
loud bolt
#

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,
    );
  }
};
restive yarrow
# loud bolt what `src_xxx` ??

The ID of a Source object, legacy API. You should just not set that parameter, invoice_settings[default_payment_method] is what you need

loud bolt
#

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?

restive yarrow
#

Yes, remove the default_source param

loud bolt
#

Wait, let me try again then

loud bolt
#

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?

restive yarrow
loud bolt
#

Thanks @restive yarrow โค๏ธ