<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Perl example based on Accept.JS in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Perl-example-based-on-Accept-JS/m-p/70385#M43217</link>
    <description>&lt;P&gt;I spent some time putting together some Perl code for anyone interested. It’s based on Accept.JS. &amp;nbsp;I’ve included my example sandbox code below. It’s not complete but should provide the process flow and technique. &amp;nbsp;I’m sure there’s room for improvement. If anyone see’s any issues or concerns on this approach please comment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
 &amp;lt;title&amp;gt;sandbox test&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;script type="text/javascript" src="https://jstest.authorize.net/v1/Accept.js" charset="utf-8"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;input  type="text" name="cardNumber"    id="cardNumber" value="5424000000000015" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="expMonth"      id="expMonth"   value="12" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="expYear"       id="expYear"    value="2020" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="cardCode"      id="cardCode"   value="999" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;button type="button" onclick="sendPaymentDataToAnet()"&amp;gt;Pay&amp;lt;/button&amp;gt;

&amp;lt;div id="results"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;

 function sendPaymentDataToAnet() {

  var authData = {};
      authData.clientKey  = "&amp;lt;your sandbox key&amp;gt;";
      authData.apiLoginID = "&amp;lt;your sandbox id&amp;gt;";
  var cardData = {};
      cardData.cardNumber = document.getElementById("cardNumber").value;
      cardData.month      = document.getElementById("expMonth").value;
      cardData.year       = document.getElementById("expYear").value;
      cardData.cardCode   = document.getElementById("cardCode").value;
  var secureData = {};
      secureData.authData = authData;
      secureData.cardData = cardData;

  Accept.dispatchData(secureData, responseHandler);

 }

 function responseHandler(response) {

  var F = new FormData();
  var R = JSON.stringify(response);
  var T = new Date().getTime();
  F.append("response",R);
  F.append("timestamp",T);

  if (window.XMLHttpRequest) {
      var XHR = new XMLHttpRequest();
  } else {
      var XHR = new ActiveXObject("Microsoft.XMLHTTP");
  }
  XHR.open("POST","&amp;lt;perl script location&amp;gt;",true);
  XHR.onreadystatechange = function () {
    if (XHR.readyState == 4 &amp;amp;&amp;amp; XHR.status == 200) {
        document.getElementById("results").innerHTML = XHR.responseText;
    }
  }
  XHR.send(F);

 }

&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/PRE&gt;&lt;P&gt;PERL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl

