#rajput.abd_22
1 messages ยท Page 1 of 1 (latest)
hello! I'd suggest going through this guide for how to create Subscriptions : https://stripe.com/docs/billing/quickstart
Once the customer's default payment method is saved, you wouldn't need to have the customer input the card details again
but i want to do like recurring that why i am using subscription
can i share my code here
sure
I wrote the below code for creating the new subscription. I also want payment to be accepted while subscription is being created. But as i read stripe doc there is user action is needed but i want to proceed any user action because users already perform an action while enrollment.module.export...
please check this
please paste whatever information you would like to share here in this channel
we won't open a Google doc to read any information inside
okay
module.exports.createProduct = async (clientFullName, nickname) => {
return await stripe.products.create({
name: ${clientFullName}-${nickname},
description: This product is for ${nickname} clientName: ${clientFullName}
});
}
module.exports.createPrice = async (nickname, amount, currency, productId, recurring = {}) => {
console.log("๐ ~ file: common.js:825 ~ module.exports.createPrice= ~ amount:", amount)
// let unit_amount = (parseFloat(amount) * 100).toFixed(2)
// console.log("๐ ~ file: common.js:828 ~ module.exports.createPrice= ~ unit_amount:", unit_amount)
console.log(typeof amount);
amount = parseFloat(amount);
console.log("๐ ~ file: common.js:830 ~ module.exports.createPrice= ~ amount:", amount)
console.log(typeof amount);
return await stripe.prices.create({
nickname: nickname,
unit_amount: parseInt(amount * 100),
currency: currency,
product: productId,
...recurring
})
}
module.exports.createSubscriptions = async (data) => {
const { customerId, description, items, add_invoice_items } = data;
return await stripe.subscriptions.create({
customer: customerId,
description: description,
items: items,
add_invoice_items: add_invoice_items,
payment_settings: {
payment_method_options: {
card: {
request_three_d_secure: 'any',
},
},
payment_method_types: ['card'],
save_default_payment_method: 'on_subscription',
},
expand: ['latest_invoice.payment_intent'],
});
}
module.exports.createSubscriptionOnUgradePlan = async (customerId, clientFullName, subscriptionAmount, interval) => {
const nickname = interval == constants.priceRecurringTimePeriod.MONTH ? 'Stikkum Monthly' : 'Stikkum Yearly'
const product = await exports.createProduct(clientFullName, nickname);
const recurringSubscription = await exports.createPrice(${clientFullName}-${nickname} PlatForm Amount, subscriptionAmount, currency, product.id, { recurring: { interval: interval } });
const subscription = await exports.createSubscriptions({
customerId: customerId,
description: `${clientFullName} ${nickname} Subscription`,
items: [{ price: recurringSubscription.id }],
});
console.log("๐ ~ file: common.js:886 ~ module.exports.createSubscriptionOnStripe= ~ subscription:", subscription);
return subscription;
}
Please check now
what do you want me to check?
subscription is created with status: 'incomplete', but want it to created as succeceed
Hi! I'm taking over this thread.
what extra i need to do this
Can you share the Subscription ID (sub_xxx)?