initialize method

Future<bool> initialize (
  1. {@required String merchantID,
  2. @required List<FawryItem> items,
  3. String merchantRefNumber,
  4. Language language: Language.EN,
  5. Environment environment: Environment.TEST,
  6. Map<String, dynamic> customParam}
)

Initialize FawryPay payment charge.

Initialize the payment charge by adding some parameters. Returns true if it initialized fine. Throws exception if not.

merchantID sets the merchantID that you have received from Fawry. items sets the list of items that the user will pay for. merchantRefNumber sets an optional number consists of 16 random characters and numbers. language sets the language of payment, whether English or Arabic, default English. environment sets the environment of payment, whether Test or Live, default Test. customParam sets a map of custom data you want to receive back with result data after payment.

Implementation

Future<bool> initialize({
  @required String merchantID,
  @required List<FawryItem> items,
  String merchantRefNumber,
  Language language = Language.EN,
  Environment environment = Environment.TEST,
  Map<String, dynamic> customParam,
}) async {
  try {
    return await _channel.invokeMethod(_METHOD_INITIALIZE, <String, dynamic>{
      'merchantID': merchantID,
      'items': items.map((e) => e.toJSON()).toList(),
      'merchantRefNumber': merchantRefNumber,
      'language': language.toString(),
      'environment': environment.toString(),
      'customParam': customParam,
    });
  } on PlatformException catch (e) {
    if (e.code == _ERROR_INITIALIZE)
      throw "Error Occurred: Code: $_ERROR_INITIALIZE. Message: ${e.message}. Details: SDK Initialization Error";
    throw "Error Occurred: Code: ${e.code}. Message: ${e.message}. Details: ${e.details}";
  } catch (e) {
    throw "Error Occurred: $e";
  }
}