Commit 339f6ca0 authored by jenlampton's avatar jenlampton

Authnet js added. not working yet.

parent 4905884b
This diff is collapsed.
<?php
/**
* @file
* Webform components for the Authorize.Net Webform module.
*/
......@@ -26,9 +26,12 @@ function authorizenetwebform_available_fields() {
'x_card_code' => 'Card Security Code',
'x_description' => 'Transaction Description',
'x_exp_date' => 'Expiration Date (Digits Only)',
'x_exp_month' => 'Expiration Month (2 Digits)', // Needed for accept.js
'x_exp_year' => 'Expiration Year (2 Digits)', // Needed for accept.js
'x_trans_id' => 'Transaction ID (Must be Mapped - Hidden Field)',
//Cardholder Info
'x_full_name' => 'Full Name', // Needed for accept.js
'x_first_name' => 'First Name',
'x_last_name' => 'Last Name',
'x_address' => 'Address',
......
<?php
$xmlstr = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name></name>
<transactionKey></transactionKey>
</merchantAuthentication>
<refId></refId>
<transactionRequest>
<transactionType>authCaptureTransaction</transactionType>
<amount></amount>
<payment>
<opaqueData>
<dataDescriptor>COMMON.ACCEPT.INAPP.PAYMENT</dataDescriptor>
<dataValue></dataValue>
</opaqueData>
</payment>
</transactionRequest>
</createTransactionRequest>
XML;
/**
* @file
* Authorizenetwebform JavaScript integration.
*/
(function($){ // Create local scope.
Drupal.behaviors.authorizenetwebform = {
attach: function (context) {
// Find the weborm that submits to authnet.
$(context).find("[data-authnet-form]").once(function () {
// Get the whole form.
var $webform = $(this);
// Find the submit button.
var $button = $(this).find("[data-authnet-submit]");
// Submit to AuthNet on click.
$button.click(sendPaymentDataToAnet);
/**
* Sends the payment information to AuthNet.
*/
function sendPaymentDataToAnet(e) {
var secureData = {}, authData = {}, cardData = {};
for (var key in Drupal.settings.authorizeNetWebform.mapping) {
if (Drupal.settings.authorizeNetWebform.mapping.hasOwnProperty(key)) {
var value = Drupal.settings.authorizeNetWebform.mapping[key];
cardData[key] = $webform.find("[" + value + "]").val();
}
}
secureData.cardData = cardData;
authData.clientKey = Drupal.settings.authorizeNetWebform.clientKey;
authData.apiLoginID = Drupal.settings.authorizeNetWebform.apiLoginID;
secureData.authData = authData;
Accept.dispatchData(secureData, 'responseHandler');
// Prevent the webform from submitting now. @see line 73.
e.preventDefault();
}
/**
* Handles the response from AuthNet.
*/
responseHandler = function(response) {
if (response.messages.resultCode === 'Error') {
for (var i = 0; i < response.messages.message.length; i++) {
console.log(response.messages.message[i].code + ': ' + response.messages.message[i].text);
}
}
else {
useOpaqueData(response.opaqueData);
}
}
/**
* Updtes the webform with the transaction ID returned from AuthNet.
*/
useOpaqueData = function(responseData) {
//console.log(responseData.dataDescriptor);
//console.log(responseData.dataValue);
//alert(responseData.dataValue);
// Insert the data value into the hidden Transaction ID field.
$(context).find("[data-authnet-field-transaction_id=x_trans_id]").val(responseData.dataValue);
// Submit the webform when done.
$(context).find("[data-authnet-form]").submit();
}
});
}
};
})(jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment