Skip to content
New issue

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

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

Already on GitHub? # to your account

Cannot sync Stripe payment sources "Cannot assign null to property PaymentSource::$customerId of type int" #316

Closed
hayhaydz opened this issue Jan 10, 2025 · 3 comments

Comments

@hayhaydz
Copy link

hayhaydz commented Jan 10, 2025

Description

An error is occurring whilst trying to run a payment sources sync after we have migrated to a new Stripe account. All previous Stripe customers were migrated across with some new ones added (not by Craft CMS/Commerce). It seems to hit an error because some Stripe customers don't have a valid Craft CMS customer ID but that is just my assumption.

Steps to reproduce

  1. Run payment source sync console command
    su-exec www-data php craft commerce-stripe/sync/payment-sources Which gateway would you like to sync payment sources for? (stripe,?): stripe This will sync down all payment sources in your Stripe account, and create inactive local users if one is not found for that customer’s email. If you are using testing keys, your development environment may end up with inconsistent customer information. Do you want to continue? (yes|no) [no]:yes Syncing... Error: Cannot assign null to property craft\commerce\models\PaymentSource::$customerId of type int

2025-01-10 17:57:12 [console.ERROR] [TypeError] Cannot assign null to property craft\commerce\models\PaymentSource::$customerId of type int {"trace":["#0 /var/www/project/cms/vendor/craftcms/commerce-stripe/src/services/PaymentMethods.php(51): craft\\commerce\\stripe\\base\\SubscriptionGateway->handlePaymentMethodUpdated(Array)","#1 /var/www/project/cms/vendor/craftcms/commerce-stripe/src/console/controllers/SyncController.php(61): craft\\commerce\\stripe\\services\\PaymentMethods->syncAllPaymentMethods(Object(craft\\commerce\\stripe\\gateways\\PaymentIntents))","#2 [internal function]: craft\\commerce\\stripe\\console\\controllers\\SyncController->actionPaymentSources()","#3 /var/www/project/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)","#4 /var/www/project/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)","#5 /var/www/project/cms/vendor/yiisoft/yii2/console/Controller.php(180): yii\\base\\Controller->runAction('payment-sources', Array)","#6 /var/www/project/cms/vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\\console\\Controller->runAction('payment-sources', Array)","#7 /var/www/project/cms/vendor/craftcms/cms/src/console/Controller.php(216): craft\\console\\Controller->traitRunAction('payment-sources', Array)","#8 /var/www/project/cms/vendor/yiisoft/yii2/base/Module.php(552): craft\\console\\Controller->runAction('payment-sources', Array)","#9 /var/www/project/cms/vendor/yiisoft/yii2/console/Application.php(180): yii\\base\\Module->runAction('commerce-stripe...', Array)","#10 /var/www/project/cms/vendor/craftcms/cms/src/console/Application.php(91): yii\\console\\Application->runAction('commerce-stripe...', Array)","#11 /var/www/project/cms/vendor/yiisoft/yii2/console/Application.php(147): craft\\console\\Application->runAction('commerce-stripe...', Array)","#12 /var/www/project/cms/vendor/craftcms/cms/src/console/Application.php(122): yii\\console\\Application->handleRequest(Object(craft\\console\\Request))","#13 /var/www/project/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\\console\\Application->handleRequest(Object(craft\\console\\Request))","#14 /var/www/project/cms/craft(27): yii\\base\\Application->run()","#15 {main}"],"memory":35228608,"exception":"[object] (TypeError(code: 0): Cannot assign null to property craft\\commerce\\models\\PaymentSource::$customerId of type int at /var/www/project/cms/vendor/craftcms/commerce-stripe/src/base/SubscriptionGateway.php:735)"}

Additional info

  • Craft CMS version: 4.12.6.1
  • Stripe for Craft Commerce version: 4.1.5
  • PHP version: 8.0.13
  • Database driver & version: MariaDB 11.2.6
  • Plugins & versions:
    • Amazon SES 2.1.0
    • Chunked File Uploads 2.0.3
    • Cloner 2.0.4
    • CP Field Inspect 1.4.4
    • Craft Commerce 4.6.13
    • Embedded Assets 4.1.2
    • Expanded Singles 2.0.5
    • Formie 2.1.31
    • Imager X 4.4.1
    • Incognito Field 1.3.0
    • MJML 2.0.2
    • Redactor 3.1.0
    • Stripe for Craft Commerce 4.1.5
    • Tags 2.0.0
    • Vizy 2.1.23
@lukeholder
Copy link
Member

Thanks for reporting, I have fixed this for the next release.

To get the fix early, change your craftcms/commerce-stripe requirement in composer.json to:

"require": {
  "craftcms/commerce-stripe": "5.x-dev#1442e77821d8ba0ee789769d94f166d5cb69c41a as 5.0.4.3",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release is out.

@lukeholder lukeholder reopened this Feb 2, 2025
@lukeholder
Copy link
Member

This was release in 5.0.4.4, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants