#leonardo-charge-flow
1 messages · Page 1 of 1 (latest)
Hi Koo
This is our code currently
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => Config::PRODUCT_NAME,
'images' => [Config::PRODUCT_IMAGE],
'quantity' => 1,
'amount' => $unitAmount,
'currency' => Config::CURRENCY,
]],
'payment_intent_data' => [
'application_fee_amount' => '5767',
],
'mode' => 'payment',
'success_url' => 'https://www.masteroftraditions.com/thank-you-page?session_id=%7BCHECKOUT_SESSION_ID%7D',
'cancel_url' => Config::ROOT_PATH . '/index.php?status=cancel',
], ['stripe_account' => 'acct_1JNPFPGcEhH2TiWT']);
what's the error?
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such payment_page: 'cs_live_a1vtr9328PgZONgZdTemydYaVEQMEc8rN32He09BmJozcXf2LXwksmJ7Qd'",
"param": "payment_page",
"type": "invalid_request_error"
}
The code above creates a Session, that works, since you get the Session id
something else is causing the error, some other code that is trying to retrieve the Session maybe?
this was initially workign when we used destination charges
but we wanted to switch to direct charges
sure sure but it's not the PHP code that you shared the problem
another part of your code is crashing
are you doing client-side redirect with redirectToCheckout()?
Let me check
We dont think so
this is what we are getting
we could upload a online version
sure but how are you getting to that page?
What code to you use to load Checkout's URL?
ill show you
My guess is that client-side, in Javascript, you call redirectToCheckout and you have initialized Stripe.js with the wrong API key (the platform's) and forgot to also pass the connected account id in the stripeAccount option
(we are checking what you just said)
yeah all of that is PHP code
hang on, ill write it again
you seem to return the whole Session from PHP back to the client (you shouldn't!)
i found the redirectocheckout
Recapping:
we have the following ajax code
`namespace Phppot;
use Phppot\StripeService;
use Phppot\StripePayment;
$orderReferenceId = rand(100000, 999999);
require_once DIR . "/../lib/StripeService.php";
require_once DIR .'/../Common/Config.php';
require_once DIR . '/../lib/StripePayment.php';
$stripePayment = new StripePayment();
$stripeService = new StripeService();
$currency = Config::CURRENCY;
//$orderId = $stripePayment->insertOrder(Config::PRODUCT_PRICE, $currency, $orderReferenceId, "Payment in-progress");
$unitAmount = Config::PRODUCT_PRICE * 100;
$session = $stripeService->createCheckoutSession($unitAmount, 1);
echo json_encode($session);`
that calls to the javascript:
checkoutButton.addEventListener('click', function() { fetch('ajax-endpoint/create-checkout-session.php', { method: 'POST', }) .then(function(response) { return response.json(); }) .then(function(session) { return stripe.redirectToCheckout({ sessionId: session.id }); }) .then(function(result) { if (result.error) { alert(result.error.message); } }) .catch(function(error) { console.error('Error:', error); }); });
Just to help: please when you pipe so much code wrap it between three ` on both sides
oh, i was looking fo that
Right now, your code is trying to redirect to Checkout for a session on the platform but the Session exists on the connected account instead
you need to change the way you initialize Stripe.js (none of the code you shared) so that you explicitly configure it for the right connected account as documented in https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application
stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
});```
wherever your code loads Stripe, you need to tweak it
Alternatively, and way easier, stop doing a JS redirect. The Session has a url property and you can redirect server-side in PHP, way faster/easier. But you can't use a fetch() client-side anymore, you need a form submission instead
Understood, we'll try the first option right now
we were definitely not doing that
@hollow hearth are you unblocked?