restore method

Future<List<DVPurchaseResult>> restore({
  1. Object? customer,
  2. DVStore? store,
  3. List<String>? receipts,
})

Revalidates each of receipts with store for customer.

The device supplies what the store account owns; each receipt is then verified here like a new purchase. One that is refused -- by the store, or because it belongs to another application user -- is reported in its result and grants nothing, without stopping the rest.

On a device (DVPurchases.device) it takes no arguments: the store is asked what this store account owns and the backend revalidates each.

Implementation

Future<List<DVPurchaseResult>> restore({
  Object? customer,
  DVStore? store,
  List<String>? receipts,
}) async {
  final DVPurchaseDevice? onDevice = device;
  if (onDevice != null) return onDevice.restore();
  if (customer == null || store == null || receipts == null) {
    throw ArgumentError(
        'restore on the server takes the customer, the store and the '
        'receipts the device sent');
  }
  final List<DVPurchaseResult> results = <DVPurchaseResult>[];
  for (final String receipt in receipts) {
    try {
      results.add(await verifyPurchase(store, receipt, customer: customer));
    } on DVPurchaseRefused catch (refusal) {
      results.add(DVPurchaseResult(
          refused: true, reason: refusal.reason, code: refusal.code));
    }
  }
  return results;
}