#leonardo-charge-flow

1 messages · Page 1 of 1 (latest)

elder shadow
#

@hollow hearth here

hollow hearth
#

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']);
elder shadow
#

what's the error?

hollow hearth
#

"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"
}

elder shadow
#

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?

hollow hearth
#

this was initially workign when we used destination charges

#

but we wanted to switch to direct charges

elder shadow
#

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()?

hollow hearth
#

Let me check

#

We dont think so

#

this is what we are getting

#

we could upload a online version

elder shadow
#

sure but how are you getting to that page?

#

What code to you use to load Checkout's URL?

hollow hearth
#

ill show you

elder shadow
#

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

hollow hearth
#

(we are checking what you just said)

elder shadow
#

yeah all of that is PHP code

hollow hearth
#

hang on, ill write it again

elder shadow
#

you seem to return the whole Session from PHP back to the client (you shouldn't!)

hollow hearth
#

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); }); });

elder shadow
#

Just to help: please when you pipe so much code wrap it between three ` on both sides

hollow hearth
#

oh, i was looking fo that

elder shadow
#

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

#
  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

hollow hearth
#

Understood, we'll try the first option right now

#

we were definitely not doing that

elder shadow
#

@hollow hearth are you unblocked?

hollow hearth
#

We were able to do an opération, yes

#

sorry for the delay, the message was unsent

#

All good for now, thanks a lot for the help koopajah