Create Charge With Customer In Clover Using C#

Today I will show you how we can create a charge using asking the customer for all the card info and just by using the clover customer Id we can achieve the same.

Here, is the article for how we can create clover customer using the card token

https://www.thecodehubs.com/create-customer-in-clover-using-c

The charge process will be same as I have demonstrated in my previous article for create charge. You can find the article here

One difference will be the request for the charge API. Below will be the model class for the charge request

 

public class CloverNewTransactionRequest
{
  public long amount { get; set; }
  public string currency { get; set; }
  public bool capture { get; set; }
  public string description { get; set; }
  public string ecomind { get; set; }
  public string external_reference_id { get; set; }
  public string receipt_email { get; set; }
  public Soft_Descriptor soft_descriptor { get; set; }
  public string source { get; set; }
  public Stored_Credentials stored_credentials { get; set; }
  public Level2 level2 { get; set; }
  public string tax_rate_uuid { get; set; }
  public int tax_amount { get; set; }
  public int tip_amount { get; set; }
  public Tender tender { get; set; }
}

public class Soft_Descriptor
{
  public string dba_name { get; set; }
  public string street { get; set; }
  public string city { get; set; }
  public string region { get; set; }
  public string postal_code { get; set; }
  public string country_code { get; set; }
  public string merchant_contact_info { get; set; }
}

public class Stored_Credentials
{
  public string sequence { get; set; }
  public bool is_scheduled { get; set; }
  public string initiator { get; set; }
  public Installment_Info installment_info { get; set; }
}

public class Installment_Info
{
  public string bill_pay_indicator { get; set; }
  public string invoice_number { get; set; }
  public string description { get; set; }
}

public class Level2
{
  public int tax_amount { get; set; }
  public int tax_indicator { get; set; }
  public string purchase_identifier { get; set; }
  public string order_number { get; set; }
  public int discount_amount { get; set; }
  public int freight_amount { get; set; }
  public int duty_amount { get; set; }
  public string destination_postal_code { get; set; }
  public string shipping_from_postal_code { get; set; }
  public int destination_country_code { get; set; }
  public string merchant_tax_id { get; set; }
  public string product_description { get; set; }
}

public class Tender
{
  public string label_key { get; set; }
  public string label { get; set; }
  public string id { get; set; }
}

Now, the request method will look something like this

private string CloverAuthCaptureRequest()
{
  var post_string = "";	
  CloverNewTransactionRequest saleRequest = new CloverNewTransactionRequest();

  try
  {
  
    saleRequest.amount = 100;
    saleRequest.capture = true;
    saleRequest.ecomind = "ecom";
    saleRequest.currency = "usd";
    saleRequest.description = "test charge";                
    saleRequest.source = "Your customer ID";  		
    saleRequest.stored_credentials = new Stored_Credentials()
    {
      sequence = CLOVER_SEQUENCE,
      is_scheduled = false,
      initiator = CLOVER_INITIATOR
    };
    
    saleRequest.level2 = new Level2()
    {
      order_number = "Invoice Number"
    };

    post_string = new JavaScriptSerializer().Serialize(saleRequest);
    
  }
  catch (Exception ex)
  {
    post_string = "";
  }
  return post_string;
}

Now, we can the above method in the same Web Request for API as I have show in the article here

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories