startPayment static method

Future<PaymentResponse> startPayment({
  1. required BuildContext context,
  2. bool showServiceCharge = false,
  3. Widget builder(
    1. List<PaymentMethod> methods,
    2. LoadingState state,
    3. Future submit(
      1. PaymentMethod method
      )
    )?,
  4. required MyfatoorahRequest request,
  5. Widget? errorChild,
  6. Widget? successChild,
  7. AfterPaymentBehaviour afterPaymentBehaviour = AfterPaymentBehaviour.None,
  8. PreferredSizeWidget buildAppBar(
    1. BuildContext context
    )?,
  9. List<PaymentMethod> filterPaymentMethods(
    1. List<PaymentMethod> methods
    )?,
  10. DirectPaymentCallBack? directPayment,
})

Implementation

static Future<PaymentResponse> startPayment({
  required BuildContext context,
  //If this is true service charge will be shown in subtitle defaults to false
  bool showServiceCharge = false,

  /// user this to build your own ui and then at the end call submit
  /// submit method is future so you can wait it
  /// the default is `ListView`
  Widget Function(List<PaymentMethod> methods, LoadingState state,
          Future Function(PaymentMethod method) submit)?
      builder,
  required MyfatoorahRequest request,
  //Will be shown after failed payment `afterPaymentBehaviour must be none`
  Widget? errorChild,
  //Will be shown after success payment `afterPaymentBehaviour must be none`
  Widget? successChild,

  /// this will controls what happen after payment done
  ///
  /// [AfterPaymentBehaviour.None] the default value , nothing will happen
  ///
  /// [AfterPaymentBehaviour.AfterCallbackExecution] will pop after payment done and error or success callbacks finish
  ///
  /// [AfterPaymentBehaviour.BeforeCallbackExecution] will pop after payment done and before error or success callbacks start
  AfterPaymentBehaviour afterPaymentBehaviour = AfterPaymentBehaviour.None,
  //Note if you override leading please use mayBePop instead of pop
  PreferredSizeWidget Function(BuildContext context)? buildAppBar,

  /// Filter payment methods after fetching it
  List<PaymentMethod> Function(List<PaymentMethod> methods)?
      filterPaymentMethods,
  DirectPaymentCallBack? directPayment,
}) {
  return showDialog(
    context: context,
    builder: (ctx) {
      return Dialog(
        child: _PaymentMethodsBuilder(
          errorChild: errorChild,
          directPayment: directPayment,
          getAppBar: buildAppBar,
          onResult: null,
          successChild: successChild,
          filterPaymentMethods: filterPaymentMethods,
          afterPaymentBehaviour: afterPaymentBehaviour,
          request: request,
          showServiceCharge: showServiceCharge,
          builder: builder,
        ),
      );
    },
  ).then((res) {
    if (res is PaymentResponse)
      return res;
    else
      throw Exception("The payment is not completed");
  });
}