#satyra1
1 messages · Page 1 of 1 (latest)
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.
- satyra1, 1 hour ago, 26 messages
Can you send me your code for how you are creating these subscriptions?
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;
};```
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
its failing but if i add subscription via dashboard its working fine
What's failing exactly?
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('');
});
What error are you getting?
the same one?
can you share a request ID?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support site provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
StripeInvalidRequestError: This customer has no attached payment source or default payment method. Please consider adding a default payment method. For more information, visit https://stripe.com/docs/billing/subscriptions/payment-methods-setting#payment-method-priority.
req_V5yKigxl052mEN
did you try what my colleague suggested here?
#1176178357117927464 message
ill try in a sec but how it will look like if it works
it should create a subscription
i am getting this warning ```Type '"allow_incomplete"' is not assignable to type 'CollectionMethod | undefined'.ts(2322)
Apologies, I said collection_behavior but should have said payment_behavior
Set payment_behavior
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
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
those last one req idreq_oPdmoeHjGMj9sk
ok so now its creating subscription but marked as uncompleted and its telling me that it will last for 24 h
yes, so customer will need to provide a payment method in order for the subscription to continue after 24 hours
can you give me one more advice
how can i make some kind of payment sheet from react native to pay for this subscription
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