Closed carolineboeykens closed 5 years ago
I found the issue. Our test account on Stripe didn't have any products or plans yet, so the subscription plan from Commerce only found itself and this got the error.
Thanks for the investigation! I plan to address a few subscription issues for this plugin tomorrow, so I'll see if I can pick this one up as well!
After playing around with this, it seems like the best way to handle this. Just throw an exception. To clarify, this would happen only when you changed the gateway type to Stripe but didn't provide any new information for the plan name, so Commerce tried to query Stripe about the dummy subscription plan.
All in all a very rare circumstance, so for now I feel like throwing an exception there is not a bad move per se.
When we try to link our Stripe Gateway to the subscription plan it throws an error:
`Stripe\Error\InvalidRequest: No such plan: dummy.reference in /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiRequestor.php:210 from API request 'req_Vj65oZDbgjruFv' Stack trace:
0 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiRequestor.php(173): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
1 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiRequestor.php(473): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array)
2 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiRequestor.php(126): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray))
3 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiResource.php(62): Stripe\ApiRequestor->request('get', '/v1/plans/dummy...', Array, Array)
4 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php(24): Stripe\ApiResource->refresh()
5 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/commerce-stripe/src/gateways/Gateway.php(511): Stripe\Plan::retrieve('dummy.reference')
6 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/commerce/src/controllers/PlansController.php(109): craft\commerce\stripe\gateways\Gateway->getSubscriptionPlanByReference('dummy.reference')
7 [internal function]: craft\commerce\controllers\PlansController->actionSavePlan()
8 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
9 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
10 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('save-plan', Array)
11 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-plan', Array)
12 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('commerce/plans/...', Array)
13 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/cms/src/web/Application.php(561): craft\web\Application->runAction('commerce/plans/...', Array)
14 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
15 /Users/carolineboeykens/Documents/Sites/seaplb/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
16 /Users/carolineboeykens/Documents/Sites/seaplb/public/index.php(21): yii\base\Application->run()
17 {main}`
The api credentials for the Stripe Gateway are filled in.
Craft: 3.1.16 Commerce Lite: 2.1.0.2 Commerce Stripe: 1.1.0