init method

Future<bool> init (
  1. {dynamic style: Style.STYLE1,
  2. dynamic enableLogging: false,
  3. dynamic enableMockups: false,
  4. dynamic skipCustomerInput: false,
  5. String username,
  6. String email}
)

Init FawryPay SDK services.

This initialize the SDK for one time only and also can change at anytime. Set here some parameters to configure the SDK. Returns true if it initialized fine. Throws exception if not.

style sets the style of SDK. enableLogging sets whether enable logs from SDK or not. skipCustomerInput sets whether you let user enter username and email, or there's a default username and email. If you set it to true, then you are required to set default username and email. username sets the default username if you set skipCustomerInput = true, it should be a phone number. email sets the default email if you set skipCustomerInput = true.

Implementation

Future<bool> init({
  style = Style.STYLE1,
  enableLogging = false,
  enableMockups = false,
  skipCustomerInput = false,
  String username,
  String email,
}) async {
  // Check if skipCustomerInput is true, but username or email is equals null.
  assert(!skipCustomerInput || (skipCustomerInput && username != null && email != null),
      "If skipCustomerInput is true, then you should set username and email.");

  try {
    return await _channel.invokeMethod(_METHOD_INIT, <String, dynamic>{
      'style': style.toString(),
      'enableLogging': enableLogging,
      'enableMockups': enableMockups,
      'skipCustomerInput': skipCustomerInput,
      'username': username,
      'email': email,
    });
  } on PlatformException catch (e) {
    if (e.code == _ERROR_INIT) throw "Error Occurred: Code: $_ERROR_INIT. Message: ${e.message}. Details: SDK Init Error";
    throw "Error Occurred: Code: ${e.code}. Message: ${e.message}. Details: ${e.details}";
  } catch (e) {
    throw "Error Occurred: Message: $e";
  }
}