initialize method

dynamic initialize()

Implementation

initialize() async {
  // assert( publicKey != null && publicKey.isNotEmpty );
  assert(secretKey.isNotEmpty);
  assert(reference.isNotEmpty);
  assert(email.isNotEmpty);
  assert(amount > 0);
  assert(currency.isNotEmpty);

  final mPaymentInfo = PaymentInfo(
    secretKey: secretKey,
    reference: reference,
    /*
    Paystack makes use of the ISO 4217 format for currency codes.
    When sending an amount, it must be sent in the subunit of that currency.
    Sending an amount in subunits simply means multiplying the base amount by 100.
    For example, if a customer is supposed to make a payment of NGN 100,
    you would send 10000 = 100 * 100 in your request.
    */
    amount: amount * 100,
    country: country,
    currency: currency,
    email: email,
    firstName: firstName,
    lastName: lastName,
    metadata: metadata,
    companyAssetImage: companyAssetImage,
    paymentCard: null,
  );

  Transaction transactionResult = await Navigator.push(
    context,
    MaterialPageRoute(
      builder: (BuildContext context) => PaystackPaymentCheckOutPage(
        paymentInfo: mPaymentInfo,
      ),
    ),
  );

  if (transactionResult.state == TransactionState.SUCCESS) {
    onSuccessful(transactionResult);
  } else if (transactionResult.state == TransactionState.PENDING) {
    onPending(transactionResult);
  } else if (transactionResult.state == TransactionState.FAILED) {
    onFailed(transactionResult);
  } else {
    onCancelled(transactionResult);
  }
}