-1

I'm building this with Wave, which is just kit type thing that implements a few things that you need to get a SaaS off the ground quickly...one of the things it has configured is Paddle. Unfortunately it does not have an option to where if a user cancels their membership, it allows them to finish out their paid period instead of removing access right away. So I'm trying to add this. I can see in the Paddle docs that the id for this in a received webhook payload is cancellation_effective_date. Here is the relevant bit of the cancel button function that I'm adding to:

private function cancelSubscription( $subscription_id){
$subscription = PaddleSubscription::where('subscription_id', $subscription_id)->first();
$subscription->cancelled_at = Carbon::now();
$subscription->status = 'cancelled';
$subscription->save();

I've tried splicing in both of these, just trying to deduce the syntax but I'm wrong, and I can't figure out why. It said I need to define the variable when I do this, but I cannot figure out how to do this.

$subscription->cancellation_effective_date = $request->cancellation_effective_date;

$subscription->cancellation_effective_date = $cancellation_effective_date;

Any suggestions?

Here is the full file if anyone needs to see it. https://github.com/thedevdojo/wave/blob/main/wave/src/Http/Controllers/SubscriptionController.php

Here is a sample payload return from Paddle

Array
(
[alert_id] => 1282370466
[alert_name] => subscription_cancelled
[cancellation_effective_date] => 2023-04-10
[checkout_id] => 9-d11a2ef3289d6c8-ccdeb4a3ad
[currency] => EUR
[custom_data] => custom_data
[email] => irunolfsdottir@example.net
[event_time] => 2023-04-05 20:13:54
[linked_subscriptions] => 7, 2, 7
[marketing_consent] => 1
[passthrough] => Example String
[quantity] => 18
[status] => deleted
[subscription_id] => 6
[subscription_plan_id] => 8
[unit_price] => unit_price
[user_id] => 1
]

Thank you

1 Answers1

0

here is how i would do it:

-first make a migration to add a column (cancellation_effective_date) to the subscription table

-then override the SubscriptionController class, specifically the public webhook method and the cancelSubscription method, the latter will become:

$this->cancelSubscription($subscription_id, $request->cancellation_effective_date);

now you are ready to save the effective date to the db.

suxgri
  • 86
  • 3