updateSubscription method

Future<void> updateSubscription(
  1. String subscriptionId,
  2. List<Patch> patchRequests
)

Updates a subscription which could be in ACTIVE or SUSPENDED status. You can override plan level default attributes by providing customised values for plan path in the patch request.

  • You cannot update attributes that have already completed (Example - trial cycles can’t be updated if completed).
  • Once overridden, changes to plan resource will not impact subscription.
  • Any price update will not impact billing cycles within next 10 days (Applicable only for subscriptions funded by PayPal account).
Following are the fields eligible for patch:
  • billing_info.outstanding_balance. Operations: replace
  • custom_id. Operations: add, replace
  • plan.billing_cycles[@sequence==n]. pricing_scheme.fixed_price. Operations: add, replace
  • plan.billing_cycles[@sequence==n]. pricing_scheme.tiers. Operations: replace
  • plan.billing_cycles[@sequence==n].total_cycles. Operations: replace
  • plan.payment_preferences.auto_bill_outstanding. Operations: replace
  • plan.payment_preferences.payment_failure_threshold. Operations: replace
  • plan.taxes.inclusive. Operations: add, replace
  • plan.taxes.percentage. Operations: add, replace
  • shipping_amount. Operations: add, replace
  • start_time. Operations: replace
  • subscriber.shipping_address. Operations: add, replace
  • subscriber.payment_source (for subscriptions funded by card payments). Operations: replace

Implementation

Future<void> updateSubscription(
    String subscriptionId, List<Patch> patchRequests) async {
  var url =
      _payPalHttpClient.getUrl('/v1/billing/subscriptions/$subscriptionId');

  var patchRequest = List.generate(
      patchRequests.length, (index) => patchRequests[index].toJson());

  var body = jsonEncode(patchRequest);

  await _payPalHttpClient.patch(url, body: body);
}