showNativePay static method

Future<PaymentResult> showNativePay(
  1. Map<String, dynamic> args
)

Present the native pay sheet on the device (Apple/Google) via platform channels. The args map should include at least:

  • method: 'apple_pay' | 'google_pay'
  • amountCents: integer amount in cents
  • currency: currency code
  • merchantArgs: normalized merchant args map Other fields (apiKey, merchantId) are optional and forwarded.

Implementation

static Future<PaymentResult> showNativePay(Map<String, dynamic> args) async {
  try {
    final dynamic resp =
        await _channel.invokeMethod('presentNativePay', args);
    if (resp is Map) {
      final success = resp['success'] == true;
      final error = resp['error']?.toString();
      final errorMessage = resp['errorMessage']?.toString();
      return PaymentResult(
        success: success,
        error: error,
        errorMessage: errorMessage,
      );
    }
    return const PaymentResult(
        success: false, error: 'No response', errorMessage: 'No response');
  } on PlatformException catch (e) {
    return PaymentResult(
        success: false, error: e.code, errorMessage: e.message);
  } catch (e) {
    return PaymentResult(
        success: false,
        error: 'Native pay error.',
        errorMessage: e.toString());
  }
}