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

Bug when one-time setup fee to subscriptions is 0 #45

Closed
aelvan opened this issue Sep 7, 2019 · 1 comment
Closed

Bug when one-time setup fee to subscriptions is 0 #45

aelvan opened this issue Sep 7, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@aelvan
Copy link

aelvan commented Sep 7, 2019

Description

This commit introduces a critical bug that breaks Stripe Checkout in 2.0.4 if there is no setup fee for a sca enabled, single plan subscription. The bug happens in when the create-checkout-session controller action is called, and the error in the javascript console is "Invalid positive integer".

The error in the log with the stacktrace is:

2019-09-07 22:12:01 [-][16577][-][error][Stripe\Error\InvalidRequest] Stripe\Error\InvalidRequest: Invalid positive integer in /mypath/vendor/stripe/stripe-php/lib/ApiRequestor.php:210 from API request 'req_XXXXX'
Stack trace:
#0 /mypath/vendor/stripe/stripe-php/lib/ApiRequestor.php(173): Stripe\ApiRequestor::_specificAPIError('{\n  "error": {\n...', 400, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#1 /mypath/vendor/stripe/stripe-php/lib/ApiRequestor.php(473): Stripe\ApiRequestor->handleErrorResponse('{\n  "error": {\n...', 400, Object(Stripe\Util\CaseInsensitiveArray), Array)
#2 /mypath/vendor/stripe/stripe-php/lib/ApiRequestor.php(126): Stripe\ApiRequestor->_interpretResponse('{\n  "error": {\n...', 400, Object(Stripe\Util\CaseInsensitiveArray))
#3 /mypath/vendor/stripe/stripe-php/lib/ApiOperations/Request.php(57): Stripe\ApiRequestor->request('post', '/v1/checkout/se...', Array, Array)
#4 /mypath/vendor/stripe/stripe-php/lib/ApiOperations/Create.php(23): Stripe\ApiResource::_staticRequest('post', '/v1/checkout/se...', Array, NULL)
#5 /mypath/vendor/enupal/stripe/src/services/Checkout.php(111): Stripe\Checkout\Session::create(Array)
#6 /mypath/vendor/enupal/stripe/src/controllers/CheckoutController.php(39): enupal\stripe\services\Checkout->createCheckoutSession(Object(enupal\stripe\elements\PaymentForm), Array)
#7 [internal function]: enupal\stripe\controllers\CheckoutController->actionCreateSession()
#8 /mypath/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /mypath/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /mypath/vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('create-session', Array)
#11 /mypath/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('create-session', Array)
#12 /mypath/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('enupal-stripe/c...', Array)
#13 /mypath/vendor/craftcms/cms/src/web/Application.php(566): craft\web\Application->runAction('enupal-stripe/c...', Array)
#14 /mypath/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#15 /mypath/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#16 /mypath/web/index.php(21): yii\base\Application->run()
#17 {main}

Here is a dump of the parameters passed to Session::create($sessionParams) in line 112 of Checkout.php:

[
    'payment_method_types' => [
        0 => 'card'
    ]
    'success_url' => 'http://mydomain.test/enupal/stripe-payments/finish-order?session_id={CHECKOUT_SESSION_ID}'
    'cancel_url' => 'http://mydomain.test/user/cancel'
    'subscription_data' => [
        'items' => [
            0 => [
                'plan' => 'plan_FlAu6aKKl9v3fM'
                'quantity' => 1
            ]
        ]
        'metadata' => [
            'stripe_payments_form_id' => '54268'
            'stripe_payments_user_id' => '16577'
            'stripe_payments_quantity' => 1
            'stripe_payments_coupon_code' => ''
            'stripe_payments_amount_before_coupon' => '9900'
        ]
    ]
    'line_items' => [
        0 => [
            'amount' => 0
            'currency' => 'NOK'
            'name' => 'One time set-up fee'
            'quantity' => 1
        ]
    ]
    'customer' => 'cus_XXXXX'
    'locale' => 'auto'
]

The problem is most likely this conditional which will always be true, because the value if set to 0, is '0.000'.

Steps to reproduce

(Again, see my other issues)

Additional info

  • Craft version: 3.3.1.1
  • PHP version: 7.3.8
  • Database driver & version: Mysql 5.7.26
  • Plugin version: 2.0.4
@andrelopez andrelopez self-assigned this Sep 7, 2019
@andrelopez andrelopez added the bug Something isn't working label Sep 7, 2019
@andrelopez
Copy link
Member

Hi @aelvan we just released v2.0.5 with a fix to this issue.

Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants