#SupraLP
1 messages · Page 1 of 1 (latest)
Can you share the screenshot of the error?
It should include the line number and you should be able to click it so where the problem is
Your code doesn't look right though. Why did you insert a semicolon before success_url?
oh I didnt see that one. i think its just a copy paste mistake
but my error is still there
You can't use price_data (ad-hoc) prices with client-only Checkout: https://stripe.com/docs/js/deprecated/redirect_to_checkout#stripe_checkout_redirect_to_checkout-options-lineItems
It's deprecated too, I'd recommend switching to a server integration or Payment Links
But yes, the syntax of your code is wrong. You have:
lineItems: [[
price_data: []
]]
When in reality with server Checkout it would be:
line_items: [{
price_data: {}
}]
oh yeah thats what i thought. I got the code from another supporter but it was written in PHP and I tried to translate it in JS
But yeah, price_data won't work with redirectToCheckout regardless of syntax
so I need to use this code right here:
// Call your backend to create the Checkout Session
fetch('/create-checkout-session', {
method: 'POST',
})
.then(function(response) {
return response.json();
})
.then(function(session) {
return stripe.redirectToCheckout({ sessionId: session.id });
})
.then(function(result) {
// If `redirectToCheckout` fails due to a browser or network
// error, you should display the localized error message to your
// customer using `error.message`.
if (result.error) {
alert(result.error.message);
}
});
Yes, a server-side Checkout integration: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout
so I code with a Server side language called Coldfusion. and the documentation doesnt tell me much how to do it in coldfusion :/
That's PHP, right?
its a server side language but not php
thats why its so hard to do it like in the documentation
Ah. It should be adaptable as long as you can make HTTP requests from it (you don't need to use our client libs)
like looking example: is it index.html oder payment.html right?
Not sure I understand
easy explained: a request that gives you the HTTP path right?
No, I mean your CF server needs to be able to make a HTTP request to our API to create the Checkout Session
This step: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#redirect-customers
The /create-checkout-session endpoint in this snippet
like somthing like that?
httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://www.google.com/accounts/ClientLogin");
I've no idea, I'm not familiar with CF at all I'm afraid
yeah i'm a beginner too :/
Have you tried Payment Links? They're a drop-in, no-code solution that replaces redirectToCheckout: https://stripe.com/docs/payments/payment-links
so I read the Documentation, that means I have to add every product from our shop to my dashboard?
With Payment Links, yes. If you need to use inline pricing then you'll need to create a Checkout Session on your server: https://stripe.com/docs/products-prices/pricing-models#variable-pricing
but with a checkout session I need the customerid and the Price_ID from the dashboard right?
and that means I need to insert all products from our shop to the dashboard
No, you can use price_data as stated (and shown at the URL above). customer is not required, no
do you mean that code?
$stripe = new \Stripe\StripeClient('sk_test_51LuWsXFb62et6iQJ4AxT7yQWsNmrxHBSdGsLPnI1PXZJeia8FumIW9uFG8dwosyTjnadDUn3Ojm66R2uHO61TjAo00QwL4L60Y');
$stripe->subscriptions->create(
[
'customer' => '{{CUSTOMER_ID}}',
'items' => [
[
'price_data' => [
'unit_amount' => 5000,
'currency' => 'usd',
'product' => '{{PRODUCT_ID}}',
'recurring' => ['interval' => 'month'],
],
],
],
]
);
Well, similar. That's for a subscription. You'd adapt it to for Checkout Sessions. Here's the API ref: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
so something like that?
$stripe = new \Stripe\StripeClient(
'sk_test_51LuWsXFb62et6iQJ4AxT7yQWsNmrxHBSdGsLPnI1PXZJeia8FumIW9uFG8dwosyTjnadDUn3Ojm66R2uHO61TjAo00QwL4L60Y'
);
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
'mode' => 'payment',
]);
Yes, but rather than price you'd use price_data (otherwise you'd need to create the Prices in the Dashboard ahead of time, which you don't want to do)
$stripe = new \Stripe\StripeClient(
'sk_test_51LuWsXFb62et6iQJ4AxT7yQWsNmrxHBSdGsLPnI1PXZJeia8FumIW9uFG8dwosyTjnadDUn3Ojm66R2uHO61TjAo00QwL4L60Y'
);
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'cancel_url' => 'https://example.com/cancel',
'line_items' => [
[
price_data: [
product_data: [
name: 'testname'
],
unit_amount: 1,
currency: "chf"
],
quantity: 1,
],
],
'mode' => 'payment',
]);
so something like that?
sorry for the bad formating
Yes, that looks right (probably want to bump unit_amount, it's in the lowest currency denominator, I guess cents?)
e.g. €1 === unit_amount: 100
I could use this code in JS or do I need a server-side language for that?
This needs to be server-side (Node.js would work)
so thats means in my case I need to write it in coldfusion right?
Yes, as stated:
No, I mean your CF server needs to be able to make a HTTP request to our API to create the Checkout Session
alright i try to translate ist to coldfusion and will write you(in this discord) if I have any more trouble