#penguin420_
1 messages · Page 1 of 1 (latest)
hey!
Hi, there is no payment_method_types parameter in our Create a subscription API: https://stripe.com/docs/api/subscriptions/create.
what is there then?
That is what the error is and instead use: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings
cause there was in payment intent
- error Error: Received unknown parameter: payment_method_options. Did you mean payment_settings?
On the Payment Intent creation API, https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types we do have that parameter. However, on the Subscirption creation API, it's nested under payment_settings: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-payment_method_types
right done,
- error Error: Received unknown parameters: 0, 1
at StripeError.generate (C:\Users\fuzzb\Downloads\UI update urlcut\urlcut\node_modules\stripe\cjs\Error.js:10:20)
at res.toJSON.then.Error_js_1.StripeAPIError.message (C:\Users\fuzzb\Downloads\UI update urlcut\urlcut\node_modules\stripe\cjs\RequestSender.js:105:54)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
digest: undefined
}
where am i getting this from
nvm
- error Error: 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.
ill check the link
- error Error: No such source: 'card'
how
if (items[0].id === "Personal") {
const customer = await stripe.customers.create({
email: userinfo.email,
name: userinfo.username,
});
const paymentIntent = await stripe.subscriptions.create({
customer: customer.id,
items: [
{
price: "price_1NQGBeL6k3oFrmnnKPdotzOD",
},
],
currency: "gbp",
payment_settings: {
payment_method_types: ["card", "paypal"],
},
default_source: "card",
});
}
does default source go into payment settings object?
That is because you need create the source first. However, that is a legacy approach and you should instead use default_payment_method, https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method. To charge the customer for that subscription, you need to have a payment method saved on the customer (can use a test card: https://stripe.com/docs/testing#cards-responses), or pass in a payment method id: https://stripe.com/docs/api/payment_methods/create.
I like to use this document, https://stripe.com/docs/billing/subscriptions/overview to understand how Subscriptions work. If you pass in the payment method id that is attached to the customer under default_payment_method, it should work.
You can use one of our test cards here: https://stripe.com/docs/testing#cards-responses
Let's back up, what integration documentation are you using?
i used this at firs
// This is your test secret API key.
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const calculateOrderAmount = (items) => {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// people from directly manipulating the amount on the client
return 1400;
};
export default async function handler(req, res) {
const { items } = req.body;
// Create a PaymentIntent with the order amount and currency
const paymentIntent = await stripe.paymentIntents.create({
amount: calculateOrderAmount(items),
currency: "eur",
automatic_payment_methods: {
enabled: true,
},
});
res.send({
clientSecret: paymentIntent.client_secret,
});
};
and that is how easy it was
{clientSecret && (
<Elements options={options} stripe={stripePromise}>
<CheckoutForm />
</Elements>
)}
``` and this is my frontend
I would recommend going through this guide first: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
Which part on the document do you not understand?
I would have to recode? also it is in nodejs not nexjts
look
used to be like that
// This is your test secret API key.
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const calculateOrderAmount = (items) => {
// Replace this constant with a calculation of the order's amount
// Calculate the order total on the server to prevent
// people from directly manipulating the amount on the client
return 1400;
};
export default async function handler(req, res) {
const { items } = req.body;
console.log(items[0].id);
if (items[0].id === "Personal") {
const paymentIntent = await stripe.paymentIntents.create({
amount: calculateOrderAmount(items),
currency: "gbp",
payment_method_types: ["card", "paypal"],
});
res.send({
clientSecret: paymentIntent.client_secret,
});
}
}
and i want it like that
with subscribtions tho
not recoding the whole thing
I do not think you need to recode everything. We don't have a Nextjs example on this guideline, https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements but you can compare the specific steps you've implemented so far.
??
app.post('/create-checkout-session', async (req, res) => {
what is that
i can tell it is nodejs backend but still
const paymentIntent = await stripe.subscriptions.create({
customer: customer.id,
items: [
{
price: "price_1NQGBeL6k3oFrmnnKPdotzOD",
},
],
currency: "gbp",
payment_settings: {
payment_method_types: ["card", "paypal"],
},
});
}
i just want it like this simple
Ah, sorry wrong copy and paste. It's the document I shared ealrier: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
On the server-side, after your create the subscription with status incomplete using payment_behavior=default_incomplete. You'd want to return the client_secret from the subscription’s first payment intent to the frontend to complete payment.
Yea!
thanks!
how can i get this
like credit card or like what they paid with
is it possible not to use webhooks and validate by payment intent secret
cause it seems to change on every payment
You can retrieve the Payment Intent, https://stripe.com/docs/api/payment_intents/retrieve to attain the payment method details used. I do not understand what you mean by 'is it possible not to use webhooks and validate by payment intent secret', can you add more details?
right, so after the user has paid they get redirected to "http://localhost:3000/premium?payment_intent=pi_3NdGy1L6k3oFrmnn1SSCPK6r&payment_intent_client_secret=pi_3NdGy1L6k3oFrmnn1SSCPK6r_secret_R8fbblACQbHn0yEzJpVhFtlWz&redirect_status=succeeded" by the query can i make a request to the backend and validate the payment?
It's intended the client secret changes, it's unique to each Payment Intent: https://stripe.com/docs/payments/payment-intents
What does 'validate' mean here?
to make sure they have paid
and then i can give the user premium
on the backend
so they cannot just go to premium? a random query and get premium
Ah, I see. It's highly recommended that you listen to webhook for Payment Intents that succeeded.
and is it normal to have the same customer cause each time i make a request to the backend it makes one
okay np!
If you do not want to use webhooks, you can retrieve the Payment Intents, https://stripe.com/docs/api/payment_intents/retrieve and look at it's status but that is not scalable.
right why is that not scalable?
Bevause you're making requests each time to retirve the Payment Intent, and when you grow 10X, you put way too much load on making these requests.
ahh i see!
The reason why you have a customer created each time is because on your server-code you're asking to create a customer. Instead, if you already have a customer, you can pass in teh customer id: https://stripe.com/docs/api/subscriptions/create#create_subscription-customer when creating the subscription and only create a new customer if you need to.
You can use Stripe CLI to test: https://stripe.com/docs/stripe-cli webhooks and this document has instructions on how to set this up/ install the CLI.
Thank you very much!
Happy to help!
it works perfect!!! thanks alot for your time and help!
Sure, have a great day!