#satyra1

1 messages · Page 1 of 1 (latest)

limpid compassBOT
#

Hello! 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.

maiden roost
#

Can you send me your code for how you are creating these subscriptions?

small wharf
#

sure thing

#
const createSubscription = async (userId: Types.ObjectId, userRole: string) => {
  const sub = Subscriptions.find((el) => el.role === userRole);
  if (!sub) throw new Error('subscription error');
  const subPrice = await StripePrice.findOne({
    price_data: sub.connectedName,
  });
  if (!subPrice) throw new Error('Subscription is not defined');

  const user = await User.findById(userId);

  if (!user) throw new Error('user not found');
  const account = await stripe.accounts.create({
    type: 'standard',
  });

  const address = await Address.findById(user.address);
  if (!address) throw new Error('user address failed');
  const customer = await retriveCustomer(account.id);

  const subscriptionStripe = await stripe.subscriptions
    .create({
      customer: customer.id,
      items: subPrice ? [{ price: subPrice.price_id }] : [],
    })
    .catch((error) => {
      console.log('error: ');
      console.log(error);
      console.log('');
    });

  console.log(subscriptionStripe);

  const updatedUser = await User.findByIdAndUpdate(
    userId,
    {
      //TODO: work on subscriptions
      // stripe_subscription_id: subscriptionStripe.id,
      stripe_id: account.id,
      stripe_customer_id: customer.id,
    },
    { new: true }
  );

  return updatedUser;
};```
limpid compassBOT
maiden roost
#

I think you may want to use a collection_behavior like allow_incomplete or default_incomplete , they will let you create a subscription that the customer has up to 24 hours to complete their first payment on https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_behavior

small wharf
#

its failing but if i add subscription via dashboard its working fine

onyx pewter
#

What's failing exactly?

small wharf
#

this part where actual subscription is created

#
const subscriptionStripe = await stripe.subscriptions
    .create({
      customer: customer.id,
      items: subPrice ? [{ price: subPrice.price_id }] : [],
    })
    .catch((error) => {
      console.log('error: ');
      console.log(error);
      console.log('');
    });
onyx pewter
#

What error are you getting?

#

the same one?

small wharf
#

req_V5yKigxl052mEN

onyx pewter
small wharf
#

ill try in a sec but how it will look like if it works

onyx pewter
#

it should create a subscription

small wharf
#

i am getting this warning ```Type '"allow_incomplete"' is not assignable to type 'CollectionMethod | undefined'.ts(2322)

maiden roost
#

Apologies, I said collection_behavior but should have said payment_behavior

#

Set payment_behavior

small wharf
#

and for example if i have 14 days free trial user can set payment method within those 14 days

#

?

#
const subscriptionStripe = await stripe.subscriptions
    .create({
      customer: customer.id,
      items: subPrice ? [{ price: subPrice.price_id }] : [],
      payment_behavior: 'allow_incomplete',
    })
    .catch((error) => {
      console.log('error: ');
      console.log(error);
      console.log('');
      throw new Error(error.message);
    });
#

after changing like this still getting same error

onyx pewter
#

Please share the relevant request IDs with the error

#

and for example if i have 14 days free trial user can set payment method within those 14 days
Yes

small wharf
#

those last one req idreq_oPdmoeHjGMj9sk

onyx pewter
#

can you try setting payment_behavior to default_incomplete ?

small wharf
#

ok so now its creating subscription but marked as uncompleted and its telling me that it will last for 24 h

onyx pewter
#

yes, so customer will need to provide a payment method in order for the subscription to continue after 24 hours

small wharf
#

can you give me one more advice

#

how can i make some kind of payment sheet from react native to pay for this subscription

onyx pewter
#

It's the same flow as this one
https://stripe.com/docs/payments/accept-a-payment?platform=react-native

except for the part where you get the PaymentIntent from server. Instead of creating a new payment intent in step 3, you'll need to use the PaymentIntent generated by the subscription invoice

you'll find that under subscription.latest_invoice.payment_intent