changeSubscriptionPlan method

  1. @override
Future<void> changeSubscriptionPlan({
  1. required Object customer,
  2. required BillingPlan plan,
  3. bool prorate = true,
})
override

Moves the subscription to plan's product. Bachs invoices the difference now when prorate, and bills the new price from the next cycle otherwise.

Implementation

@override
Future<void> changeSubscriptionPlan({
  required Object customer,
  required BillingPlan plan,
  bool prorate = true,
}) async {
  final String? product = products[plan.id];
  if (product == null) {
    throw DVBillingError('Plan "${plan.id}" has no Bachs product configured.');
  }
  final String id = await _subscriptionIdFor(customer);
  await _request(
    'PATCH',
    '/v1/subscriptions/${Uri.encodeComponent(id)}',
    body: <String, Object?>{
      'product_id': product,
      'proration_behavior': prorate ? 'invoice_now' : 'next_cycle',
    },
    idempotencyKey: _idempotencyKey(),
  );
}