Search code examples
paypalpaypal-sandboxpaypal-subscriptions

Create PayPal subscription with custom trial duration


I have a PayPal subscription with a 2-week trial, and monthly billing after.

There is a scenario I'm having trouble with: what if the user cancels their subscription during the trial, but then decides to create a new one?

The client doesn't want to give him a whole new 2-week trial, and he also doesn't want to leave the user with no trial at all. Ideally, if the user had 6 days left on their original trial period, we should now create a subscription with a 6-day trial at the beginning. After that, monthly billing as usual.

Is there a way to do this? The plan object looks like this:

"name": "Test Plan",
"status": "ACTIVE",
"description": "Desc",
"usage_type": "LICENSED",
"billing_cycles": [
    {
        "frequency": {
            "interval_unit": "WEEK",
            "interval_count": 2
        },
        "tenure_type": "TRIAL",
        "sequence": 1,
        "total_cycles": 1
    },
    {
        "pricing_scheme": {
            "version": 1,
            "fixed_price": {
                "currency_code": "USD",
                "value": "29.0"
            },
            "create_time": "2020-07-16T08:30:54Z",
            "update_time": "2020-07-16T08:30:54Z"
        },
        "frequency": {
            "interval_unit": "MONTH",
            "interval_count": 1
        },
        "tenure_type": "REGULAR",
        "sequence": 2,
        "total_cycles": 0
    }
],
"payment_preferences": {
    "service_type": "PREPAID",
    "auto_bill_outstanding": true,
    "setup_fee": {
        "currency_code": "USD",
        "value": "0.0"
    },
    "setup_fee_failure_action": "CONTINUE",
    "payment_failure_threshold": 3
},

When I create a subscription normally, all I send to the API is:

"plan_id" : "P-XXXXXXXXXXXXXXXX",
"application_context": {
    "brand_name": "Name",
    "user_action": "SUBSCRIBE_NOW",
    "payment_method": {
        "payer_selected": "PAYPAL",
        "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
    },
    "return_url": "https://example.com/returnUrl",
    "cancel_url": "https://example.com/cancelUrl"
}

I don't see an option in the documentation to overwrite the billing cycles when creating the subscription:

https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create

How can I do this (if it's doable)?


Solution

  • For a different trial period length, you need to create a new Plan object with a different trial length, and use this different Plan for the subscription.