startPayment static method

void startPayment({
  1. required String paymentApp,
  2. required String payeeVpa,
  3. required String payeeName,
  4. required String transactionId,
  5. String? transactionRefId,
  6. required String payeeMerchantCode,
  7. required String description,
  8. required String amount,
  9. String? currency,
  10. required dynamic response(
    1. UpiResponse,
    2. String
    ),
  11. required dynamic error(
    1. String
    ),
})

Initiates a UPI payment transaction.

Parameters:

  • paymentApp: The UPI payment app to be used for the transaction.
  • payeeVpa: The VPA (Virtual Payment Address) of the payee.
  • payeeName: The name of the payee.
  • transactionId: The unique ID for the transaction.
  • transactionRefId: The reference ID for the transaction (optional).
  • payeeMerchantCode: The merchant code of the payee.
  • description: The description of the transaction.
  • amount: The amount to be transferred.
  • currency: The currency for the transaction (default is "INR").
  • response: A callback function to handle the UPI response.
  • error: A callback function to handle errors during the transaction.

Implementation

static void startPayment({
  required String paymentApp,
  required String payeeVpa,
  required String payeeName,
  required String transactionId,
  String? transactionRefId,
  required String payeeMerchantCode,
  required String description,
  required String amount,
  String? currency,
  required Function(UpiResponse, String) response,
  required Function(String) error,
}) async {
  UPIRequestParameters upiRequestParams =
      UPIRequestParameters.builder((upiRequestBuilder) {
    upiRequestBuilder
      ..setPaymentApp(paymentApp)
      ..setPayeeVpa(payeeVpa)
      ..setPayeeName(payeeName)
      ..setPayeeMerchantCode(payeeMerchantCode)
      ..setTransactionId(transactionId)
      ..setTransactionRefId(transactionRefId ?? transactionId)
      ..setDescription(description.isNotEmpty ? description : transactionId)
      ..setAmount(amount)
      ..setCurrency(currency ?? "INR");
  });
  try {
    if (Platform.isAndroid) {
      UpiResponse upiInstance =
          await FlutterNativeUpi(const MethodChannel('flutter_pay_upi'))
              .initiateTransaction(upiRequestParams);
      response(upiInstance, amount);
      // _showTransactionDetailsDialog(upiInstance);
    } else {
      String url = appendAndMakeUrl(upiRequestParams);
      String response =
          await FlutterNativeUpi(const MethodChannel('flutter_pay_upi'))
              .initiateTransactioniOS(url);
      if (response == "Please install app!") {
        redirectToAppstore(paymentApp);
      }
    }
  } on PlatformException catch (e) {
    error(e.message.toString());
  } catch (e) {
    if (e is UpiException) {
      // _showRoundedDialog(context,e.message);
      error(e.message.toString());
    } else {
      error(e.toString());
    }
  }
}