showCheckout method

  1. @override
Future<ZohoPaymentsResult> showCheckout(
  1. ZohoPaymentsCheckoutOptions options, {
  2. required ZohoPaymentsDomain domain,
  3. ZohoPaymentsEnvironment environment = ZohoPaymentsEnvironment.live,
})
override

Launches the ZohoPay payment checkout UI.

Returns a ZohoPaymentsResult — either ZohoPaymentsSuccess or ZohoPaymentsFailure.

Implementation

@override
Future<ZohoPaymentsResult> showCheckout(
  ZohoPaymentsCheckoutOptions options, {
  required ZohoPaymentsDomain domain,
  ZohoPaymentsEnvironment environment = ZohoPaymentsEnvironment.live,
}) async {
  final args = {
    ...options.toMap(),
    'domain': _domainString(domain),
    'environment': _environmentString(environment),
  };

  try {
    final result = await methodChannel.invokeMapMethod<String, dynamic>(
      'showCheckout',
      args,
    );

    if (result == null) {
      return ZohoPaymentsFailure(
        code: 'INVALID_RESPONSE',
        message: 'Platform returned null result',
      );
    }

    final paymentId = result['paymentId'] as String?;
    final signature = result['signature'] as String?;

    if (paymentId == null || signature == null) {
      return ZohoPaymentsFailure(
        code: 'INVALID_RESPONSE',
        message: 'Payment response missing required fields',
      );
    }

    return ZohoPaymentsSuccess(
      paymentId: paymentId,
      signature: signature,
      mandateId: result['mandateId'] as String?,
    );
  } on PlatformException catch (e) {
    return ZohoPaymentsFailure(code: e.code, message: e.message ?? '');
  }
}