Closed bryantwells closed 8 months ago
For anyone having a similar issue and looking for a cleaner fix, I was able to get this working by creating a new module and tying into the buildGatewayRequest
event
use craft\commerce\models\Transaction;
use craft\commerce\stripe\events\BuildGatewayRequestEvent;
use craft\commerce\stripe\gateways\PaymentIntents;
use yii\base\Event;
use craft\helpers\UrlHelper;
Event::on(
PaymentIntents::class,
PaymentIntents::EVENT_BUILD_GATEWAY_REQUEST,
function(BuildGatewayRequestEvent $e) {
/** @var Transaction $transaction */
$transaction = $e->transaction;
$order = $transaction->getOrder();
$e->request['cancel_url'] = UrlHelper::baseUrl() . $order->cancelUrl;
}
);
@bryantwells I think the issue is the formatting of your URL and hash.
You're using:
{{ hiddenInput('cancelUrl', currentSite.baseUrl ~ '/checkout'|hash) }}
Which gives an output of:
<input type="hidden" name="cancelUrl" value="https://yoursite.com/[hash]/checkout">
Instead you need to format your URL so that the hash is added in the right place, for example:
{{ hiddenInput('cancelUrl', siteUrl('/checkout')|hash) }}
{# Or url('/checkout')|hash or maybe just (currentSite.baseUrl ~ '/checkout')|hash #}
That should give you a correct output like:
<input type="hidden" name="cancelUrl" value="[hash]https://yoursite.com/checkout">
At least I can confirm this is working correctly for me.
Closed as confirmed the hashing of the URL was not done on the whole value. Thanks @pixelmachine
Description
Stripe Checkout does not work as outlined in the docs. It seems Craft requires a relative path for a Cancel URL, which is incompatible with Stripe's requirement of an HTTPS Cancel URL.
Steps to reproduce
Scenario 1
Results in Stripe error: "Not a Valid URL"
Scenario 2
Results in Craft error: "Request contained an invalid body param"
Fix?
I was only able to get this to work by changing line 537 in
PaymentIntents.php
:Additional info