#marlin_98353

1 messages Β· Page 1 of 1 (latest)

knotty forumBOT
#

Hello marlin_98353, we'll be with you shortly! 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.
β€’ marlin_98353, 9 hours ago, 18 messages

gloomy violet
#

generally, integrating with automatic_payment_methods is easier because Stripe will automatically determine the appropriate payment methods based off a variety of factors e.g. currency, etc. if you're saving it for future usage. Otherwise, you have to implement this logic yourself

green flame
#

do you know the earliest version of the node sdk that supports that feature? As I mentioned we're still using 8.203.0 and I'd like to avoid upgrading too many major version.

gloomy violet
green flame
#

sure

#

acct_1HfDkIEYhBixhkgT

gloomy violet
#

The reason why your code below isn't working is likely cause you're explicitly passing in the payment_method_types. Can you try including automatic_payment_methods.enabled=true instead and share with me the corresponding request id?

const intent = await stripe.setupIntents.create({
      customer: customer!,
      payment_method_types: ['card'],
    })
green flame
#

ok, but I think i'll need to upgrade the node stripe sdk and i'm not sure exactly which version is the minimum required version.

#

it looks like 11.16.0 according to the changelog?

gloomy violet
#

i think you don't need to upgrade. Are you able to test this out?

green flame
#

i'm using version 8.203 and the typescript is rejecting the "payment_method_types" property

#

i just upgraded to 11.16.0 and typescript is happy, but now there are other breaking issues with our stripe integration code.

gloomy violet
#

ah, okay, you're using typescript, give me a while to πŸ‘€

green flame
#

the main issue is

paymentIntent.charges

i think i saw "charges" was removed in one of the major updates

#

yes, sorry, thank you

gloomy violet
#

you can consider using // @ts-ignore just for automatic_payment_methods, but i think it’s generally unsafe because this will bypass the TypeScript validations and might be hard to maintain your code in the future. I’d recommend just upgrading to 11.16.0 - this is the minimum

green flame
#

ok, i'll have to make a few code changes before i can test this. Can i message you later with a request id to check our account?

gloomy violet
#

you can post again in this thread, or in the main channel if the thread is closed. Either me or someone else from my team will be around to help πŸ˜„

green flame
#

thanks

green flame
#

hey, if you're around I have another question related to a breaking change moving to version 11.16.0

we used to use:

payment_intent.charges.data[0]

which had the type stripe.Charge

in version 11.16.0 charges was removed and replaced with latest_charge

payment_intent.latest_charge

but the type here is string | null | undefined | Charge

in the API documentation I only ever see example values that look like ids, e.g. ch_3KTu4BEYhBixhkgT0XDo9Dyb

how can i safely retrieve the same charge information using "latest_charges"?

gloomy violet
#

is this with regards to when you retrieve a PaymentIntent?

green flame
#

sorry just saw this.

yes, this is an example

const paymentIntent = await stripe.paymentIntents.capture(paymentIntentID, {
      amount_to_capture: captureAmount, // This refunds the rest
      expand: ['latest_charge'], // <---- this is new
    })

we also retrive a payment intent from a web hook like so

export function getStripeEventFrom(req: express.Request, secret: string): Stripe.PaymentIntent {
  const signature = req.headers['stripe-signature'] as string
  return stripe.webhooks.constructEvent(req.rawBody, signature, secret ).data.object as Stripe.PaymentIntent
}
gloomy violet
#

it might be problematic (i.e. you'll need to make changes) for the webhook event if you upgrade your webhook endpoint version also

#

from v2022-11-15, by default, latest_charge is no longer expanded, so you'll need to make a subsequent request if you need that info

green flame
#

hmm. ok. this is becoming a larger refactor. I noticed there is another way to handle Affirm integration
https://stripe.com/docs/payments/affirm/accept-a-payment

I wonder if this will be easier. We would have to switch from SetupIntent to PaymentIntent though. We currently use SetupIntent to save a payment method for charges in the future.

Learn how to accept Affirm, a buy now and pay later payment method.

gloomy violet
#

if you really want to do it quickly, then have you considered just using // @ts-ignore first? Then slowly refactor?

#

The problem with using affirm via the Direct API method, when you intend to integrate other payment methods, are you planning to do each of them one by one too? Otherwise you're going to need to refactor your current code again. Must as well do it right the first time round

green flame
#

hmm definitely good advice. I will try with ts-ignore. I'm not sure I understand why that will work though... even though we have declared "stripe": "^8.203.0", in our package.json (node/server side) we can use the latest stripe features?

gloomy violet
#

it should, i would suggest trying it out to make sure it works.

green flame
#

it did not seem to work, but I want to confirm with you.

in our backend/server

    // @ts-ignore
    const intent = await stripe.setupIntents.create({
      customer: customer!,
      automatic_payment_methods: {
        enabled: true,
      },
    })

    const secret = intent?.client_secret
    if (!secret) {
      throw new functions.https.HttpsError('failed-precondition', 'Unable to get a SetupIntent')
    }
    res.send(intent)

this is the resulting intent object

{
    "id": "seti_1O4whwEYhBixhkgT80CCUw5A",
    "object": "setup_intent",
    "application": null,
    "automatic_payment_methods": {
        "allow_redirects": "always",
        "enabled": true
    },
    "cancellation_reason": null,
    "client_secret": "seti_1O4whwEY...",
    "created": 1698200432,
    "customer": "cus_Os...",
    "description": null,
    "flow_directions": null,
    "last_setup_error": null,
    "latest_attempt": null,
    "livemode": false,
    "mandate": null,
    "metadata": {},
    "next_action": null,
    "on_behalf_of": null,
    "payment_method": null,
    "payment_method_configuration_details": {
        "id": "pmc_1K...",
        "parent": null
    },
    "payment_method_options": {
        "card": {
            "mandate_options": null,
            "network": null,
            "request_three_d_secure": "automatic"
        }
    },
    "payment_method_types": [
        "card"
    ],
    "single_use_mandate": null,
    "status": "requires_payment_method",
    "usage": "off_session",
}

and on the client, using the PaymentElement from the most recent stripe version, affirm is not a payment option.

as you can see the payment_method_types in the SetupIntent still lists only "card"

do you see any other issues with my code or any other solutions I could try?

gloomy violet
#

πŸ‘€

#

enable the payment methods you want to offer

green flame
#

ok let me check

#

ahh ok i was enabling Affirm for "connected accounts"... let me try in "Your accounts"

#

ok, i've turn on Affirm for the main account in test mode. i'm still seeing only "card" listed as a method type. Does it take a few minutes for the change to take effect?

{
    "id": "seti_1O4wwYEYhBixhkgTrXsA2cny",
    "object": "setup_intent",
    "application": null,
    "automatic_payment_methods": {
        "allow_redirects": "always",
        "enabled": true
    },
    "cancellation_reason": null,
    "client_secret": "seti_1O4wwYEYhBix....",
    "created": 1698201338,
    "customer": "cus_Osf...",
    "description": null,
    "flow_directions": null,
    "last_setup_error": null,
    "latest_attempt": null,
    "livemode": false,
    "mandate": null,
    "metadata": {},
    "next_action": null,
    "on_behalf_of": null,
    "payment_method": null,
    "payment_method_configuration_details": {
        "id": "pmc_1KPM6PE....",
        "parent": null
    },
    "payment_method_options": {
        "card": {
            "mandate_options": null,
            "network": null,
            "request_three_d_secure": "automatic"
        }
    },
    "payment_method_types": [
        "card"
    ],
    "single_use_mandate": null,
    "status": "requires_payment_method",
    "usage": "off_session",
}
gloomy violet
#

πŸ€¦β€β™‚οΈ sorry, totally slipped my mind. It looks like Affirm isn't supported for SetupIntents i.e. saving for future usage. What if you create a PaymentIntent instead? Does it show in the list of payment methods?