enupal / stripe

Allows customers sign up for recurring and one-time payments with Stripe, perfect for orders, donations, subscriptions, and events. Create simple payment forms in seconds easily without coding. For Craft CMS
https://enupal.com/craft-plugins/stripe-payments/
Other
33 stars 19 forks source link

Unable to display subscription details after updating #262

Closed williamhibberd closed 2 years ago

williamhibberd commented 2 years ago

Description

After updating to the latest version I am now unable to display user subscription details with the following code:

{% if subscriptions|length %}
    <div class="detail">
        <h2 class="headingMedium">My Subscription{{ subscriptions|length > '1' ? 's' }}</h2>
        {% for order in subscriptions %}
            {% set subscription = order.getSubscription() %}
            {% set formData = order.getFormFields() %}
            <div class="subscription">
                <div class="table">
                    {% set planNickName = subscription.planNickName %}
                    {% if planNickName|length %}
                    <div class="grid-noBottom">
                        <div class="col_sm-8">Subscription Plan</div>
                        <div class="col_sm-4 align-right">{{ planNickName }}</div>
                    </div>
                    {% endif %}
                    <div class="grid-noBottom">
                        <div class="col_sm-8">Subscription Status</div>
                        <div class="col_sm-4 align-right">{{ subscription.status }}</div>
                    </div>
                    <div class="grid-noBottom">
                        <div class="col_sm-8">Subscription Ref</div>
                        <div class="col_sm-4 align-right">{{ order.number }}</div>
                    </div>
                    {% if formData|length %}
                        {% for handle, value in formData if value is not iterable %}
                            <div class="grid-noBottom">
                                <div class="col_sm-8">{{ handle|replace('_', ' ') }}</div>
                                <div class="col_sm-8 align-right">{{ value }}</div>
                            </div>
                        {% endfor %}
                    {% endif %}
                    <div class="grid-noBottom">
                        <div class="col_sm-8">Subscription Period Start</div>
                        <div class="col_sm-4 align-right">{{ subscription.startDate|date('d/m/y') }}</div>
                    </div>
                    <div class="grid-noBottom">
                        <div class="col_sm-8">Subscription Period End</div>
                        <div class="col_sm-4 align-right">{{ subscription.endDate|date('d/m/y') }}</div>
                    </div>
                </div>
            </div>
        {% endfor %}
        <form method="POST" action="/enupal-stripe/customer-portal">
            {{ csrfInput() }}
            <input type="hidden" name="returnUrl" value="{{ siteUrl('/account') }}">
            <button class="button" type="submit">Manage subscription{{ subscriptions|length > '1' ? 's' }}</button>
        </form>
    </div>
{% endif %}

Stack Trace

yii\base\ErrorException: Trying to access array offset on value of type null in /app/vendor/enupal/stripe/src/models/Subscription.php:58 Stack trace:

0 {main}

Additional info

williamhibberd commented 2 years ago

This is a fairly big issue for one of my client sites as subsubscibers are unable to change their subscriptions. @andrelopez any idea of when there may be a fix coming?

Thanks

andrelopez commented 2 years ago

Hi @williamhibberd could you please share the code on how do you get the subscriptions variable on your example?

williamhibberd commented 2 years ago
{% set subscriptions = craft.enupalStripe.getSubscriptionsByUser(currentUser.id) %}
andrelopez commented 2 years ago

Hi @williamhibberd We just released Stripe Payments v3.4.2 with a fix to this issue. Thanks for reporting.

Be aware that this issue could be potentially caused due that the subscription was deleted on the Stripe Dashboard, so the subscription model will return empty for almost all the properties.

williamhibberd commented 2 years ago

Hi @andrelopez I am running into this issue again... I'm getting the subscriptions and looping though them in the same way as before.

Additional info

Craft version: 3.7.47.1
PHP version: 8.1.8
Database driver & version: MySQL 8.0.22
Plugin version: 4.0.6
Is [SCA](https://docs.enupal.com/stripe-payments/getting-started/sca.html) and Stripe Checkout enabled?: Yes

Stack trace:

yii\base\ErrorException: Trying to access array offset on value of type null in /home/forge/marthadelacey.com/vendor/enupal/stripe/src/models/Subscription.php:87
Stack trace:
#0 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/ErrorHandler.php(84): yii\base\ErrorHandler->handleError()
#1 /home/forge/marthadelacey.com/vendor/enupal/stripe/src/models/Subscription.php(87): craft\web\ErrorHandler->handleError()
#2 /home/forge/marthadelacey.com/vendor/enupal/stripe/src/models/Subscription.php(51): enupal\stripe\models\Subscription->getNickNames()
#3 /home/forge/marthadelacey.com/vendor/enupal/stripe/src/services/Subscriptions.php(72): enupal\stripe\models\Subscription->__construct()
#4 /home/forge/marthadelacey.com/vendor/enupal/stripe/src/elements/Order.php(775): enupal\stripe\services\Subscriptions->getSubscriptionModel()
#5 /home/forge/marthadelacey.com/vendor/twig/twig/src/Extension/CoreExtension.php(1566): enupal\stripe\elements\Order->getSubscription()
#6 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute()
#7 /home/forge/marthadelacey.com/storage/runtime/compiled_templates/2f/2fe5dc6b19ad2ea753e2c7f2c1c95177.php(280): craft\helpers\Template::attribute()
#8 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(405): __TwigTemplate_0ea5cc6eb7b22d79ea5c191072d66a38->doDisplay()
#9 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#10 /home/forge/marthadelacey.com/storage/runtime/compiled_templates/78/78152a04462ddd885f10ba86433082ae.php(127): Twig\Template->display()
#11 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(182): __TwigTemplate_8ee07b1991d2d03e5f1b6050013dbb72->block_content()
#12 /home/forge/marthadelacey.com/storage/runtime/compiled_templates/2c/2c3a9655893d1ac54c19c7352c5548be.php(128): Twig\Template->displayBlock()
#13 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(405): __TwigTemplate_7f7298d917e490c7f167e6ec4b538f32->doDisplay()
#14 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#15 /home/forge/marthadelacey.com/storage/runtime/compiled_templates/78/78152a04462ddd885f10ba86433082ae.php(55): Twig\Template->display()
#16 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(405): __TwigTemplate_8ee07b1991d2d03e5f1b6050013dbb72->doDisplay()
#17 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#18 /home/forge/marthadelacey.com/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#19 /home/forge/marthadelacey.com/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render()
#20 /home/forge/marthadelacey.com/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render()
#21 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/View.php(408): Twig\Environment->render()
#22 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/View.php(461): craft\web\View->renderTemplate()
#23 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/Controller.php(201): craft\web\View->renderPageTemplate()
#24 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/controllers/TemplatesController.php(102): craft\web\Controller->renderTemplate()
#25 [internal function]: craft\controllers\TemplatesController->actionRender()
#26 /home/forge/marthadelacey.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#27 /home/forge/marthadelacey.com/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#28 /home/forge/marthadelacey.com/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#29 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction()
#30 /home/forge/marthadelacey.com/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction()
#31 /home/forge/marthadelacey.com/vendor/craftcms/cms/src/web/Application.php(278): yii\web\Application->handleRequest()
#32 /home/forge/marthadelacey.com/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#33 /home/forge/marthadelacey.com/web/index.php(22): yii\base\Application->run()
#34 {main}