refresh method

Future<void> refresh({
  1. required StripePurchaseModel purchase,
})

Change the purchase payment method to the default set in the app.

If an existing payment fails, run StripePayment.setDefault to change the payment method and then run this.

purchaseの支払い方法をアプリ内で設定されているデフォルトに変更します。

既存の支払いに失敗した際にStripePayment.setDefaultを実行し支払い方法を変更した後こちらを実行してください。

Implementation

Future<void> refresh({
  required StripePurchaseModel purchase,
}) async {
  if (_completer != null) {
    return _completer!.future;
  }
  _completer = Completer<void>();
  try {
    if (purchase.success) {
      throw Exception("The payment has already been succeed.");
    }
    if (!purchase.error) {
      return;
    }
    final functionsAdapter =
        StripePurchaseMasamuneAdapter.primary.functionsAdapter ??
            FunctionsAdapter.primary;

    await functionsAdapter.execute(
      StripeRefreshPurchaseAction(
        userId: userId,
        orderId: purchase.orderId,
      ),
    );

    _completer?.complete();
    _completer = null;
    notifyListeners();
  } catch (e) {
    _completer?.completeError(e);
    _completer = null;
    rethrow;
  } finally {
    _completer?.complete();
    _completer = null;
  }
}