Search code examples
paypalpaypal-sandboxpaypal-rest-sdkpaypal-subscriptions

How do you create a subscription with a trial period with the Paypal Javascript SDK?


Is there a way to create a subscription with a trial period using the Paypal Javascript SDK? Alternatively is there a way to customize a subscription (after it was created via the Paypal Javascript SDK - button)?

Creating multiple plans with different trial or discounts is not a good option as my implementation is meant to have any number or type of discounts. I'd rather choose to have only 2 plans: one monthly and yearly and then apply a discount or a trial to the subscription if at all possible.

My code is the standard for creating a subscription (a product - v1/catalogs/products - and a plan - v1/billing/plans - have already been created so I am only passing the PLAN_ID to JS):

<script>
      paypal.Buttons({
        createSubscription: function(data, actions) {
          return actions.subscription.create({
            'plan_id': 'PLAN_ID' // Creates the subscription
          });
        },
        onApprove: function(data, actions) {
          alert('You have successfully created subscription ' + data.subscriptionID); // Optional message given to subscriber
        }
      }).render('#paypal-button-container'); // Renders the PayPal button
    </script>

Solution

  • I'd rather choose to have only 2 plans: one monthly and yearly and then apply a discount or a trial to the subscription if at all possible.

    This cannot be done. The plan specifies the billing amounts and times.

    The only amount that can be set at subscription time is added shipping.

    Plans can be created dynamically via the Subscriptions API's Plans resource group, documented here.