#JCoDog-checkout-prefill

1 messages · Page 1 of 1 (latest)

supple axle
#

Hello, what issues are you having?

#

If there is not a customer ID, you can only prefill their email I believe

mellow pawn
#

I cannot find anything to send Data from my site to the checkout to create a user against. i have a Name I want to save to reference a discord user

supple axle
#

Though if you have those, you can create a customer object with them and pass the ID of that in

#

To preset the email you can pass it in to the customer_email parameter and if you have a Customer object for them you can pass the Customer ID in to the customer parameter

mellow pawn
#

So there is no way to set their name to their username from my site?

supple axle
#

You can set that on the customer object if you want

mellow pawn
#

But when I dont have a customer object, how can I do that?

supple axle
#

But keep in mind, the name in the Checkout Session is supposed to be the name on the card

mellow pawn
#

Nevermind then, can I set a customer nickname?

#

Or just use that method through my website alone?

supple axle
#

Not sure I understand your second question. Can you rephrase?

mellow pawn
#

Ok but how do I set customer metadata within the session

#

In checkout...

supple axle
#

Unfortunately that can't be done with the Checkout Session. But if you are already server-side making calls and have this info, you can create a Customer object with that data and pass in its ID to the Session::create call

mellow pawn
#

I dont... I have only the checkout session made...

#

So I am assuming that they would have to provide the email and username themselves and then i can collect the ID and store it against their website user account instead

#

The only issue I have then is, within the success URL how would I call the response to get the ID?

supple axle
#

Yes that data would have to be collected outside of the session unfortunately. It might make sense to have your flow request that information upfront so you can have it when you need it

mellow pawn
#

How do I get information such as customer ID response from the session within the success url?

#

Do I need to swap one time payments to webhooks?

supple axle
mellow pawn
#

Yes, thank you.

#

Do i just put the {CHECKOUT_SESSION_ID} in as I have some php objects in it

supple axle
#

Put it in where?

mellow pawn
#

the url...

#

I assume it is this?

supple axle
#

Yep, that will work

mellow pawn
#

So this should be fine then?

#

And this should be how I retrieve the customer?

supple axle
#

That looks good to me. Have you tried running it?

mellow pawn
#

I just swapped to test

#

It doesnt work

supple axle
#

Which part goes wrong?

mellow pawn
#
if ($product == 'buyVerify') {
  $_SESSION['code'] = $code;

  // live price price_1Jm2SYEOJsqRXL0Rm2xIZkZI
  // test price price_1K2GvGEOJsqRXL0R7vj4Lyvq

  $result = mysqli_query($conn, "SELECT * FROM customers WHERE ID ='".$_SESSION['userID']."'");

  if ($result) {
    $num_rows = mysqli_num_rows($result);
    $userDB = mysqli_fetch_all($result, MYSQLI_ASSOC);
    $stripeSession = \Stripe\Checkout\Session::create([
      'payment_method_types' => [
        'card',
      ],
      'line_items' => [[
        # TODO: replace this with the `price` of the product you want to sell
        'price' => 'price_1K2GvGEOJsqRXL0R7vj4Lyvq',
        'quantity' => 1,
        'description' => "JCoNet Digital ID verification fee. Payment gets you one(1) token to verify your identity and age on your JCN Digital ID via our supplier (Stripe Identity)"
      ]],
      'mode' => 'payment',
      'customer' => $userDB[0]['stripeID'],
      'success_url' => $YOUR_DOMAIN . '/idfunctions.php?status=SUCCESS&code='.$code.'&session_id={CHECKOUT_SESSION_ID}',
      'cancel_url' => $YOUR_DOMAIN . '/idfunctions.php?status=CANCEL&code='.$code,
    ]);
  } else {
    $stripeSession = \Stripe\Checkout\Session::create([
      'payment_method_types' => [
        'card',
      ],
      'line_items' => [[
        # TODO: replace this with the `price` of the product you want to sell
        'price' => 'price_1K2GvGEOJsqRXL0R7vj4Lyvq',
        'quantity' => 1,
        'description' => "JCoNet Digital ID verification fee. Payment gets you one(1) token to verify your identity and age on your JCN Digital ID via our supplier (Stripe Identity)"
      ]],
      'mode' => 'payment',
      'success_url' => $YOUR_DOMAIN . '/idfunctions.php?status=SUCCESS&code='.$code.'&tocreate=TRUE&session_id={CHECKOUT_SESSION_ID}',
      'cancel_url' => $YOUR_DOMAIN . '/idfunctions.php?status=CANCEL&code='.$code,
    ]);
  };
} elseif ($product == 'Verify') {
  $_SESSION['code'] = $code;
  $stripeSession = $stripe->identity->verificationSessions->create([
    'type' => 'document',
    'options' => [
      'document' => [
        'require_matching_selfie' => true,
      ],
    ],
    'return_url' => $YOUR_DOMAIN.'/idfunctions.php?status=VERIFIED&code='.$code,
    'metadata' => [
      'user_id' => $_SESSION['userID'],
    ],
  ]);
};

header("HTTP/1.1 303 See Other");
header("Location: " . $stripeSession->url);```
#

I dont know as there is no error shown, it just isnt redirecting. And I have a customer ID in my database...

supple axle
#

Can you see if it is getting to the end of your server side code that tries to redirect?

mellow pawn
#

hmm

#

I can try

#

Yeah, still erroring but now I can see an error.

supple axle
#

So what line is that json parse error happening on?

mellow pawn
#

No clue just checking

#

It isnt even echoing the result

#

Its to do with how I contruct the stripe session

#

Ok fixed that issue... But it isnt showing any customer info

supple axle
#

What was the customer ID that you supplied?

mellow pawn
#

I am using my live version as I have my ID from when I was last a customer

#

cus_KhfzKiBmXMI12G

#

pi_3K2HJiEOJsqRXL0R0IlQQZQY shows no customer

#

Neither of these are showing

#

I noticed that when I pass in the actual customer ID and Email it fails. But when I remove the [0] from userDB and customerDB it doesnt actually show results

#

To get customer ID I have to do $customerDB[0]['stripeID']

supple axle
#

How is it failing when you pass in the customer ID?

mellow pawn
#

if I remove the [0] it passes in nothing

#

and works

#

it is completely the issue of customer ID when it is passed in as a string.

#

'customer' => $customerDB[0]['stripeID'], is this how to set customer?

supple axle
#

Should be. Can you try just using the string literal 'cus_123' and see if that works?

mellow pawn
#

ok

supple axle
#

Also you should only have to pass in either customer or customer_email

mellow pawn
#

yes just passed in customer ID and it worked

#

Why isnt it working with the db access?

#

I had to set the database value to a variable instead of using the $customerDB array itself

supple axle
#

Nice! So when you set the value like that, it is all working?

mellow pawn
#

YES

supple axle
#

Looks fine to me

#

Removed that screenshot because it has your secret key in it. This is a public channel so we don't want other people taking/using your secret key

mellow pawn
#

yep forgot about that lol

#

Something in here has stopped my entire return page from working

#

Basically a success and cancel didnt work

supple axle
#

So you are getting redirected and then what happens on your server?

mellow pawn
#

nothing

#

its not even processing anything

#

Yeah I put an echo at every step and the page is not loading them

supple axle
#

So the browser is getting redirected but you aren't seeing your server get hit at all?

mellow pawn
#

nope

supple axle
#

If you open the browser console do you see any errors?

mellow pawn
split cedar
#

catching up here one sec @mellow pawn

mellow pawn
mellow pawn
split cedar
#

that is a 500 returned from your backend endpoint, no?

mellow pawn
#

yes

#

So there is something in my code causing the error and I cannot find it nor can my debug tool

split cedar
#

ok could you summarize your question then? a 500 from your own code would be something you debug on your end

#

add additional log statements

#

and step through your code

#

until you find it hits line X but not Y

mellow pawn
#

There is no echo to the page

#

I tried to log errors

split cedar
#

there should be a crash/exception in your server-side logs

mellow pawn
#

There isnt

#

I just have the things in concole.

#

fixed it...

#

i forgot a .

#

@split cedar Just got an error with this code

split cedar
#

ah great!

mellow pawn
#

Why is the retrieved information not showing?

#

ffs... autocomplete doesnt know the stripe api and put session before customer when there isnt a retrieved variable of session that has a variable of customer in it.

split cedar
#

yeah autocomplete can make things hard like that

#

or lack of

mellow pawn
#

Ok that is everything with that session. Now to replicate it for subscriptions. Thanks anyways.

split cedar
#

np

mellow pawn
#

I assume that once someone changes something on portal it is fine?

#

And any changes to the subscription go to the webhook for subscriptions?

split cedar
#

can you rephrase, not sure I understand

mellow pawn
#

I have subscription set up to customer portal. Any changes they make are handled by the subscription webhook and I dont need to handle any returned portal data outside of the webhook correct?

split cedar
#

can you explain? not sure I understand your question