Code Example : HTML - JavaScript

Code Example : HTML - JavaScript

form.html

  1. <html>
  2. <body>

  3. <script type="text/javascript">
  4. function encodeString(str) {
  5. document.PURCHASE.payload.value = btoa(str);
  6. }
  7. </script>

  8. <form name="PURCHASE" action="https://test.api.payfacto.com/v1/purchase" method="POST">
  9. auth-api-key<input type="text" name="auth-api-key" value="00000000000000000000000000000000000">
  10. <textarea name="input" placeholder="Some text">CompanyNumber=00000&MerchantNumber=00000000&CustomerNumber=00000000&Amount=00000001000&InvoiceNumber=505836912354&OriginalInvoiceNumber=505836912354&InputType=I&CardType= &CardNumber=4502285070000007&ExpirationDate=0726&Cvv2Cvc2Number=123&MerchantTerminalNumber=     &LanguageCode=F&CurrencyCode=CAD&OperatorID=CTPSIMUL</TextArea>
  11. <input type="button" onclick="encodeString(document.PURCHASE.input.value);" value="Encode" >
  12. <input type="text" size="1024" name="payload" value="">
  13. <input type="submit" value="Submit">
  14. </form>

  15. </body>
  16. </html>

javascript.html

  1. <!DOCTYPE html>
  2. <html>
  3. <body>

  4. <h1>The Javascript example</h1>

  5. <button type="button" onclick="loadDoc()">Request data</button>

  6. <p id="demo"></p>
  7.  
  8. <script>
  9. var str = "CompanyNumber=00000&MerchantNumber=00000000&CustomerNumber=00000000&Amount=00000001000&InvoiceNumber=505836912354&OriginalInvoiceNumber=505836912354&InputType=I&CardType= &CardNumber=4502285070000007&ExpirationDate=0726&Cvv2Cvc2Number=123&MerchantTerminalNumber=     &LanguageCode=F&CurrencyCode=CAD&OperatorID=CTPSIMUL";


  10. function loadDoc() {
  11.   var xhttp = new XMLHttpRequest();
  12.   xhttp.onreadystatechange = function() {
  13.     if (this.readyState == 4 && this.status == 200) {
  14.       document.getElementById("demo").innerHTML = this.responseText;
  15.     }
  16.   };
  17.   xhttp.open("POST", "https://test.api.payfacto.com/v1/purchase", true);
  18.   xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  19.   xhttp.setRequestHeader("Accept", "application/json");
  20.   xhttp.send("auth-api-key=00000000000000000000000000000000000&payload=" + btoa(str));
  21. }
  22. </script>

  23. </body>
  24. </html>
    • Related Articles

    • Code Example Microsoft .NET

      Microsoft .NET Edit main.cs PaymentTransaction paymentTransaction = new PaymentTransaction("https://test.api.payfacto.com/v1", "00000000000000000000000000000000000"); String purchaseInput = FillPurchaseInput(); transactionOutput = ...
    • 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>(); ...
    • 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"); // ...
    • Code Example : PHP

      PHP Edit main.php <?php $payload="CompanyNumber=00000&MerchantNumber=00000000&CustomerNumber=00000000&Amount=00000001000&InvoiceNumber=505836912354&OriginalInvoiceNumber=505836912354&InputType=I&CardType= ...
    • SPL - Secure Pay By Link

      Secure Pay By Link Secure Pay By Link (SPL) is a new offering from PayFacto that allows a merchant to defer a SHC session to another time. It does that by creating a link that the cardholder can follow to a hosted page. When the cardholder navigates ...