buildBankUrl method

String buildBankUrl({
  1. required String bankId,
  2. required String mobile,
  3. required int amount,
  4. required String productIdentity,
  5. required String productName,
  6. required PaymentType paymentType,
  7. required String returnUrl,
  8. String? productUrl,
  9. Map<String, Object>? additionalData,
})

Constructs a bank payment URL.

bankId is the unique bank identifier which can be obtained from the bank list API

mobile : The Khalti registered mobile number of payer

amount : The amount value of payment. Amount must be in paisa and greater than equal to 1000 i.e Rs 10

productIdentity : A unique string to identify the product

productName : Descriptive name for the product

paymentType is one of the available PaymentType

returnUrl is the redirection url after successful payment. The redirected URL will be in the following format.

<returnUrl>/?<data>

An additionalData to be sent alongside the payment configuration. This is only for reporting purposes.

See: https://docs.khalti.com/checkout/diy-ebanking/#2-initiate-transaction

Implementation

String buildBankUrl({
  required String bankId,
  required String mobile,
  required int amount,
  required String productIdentity,
  required String productName,
  required PaymentType paymentType,
  required String returnUrl,
  String? productUrl,
  Map<String, Object>? additionalData,
}) {
  final params = {
    'bank': bankId,
    'public_key': publicKey,
    'amount': amount.toString(),
    'mobile': mobile,
    'product_identity': productIdentity,
    'product_name': productName,
    'source': 'custom',
    ...config.raw,
    if (productUrl != null) 'product_url': productUrl,
    if (additionalData != null) ...additionalData.map(_stringifyValue),
    'return_url': returnUrl,
    'payment_type': paymentType.value,
  };
  final uri = Uri.https('khalti.com', 'ebanking/initiate/', params);
  return uri.toString();
}