create method

dynamic create(
  1. dynamic apiKey, {
  2. required int amount,
  3. required String returnLink,
  4. required bool testMode,
  5. required String cardID,
  6. required String clientID,
  7. Map<String, dynamic>? metadata,
  8. required void onDone(
    1. ConformPaymentModel data,
    2. CreatePaymentModel pData
    ),
  9. required void onError(
    1. Map<String, dynamic> data
    ),
})

Implementation

create(apiKey,
    {required int amount,
    required String returnLink,
    required bool testMode,
    required String cardID,
    required String clientID,
    Map<String, dynamic>? metadata,
    required void Function(ConformPaymentModel data, CreatePaymentModel pData)
        onDone,
    required void Function(Map<String, dynamic> data) onError}) {
  // https://uatcheckout.thawani.om/api/v1/payment_intents
  String url = testMode
      ? "https://uatcheckout.thawani.om/api/v1/payment_intents"
      : 'https://checkout.thawani.om/api/v1/payment_intents';
  Request.post(url: url, data: {
    "payment_method_id": cardID,
    "amount": amount,
    "client_reference_id": clientID,
    "return_url": returnLink,
    if (metadata != null) "metadata": metadata
  }, headers: {
    'Content-Type': "application/json",
    'thawani-api-key': apiKey
  }).then((value) {
    if (value['status'] == 200) {
      CreatePaymentModel model = CreatePaymentModel.fromJson(value['data']);
      conform(
          id: model.data!.id!,
          apiKey: apiKey,
          testMode: testMode,
          onDone: (data) {
            onDone(data, model);
          },
          onError: (error) {
            onError(error);
          });
    } else {
      onError(value['data']);
    }
  });
}