payWithApp method
Future<UpiPaymentResult>
payWithApp(
- UpiPaymentRequest request, {
- required String appId,
override
Initiates a UPI payment using a specific app target (appId / package name).
Implementation
@override
Future<UpiPaymentResult> payWithApp(UpiPaymentRequest request, {required String appId}) async {
request.validate();
if (appId.trim().isEmpty) {
throw const UpiException(
code: UpiErrorCode.selectedAppNotAvailable,
message: 'App ID / Package name cannot be empty.',
);
}
final paymentUri = UpiUriBuilder.buildPaymentUri(request);
try {
final rawResponse = await methodChannel.invokeMethod<String>('payWithApp', {
'uri': paymentUri.toString(),
'appId': appId.trim(),
'request': request.toMap(),
});
return UpiResponseParser.parseResponse(rawResponse, rawUri: paymentUri);
} on PlatformException catch (e) {
if (e.code == 'USER_CANCELLED') {
return UpiPaymentResult(
status: UpiPaymentStatus.cancelled,
message: e.message ?? 'User cancelled payment.',
rawResponse: e.details?.toString(),
rawUri: paymentUri,
);
}
throw UpiException(
code: _mapErrorCode(e.code),
message: e.message ?? 'Targeted payment initiation failed.',
details: e.details,
);
}
}