generateTransactionCheckoutURI method

Future<Uri> generateTransactionCheckoutURI({
  1. required PaywayCreateTransaction transaction,
  2. required String checkoutApiUrl,
})

Implementation

Future<Uri> generateTransactionCheckoutURI({
  required PaywayCreateTransaction transaction,
  required String checkoutApiUrl,
}) async {
  assert(checkoutApiUrl.isNotEmpty);
  var _transaction = transaction;
  if (![ABAPaymentOption.cards, ABAPaymentOption.abapay]
      .contains(transaction.option)) {
    _transaction = _transaction.copyWith(option: ABAPaymentOption.cards);
  }

  assert([
    ABAPaymentOption.cards,
    ABAPaymentOption.abapay,
  ].contains(_transaction.option));
  Map<String, dynamic> map = _transaction.toFormDataMap();

  var parsed = Uri.tryParse(checkoutApiUrl)!;

  return parsed.authority.contains("https")
      ? Uri.https(parsed.authority, parsed.path, map)
      : Uri.http(parsed.authority, parsed.path, map);
}