mollie / laravel-cashier-mollie

Official Mollie integration for Laravel Cashier
https://www.cashiermollie.com/
MIT License
136 stars 44 forks source link

Is there any support for Team subscription? #241

Closed roy-at-binate closed 5 months ago

roy-at-binate commented 5 months ago

My requirement is:

Let's assume i am a Team leader and i have purchased a subscription. Now, what i want is by using my subscription plan (which I've purchased already) all of my team members can use the application. They don't need to buy the plan separately.

So, is there any way to do that?

sandervanhooft commented 5 months ago

Hi @roy-at-binate,

For managing team subscriptions you'd typically apply the Billable trait to a Team model instead of the User.

roy-at-binate commented 5 months ago

Hi @roy-at-binate,

For managing team subscriptions you'd typically apply the Billable trait to a Team model instead of the User.

Thanks for the reply @sandervanhooft But if I add Billable to Team then who will be responsible to buy the subscription?

Naoray commented 5 months ago

Hi @roy-at-binate,

But if I add Billable to Team then who will be responsible to buy the subscription?

That's up to the developer to implement. Imagine you setup your App to include a Team that has the Billable trait. You could setup a team owner similar to Laravel Jetstream's approach. Then you would only allow the team owner to manage the billing details for the team and create the subscription.


public function createSubscription(Team $team)
{
        // authorizing through Policies
        abort_unless($user->can('create', Subscription::class));

        return $team
              ->newSubscription('subscription_name', 'plan_name')
              ->create();
}

Hope that helps.

roy-at-binate commented 5 months ago

Thanks @Naoray that's what i actually did

And the whole subscription flow is now working properly except the issue about charging $1 while purchasing any plan. Actually when i am redirecting user to the checkout page from REACT app it charges $1 though the price was $40.99

Naoray commented 5 months ago

@roy-at-binate glad I could help you out.

Regarding the charging issue. Can you provide the code sample that's executed when you charge the user and also your cashier_plans and cashier config files, please?

roy-at-binate commented 5 months ago

@Naoray Thanks for quick response :)

I am initiating the payment from controller like this:

$result = $user->newSubscription($cashier['slug'], $cashier['plan'])
            ->trialDays(config('project.subscription.trial_days', 7))
            ->quantity($request->get('quantity'))
            ->create();

if(is_a($result, RedirectToCheckoutResponse::class)) {
    return ResponseHelper::success('Payment initiation done!', $this->service->getPaymentInitResponse($result), 302);
}

And i have also attached the cashier.php and cashier_plans.php file as you want :) cashier.txt cashier_plans.txt

Naoray commented 4 months ago

@roy-at-binate, you uploaded the cashier_plans config twice.

Anyways, I likely figured out why you only charge $1 for your first charge: You most likely haven't altered the cashier.first_payment.amount config value, have you? This is a default value that is applied for the first payment. This value can be overriden per plan by adding a firstPaymentAmount config to each plan.

plans' => [
        // SMALL TEAM
        'small-team-monthly' => [

              'firstPaymentAmount' => [
                  'value' => '100.00',
                  'currency' => 'EUR',
              ],
              //...
        ],
]

I don't like the current implementation of this functionality and will note it down to improve it for future releases.

Hope it didn't cause too much trouble!!!