#ian-reactnative-defaultpm
1 messages ยท Page 1 of 1 (latest)
ian-reactnative-defaultpm
@tacit owl Are you using our Billing product to do recurring payments/Subscriptions?
yes
Okay so let's ignore React Native just for a second. Can you share the code you use to create the Subscription?
/**
* creates a subscription with a trial period
*/
async createSubscriptionTrial({ customer_id, price_id, coupon_id, product_id }: StripePurchase) {
const payload: Stripe.SubscriptionCreateParams = {
customer: customer_id,
items: [{ price: price_id }],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
trial_period_days: trialLength,
coupon: coupon_id,
};
const subscriptionPayload = await this.setSubscriptionDestinationAccount(product_id, payload);
const [ephemeralKey, setupIntent] = await Promise.all([
this.client.ephemeralKeys.create({ customer: customer_id }, { apiVersion }),
this.client.setupIntents.create({ customer: customer_id }),
this.createSubscription(subscriptionPayload),
]);
return {
id: setupIntent.id,
client_secret: setupIntent.client_secret,
ephemeral_key: ephemeralKey.secret,
customer_id,
};
}
the create subscription function just wraps the stripe create subscription function
Okay so that's your problem! On that code when you create the Subscription you forgot a really important setting that says basically "hey whenever you pay an Invoice please make this PaymentMethod the default"
It can seem a bit convoluted but look at https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-save_default_payment_method
basically you add payment_settings: { save_default_payment_method: 'on_subscription', }, to your code and then try paying again in your app and you'll see it will be made the default for that Subscription
got it. i thought i was missing something like that! thanks
try it and let me know if that doesn't work and we can look together
ok
going to try it soon just wondering if a trial will charge the payment method added when the subscription starts and set the default payment method if the payment method is not already set as the default
If you do trials, you should not be creating the SetupIntent yourself at all.
Instead the Subscription will create one for you and return it in pending_setup_intent
Try that code and look at the response, you should see pending_setup_intent: 'seti_123' on the Subscription. That's the SetupIntent to confirm with ReactNative not a separate one
So there's quite a lot to change in your overall integration here
If you don't want to change all of that it's fine. In that case what you need to do really is after the SetupIntent is confirmed, write code that will go and call the Update Customer API https://stripe.com/docs/api/customers/update and then set invoice_settings[default_payment_method]: 'pm_12345' but it won't be automatic
yeah maybe my last option will be a lot easier for you
you must have some kind of code that detectsthe SetupIntent succeeding already and then you can just update the Customer
yeah i think thats how we did it previously but i think expanding the pending setup intent and returning the setup intent id and client secret shouldnt be a problem
ah yeah if you're already familiar with expansion and all that, it's definitely better that way ๐
yes thank you this looks to be working as expected
damn you're fast ๐
while i have you here i need to update my api version to the latest (2022-11-15 how do you recommend doing that on my live account?
okay so you're not too far behind. I'd recommend reading all the breaking changes on https://stripe.com/docs/upgrades first to gather what that means to your own code.
Then I would recommend changing your code to pin to the latest API version first using https://stripe.com/docs/api/versioning to ensure all your code server-side is pinned
then move to your webhook handler, adding a new endpoint with the latest API version and start processing all Events that way
the sdk needed an upgrade but ive done that before and im familiar with the breaking changes
after all of that is done, changing the default API version on your account should change nothing else since everything is already "pinned"
got it