-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
Description
Hi, I have a templated form for payment source to save. the form is default from Craft Commerce templates. I also connected the stripe keys and webhook properly from my Stripe sandbox account and I can able to purchase a product.
I am having error while saving my payment source/card on front-end form but I can see the setup_intent from the logs on my stripe account.
I am trying to save my payment source using this form code.
<form id="gateway-{{ gateway.id }}" method="post" action="">
{{ csrfInput() }}
{{ actionInput("commerce/payment-sources/add") }}
{{ hiddenInput("gatewayId", gateway.id) }}
{{ redirectInput("/account/store-cards") }}
{{ hiddenInput("savePaymentSource", 1) }}
{% namespace 'paymentForm' %}
{{ gateway.getPaymentFormHtml({})|raw }}
{% endnamespace %}
<label id="save-new-card">
{{ input('checkbox', 'savePaymentSource', 1, {
class: ['inline-block', 'mr-1']
}) }}
{{ 'Save card for future purchases'|t }}
</label>
<div class="checkout-address-form-input set-as-primary">
<label>
{{ input('checkbox', 'isPrimaryPaymentSource', 1) }} {{ 'Set as primary payment source?'|t }}
</label>
</div>
<div class="mt-4 text-right checkout-bottom-navigation d-block">
{{ tag('button', {
type: 'submit',
class: 'cursor-pointer rounded px-4 py-2 inline-block bg-red-500 hover:bg-red-600 text-white hover:text-white',
text: 'Add card'|t
}) }}
</div>
</form>
I got the error on front-end "Could not create the payment source." and here is the error on the error log
The resource ID cannot be null or whitespace.
{"trace":["#0 /httpdocs/vendor/craftcms/commerce/src/services/PaymentSources.php(271): craft\\commerce\\stripe\\gateways\\PaymentIntents->createPaymentSource()",
"#1 /httpdocs/vendor/craftcms/commerce/src/controllers/PaymentSourcesController.php(67): craft\\commerce\\services\\PaymentSources->createPaymentSource()",
"#2 [internal function]: craft\\commerce\\controllers\\PaymentSourcesController->actionAdd()",
"#3 /httpdocs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()",
"#4 /httpdocs/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams()",
"#5 /httpdocs/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction()",
"#6 /httpdocs/vendor/craftcms/cms/src/web/Application.php(348): yii\\base\\Module->runAction()",
"#7 /httpdocs/vendor/craftcms/cms/src/web/Application.php(647): craft\\web\\Application->runAction()",
"#8 /httpdocs/vendor/craftcms/cms/src/web/Application.php(310): craft\\web\\Application->_processActionRequest()",
"#9 /httpdocs/vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest()",
"#10 /httpdocs/web/index.php(22): yii\\base\\Application->run()",
"#11 {main}"],
"memory":36118688,"exception":"[object] (craft\\commerce\\stripe\\errors\\PaymentSourceException(code: 0): The resource ID cannot be null or whitespace. at /httpdocs/vendor/craftcms/commerce-stripe/src/gateways/PaymentIntents.php:381)"}
Steps to reproduce
- Install Craft Commerce and Stripe for Craft Commerce Plugin
- Create a front-end add payment form using the form templated mentioned above
- Connect your Stripe Sandbox keys and connect to your Stripe gateway at Commercer Settings
- On front-end form, save the dummy card details
Card number: 4242 4242 4242 4242
Expiration: 12 / 33
CVC 123
Additional info
- Craft CMS version: PRO 4.15.0.2
- Stripe for Craft Commerce version: 4.1.7
- Craft Commerce: 4.8.3
- PHP version: 8.3.21
- Database driver & version: MariaDB 10.5.26