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

Cannot set the period limit #196

Closed
handhikadj opened this issue Aug 8, 2023 · 1 comment
Closed

Cannot set the period limit #196

handhikadj opened this issue Aug 8, 2023 · 1 comment

Comments

@handhikadj
Copy link

handhikadj commented Aug 8, 2023

I can't find any reference on how to set the period limit.
This will monthly-bill the user endlessly:

public function buildCashierPlan(): Plan
    {
        $plan = new Plan($this->name);

        $amount = [
            'value' => 50.00,
            'currency' => 'EUR'
        ];

        return $plan->setAmount(mollie_array_to_money($amount))
            ->setInterval('1 month')
            ->setDescription('Pay description')
            ->setFirstPaymentMethod([])
            ->setFirstPaymentAmount(mollie_array_to_money($amount))
            ->setFirstPaymentDescription('Pay description')
            ->setFirstPaymentRedirectUrl(config('app.front_end_url') . '/premium?success=true')
            ->setFirstPaymentWebhookUrl(config('cashier.first_payment.webhook_url'));
    }

related: laravel/cashier-mollie#115
any reference / workaround?

@Naoray
Copy link
Collaborator

Naoray commented Aug 9, 2023

Hi @handhikadj,

I’ve noted down that the times-feature is highly requested and I will work on it as soon as possible.

Meanwhile you can implement a workaround yourself by

  1. Implementing your own Plan Model which offers a times column -> I believe based on your code piece, that you followed the examples from the docs on how to load your plans from the database. Only thing that you has to change is to let your Plan model implement the \Laravel\Cashier\Plan\Contracts\Plan contract
  2. Add a times column to your Subscription model
  3. Listen to OrderPaymentPaid and increment your Subscription’s times column with $event->order->orderItems->first()->orderable->increment(’times’)
  4. Instead of calling cashier::run from your console kernel directly, you have to create your own job/command which (1) queries Subscriptions, (2) checks if there plan’s times equals the subscription’s times
use Laravel\Cashier\Cashier;
use App\Models\Subscription;

Subscription::whereActive()
    ->cursor()
    ->each(function (Subscription $subscription) {
        if ($subscription->times === $subscription->plan()->times) {
            $subscription->cancel();
        }
    });

Cashier::run();

If you have questions, please let me know!

@Naoray Naoray closed this as completed Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants