#JCoDog-checkout-prefill
1 messages · Page 1 of 1 (latest)
Hello, what issues are you having?
If there is not a customer ID, you can only prefill their email I believe
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
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
This is for the session creation call https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer_email
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 there is no way to set their name to their username from my site?
You can set that on the customer object if you want
But when I dont have a customer object, how can I do that?
But keep in mind, the name in the Checkout Session is supposed to be the name on the card
Nevermind then, can I set a customer nickname?
Or just use that method through my website alone?
You can set it as metadata on the customer https://stripe.com/docs/api/customers/create#create_customer-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Not sure I understand your second question. Can you rephrase?
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
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?
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
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?
You can add session_id={CHECKOUT_SESSION_ID} to the Session's success_url, when your customer gets redirected to that, the session's ID will filled out so you can use that to look up the session's info https://stripe.com/docs/payments/checkout/custom-success-page
Yes, thank you.
Do i just put the {CHECKOUT_SESSION_ID} in as I have some php objects in it
Put it in where?
Yep, that will work
That looks good to me. Have you tried running it?
Which part goes wrong?
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...
Can you see if it is getting to the end of your server side code that tries to redirect?
So what line is that json parse error happening on?
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
What was the customer ID that you supplied?
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']
The request I see for the session that created pi_3K2HJiEOJsqRXL0R0IlQQZQY did not pass the customer ID in as a param https://dashboard.stripe.com/logs/req_84zSX1b0Y9HbPr
How is it failing when you pass in the customer ID?
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?
Should be. Can you try just using the string literal 'cus_123' and see if that works?
ok
Also you should only have to pass in either customer or customer_email
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
Nice! So when you set the value like that, it is all working?
YES
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
yep forgot about that lol
Something in here has stopped my entire return page from working
Something in this breaks the page
Basically a success and cancel didnt work
So you are getting redirected and then what happens on your server?
nothing
its not even processing anything
Yeah I put an echo at every step and the page is not loading them
So the browser is getting redirected but you aren't seeing your server get hit at all?
nope
If you open the browser console do you see any errors?
catching up here one sec @mellow pawn
Its this code causing my entire response from checkout not to work.
that is a 500 returned from your backend endpoint, no?
yes
So there is something in my code causing the error and I cannot find it nor can my debug tool
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
there should be a crash/exception in your server-side logs
There isnt
I just have the things in concole.
fixed it...
i forgot a .
@split cedar Just got an error with this code
ah great!
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.
Ok that is everything with that session. Now to replicate it for subscriptions. Thanks anyways.
np
I assume that once someone changes something on portal it is fine?
And any changes to the subscription go to the webhook for subscriptions?
can you rephrase, not sure I understand
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?
can you explain? not sure I understand your question