Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

StartSubscription error concerning owner #24

Closed
peterjaap opened this issue Jun 29, 2019 · 8 comments
Closed

StartSubscription error concerning owner #24

peterjaap opened this issue Jun 29, 2019 · 8 comments

Comments

@peterjaap
Copy link

The first payment webhook throws this error;

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'owner_id' cannot be null (SQL: insert into `order_items` (`owner_id`, `owner_type`, `process_at`, `currency`, `unit_price`, `quantity`, `tax_percentage`, `description`, `orderable_id`, `orderable_type`, `updated_at`, `created_at`) values (?, ?, 2019-06-29 14:16:40, EUR, 650, 1, 0, 6 Month Subscription, 6, Laravel\Spark\Subscription, 2019-06-29 14:30:34, 2019-06-29 14:30:34))

This data is filled in \Laravel\Cashier\SubscriptionBuilder\MandatedSubscriptionBuilder::create;

            $subscription = $this->owner->subscriptions()->create([
                'name' => $this->name,
                'plan' => $this->plan->name(),
                'quantity' => $this->quantity,
                'tax_percentage' => $this->owner->taxPercentage() ?: 0,
                'trial_ends_at' => $this->trialExpires,
                'cycle_started_at' => $now,
                'cycle_ends_at' => $this->nextPaymentAt,
            ]);

The fields owner_id and owner_type are missing here. When I add them, everything works;

            $subscription = $this->owner->subscriptions()->create([
                'name' => $this->name,
                'plan' => $this->plan->name(),
                'quantity' => $this->quantity,
                'owner_type' => get_class($this->owner),
                'owner_id' => $this->owner->id,
                'tax_percentage' => $this->owner->taxPercentage() ?: 0,
                'trial_ends_at' => $this->trialExpires,
                'cycle_started_at' => $now,
                'cycle_ends_at' => $this->nextPaymentAt,
            ]);
@sandervanhooft
Copy link
Collaborator

Hi Peter,

Thanks for opening this ticket.

The polymorphic subscriptions() relationship (via the Billable trait) should be taking care of setting the owner_id and owner_type.

Is there any reason the id would be inaccessible in your case?

@peterjaap
Copy link
Author

Woops, totally skipped over the step where I needed to add Laravel\Cashier\Billable to the User model. My implementation is a bit different since I'm implementing it in Spark. Thanks!

@sandervanhooft
Copy link
Collaborator

👍 Thanks for following up!

@sandervanhooft
Copy link
Collaborator

Also, we're looking into Spark support, but it will not work out of the box.

Cashier for Stripe/Braintree have a lot of explicit switches each and settings in the Spark codebase.

Also, the redirect behaviour of Cashier Mollie requires some further Spark adjustments.

@peterjaap
Copy link
Author

Yep I'm pretty much done with all of those. Spark also has a migration for the subscriptions table, which we don't need now (this tripped me up at first, since it has a user_id column instead or owner_type and owner_id combo).

@peterjaap
Copy link
Author

peterjaap commented Jun 29, 2019

FYI, here are the files I've modified (so which needed switches etc for Mollie);

resources/views/vendor/spark/settings/subscription/subscribe-address.blade.php
resources/views/vendor/spark/settings/subscription/subscribe-common.blade.php
app/Providers/SparkServiceProvider.php
resources/js/spark-components/bootstrap.js
resources/views/vendor/spark/settings.blade.php
resources/views/vendor/spark/settings/payment-method.blade.php
resources/views/vendor/spark/settings/subscription/subscribe-address.blade.php
resources/views/vendor/spark/settings/subscription/subscribe.blade.php

Here are the files I added;

resources/js/spark-components/settings/payment-method-mollie.js
resources/js/spark-components/settings/subscription/subscribe-mollie.js
resources/js/spark-components/settings/subscription/subscribe-mollie.js
resources/views/vendor/spark/settings/payment-method-mollie.blade.php
resources/views/vendor/spark/settings/subscription/subscribe-mollie.blade.php

@peterjaap
Copy link
Author

All in all, thanks for all your work 🎉

@sandervanhooft
Copy link
Collaborator

Feel free to follow-up on E-mail: info@sandervanhooft.com I can keep you in the loop from there on any not-yet official developments, if any :).

Thanks for sharing! You too! 🎉

sandervanhooft added a commit to sandervanhooft/cashier-mollie that referenced this issue Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants