Code Example Microsoft .NET

Code Example Microsoft .NET

Edit

main.cs

  1. PaymentTransaction paymentTransaction = new PaymentTransaction("https://test.api.payfacto.com/v1", "00000000000000000000000000000000000");

  2. String purchaseInput = FillPurchaseInput();
  3. transactionOutput = paymentTransaction.purchase(purchaseInput);

  4. if (transactionOutput != null && transactionOutput.returnCode == "  00")
  5. {
  6.   String ackInput = TransactionInput.COMPANY_NUMBER + "=" + Request.Form["NUM_CIE"]
  7.      + "&" + TransactionInput.MERCHANT_NUMBER + "=" + Request.Form["NUM_MARC"]
  8.      + "&" + TransactionInput.TRANSACTION_NUMBER + "=" + transactionOutput.transactionNumber;
  9.   autoAckOutput = paymentTransaction.ack(ackInput);
  10. }

  11. private TransactionInput FillTransactionInfo()
  12. {
  13.   TransactionInput transactionInput = new TransactionInput();
  14.   transactionInput.companyNumber = Request.Form["NUM_CIE"];
  15.   transactionInput.merchantNumber = Request.Form["NUM_MARC"];
  16.   transactionInput.customerNumber = Request.Form["NUM_CLIE"];
  17.   transactionInput.amount = Request.Form["MONT_TX"];
  18.   transactionInput.invoiceNumber = Request.Form["NUM_FACT"];
  19.   transactionInput.originalInvoiceNumber = Request.Form["NUM_FACT_ORIG"];
  20.   transactionInput.inputType = Request.Form["TYPE_SAIS"];
  21.   transactionInput.cardType = Request.Form["TYPE_CART"];
  22.   transactionInput.cardNumber = Request.Form["NUM_CART"];
  23.   transactionInput.expirationDate = Request.Form["DATE_EXPI"];
  24.   transactionInput.cvv2cvc2Number = Request.Form["CVV2CVC2"];
  25.   transactionInput.merchantTerminalNumber = Request.Form["NUM_TPV_MARC"];
  26.   transactionInput.languageCode = Request.Form["CODE_LANG"];
  27.   transactionInput.currencyCode = Request.Form["DEVI"];
  28.   transactionInput.operatorID = Request.Form["OPER_ID"];

  29.   return transactionInput;
  30. }
  31. private string FillPurchaseInput()
  32. {
  33.   return FillTransactionInfo().toPurchaseInput();
  34. }
  35. </payfacto-code>

  36. ==== PaymentTransaction.cs ====

  37. <payfacto-code lang="csharp">

  38. public class PaymentTransaction
  39. {
  40.   private string URL = "https://test.api.payfacto.com/v1";
  41.   private string AUTH_API_KEY = "00000000000000000000000000000000000";

  42.   public PaymentTransaction(string URL, string AUTH_API_KEY)
  43.   {
  44.     this.URL = URL;
  45.     this.AUTH_API_KEY = AUTH_API_KEY;
  46.   }


  47.   private HttpWebRequest SendRequest(string url, string content)
  48.   {
  49.     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  50.     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  51.     request.Method = "POST";

  52.     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

  53.     string postContent = "auth-api-key=" + AUTH_API_KEY;
  54.     postContent += "&payload=" + Convert.ToBase64String(encoding.GetBytes(content));

  55.     Byte[] byteArray = encoding.GetBytes(postContent);

  56.     request.ContentLength = byteArray.Length;
  57.     request.ContentType = @"application/x-www-form-urlencoded";
  58.     request.Accept = @"application/json";
  59.     request.UserAgent = "CodeExample";

  60.     using (Stream dataStream = request.GetRequestStream())
  61.     {
  62.       dataStream.Write(byteArray, 0, byteArray.Length);
  63.     }
  64.     return request;
  65.   }

  66.   private void POST(string url, string content, Action<TransactionOutput> callback)
  67.   {
  68.     HttpWebRequest request = SendRequest(url, content);

  69.     try
  70.     {
  71.       using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  72.       {
  73.         if (callback != null)
  74.         {
  75.           DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(TransactionOutput));
  76.           callback(ser.ReadObject(response.GetResponseStream()) as TransactionOutput);
  77.         }
  78.       }
  79.     }
  80.     catch (WebException ex)
  81.     {
  82.       // Log exception and throw as for POST example above
  83.     }
  84.   }
  85.   
  86.   private TransactionOutput getResponse(string transaction, string transactiondata)
  87.   {
  88.     TransactionOutput response = null;
  89.     POST(URL + transaction, transactiondata, (x) =>
  90.     {
  91.       response = x;
  92.     });

  93.     return response;
  94.   }
  95.   
  96.   public TransactionOutput purchase(String purchaseInput)
  97.   {
  98.     return getResponse("/purchase", purchaseInput);
  99.   }   
  100. }
  101. </payfacto-code>

  102. ==== TransactionInput.cs ====

  103. <payfacto-code lang="csharp">
  104. public class TransactionInput
  105. {
  106.   /** The TRANSACTION_NUMBER. */
  107.   public static String TRANSACTION_NUMBER = "TransactionNumber";

  108.   /** The COMPANY_NUMBER. */
  109.   public static String COMPANY_NUMBER = "CompanyNumber";

  110.   /** The MERCHANT_NUMBER. */
  111.   public static String MERCHANT_NUMBER = "MerchantNumber";

  112.   /** The CUSTOMER_NUMBER. */
  113.   public static String CUSTOMER_NUMBER = "CustomerNumber";

  114.   /** The AMOUNT. */
  115.   public static String AMOUNT = "Amount";

  116.   /** The INVOICE_NUMBER. */
  117.   public static String INVOICE_NUMBER = "InvoiceNumber";

  118.   /** The ORIGINAL_INVOICE_NUMBER. */
  119.   public static String ORIGINAL_INVOICE_NUMBER = "OriginalInvoiceNumber";

  120.   /** The INPUT_TYPE. */
  121.   public static String INPUT_TYPE = "InputType";

  122.   /** The CARD_TYPE. */
  123.   public static String CARD_TYPE = "CardType";

  124.   /** The CARD_NUMBER. */
  125.   public static String CARD_NUMBER = "CardNumber";

  126.   /** The EXPIRATION_DATE. */
  127.   public static String EXPIRATION_DATE = "ExpirationDate";

  128.   /** The CVV2CVC2_NUMBER. */
  129.   public static String CVV2CVC2_NUMBER = "Cvv2Cvc2Number";

  130.   /** The MERCHANT_TERMINAL_NUMBER. */
  131.   public static String MERCHANT_TERMINAL_NUMBER = "MerchantTerminalNumber";

  132.   /** The LANGUAGE_CODE. */
  133.   public static String LANGUAGE_CODE = "LanguageCode";

  134.   /** The CURRENCY_CODE. */
  135.   public static String CURRENCY_CODE = "CurrencyCode"; 

  136.   /** The OPERATOR_ID. */
  137.   public static String OPERATOR_ID = "OperatorID"; 

  138.   /** The CARDHOLDER_ADDRESS. */
  139.   public static String CARDHOLDER_ADDRESS = "CardHolderAddress"; 

  140.   /** The CARDHOLDER_POSTALCODE. */
  141.   public static String CARDHOLDER_POSTALCODE = "CardHolderPostalCode"; 

  142.   /** The CARDHOLDER_AVV. */
  143.   public static String CARDHOLDER_AVV = "CardHolderAVV"; 

  144.   /** The XID. */
  145.   public static String XID = "xID"; 

  146.   /** The UCAF. */
  147.   public static String UCAF = "uCAF"; 

  148.   /** The USER_ECHO_DATA. */
  149.   public static String USER_ECHO_DATA = "UserEchoData"; 

  150.   /** The TRX_OPTIONS. */
  151.   public static String TRX_OPTIONS = "TrxOption"; 

  152.   /** The ORIGINAL_TRANSACTION_NUMBER. */
  153.   public static String ORIGINAL_TRANSACTION_NUMBER = "OriginalTransactionNumber"; 

  154.   /** The ORIGINAL_AUTHORIZATION_NUMBER. */
  155.   public static String ORIGINAL_AUTHORIZATION_NUMBER = "OriginalAuthorizationNumber"; 

  156.   /** The ORIGNAL_AMOUNT. */
  157.   public static String ORIGNAL_AMOUNT = "OriginalAmount"; 

  158.   /** The ORIGINAL_TERMINAL_INVOICE_NUMBER. */
  159.   public static String ORIGINAL_TERMINAL_INVOICE_NUMBER = "OriginalTerminalInvoiceNumber"; 

  160.   /** The TOKEN. */
  161.   public static String TOKEN = "Token"; 

  162.   /** The SUCCESS_URL. */
  163.   public static String SUCCESS_URL = "SuccessURL"; 

  164.   /** The FAILURE_URL. */
  165.   public static String FAILURE_URL = "FailureURL"; 

  166.   /** The EMAIL. */
  167.   public static String EMAIL = "Email"; 

  168.   /** The SESSION_ID. */
  169.   public static String SECURE_ID = "SecureID"; 

  170.   /** The IOP_ISSUER_CONFIRMATION_NUMBER. */
  171.   public static String IOP_ISSUER_CONFIRMATION_NUMBER = "IopIssuerConfirmationNumber"; 

  172.   /** The IOP_ISSUER_NAME. */
  173.   public static String IOP_ISSUER_NAME = "IopIssuerName"; 

  174.   /** The IOP_TRANSACTION_ID. */
  175.   public static String IOP_TRANSACTION_ID = "IopTransactionId"; 

  176.   /** The BATCH_NUMBER. */
  177.   public static String BATCH_NUMBER = "BatchNumber"; 

  178.   /** The RECUR_ID. */
  179.   public static String ID = "ID"; 

  180.   /** The NAME. */
  181.   public static String NAME = "Name"; 

  182.   /** The FREQUENCY. */
  183.   public static String FREQUENCY = "Frequency"; 

  184.   /** The START. */
  185.   public static String START_DATE = "StartDate"; 

  186.   /** The FINISH. */
  187.   public static String END_DATE = "EndDate";  

  188.   /** The NUMBER. */
  189.   public static String NUMBER_OF_PAYMENTS = "NumberOfPayments"; 

  190.   /** The ACCOUNT. */
  191.   public static String ACCOUNT_NUMBER = "AccountNumber"; 

  192.   /** The DESCRIPTION. */
  193.   public static String DESCRIPTION = "Description"; 

  194.   /** The STATUS. */
  195.   public static String STATUS = "Status"; 


  196.   public string account { get; set; }
  197.   public string amount { get; set; }
  198.   public string invoiceNumber { get; set; }
  199.   public string companyNumber { get; set; }
  200.   public string cardNumber { get; set; }
  201.   public string cardType { get; set; }
  202.   public string currencyCode { get; set; }
  203.   public string customerNumber { get; set; }
  204.   public string cvv2cvc2Number { get; set; }
  205.   public string description { get; set; }
  206.   public string eMail { get; set; }
  207.   public string expirationDate { get; set; }
  208.   public string failureUrl { get; set; }
  209.   public string finishDate { get; set; }
  210.   public string frequency { get; set; }
  211.   public string id { get; set; }
  212.   public string inputType { get; set; }
  213.   public string languageCode { get; set; }
  214.   public string merchantNumber { get; set; }
  215.   public string merchantTerminalNumber { get; set; }
  216.   public string name { get; set; }
  217.   public string nbr { get; set; }
  218.   public string operatorID { get; set; }
  219.   public string originalAuthorizationNumber { get; set; }
  220.   public string originalInvoiceNumber { get; set; }
  221.   public string originalTransactionNumber { get; set; }
  222.   public string secureId { get; set; }
  223.   public string startDate { get; set; }
  224.   public string status { get; set; }
  225.   public string successUrl { get; set; }
  226.   public string token { get; set; }
  227.   public string trackNumber { get; set; }
  228.   public string holderAddress { get; set; }
  229.   public string holderPostalCode { get; set; }
  230.   public string iopIssuerConfirmationNumber { get; set; }
  231.   public string iopIssuerName { get; set; }
  232.   public string iopTransactionId { get; set; }
  233.   public string batchNumber { get; set; }
  234.   public string originalAmount { get; set; }
  235.   public string cAVV { get; set; }
  236.   public string xID { get; set; }
  237.   public string uCAF { get; set; }
  238.   public string trxOptions { get; set; }
  239.   public string userEchoData { get; set; }

  240.   private string GenericTransactionData()
  241.   {
  242.     String s = COMPANY_NUMBER + "=" + companyNumber
  243.      + "&" + MERCHANT_NUMBER + "=" + merchantNumber
  244.      + "&" + CUSTOMER_NUMBER + "=" + customerNumber                   
  245.      + "&" + INVOICE_NUMBER + "=" + invoiceNumber                   
  246.      + "&" + INPUT_TYPE + "=" + inputType
  247.      + "&" + CARD_TYPE + "=" + cardType
  248.      + "&" + CARD_NUMBER + "=" + cardNumber
  249.      + "&" + EXPIRATION_DATE + "=" + expirationDate
  250.      + "&" + CVV2CVC2_NUMBER + "=" + cvv2cvc2Number
  251.      + "&" + MERCHANT_TERMINAL_NUMBER + "=" + merchantTerminalNumber
  252.      + "&" + LANGUAGE_CODE + "=" + languageCode
  253.      + "&" + CURRENCY_CODE + "=" + currencyCode
  254.      + "&" + OPERATOR_ID + "=" + operatorID
  255.      ;
  256.     return s;
  257.   }

  258.   public String toPurchaseInput()
  259.   {
  260.     String s = GenericTransactionData(); 
  261.     s += "&" + AMOUNT + "=" + amount;
  262.     s += "&" + ORIGINAL_INVOICE_NUMBER + "=" + originalInvoiceNumber;

  263.     if (holderAddress.Length != 0)
  264.     {
  265.         s += "&" + CARDHOLDER_ADDRESS + "=" + holderAddress;
  266.     }

  267.     if (holderPostalCode.Length != 0)
  268.     {
  269.         s += "&" + CARDHOLDER_POSTALCODE + "=" + holderPostalCode;
  270.     }

  271.     if (cAVV.Length != 0)
  272.     {
  273.         s += "&" + CARDHOLDER_AVV + "=" + cAVV;
  274.     }

  275.     if (xID.Length != 0)
  276.     {
  277.         s += "&" + XID + "=" + xID;
  278.     }

  279.     if (uCAF.Length != 0)
  280.     {
  281.         s += "&" + UCAF + "=" + uCAF;
  282.     }


  283.     if (this.trxOptions != null && this.trxOptions.Length != 0)
  284.     {
  285.         s += "&" + TRX_OPTIONS + "=" + this.trxOptions.Split('\n'); ;
  286.     }


  287.     if (userEchoData.Length != 0)
  288.     {
  289.         s += "&" + USER_ECHO_DATA + "=" + userEchoData;
  290.     }

  291.     return s;
  292.   }
  293. }
    • Related Articles

    • Code Example - Java

      JAVA Edit main.java CTPaymentClient restv1Client = new CTPaymentClient("https://test.api.payfacto.com/", "00000000000000000000000000000000000" ); // PURCHASE EXAMPLE HashMap<String, String> params = new HashMap<String, String>(); ...
    • Code Example : HTML - JavaScript

      form.html <html> <body> <script type="text/javascript"> function encodeString(str) { document.PURCHASE.payload.value = btoa(str); } </script> <form name="PURCHASE" action="https://test.api.payfacto.com/v1/purchase" method="POST"> auth-api-key<input ...
    • Code Example : PHP

      PHP Edit main.php <?php $payload="CompanyNumber=00000&MerchantNumber=00000000&CustomerNumber=00000000&Amount=00000001000&InvoiceNumber=505836912354&OriginalInvoiceNumber=505836912354&InputType=I&CardType= ...
    • Example Calls to the Secure Payment Application

      This page lists code examples for the various Secure Payment transactions Purchase JavaScript Intent intent = new Intent("com.payfacto.terminal.payment.PAYMENT_ACTIVITY");   intent.putExtra("TRANSACTION", "SALE"); intent.putExtra("AMOUNT", "100"); // ...
    • Credit Card Verification Code (CVV)

      Introduction This code is not found on the magnetic stripe, making it impossible for the defrauder to copy the magnetic stripe or to learn the card’s verification code. This code is not embossed on the credit card either (characters engraved in the ...