MAIN:
{
 use CGI;
 $CGI=new CGI;
 use LWP::UserAgent; # yum install perl-LWP-Protocol-https perl-libwww-perl perl-JSON
 use JSON;

 $API_URL             = 'https://apitest.authorize.net/xml/v1/request.api';
 $API_LOGIN_ID        = "&amp;lt;your sanfbox id&amp;gt;";
 $API_TRANSACTION_KEY = "&amp;lt;your sandbox key&amp;gt;";
 $AMOUNT              = "10";  # test amount

 $response = $CGI-&amp;gt;param('response');
 $response = decode_json($response);

 my $log = "&amp;lt;br&amp;gt;";
 $log.="resultCode   = $$response{messages}{resultCode}&amp;lt;br&amp;gt;";
 $log.="message code = $$response{messages}{message}[i]{code}&amp;lt;br&amp;gt;";
 $log.="message text = $$response{messages}{message}[i]{text}&amp;lt;br&amp;gt;";

 if ($$response{messages}{resultCode} ne "Error") {

     &amp;amp;post_transactionRequest;
     $response = decode_json($postresponse);

     $log.="responseCode         = $$response{transactionResponse}{responseCode}&amp;lt;br&amp;gt;";
     $log.="messages code        = $$response{transactionResponse}{messages}[0]{code}&amp;lt;br&amp;gt;";
     $log.="messages description = $$response{transactionResponse}{messages}[0]{description}&amp;lt;br&amp;gt;";

 }
 print qq~Content-type: text/html\n\n$log~;
 exit;

 #############################
 
 sub post_transactionRequest {
     #
     my $json=qq~{ "createTransactionRequest": {
  "merchantAuthentication": {
   "name": "$API_LOGIN_ID",
   "transactionKey": "$API_TRANSACTION_KEY"
  },
  "transactionRequest": {
   "transactionType": "authCaptureTransaction",
   "amount": "$AMOUNT",
   "payment": {
    "opaqueData": {
     "dataDescriptor": "$$response{opaqueData}{dataDescriptor}",
     "dataValue": "$$response{opaqueData}{dataValue}" }}}}}~;
     #
     my $ua        = new LWP::UserAgent();
     my $response  = $ua-&amp;gt;post($API_URL, Content =&amp;gt; $json);
     $postresponse = $response-&amp;gt;decoded_content;
     $postresponse =~ s/[^{]+//;
     return;
 }

}&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Jan 2020 22:59:08 GMT</pubDate>
    <dc:creator>airman81</dc:creator>
    <dc:date>2020-01-16T22:59:08Z</dc:date>
    <item>
      <title>Perl example based on Accept.JS</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Perl-example-based-on-Accept-JS/m-p/70385#M43217</link>
      <description>&lt;P&gt;I spent some time putting together some Perl code for anyone interested. It’s based on Accept.JS. &amp;nbsp;I’ve included my example sandbox code below. It’s not complete but should provide the process flow and technique. &amp;nbsp;I’m sure there’s room for improvement. If anyone see’s any issues or concerns on this approach please comment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
 &amp;lt;title&amp;gt;sandbox test&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;script type="text/javascript" src="https://jstest.authorize.net/v1/Accept.js" charset="utf-8"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;input  type="text" name="cardNumber"    id="cardNumber" value="5424000000000015" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="expMonth"      id="expMonth"   value="12" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="expYear"       id="expYear"    value="2020" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
&amp;lt;input  type="text" name="cardCode"      id="cardCode"   value="999" /&amp;gt; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;

&amp;lt;button type="button" onclick="sendPaymentDataToAnet()"&amp;gt;Pay&amp;lt;/button&amp;gt;

&amp;lt;div id="results"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;

 function sendPaymentDataToAnet() {

  var authData = {};
      authData.clientKey  = "&amp;lt;your sandbox key&amp;gt;";
      authData.apiLoginID = "&amp;lt;your sandbox id&amp;gt;";
  var cardData = {};
      cardData.cardNumber = document.getElementById("cardNumber").value;
      cardData.month      = document.getElementById("expMonth").value;
      cardData.year       = document.getElementById("expYear").value;
      cardData.cardCode   = document.getElementById("cardCode").value;
  var secureData = {};
      secureData.authData = authData;
      secureData.cardData = cardData;

  Accept.dispatchData(secureData, responseHandler);

 }

 function responseHandler(response) {

  var F = new FormData();
  var R = JSON.stringify(response);
  var T = new Date().getTime();
  F.append("response",R);
  F.append("timestamp",T);

  if (window.XMLHttpRequest) {
      var XHR = new XMLHttpRequest();
  } else {
      var XHR = new ActiveXObject("Microsoft.XMLHTTP");
  }
  XHR.open("POST","&amp;lt;perl script location&amp;gt;",true);
  XHR.onreadystatechange = function () {
    if (XHR.readyState == 4 &amp;amp;&amp;amp; XHR.status == 200) {
        document.getElementById("results").innerHTML = XHR.responseText;
    }
  }
  XHR.send(F);

 }

&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/PRE&gt;&lt;P&gt;PERL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/perl

MAIN:
{
 use CGI;
 $CGI=new CGI;
 use LWP::UserAgent; # yum install perl-LWP-Protocol-https perl-libwww-perl perl-JSON
 use JSON;

 $API_URL             = 'https://apitest.authorize.net/xml/v1/request.api';
 $API_LOGIN_ID        = "&amp;lt;your sanfbox id&amp;gt;";
 $API_TRANSACTION_KEY = "&amp;lt;your sandbox key&amp;gt;";
 $AMOUNT              = "10";  # test amount

 $response = $CGI-&amp;gt;param('response');
 $response = decode_json($response);

 my $log = "&amp;lt;br&amp;gt;";
 $log.="resultCode   = $$response{messages}{resultCode}&amp;lt;br&amp;gt;";
 $log.="message code = $$response{messages}{message}[i]{code}&amp;lt;br&amp;gt;";
 $log.="message text = $$response{messages}{message}[i]{text}&amp;lt;br&amp;gt;";

 if ($$response{messages}{resultCode} ne "Error") {

     &amp;amp;post_transactionRequest;
     $response = decode_json($postresponse);

     $log.="responseCode         = $$response{transactionResponse}{responseCode}&amp;lt;br&amp;gt;";
     $log.="messages code        = $$response{transactionResponse}{messages}[0]{code}&amp;lt;br&amp;gt;";
     $log.="messages description = $$response{transactionResponse}{messages}[0]{description}&amp;lt;br&amp;gt;";

 }
 print qq~Content-type: text/html\n\n$log~;
 exit;

 #############################
 
 sub post_transactionRequest {
     #
     my $json=qq~{ "createTransactionRequest": {
  "merchantAuthentication": {
   "name": "$API_LOGIN_ID",
   "transactionKey": "$API_TRANSACTION_KEY"
  },
  "transactionRequest": {
   "transactionType": "authCaptureTransaction",
   "amount": "$AMOUNT",
   "payment": {
    "opaqueData": {
     "dataDescriptor": "$$response{opaqueData}{dataDescriptor}",
     "dataValue": "$$response{opaqueData}{dataValue}" }}}}}~;
     #
     my $ua        = new LWP::UserAgent();
     my $response  = $ua-&amp;gt;post($API_URL, Content =&amp;gt; $json);
     $postresponse = $response-&amp;gt;decoded_content;
     $postresponse =~ s/[^{]+//;
     return;
 }

}&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jan 2020 22:59:08 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Perl-example-based-on-Accept-JS/m-p/70385#M43217</guid>
      <dc:creator>airman81</dc:creator>
      <dc:date>2020-01-16T22:59:08Z</dc:date>
    </item>
  </channel>
</rss>

