laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
245 stars 57 forks source link

Fix resume #206

Closed driesvints closed 11 months ago

driesvints commented 11 months ago

Fixes an issue with resuming paused subscriptions which are still in their pause grace period. Also adds the ability to pick the moment in time when the resume should take place.

karlomikus commented 11 months ago

I did some more testing in paddle sandbox.

Testing pauseNow, then resume - works. Testing pauseNow then resume with future date - works.

Only one not working is basic pause then resume. But it looks like if effective_from is set to null it will default to next_billing_period (in docs), while if explicitly set to next_billing_period paddle returns an 500 error.

My suggestion is then to change onPausedGracePeriod condition to this:

elseif ($this->onPausedGracePeriod()) {
    $effectiveFrom = null;
}

Otherwise, lgtm

Sorry for spamming with this :|

driesvints commented 11 months ago

Sorry for spamming with this :|

This is the opposite of spamming. This feedback is very useful, thank you 👍

But it looks like if effective_from is set to null it will default to next_billing_period (in docs)

Where do you see this? The docs show this as an allowed value:

Screenshot 2023-11-28 at 17 18 47

while if explicitly set to next_billing_period paddle returns an 500 error.

You mean the Paddle API is returning a 500 error?

I really think we're missing something as next_billing_period should be an allowed value. I'll get Paddle to have a look as well.

karlomikus commented 11 months ago

I'll post some examples with request info, it's also possible I'm doing something wrong.

I have the following subscription with schedules change to pause:

{
    "data": {
        "id": "sub_01hgb819ys16n3trpgtfcbvng7",
        -- snip --
        "status": "active",
        "created_at": "2023-11-28T15:16:19.545Z",
        "updated_at": "2023-11-28T16:55:14.194Z",
        "started_at": "2023-11-28T15:16:17.961971Z",
        "first_billed_at": "2023-11-28T15:16:17.961971Z",
        "next_billed_at": null,
        "paused_at": null,
        "canceled_at": null,
        "collection_mode": "automatic",
        "billing_details": null,
        "current_billing_period": {
            "starts_at": "2023-11-28T15:43:32.54Z",
            "ends_at": "2023-12-28T15:43:32.54Z"
        },
        "billing_cycle": {
            "frequency": 1,
            "interval": "month"
        },
        "scheduled_change": {
            "action": "pause",
            "effective_at": "2023-12-28T15:43:32.54Z",
            "resume_at": null
        },
        -- snip --
    },
    "meta": {
        "request_id": "8d16bd30-b2ea-4e92-bd3b-3dbb5fcb935d"
    }
}

If I do POST request to /subscriptions/sub_01hgb819ys16n3trpgtfcbvng7/resume with the following body:

{
    "effective_from": "next_billing_period"
}

I get the following response:

{
    "error": {
        "type": "api_error",
        "code": "internal_error",
        "detail": "Paddle API can't process your request",
        "documentation_url": "https://developer.paddle.com/v1/errors/shared/internal_error"
    },
    "meta": {
        "request_id": "b9eb34f7-f42a-407d-af1e-f6b35516ce86"
    }
}

But if I do POST with

{
    "effective_from": null
}

It correctly resumes the subscription.

driesvints commented 11 months ago

@karlomikus yeah that really seems like a Paddle issue because it's an internal error.

driesvints commented 11 months ago

@karlomikus Paddle acknowledged that this was an issue on their end. They updated the docs and are also going to provide a better handling of that error.

I've sent in a PR to fix the immediate issue: https://github.com/laravel/cashier-paddle/pull/209

Thanks for testing!