#dev123 - Customer Portal

1 messages ยท Page 1 of 1 (latest)

pure sedge
#

Hello! Can you reply in this thread instead of the main channel please? ๐Ÿ™‚

#

and i have the return
Uncaught Stripe\Exception\UnexpectedValueException: Could not determine which URL to request:

#

so I don't understand what happen. When I uncomment $checkout_session = \Stripe\Checkout\Session::retrieve($_POST['session_id']); I have a message with wrong session_id. I followed the example from docs, but nothing work

keen anchor
#

ho sorry, ok

keen anchor
#

sory, but I think I have no request id in fact. The error occur before sending the post

pure sedge
#

Which line of code is throwing that error? The \Stripe\BillingPortal\Session::create() call?

keen anchor
#

I suppose, lets'me show you my code if you agree

#

first : php page is : echo '<form action="create-portal-session.php" method="POST">';
// echo '<input type="hidden" id="session-id" name="session_id" value="'.$_SESSION['session_id'].'" />';
echo '<button id="checkout-and-portal-button" type="submit">Manage your billing information</button>';
echo '</form>';

#

and after i have create-portal-session.php

#

like this :
try {
// $checkout_session = \Stripe\Checkout\Session::retrieve($_POST['session_id']);

// Authenticate your user.
$session = \Stripe\BillingPortal\Session::create([
  'customer' => 'cus_KdzgZElr2FQBoC',
  'return_url' => $return_url,
]);
// header("HTTP/1.1 303 See Other");
header("Location: " . $session->url);

} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}

#

so i have the button :
Manage your billing information

#

and when I click on it it give me the error that I don't understand

pure sedge
#

What is $return_url set to?

keen anchor
#

i hard coded customerid for the moment to debug

#

wait a instant please, return_url was commentted...I re-test

#

ok

#

return_url is the same that I use for checkout

#

it is like this :
$return_url = $_SESSION['server'].'/admin/frmAdmin.php?affAdmin=17&aff2=0&codeRetourPaiement=2';

#

but as I am I dev, it'is an ip

#

do you think it should be a problem? Because checkout works

#

precisipn : $_SESSION['server'] give an IP

#

precision : $_SESSION['server'] give an IP

#

for more information here the complet message I have in return

#

<div style='word-break:break-all;white-space:normal;overflow-wrap:break-word;max-width:100%;color: #ff0000'><br />
<b>Fatal error</b>: Uncaught Stripe\Exception\UnexpectedValueException: Could not determine which URL to request: Stripe\Checkout\Session instance has invalid ID: in /datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/ApiResource.php:104
Stack trace:
#0 /datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/ApiResource.php(118): Stripe\ApiResource::resourceUrl()
#1 /datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/ApiResource.php(56): Stripe\ApiResource->instanceUrl()
#2 /datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php(26): Stripe\ApiResource->refresh()
#3 /datas/7Prod/wwwRoot/Sites/demo.wbAdm/admin/extensions/create-portal-session.php(12): Stripe\Checkout\Session::retrieve()
#4 {main}
thrown in <b>/datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/ApiResource.php</b> on line <b>104</b><br />
</div>

#

I tested whithout an ip and instead I put a full qualify domain name => give the same error

pure sedge
#

The error indicates an issue creating a Checkout Session, not a Portal Session.

keen anchor
#

ok,

pure sedge
#

The stack trace says you're trying to retrieve a Checkout Session on line 12 of create-portal-session.php. What is line 12?

keen anchor
#

ok, I think is the cache that remain the line 13

#

// $checkout_session = \Stripe\Checkout\Session::retrieve($_POST['session_id']);

#

it is commented

#

because I don't get it to work correctly, so instead i hard coded id_customer

#

because normaly the could should be like this :
'customer' => $checkout_session->customer,

#

and when I do it I have an other error that the session_id is wrong...

#

If you can help me I tried to uncomment and make it work correctly

pure sedge
#

It sounds like the code running on your server isn't matching the code you're seeing?

keen anchor
#

yes, i gues because the nline 12 in fact was try. I have to refresh the cache.

#

Let me refresh all the cahe, uncomment, try again and give you the original error if you agree ?

bitter jay
#

๐Ÿ‘‹ I'm hopping in since @pure sedge needs to head out - let me know when you've tried it again after refreshing the cache!

keen anchor
#

ok, i do my best, thank you very much for help

#

ok here the new error message

#

<div style='word-break:break-all;white-space:normal;overflow-wrap:break-word;max-width:100%;color: #ff0000'><br />
<b>Fatal error</b>: Uncaught (Status 404) (Request req_J1vvWgkaqEt5YB) Invalid checkout.session id: cs_test_a1fzrGa2ONO5Crsd6hXlHVnIdvD5ynFTvspfEKO4lL1f0G7ytMxmAxKjiU
thrown in <b>/datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php</b> on line <b>38</b><br />
</div>

#

here the new code

#

html :

#

echo '<form action="create-portal-session.php" method="POST">';
echo '<input type="hidden" id="session-id" name="session_id" value="'.$_SESSION['session_id'].'" />';
echo '<button id="checkout-and-portal-button" type="submit">Manage your billing information</button>';
echo '</form>';

#

<?php

require 'vendor/autoload.php';
// This is your real test secret API key.
\Stripe\Stripe::setApiKey('sk_test_51JyZ6lJrWP----------------------------------');

header('Content-Type: application/json');

$YOUR_DOMAIN = 'http://localhost:4242/public/success.html';

try {
$checkout_session = \Stripe\Checkout\Session::retrieve($_POST['session_id']);
$return_url = $YOUR_DOMAIN;

// Authenticate your user.
$session = \Stripe\BillingPortal\Session::create([
'customer' => $checkout_session->customer,
'return_url' => $return_url,
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $session->url);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}

#

ho, sorry, error with your domain...

#

wait i change this to correct value

bitter jay
#

This error is happening because the Checkout Session ID you're passing into retrieve was created by a different account than the one that is trying to retrieve it.

keen anchor
#

ok,

bitter jay
#

I'd suggest checking your code where you create the Checkout Session and verifying it's the same API key as the one that is retrieving

keen anchor
#

ok,

#

here the way i take the session_id with checkout API :

'success_url' => $_SESSION['server'].'/admin/frmAdmin.php?affAdmin=17&aff2=0&codeRetourPaiement=1&session_id={CHECKOUT_SESSION_ID}',

#

and when the sucess_url is reached i do this :

$session_id=$_GET['session_id']; $_SESSION['session_id']=$session_id;

#

because it is not exactly the same page, so i pass it to $_SESSION

bitter jay
#

Yes, but where is your code that is actually creating the Checkout Session?

keen anchor
#

but it works, but give a wrong session_id

#

it seem you are right, the API keys seems to be different. Let me have a new test....

#

no, it is the same result with correct api key in the two php.

#

Yes, but where is your code that is actually creating the Checkout Session? :

$checkout_session = \Stripe\Checkout\Session::create([
'success_url' => $_SESSION['server'].'/admin/frmAdmin.php?affAdmin=17&aff2=0&codeRetourPaiement=1&session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $_SESSION['server'].'/admin/frmAdmin.php?affAdmin=17&aff2=0&codeRetourPaiement=0&session_id={CHECKOUT_SESSION_ID}',
'payment_method_types' => ["card"],

//'mode' => 'payment',
'mode' => 'subscription',
'client_reference_id' => $_SESSION['idMail'],
'customer_email' => $_SESSION['idMail'],
'line_items' => [
  [
    'price' => 'price_1JyZ1YGPrFXOX5m0WAFgkVOs',
    'quantity' => 1,
  ],
], 
'locale' => $locale,

]);

#

why I have a Invalid checkout.session id: ?

#

the session_id begin like that :

cs_test_xxxxxxxxxxxxxxxxxxx

#

it should'nt not be like :

sub_xxxxxxxxxxxxxxxxxx ?<

#

it is a simple question that i ask

bitter jay
#

Let's back up for a second here - you mentioned that you are still seeing the same error. What is the most recent error you're getting?

keen anchor
#

for any reason in the error message there is some css

#

<div style='word-break:break-all;white-space:normal;overflow-wrap:break-word;max-width:100%;color: #ff0000'><br />
<b>Fatal error</b>: Uncaught (Status 404) (Request req_PXSNyTozMRQM4R) Invalid checkout.session id: cs_test_a1lfX8QbRem891WwTitGkhsdNwiMCyiRVend5DiThwctnQWI21QLXJ1nUX
thrown in <b>/datas/7Prod/wwwRoot/Sites/include/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php</b> on line <b>38</b><br />
</div>

bitter jay
#

There still must be some kind of mismatch somewhere because you are still trying to retrieve the Checkout Session cs_test_a1lfX8QbRem891WwTitGkhsdNwiMCyiRVend5DiThwctnQWI21QLXJ1nUX with a completely different account than the one that created it.

keen anchor
#

ok,

#

so you thing wrong API keys ?

bitter jay
#

Yes

keen anchor
#

we agrre it is the : privateSecretStripe ?

#

we agree it is the : privateSecretStripe ?

bitter jay
#

That's entirely up to your code - you really need to do a comprehensive look through how you're setting your API keys and make sure that they match everywhere in your code

keen anchor
#

yes I understand, the 2 api key are hard-coded (for the moment) , and the same. But perhaps a problem with the cache ? I will try again with an other browther, I have no more clue

#

It is the same with an other browser ( chrome)

#

so perhaps the code in the checkout give me a wrong session_id ?

'success_url' => $_SESSION['server'].'/admin/frmAdmin.php?affAdmin=17&aff2=0&codeRetourPaiement=1&session_id={CHECKOUT_SESSION_ID}

Do you think {CHECKOUT_SESSION_ID} is correct ?

bitter jay
#

The CHECKOUT_SESSION_ID being correct is not the issue here - it is 100% guaranteed to be an API key mismatch issue. The account that is making the retrieve call has never successfully created a Checkout Session, so there has to be some other API key in your code somewhere that is creating the sessions

keen anchor
#

ok,

#

I am in France, so it is late in the night and I will go to sleep....In the code for me the 2 private keys are the same, so there is a myster....

bitter jay
#

When you revisit this again tomorrow I'd strongly suggest adding some logging just to verify that everythign is correct

keen anchor
#

yes thank you for advice, and trying helping me !

#

we 'll see this tomorow, hope we find where is the myster....

bitter jay
#

๐Ÿ‘

keen anchor
#

๐Ÿฅฑ Thank you and have a nice day !

bitter jay
#

๐Ÿ‘‹