#SupraLP

1 messages · Page 1 of 1 (latest)

lime crownBOT
granite arrow
#

Can you share the screenshot of the error?

rustic harness
#

is there any mistake in my code?

granite arrow
#

It should include the line number and you should be able to click it so where the problem is

rustic harness
#

oh sorry my mistake i will send it correctly

granite arrow
#

Click that link on the right

#

It will show you where in your code the issue is

rustic harness
#

it doesnt do anything if I click it

#

ohhh now

granite arrow
#

Your code doesn't look right though. Why did you insert a semicolon before success_url?

rustic harness
rustic harness
#

but my error is still there

red veldt
#

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: {}
}]
rustic harness
#

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

red veldt
#

But yeah, price_data won't work with redirectToCheckout regardless of syntax

rustic harness
#

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);
  }
});
red veldt
rustic harness
#

so I code with a Server side language called Coldfusion. and the documentation doesnt tell me much how to do it in coldfusion :/

red veldt
#

That's PHP, right?

rustic harness
#

its a server side language but not php

#

thats why its so hard to do it like in the documentation

red veldt
#

Ah. It should be adaptable as long as you can make HTTP requests from it (you don't need to use our client libs)

rustic harness
#

like looking example: is it index.html oder payment.html right?

red veldt
#

Not sure I understand

rustic harness
#

easy explained: a request that gives you the HTTP path right?

red veldt
#

No, I mean your CF server needs to be able to make a HTTP request to our API to create the Checkout Session

red veldt
rustic harness
#

like somthing like that?

httpService.setMethod("post");
httpService.setCharset("utf-8");
httpService.setUrl("https://www.google.com/accounts/ClientLogin");

red veldt
#

I've no idea, I'm not familiar with CF at all I'm afraid

rustic harness
#

yeah i'm a beginner too :/

red veldt
rustic harness
#

so I read the Documentation, that means I have to add every product from our shop to my dashboard?

red veldt
rustic harness
#

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

red veldt
#

No, you can use price_data as stated (and shown at the URL above). customer is not required, no

rustic harness
#

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'],
        ],
      ],
    ],
  ]
);
red veldt
rustic harness
#

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',
]);
red veldt
#

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)

rustic harness
#
$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

red veldt
#

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

rustic harness
#

I could use this code in JS or do I need a server-side language for that?

red veldt
#

This needs to be server-side (Node.js would work)

rustic harness
#

so thats means in my case I need to write it in coldfusion right?

red veldt
rustic harness
#

alright i try to translate ist to coldfusion and will write you(in this discord) if I have any more trouble