setCallback method

dynamic setCallback(
  1. void vp(
    1. String
    ),
  2. void error(
    1. CFErrorResponse,
    2. String
    )
)

Implementation

setCallback(final void Function(String) vp, final void Function(CFErrorResponse, String) error) {
  verifyPayment = vp;
  onError = error;

  // Create Method channel here
  MethodChannel methodChannel = const MethodChannel('flutter_cashfree_pg_sdk');
  methodChannel.invokeMethod("response").then((value) {
    if(value != null) {
      final body = json.decode(value);
      var status = body["status"] as String;
      switch (status) {
        case "exception":
          var data = body["data"] as Map<String, dynamic>;
          _createErrorResponse(data["message"] as String, null, null, null);
          break;
        case "success":
          var data = body["data"] as Map<String, dynamic>;
          verifyPayment!(data["order_id"] as String);
          break;
        case "failed":
          var data = body["data"] as Map<String, dynamic>;
          var errorResponse = CFErrorResponse(
              data["status"] as String, data["message"] as String,
              data["code"] as String, data["type"] as String);
          onError!(errorResponse, data["order_id"] as String);
          break;
      }
    }
  });
}