pay static method

Future<bool> pay({
  1. required UIpgPayParams p,
  2. dynamic onPaid(
    1. bool
    )?,
  3. UReceipt? receipt,
})

Implementation

static Future<bool> pay({
  required UIpgPayParams p,
  Function(bool)? onPaid,
  UReceipt? receipt,
}) async {
  final Completer<bool> completer = Completer<bool>();
  bool paid = false;
  if (p.amount <= 0) UToast.error(message: U.s.invalidAmount);
  ULoading.show();
  await UServices.ipg.pay(
    p: UIpgPayParams(
      amount: p.amount,
      tag: p.tag,
      invoiceId: p.invoiceId,
      billId: p.billId,
      paymentId: p.paymentId,
      chargeMobileNumber: p.chargeMobileNumber,
      topUpType: p.topUpType,
      multiplexedAccounts: p.multiplexedAccounts,
    ),
    onOk: (UResponse<UIpgPayResponse> response) async {
      ULoading.dismiss();
      final UIpgAdditionalData requested = response.result!.additionalData;
      final UIpgAdditionalData? settled = await UNavigator.push<UIpgAdditionalData>(UIpgWebViewPage(url: response.result!.url, additionalData: requested));
      paid = settled?.paid ?? false;
      if (paid && receipt != null) {
        await _showReceipt(
          amount: p.amount,
          trackingNumber: settled?.trackingNumber ?? requested.trackingNumber ?? "---",
          receipt: receipt,
          rows: UReceiptKeyValues.rows(settled?.keyValues ?? <UKeyValueData>[]),
          title: _title(billId: p.billId, chargeMobileNumber: p.chargeMobileNumber, multiplexedAccounts: p.multiplexedAccounts),
        );
      }
      completer.complete(paid);
      onPaid?.call(paid);
    },
    onError: (UEmptyResponse e) {
      ULoading.dismiss();
      UToast.error(message: e.message);
      onPaid?.call(false);
      completer.complete(false);
    },
    onException: (String e) {
      ULoading.dismiss();
      UToast.error(message: e);
      onPaid?.call(false);
      completer.complete(false);
    },
  );
  return completer.future;
}