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

Can't create a subscription plan #252

Closed
cloudgrayau opened this issue Oct 4, 2023 · 3 comments
Closed

Can't create a subscription plan #252

cloudgrayau opened this issue Oct 4, 2023 · 3 comments
Labels

Comments

@cloudgrayau
Copy link

cloudgrayau commented Oct 4, 2023

Description

I am unable to add a subscription plan in Craft CMS. I have connected the Stripe gateway and added the plans in Stripe.

2023-10-04 01:00:21 [web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key "prod_OkopYDnI55jTxu" in /Users/cloudgray/Sites/cloudgray/vendor/craftcms/commerce-stripe/src/base/SubscriptionGateway.php:319

Stack trace:
#0 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/Users/cloudgra...', 319)
#1 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/commerce-stripe/src/base/SubscriptionGateway.php(319): craft\web\ErrorHandler->handleError(2, 'Undefined array...', '/Users/cloudgra...', 319)
#2 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/commerce-stripe/src/base/SubscriptionGateway.php(169): craft\commerce\stripe\base\SubscriptionGateway->getSubscriptionPlans()
#3 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Extension/CoreExtension.php(1607): craft\commerce\stripe\base\SubscriptionGateway->getPlanSettingsHtml(Array)
#4 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/helpers/Template.php(129): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\commerce\stripe\gateways\PaymentIntents), 'getPlanSettings...', Array, 'method', false, false)
#5 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/6c/6c15026ee13c21bf7cdd664efbc82229.php(211): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\commerce\stripe\gateways\PaymentIntents), 'getPlanSettings...', Array, 'method')
#6 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(171): __TwigTemplate_11b536b9ae46435c12ae4a48be1dfebb->block_content(Array, Array)
#7 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/42/42eb15a4248a946a53ab965a5b970fdb.php(645): Twig\Template->displayBlock('content', Array, Array)
#8 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(171): __TwigTemplate_0de4246bd403274546fb05b684736d9c->block_main(Array, Array)
#9 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/42/42eb15a4248a946a53ab965a5b970fdb.php(377): Twig\Template->displayBlock('main', Array, Array)
#10 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(171): __TwigTemplate_0de4246bd403274546fb05b684736d9c->block_body(Array, Array)
#11 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/18/185f9adf97586373fa3335313169410c.php(94): Twig\Template->displayBlock('body', Array, Array)
#12 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(394): __TwigTemplate_34a4d99b91a652bace4a4544cca977f0->doDisplay(Array, Array)
#13 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#14 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/17/17de2de2e9140cf987ed4ab0fced98f3.php(56): Twig\Template->display(Array, Array)
#15 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(394): __TwigTemplate_f9b9604113d7b7261f384fa3d01b1eee->doDisplay(Array, Array)
#16 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#17 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/42/42eb15a4248a946a53ab965a5b970fdb.php(180): Twig\Template->display(Array, Array)
#18 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(394): __TwigTemplate_0de4246bd403274546fb05b684736d9c->doDisplay(Array, Array)
#19 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#20 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/39/39fc035e142b61ef1359e591c1a41ef8.php(45): Twig\Template->display(Array, Array)
#21 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(394): __TwigTemplate_1e7d9abce4f32f2e6d32f93522a1c19a->doDisplay(Array, Array)
#22 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#23 /Users/cloudgray/Sites/cloudgray/storage/runtime/compiled_templates/6c/6c15026ee13c21bf7cdd664efbc82229.php(71): Twig\Template->display(Array, Array)
#24 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(394): __TwigTemplate_11b536b9ae46435c12ae4a48be1dfebb->doDisplay(Array, Array)
#25 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(367): Twig\Template->displayWithErrorHandling(Array, Array)
#26 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Template.php(379): Twig\Template->display(Array)
#27 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/TemplateWrapper.php(40): Twig\Template->render(Array, Array)
#28 /Users/cloudgray/Sites/cloudgray/vendor/twig/twig/src/Environment.php(277): Twig\TemplateWrapper->render(Array)
#29 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/web/View.php(474): Twig\Environment->render('commerce/store-...', Array)
#30 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/web/View.php(527): craft\web\View->renderTemplate('commerce/store-...', Array)
#31 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/web/TemplateResponseFormatter.php(56): craft\web\View->renderPageTemplate('commerce/store-...', Array, 'cp')
#32 /Users/cloudgray/Sites/cloudgray/vendor/yiisoft/yii2/web/Response.php(1100): craft\web\TemplateResponseFormatter->format(Object(craft\web\Response))
#33 /Users/cloudgray/Sites/cloudgray/vendor/craftcms/cms/src/web/Response.php(337): yii\web\Response->prepare()
#34 /Users/cloudgray/Sites/cloudgray/vendor/yiisoft/yii2/web/Response.php(340): craft\web\Response->prepare()
#35 /Users/cloudgray/Sites/cloudgray/vendor/yiisoft/yii2/base/Application.php(390): yii\web\Response->send()
#36 /Users/cloudgray/Sites/cloudgray/web/index.php(12): yii\base\Application->run()
#37 {main} {"memory":48720320,"exception":"[object] (yii\base\ErrorException(code: 2): Undefined array key "prod_OkopYDnI55jTxu" at /Users/cloudgray/Sites/cloudgray/vendor/craftcms/commerce-stripe/src/base/SubscriptionGateway.php:319)"}

Additional info

  • Craft CMS version: 4.5.6.1
  • Stripe for Craft Commerce version: 4.0.1
  • PHP version: 8.2
@cloudgrayau cloudgrayau added the bug label Oct 4, 2023
@cloudgrayau
Copy link
Author

cloudgrayau commented Oct 9, 2023

I found this is related to API changes. Adding 'type'=>'service' in the products API call inside the getSubscriptionPlans() function fixes this.

$products = $this->getStripeClient()->products->all([
'limit' => 100,
'type' => 'service',
'ids' => array_values($planProductMap),
]);

@lukeholder
Copy link
Member

Could you share where type is a param in product queries in the stripe API? https://docs.stripe.com/api/products/list

@cloudgrayau
Copy link
Author

Hello @lukeholder,

It appears to be an issue if your default API version is pre 2018-02-05 as per the notes below. It is probably worth including for anyone whom also runs into this issue in the future. As per the below Stripe upgrade changelog and thread below:

https://docs.stripe.com/upgrades#2018-02-05

https://stackoverflow.com/questions/64752137/node-stripe-products-list-return-empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants