MCPcopy Create free account
hub / github.com/async-labs/async / changeStripeCard

Method changeStripeCard

api/server/models/User.ts:1168–1198  ·  view source on GitHub ↗
({
    session,
    teamLeader,
  }: {
    session: Stripe.Checkout.Session;
    teamLeader: IUserDocument;
  })

Source from the content-addressed store, hash-verified

1166
1167 // used in Checkout
1168 public static async changeStripeCard({
1169 session,
1170 teamLeader,
1171 }: {
1172 session: Stripe.Checkout.Session;
1173 teamLeader: IUserDocument;
1174 }): Promise<void> {
1175 if (!teamLeader) {
1176 throw new Error('User not found.');
1177 }
1178
1179 const si: Stripe.SetupIntent = session.setup_intent as Stripe.SetupIntent;
1180 const pm: Stripe.PaymentMethod = si.payment_method as Stripe.PaymentMethod;
1181
1182 if (!pm.card) {
1183 throw new Error('No card found.');
1184 }
1185
1186 await updateCustomer(teamLeader.stripeCustomer.id, {
1187 invoice_settings: { default_payment_method: pm.id },
1188 });
1189
1190 await updateSubscription(teamLeader.stripeSubscription.id, {
1191 default_payment_method: pm.id,
1192 });
1193
1194 await this.updateOne(
1195 { _id: teamLeader._id.toString() },
1196 { stripeCard: pm.card, hasCardInformation: true },
1197 );
1198 }
1199
1200 public static async cancelSubscriptionForAccount({ userId }) {
1201 const teamLeader = await this.findById(userId).setOptions({ lean: true });

Callers

nothing calls this directly

Calls 2

updateCustomerFunction · 0.90
updateSubscriptionFunction · 0.90

Tested by

no test coverage detected