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
    ),
})

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());
    }
  }
}