pay method

  1. @override
Future<IfoodPagoPaymentResponse> pay({
  1. required IfoodPagoPaymentPayload payload,
})
override

Implementation

@override
Future<IfoodPagoPaymentResponse> pay({required IfoodPagoPaymentPayload payload}) async {
  try {
    final response = await methodChannel.invokeMethod<Map>('pay', payload.toJson());
    if (response is Map) {
      if (response['code'] == IfoodPagoStatusDeeplink.SUCCESS.name && response['data'] is Map) {
        return IfoodPagoPaymentResponse.fromJson(Map<String, dynamic>.from(response['data']));
      } else {
        throw IfoodPagoPaymentException(message: response['message']);
      }
    } else {
      throw IfoodPagoPaymentException(message: 'invalid response');
    }
  } on IfoodPagoPaymentException catch (e) {
    throw IfoodPagoPaymentException(message: e.message);
  } on PlatformException catch (e) {
    throw IfoodPagoPaymentException(message: e.message ?? 'PlatformException');
  } catch (e) {
    throw IfoodPagoPaymentException(message: "Pay Error: $e");
  }
}