Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to read property "id" on null error when subscribing to a plan #307

Open
tommysvr opened this issue Jul 30, 2024 · 1 comment
Open

Comments

@tommysvr
Copy link

Description

Getting Attempt to read property "id" on null / No payment sources are saved to use for subscriptions as back-to-back errors when subscribing to a plan. I've tested with a fresh Craft/Commerce install using the example templates.

2024-07-29 18:00:46 [web.ERROR] [craft\commerce\stripe\errors\PaymentSourceException] craft\commerce\stripe\errors\PaymentSourceException: No payment sources are saved to use for subscriptions. in /var/www/html/vendor/craftcms/commerce-stripe/src/gateways/PaymentIntents.php:400
Stack trace:
#0 /var/www/html/vendor/craftcms/commerce/src/services/Subscriptions.php(515): craft\commerce\stripe\gateways\PaymentIntents->subscribe(Object(craft\elements\User), Object(craft\commerce\stripe\models\Plan), Object(craft\commerce\stripe\models\forms\Subscription))
#1 /var/www/html/vendor/craftcms/commerce/src/controllers/SubscriptionsController.php(229): craft\commerce\services\Subscriptions->createSubscription(Object(craft\elements\User), Object(craft\commerce\stripe\models\Plan), Object(craft\commerce\stripe\models\forms\Subscription), Array)
#2 [internal function]: craft\commerce\controllers\SubscriptionsController->actionSubscribe()
#3 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('subscribe', Array)
#6 /var/www/html/packages/cms/src/web/Application.php(349): yii\base\Module->runAction('commerce/subscr...', Array)
#7 /var/www/html/packages/cms/src/web/Application.php(650): craft\web\Application->runAction('commerce/subscr...', Array)
#8 /var/www/html/packages/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#9 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#10 /var/www/html/web/index.php(12): yii\base\Application->run()
#11 {main} {"memory":1611016,"exception":"[object] (craft\\commerce\\stripe\\errors\\PaymentSourceException(code: 0): No payment sources are saved to use for subscriptions. at /var/www/html/vendor/craftcms/commerce-stripe/src/gateways/PaymentIntents.php:400)"} 
2024-07-29 18:00:46 [web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Attempt to read property "id" on null in /var/www/html/vendor/craftcms/commerce/src/controllers/SubscriptionsController.php:241
Stack trace:
#0 /var/www/html/packages/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Attempt to read...', '/var/www/html/v...', 241)
#1 /var/www/html/vendor/craftcms/commerce/src/controllers/SubscriptionsController.php(241): craft\web\ErrorHandler->handleError(2, 'Attempt to read...', '/var/www/html/v...', 241)
#2 [internal function]: craft\commerce\controllers\SubscriptionsController->actionSubscribe()
#3 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#5 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('subscribe', Array)
#6 /var/www/html/packages/cms/src/web/Application.php(349): yii\base\Module->runAction('commerce/subscr...', Array)
#7 /var/www/html/packages/cms/src/web/Application.php(650): craft\web\Application->runAction('commerce/subscr...', Array)
#8 /var/www/html/packages/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#9 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#10 /var/www/html/web/index.php(12): yii\base\Application->run()
#11 {main} {"memory":1432968,"exception":"[object] (yii\\base\\ErrorException(code: 2): Attempt to read property \"id\" on null at /var/www/html/vendor/craftcms/commerce/src/controllers/SubscriptionsController.php:241)"} 

Steps to reproduce

  1. Using the example templates, go to My Account -> My Stored Cards
  2. Under 'Add a Card', select Stripe and add payment details
  3. Go to Plans -> Subscribe to a plan
  4. Attempt to read property "id" on null

Note: it works as expected when adding a card via the 'Manage on Stripe' link.

screenshot_2024_07_30._10.10.mp4

Additional info

  • Craft CMS version: 5.2.9
  • Stripe for Craft Commerce version: 5.0.1.1
  • PHP version: 8.2
  • Database driver & version: MySQL 8.0
  • Plugins & versions:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant