checker method

dynamic checker({
  1. required bool testMode,
  2. required String apiKey,
  3. String? customer,
  4. required String customerId,
  5. required void onError(
    1. Map<String, dynamic>
    ),
  6. required void onDone(
    1. String customerID,
    2. String customerRefrensID
    ),
  7. required void newCustomer(
    1. CreateCustomerModel data
    ),
})

Implementation

checker({
  required bool testMode,
  required String apiKey,
  String? customer,
  required String customerId,
  required void Function(Map<String, dynamic>) onError,
  required void Function(String customerID, String customerRefrensID) onDone,
  required void Function(CreateCustomerModel data) newCustomer,
}) async {
  if (customer != null) await ThawaniCustomer.add(customerID: customer);
  SharedPreferences share = await SharedPreferences.getInstance();
  String? savedCustomerId = share.getString('customerId');
  if (savedCustomerId != null) {
    onDone(savedCustomerId, customerId);
  } else {
    create(
        testMode: testMode,
        apiKey: apiKey,
        customerId: customerId,
        onError: onError,
        onDone: (data) {
          newCustomer(data);
          onDone(data.data!.id!, data.data!.customerClientId!);
        });
  }
}