#Gautam- subscription

1 messages · Page 1 of 1 (latest)

violet sphinx
#

Hi Gautam, so you want to setup a subscription with ACH as the default payment method?

hazy minnow
#

yes, but dynamically I want to attach payment method while subscription

#

I have bank account ref for a customer that i want to set while subscription

violet sphinx
#

Thanks for the confirmation. Please give me some time to work out a solution for you.

hazy minnow
#

const subscription = await stripe.subscriptions.create({
customer: customerId,
transfer_data:
{
destination: destinationStripeId
},

  default_payment_method: paymentMethodRef,
  metadata: {
    subscription_id: subscriptionId,
    solution_id: solutionId,
    remmitance_org_id: remittanceOrgId,
    customer_org_id: customerOrgId
  },
  items: [
    {
      price: priceObjectId,
      tax_rates: [taxRateReference]
    },
  ]
});
return subscription;
violet sphinx
#

Can you tell me how did you get the paymentMethodRef ?

hazy minnow
#

const bankAccount = await stripeCustomerService.attachBankToCustomer(
bankAchToken.id,
existingAccounts[0].customer_reference
);

#

this way we are attaching bank to customer

#

ba_1JwilsHiJqyEPSdXb4tgVo7F this is ref which we have for bank ach and that we are attching to customer

#

const token = await stripe.tokens.create({
bank_account: {
country: constant.COUNTRY,
currency: constant.CURRENCY,
account_number: accountNumber,
routing_number: routingNumber,
account_holder_name: accountHolderName,
account_holder_type: accountHolderType
}
});
const source = await stripe.customers.createSource(customerId, {
source: token.id
});
return source;

violet sphinx
#

Thanks for the code. so you are using the source API. could you try to pass the paymentMethodRef to default_source param instead of default_payment_method?

hazy minnow
#

that will work for both card and ach

#

?

violet sphinx
violet sphinx
#

Yes, if you are using the Source API for card as well then you can pass the id to the default_source.

However, I strongly encourage you to migrate to the new payment_method API for card payments, which allows you to use the latest features such as 3DS for card transactions.

hazy minnow
#

Thanks Jack , default_source is working