craftcms / commerce-stripe

Stripe payment gateway for Craft Commerce
https://plugins.craftcms.com/commerce-stripe
MIT License
30 stars 50 forks source link

HTTP 400 Bad Request , Request contains invalid body param #122

Closed paulmendrik closed 1 year ago

paulmendrik commented 4 years ago

I have an issue which after updating to Craft 3.5. The Craft Commerce Stripe plugin was working fine before the update but now I'm getting a HTTP 400 Bad Request , Request contains invalid body param. I'm using the following to create the payment form:

{{ csrfInput() }} {{ cart.gateway.getPaymentFormHtml({})|raw }}

Finally checking the logs in stripe it gives a 200 O.K. without finalising the payment.

Any ideas ?

saltymouse commented 3 years ago

I'm getting the same error using the default Commerce templates, specifically: build/shop/checkout/payment.twig.

With the aforementioned default payment.twig form, the following error occurs with "Dummy" gateway as well as "Commerce Stripe" gateway:

HTTP 400 – Bad Request – yii\web\BadRequestHttpException
Request contained an invalid body param
Error Stacktrace
yii\web\BadRequestHttpException: Request contained an invalid body param in /var/www/html/vendor/craftcms/cms/src/web/Request.php:934
Stack trace:
#0 /var/www/html/vendor/craftcms/commerce/src/controllers/PaymentsController.php(352): craft\web\Request->getValidatedBodyParam('redirect')
#1 [internal function]: craft\commerce\controllers\PaymentsController->actionPay()
#2 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#4 /var/www/html/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('pay', Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('pay', Array)
#6 /var/www/html/vendor/craftcms/cms/src/web/Application.php(279): yii\base\Module->runAction('commerce/paymen...', Array)
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(582): craft\web\Application->runAction('commerce/paymen...', Array)
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(258): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#9 /var/www/html/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#10 /var/www/html/web/index.php(21): yii\base\Application->run()
#11 {main}
Sent POST Request
action  "commerce/payments/pay"
redirect    "768c85bdff99460d1be190a42cb116f4c0696be30cf3261b15c0a6cb93175458//kiwi-shop.ddev.site:3000/shop/customer/order?number=7623c8e3dfdec4431060a348f078030f&success=true"
cancelUrl   "9e6bafc76d62bba91db76ea7dc65edd61b5a61366b7951debab5afdb6f9d0325//kiwi-shop.ddev.site:3000/shop/checkout/payment"
orderEmail  "jenny@andrews.net"
CRAFT_CSRF_TOKEN    "VMjPq-725MKsLFIKTWtNhPXaq47qhsLzK9k5kNktCosRkiCDgeRAMjmXh-2Lt770_GlkcyIyBce2su_DvtCRqVuYe8-UYmLGc81X9_enA3c="
gatewayId   "1"
firstName   "Jenny"
lastName    "Andrews"
number  "4242424242424242"
expiry  "01/2023"
cvv "123"
registerUserOnOrderComplete ""

However, rewriting the payment.twig form according to the latest docs does work ("Commerce Stripe" gateway):

<form method="post">
    {{ csrfInput() }}
    {{ actionInput('commerce/payments/pay') }}
    {{ redirectInput('/shop/customer/order?number={number}') }}
    {{ hiddenInput('cancelUrl', '/commerce/checkout/payment'|hash) }}

    {{ cart.gateway.getPaymentFormHtml({})|raw }}

    <button type="submit">Pay Now</button>
</form>

For now, I'm just using the form in the docs, but it'd be nice to solve any problems with the default templates form. Let me know if any more info is required for debugging.

OS version Linux 5.10.25-linuxkit (DDEV) PHP 8.0.3 • MySQL 5.5.5 Craft CMS 3.6.13 • Craft Commerce 3.3.1 • Stripe for Craft Commerce 2.3.2.1

pdaleramirez commented 1 year ago

Updating to Commerce 3 latest example templates should resolve this issue.