summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergei Stryukov2012-10-08 13:44:27 (GMT)
committer Sergei Stryukov2012-10-08 13:44:27 (GMT)
commit3dee801ff0cd6ee02ed72c626bb734e119f1cbc5 (patch)
treeee4ae50ed551093c0947f242aab55edcbca259b3
Initial commit.
-rw-r--r--eWayRapid.inc562
-rw-r--r--uc_eway_rapid.info9
-rw-r--r--uc_eway_rapid.module199
3 files changed, 770 insertions, 0 deletions
diff --git a/eWayRapid.inc b/eWayRapid.inc
new file mode 100644
index 0000000..f6c7473
--- /dev/null
+++ b/eWayRapid.inc
@@ -0,0 +1,562 @@
+<?php
+
+class eWayRapid {
+ /**
+ * @var string The Username for HTTP authorization on SOAP server.
+ */
+ public $httpUsername;
+
+ /**
+ * @var string The Password for HTTP authorization on SOAP server.
+ */
+ public $httpPassword;
+
+ /**
+ * @var bool The flag, which enables "sandbox" mode for this class.
+ */
+ public $sandbox;
+
+ /**
+ * @var string The storage for error messages.
+ */
+ public $error;
+
+
+ function __construct($username, $password, $sandbox = FALSE) {
+ $this->httpUsername = $username;
+ $this->httpPassword = $password;
+ $this->sandbox = $password;
+ }
+
+ /**
+ * Returns the URL to the eWAY RapidAPI SOAP service.
+ *
+ * @return string
+ */
+ private function getPaymentServiceURL() {
+ if ($this->sandbox) {
+ return 'https://api.sandbox.ewaypayments.com/Soap.asmx?WSDL';
+ }
+ else {
+ return 'https://api.ewaypayments.com/Soap.asmx?WSDL';
+ }
+ }
+
+ /**
+ * Calls the $service service of SOAP server using $request as request and returns the $response_field field of
+ * web service's response.
+ *
+ * @param string $service
+ * @param StdClass $request
+ * @param string$response_field
+ * @return StdClass|bool
+ */
+ private function soapCall($service, $request, $response_field) {
+ $this->error = '';
+
+ try {
+ $client = new SoapClient($this->getPaymentServiceURL(), array(
+ 'trace' => TRUE,
+ 'exceptions' => TRUE,
+ 'login' => $this->httpUsername,
+ 'password' => $this->httpPassword
+ ));
+
+ $result = $client->{$service}(array('request' => get_object_vars($request)));
+ // print htmlspecialchars($client->__getLastRequest());
+ }
+ catch (Exception $e) {
+ $this->error = t('@service SOAP Error: @error', array('@service' => $service, '@error' => $e->getMessage()));
+ }
+
+ if (empty($this->error)) {
+ return $result->{$response_field};
+ }
+ else {
+ return FALSE;
+ }
+ }
+
+ /**
+ * Calls "Create Access Code" web service.
+ *
+ * @param CreateAccessCodeRequest $request
+ * @return StdClass or bool
+ */
+ public function CreateAccessCode($request) {
+ return $this->soapCall('CreateAccessCode', $request, 'CreateAccessCodeResult');
+ }
+
+ /**
+ * Calls "Get Access Code Result" web service.
+ *
+ * @param GetAccessCodeResultRequest $request
+ * @return StdClass|bool
+ */
+ private function GetAccessCodeResult($request) {
+ return $this->soapCall('GetAccessCodeResult', $request, 'GetAccessCodeResultResult');
+ }
+
+ /**
+ * @param $fieldsValues
+ * @return CheckoutResponse|bool
+ */
+ public function submitToFormActionURL($fieldsValues) {
+ require_once 'HTTP/Request2.php';
+ require_once 'HTTP/Request2/Response.php';
+ require_once 'HTTP/Request2/CookieJar.php';
+
+ // Prepare fields of the form.
+ $formFields = array(
+ 'EWAY_ACCESSCODE' => $fieldsValues->AccessCode,
+ 'EWAY_CARDNAME' => $fieldsValues->CardOwner,
+ 'EWAY_CARDNUMBER' => $fieldsValues->CardNumber,
+ 'EWAY_CARDEXPIRYMONTH' => $fieldsValues->CardExpMonth,
+ 'EWAY_CARDEXPIRYYEAR' => $fieldsValues->CardExpYear,
+ 'EWAY_CARDSTARTMONTH' => '',
+ 'EWAY_CARDSTARTYEAR' => '',
+ 'EWAY_CARDISSUENUMBER' => !empty($fieldsValues->CardIssueNumber) ? $fieldsValues->CardIssueNumber : '22',
+ 'EWAY_CARDCVN' => $fieldsValues->CardCVV,
+ );
+
+ // Submit the form.
+ $httpOut = new HTTP_Request2($fieldsValues->FormActionURL);
+ $httpOut->setMethod(HTTP_Request2::METHOD_POST)->addPostParameter($formFields);
+ $httpOut->setConfig(array('ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE, 'follow_redirects' => TRUE));
+
+ $httpIn = $httpOut->send();
+
+ // Check result.
+ if ($httpIn->getStatus() != '200') {
+ $this->error = t('FormActionURL Form Error: @error', array('@error' => print_r($httpIn, 1)));
+ return FALSE;
+ }
+
+ $url = $httpIn->geteffectiveUrl();
+
+ if (empty($url)) {
+ $this->error = t('FormActionURL Form Error: the "effectiveUrl" is missed. HTTP Response: @http', array('@http' => print_r($httpIn, 1)));
+ return FALSE;
+ }
+
+ parse_str(parse_url($url, PHP_URL_QUERY), $query);
+
+ if (empty($query['AccessCode'])) {
+ $this->error = t('FormActionURL Form Error: the "AccessCode" is missed. HTTP Response: @http', array('@http' => print_r($httpIn, 1)));
+ return FALSE;
+ }
+
+ // Build request for getting the result with the access code.
+ $request = new GetAccessCodeResultRequest();
+ $request->AccessCode = $query['AccessCode'];
+
+ // Get the result.
+ $result = $this->GetAccessCodeResult($request);
+
+ // Create CheckoutResponse Object.
+ $final = new CheckoutResponse();
+ $final->CheckoutResponse = $result;
+
+ $final->parseResponseMessage();
+
+ return $final;
+ }
+}
+
+class CreateAccessCodeRequest {
+ public $RedirectUrl;
+ public $IPAddress;
+ public $Method;
+ //public $DeviceID;
+ public $Payment;
+ public $Customer;
+ public $ShippingAddress;
+ public $Items;
+ public $Options;
+
+ function __construct() {
+ $this->Payment = new Payment();
+ $this->Customer = new Customer();
+ $this->ShippingAddress = new ShippingAddress();
+
+ $this->IPAddress = $_SERVER["SERVER_NAME"];
+
+ /**
+ * URL to the page for getting the result with an AccessCode.
+ * We use FRONT page, because we parse HTTP response from eWAY, so we don't need to do anything on RedirectUrl page.
+ */
+ $this->RedirectUrl = url('<front>', array('absolute' => TRUE));
+ }
+}
+
+class Payment {
+ //<Payment>
+ // <TotalAmount>1000</TotalAmount>
+ // <InvoiceNumber>19832261</InvoiceNumber>
+ // <InvoiceDescription>Online Purchase</InvoiceDescription>
+ // <InvoiceReference>19832261-AA12/1</InvoiceReference>
+ // <CurrencyCode>AUD</CurrencyCode>
+ //</Payment>
+
+ public $TotalAmount;
+ public $InvoiceNumber;
+ public $InvoiceDescription;
+ public $InvoiceReference;
+ public $CurrencyCode;
+}
+
+class Customer {
+ //<Customer>
+ // <Reference>Test123</Reference>
+ // <Title>Mr.</Title>
+ // <FirstName>John</FirstName>
+ // <LastName>Smith</LastName>
+ // <CompanyName>eWAY</CompanyName>
+ // <JobDescription></JobDescription>
+ // <Street1>Unit 4</Street1>
+ // <Street2>15 Smith St</Street2>
+ // <City>Sydney</City>
+ // <State>NSW</State>
+ // <PostalCode>2000</PostalCode>
+ // <Country>au</Country>
+ // <Email>sales@dummyshop123.com</Email>
+ // <Phone>1800106565</Phone>
+ // <Mobile>1800106565</Mobile>
+ // <Comments>Customer comments</Comments>
+ // <Fax>1800106565</Fax>
+ // <Url>http://www.dummyshop123.com</Url>
+ //</Customer>
+
+ public $TokenCustomerID;
+ public $Reference;
+ public $Title;
+ public $FirstName;
+ public $LastName;
+ public $CompanyName;
+ public $JobDescription;
+ public $Street1;
+ public $Street2;
+ public $City;
+ public $State;
+ public $PostalCode;
+ public $Country;
+ public $Email;
+ public $Phone;
+ public $Mobile;
+ public $Comments;
+ public $Fax;
+ public $Url;
+}
+
+class ShippingAddress {
+ //<ShippingAddress>
+ // <ShippingMethod>NextDay</ShippingMethod>
+ // <FirstName>John</FirstName>
+ // <LastName>Smith</LastName>
+ // <Street1>Unit 4</Street1>
+ // <Street2>15 Smith St</Street2>
+ // <City>Sydney</City>
+ // <State>NSW</State>
+ // <PostalCode>2000</PostalCode>
+ // <Country>au</Country>
+ // <Email>sales@dummyshop123.com</Email>
+ // <Phone>1800106565</Phone>
+ // <Fax>1800106565</Fax>
+ //</ShippingAddress>
+
+ public $ShippingMethod;
+ public $FirstName;
+ public $LastName;
+ public $Street1;
+ public $Street2;
+ public $City;
+ public $State;
+ public $PostalCode;
+ public $Country;
+ public $Email;
+ public $Phone;
+ public $Fax;
+}
+
+class Items {
+ public $LineItem = array();
+}
+
+class LineItem {
+ //<LineItem>
+ // <SKU>123456-99</SKU>
+ // <Description>Red Socks</Description>
+ // <Quantity>1</Quantity>
+ // <UnitCost>909</UnitCost>
+ // <Tax>91</Tax>
+ // <Total>1000</Total>
+ //</LineItem>
+
+ public $SKU;
+ public $Description;
+ public $Quantity;
+ public $UnitCost;
+ public $Tax;
+ public $Total;
+}
+
+class Options {
+ public $Option = array();
+}
+
+class Option {
+ public $Value;
+}
+
+class GetAccessCodeResultRequest {
+ public $AccessCode;
+}
+
+class FormActionURL {
+ public $FormActionURL;
+ public $AccessCode;
+ public $CardOwner;
+ public $CardNumber;
+ public $CardExpMonth;
+ public $CardExpYear;
+ public $CardIssueNumber;
+ public $CardCVV;
+}
+
+class CheckoutResponse {
+ public $CheckoutResponse;
+
+ // Messages, provided by each validation type.
+ public $ValidationMessages;
+ public $BeagleAlertsMessages;
+ public $TransactionMessage;
+
+ // Status of each validation type.
+ public $TransactionStatus;
+ public $BeagleStatus;
+ public $ValidationStatus;
+
+ // Final status of checkout.
+ public $CheckoutStatus;
+
+ private $ValidationResponseCodes = array(
+ 'V6000' => 'Validation error',
+ 'V6001' => 'Invalid CustomerIP',
+ 'V6002' => 'Invalid DeviceID',
+ 'V6011' => 'Invalid Payment TotalAmount',
+ 'V6012' => 'Invalid Payment InvoiceDescription',
+ 'V6013' => 'Invalid Payment InvoiceNumber',
+ 'V6014' => 'Invalid Payment InvoiceReference',
+ 'V6015' => 'Invalid Payment CurrencyCode',
+ 'V6016' => 'Payment Required',
+ 'V6017' => 'Payment CurrencyCode Required',
+ 'V6018' => 'Unknown Payment CurrencyCode',
+ 'V6021' => 'EWAY_CARDHOLDERNAME Required',
+ 'V6022' => 'EWAY_CARDNUMBER Required',
+ 'V6023' => 'EWAY_CARDCVN Required',
+ 'V6033' => 'Invalid Expiry Date',
+ 'V6034' => 'Invalid Issue Number',
+ 'V6035' => 'Invalid Valid From Date',
+ 'V6040' => 'Invalid TokenCustomerID',
+ 'V6041' => 'Customer Required',
+ 'V6042' => 'Customer FirstName Required',
+ 'V6043' => 'Customer LastName Required',
+ 'V6044' => 'Customer CountryCode Required',
+ 'V6045' => 'Customer Title Required',
+ 'V6046' => 'TokenCustomerID Required',
+ 'V6047' => 'RedirectURL Required',
+ 'V6051' => 'Invalid Customer FirstName',
+ 'V6052' => 'Invalid Customer LastName',
+ 'V6053' => 'Invalid Customer CountryCode',
+ 'V6054' => 'Invalid Customer Email',
+ 'V6058' => 'Invalid Customer Title',
+ 'V6059' => 'Invalid RedirectURL',
+ 'V6060' => 'Invalid TokenCustomerID',
+ 'V6061' => 'Invalid Customer Reference',
+ 'V6062' => 'Invalid Customer CompanyName',
+ 'V6063' => 'Invalid Customer JobDescription',
+ 'V6064' => 'Invalid Customer Street1',
+ 'V6065' => 'Invalid Customer Street2',
+ 'V6066' => 'Invalid Customer City',
+ 'V6067' => 'Invalid Customer State',
+ 'V6068' => 'Invalid Customer PostalCode',
+ 'V6069' => 'Invalid Customer Email',
+ 'V6070' => 'Invalid Customer Phone',
+ 'V6071' => 'Invalid Customer Mobile',
+ 'V6072' => 'Invalid Customer Comments',
+ 'V6073' => 'Invalid Customer Fax',
+ 'V6074' => 'Invalid Customer URL',
+ 'V6075' => 'Invalid ShippingAddress FirstName',
+ 'V6076' => 'Invalid ShippingAddress LastName',
+ 'V6077' => 'Invalid ShippingAddress Street1',
+ 'V6078' => 'Invalid ShippingAddress Street2',
+ 'V6079' => 'Invalid ShippingAddress City',
+ 'V6080' => 'Invalid ShippingAddress State',
+ 'V6081' => 'Invalid ShippingAddress PostalCode',
+ 'V6082' => 'Invalid ShippingAddress Email',
+ 'V6083' => 'Invalid ShippingAddress Phone',
+ 'V6084' => 'Invalid ShippingAddress Country',
+ 'V6091' => 'Unknown Customer CountryCode',
+ 'V6100' => 'Invalid EWAY_CARDNAME',
+ 'V6101' => 'Invalid EWAY_CARDEXPIRYMONTH',
+ 'V6102' => 'Invalid EWAY_CARDEXPIRYYEAR',
+ 'V6103' => 'Invalid EWAY_CARDSTARTMONTH',
+ 'V6104' => 'Invalid EWAY_CARDSTARTYEAR',
+ 'V6105' => 'Invalid EWAY_CARDISSUENUMBER',
+ 'V6106' => 'Invalid EWAY_CARDCVN',
+ 'V6107' => 'Invalid EWAY_ACCESSCODE',
+ 'V6108' => 'Invalid CustomerHostAddress',
+ 'V6109' => 'Invalid UserAgent',
+ 'V6110' => 'Invalid EWAY_CARDNUMBER'
+ );
+
+ private $BeagleAlertsFraudResponseMessages = array(
+ 'F9010' => 'High Risk Billing Country',
+ 'F9011' => 'High Risk Credit Card Country',
+ 'F9012' => 'High Risk Customer IP Address',
+ 'F9013' => 'High Risk Email Address',
+ 'F9014' => 'High Risk Shipping Country',
+ 'F9015' => 'Multiple card numbers for single email address',
+ 'F9016' => 'Multiple card numbers for single location',
+ 'F9017' => 'Multiple email addresses for single card number',
+ 'F9018' => 'Multiple email addresses for single location',
+ 'F9019' => 'Multiple locations for single card number',
+ 'F9020' => 'Multiple locations for single email address',
+ 'F9021' => 'Suspicious Customer First Name',
+ 'F9022' => 'Suspicious Customer Last Name',
+ 'F9023' => 'Transaction Declined',
+ 'F9024' => 'Multiple transactions for same address with known credit card',
+ 'F9025' => 'Multiple transactions for same address with new credit card',
+ 'F9026' => 'Multiple transactions for same email with new credit card',
+ 'F9027' => 'Multiple transactions for same email with known credit card',
+ 'F9028' => 'Multiple transactions for new credit card',
+ 'F9029' => 'Multiple transactions for known credit card',
+ 'F9030' => 'Multiple transactions for same email address',
+ 'F9031' => 'Multiple transactions for same credit card',
+ 'F9032' => 'Invalid Customer Last Name',
+ 'F9033' => 'Invalid Billing Street',
+ 'F9034' => 'Invalid Shipping Street',
+ );
+
+ /**
+ * @var array The list of all the possible response messages returned from the Rapid 3.0 and the relating result.
+ */
+ private $TransactionResponseMessages = array(
+ 'A2000' => array('Transaction Approved', 'Successful'),
+ 'A2008' => array('Honor With Identification', 'Successful'),
+ 'A2010' => array('Approved For Partial Amount', 'Successful'),
+ 'A2011' => array('Approved, VIP', 'Successful'),
+ 'A2016' => array('Approved, Update Track 3', 'Successful'),
+ 'D4401' => array('Refer to Issuer', 'Failed'),
+ 'D4402' => array('Refer to Issuer, Special', 'Failed'),
+ 'D4403' => array('No Merchant', 'Failed'),
+ 'D4404' => array('Pick Up Card', 'Failed'),
+ 'D4405' => array('Do Not Honor', 'Failed'),
+ 'D4406' => array('Error', 'Failed'),
+ 'D4407' => array('Pick Up Card, Special', 'Failed'),
+ 'D4409' => array('Request In Progress', 'Failed'),
+ 'D4412' => array('Invalid Transaction', 'Failed'),
+ 'D4413' => array('Invalid Amount', 'Failed'),
+ 'D4414' => array('Invalid Card Number', 'Failed'),
+ 'D4415' => array('No Issuer', 'Failed'),
+ 'D4419' => array('Re-enter Last Transaction', 'Failed'),
+ 'D4421' => array('No Action Taken', 'Failed'),
+ 'D4422' => array('Suspected Malfunction', 'Failed'),
+ 'D4423' => array('Unacceptable Transaction Fee', 'Failed'),
+ 'D4425' => array('Unable to Locate Record On File', 'Failed'),
+ 'D4430' => array('Format Error', 'Failed'),
+ 'D4431' => array('Bank Not Supported By Switch', 'Failed'),
+ 'D4433' => array('Expired Card, Capture', 'Failed'),
+ 'D4434' => array('Suspected Fraud, Retain Card', 'Failed'),
+ 'D4435' => array('Card Acceptor, Contact Acquirer, Retain Card', 'Failed'),
+ 'D4436' => array('Restricted Card, Retain Card', 'Failed'),
+ 'D4437' => array('Contact Acquirer Security Department, Retain Card', 'Failed'),
+ 'D4438' => array('PIN Tries Exceeded, Capture', 'Failed'),
+ 'D4439' => array('No Credit Account', 'Failed'),
+ 'D4440' => array('Function Not Supported', 'Failed'),
+ 'D4441' => array('Lost Card', 'Failed'),
+ 'D4442' => array('No Universal Account', 'Failed'),
+ 'D4443' => array('Stolen Card', 'Failed'),
+ 'D4444' => array('No Investment Account', 'Failed'),
+ 'D4451' => array('Insufficient Funds', 'Failed'),
+ 'D4452' => array('No Cheque Account', 'Failed'),
+ 'D4453' => array('No Savings Account', 'Failed'),
+ 'D4454' => array('Expired Card', 'Failed'),
+ 'D4455' => array('Incorrect PIN', 'Failed'),
+ 'D4456' => array('No Card Record', 'Failed'),
+ 'D4457' => array('Function Not Permitted to Cardholder', 'Failed'),
+ 'D4458' => array('Function Not Permitted to Terminal', 'Failed'),
+ 'D4459' => array('Suspected Fraud', 'Failed'),
+ 'D4460' => array('Acceptor Contact Acquirer', 'Failed'),
+ 'D4461' => array('Exceeds Withdrawal Limit', 'Failed'),
+ 'D4462' => array('Restricted Card', 'Failed'),
+ 'D4463' => array('Security Violation', 'Failed'),
+ 'D4464' => array('Original Amount Incorrect', 'Failed'),
+ 'D4466' => array('Acceptor Contact Acquirer, Security', 'Failed'),
+ 'D4467' => array('Capture Card', 'Failed'),
+ 'D4475' => array('PIN Tries Exceeded', 'Failed'),
+ 'D4482' => array('CVV Validation Error', 'Failed'),
+ 'D4490' => array('Cutoff In Progress', 'Failed'),
+ 'D4491' => array('Card Issuer Unavailable', 'Failed'),
+ 'D4492' => array('Unable To Route Transaction', 'Failed'),
+ 'D4493' => array('Cannot Complete, Violation Of The Law', 'Failed'),
+ 'D4494' => array('Duplicate Transaction', 'Failed'),
+ 'D4496' => array('System Error', 'Failed'),
+ );
+
+ public function parseResponseMessage() {
+ $this->ValidationMessage = $this->BeagleAlertsMessages = $this->TransactionMessage = array();
+
+ $messages = explode(', ', $this->CheckoutResponse->ResponseMessage);
+
+ for ($i=0; $i<count($messages); $i++) {
+ switch ($messages[$i][0]) {
+ case 'V':
+ $source = 'ValidationResponseCodes';
+ $destination = 'ValidationMessages';
+ break;
+
+ case 'F';
+ $source = 'BeagleAlertsFraudResponseMessages';
+ $destination = 'BeagleAlertsMessages';
+ break;
+
+ case 'A';
+ case 'D';
+ $source = 'TransactionResponseMessages';
+ $destination = 'TransactionMessage';
+ break;
+
+ default:
+ return t('Unknown message: @msg', array('@msg' => $messages[$i]));
+ }
+
+ if (!empty($this->{$source}[$messages[$i]])) {
+ $this->{$destination}[$messages[$i]] = $this->{$source}[$messages[$i]];
+ }
+ else {
+ $this->{$destination}[$messages[$i]] = $messages[$i];
+ }
+ }
+
+ foreach ($this->TransactionMessage as $k => $v) {
+ $this->TransactionStatus = $v[1] == 'Successful' ? 1 : 0;
+ $this->TransactionMessage[$k] = $v[0];
+ }
+
+ $this->BeagleStatus = empty($this->BeagleAlertsMessages) ? 1 : 0;
+
+ $this->CheckoutStatus = $this->TransactionStatus && $this->BeagleStatus ? 1 : 0;
+ }
+
+ public function getTransactionMessage() {
+ static $message;
+
+ if (empty($message)) {
+ $message = array_values($this->TransactionMessage);
+ $message = $message[0];
+ }
+
+ return $message;
+ }
+} \ No newline at end of file
diff --git a/uc_eway_rapid.info b/uc_eway_rapid.info
new file mode 100644
index 0000000..99f00c8
--- /dev/null
+++ b/uc_eway_rapid.info
@@ -0,0 +1,9 @@
+name = eWAY Rapid
+description = Provides an eWAY Rapid payment method.
+dependencies[] = uc_payment
+dependencies[] = uc_credit
+package = Ubercart - payment
+core = 7.x
+
+version = "7.x-1.x-dev"
+files[] = eway_rapid.module
diff --git a/uc_eway_rapid.module b/uc_eway_rapid.module
new file mode 100644
index 0000000..41085cc
--- /dev/null
+++ b/uc_eway_rapid.module
@@ -0,0 +1,199 @@
+<?php
+
+/**
+ * Implements hook_uc_payment_gateway().
+ */
+function uc_eway_rapid_uc_payment_gateway() {
+ $gateways['uc_eway_rapid'] = array(
+ 'title' => t('eWAY Rapid'),
+ 'description' => t('Process credit card payments using eWAY Rapid'),
+ 'settings' => 'uc_eway_rapid_settings_form',
+ 'credit' => 'uc_eway_rapid_charge',
+ );
+
+ return $gateways;
+}
+
+/**
+ * Callback for payment gateway settings.
+ */
+function uc_eway_rapid_settings_form($form, &$form_state) {
+ $form['uc_eway_rapid_payment_username'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Payment Username'),
+ '#default_value' => variable_get('uc_eway_rapid_payment_username', ''),
+ '#description' => t('API Key here. Please login to the Sandbox or Live business centre, create a user and view API Key.'),
+ );
+
+ $form['uc_eway_rapid_payment_password'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Payment Password'),
+ '#default_value' => variable_get('uc_eway_rapid_payment_password', ''),
+ '#description' => t('Password set for the user in the Sandbox or Live business centre.'),
+ );
+
+ $form['uc_eway_rapid_show_debug_info'] = array(
+ '#type' => 'select',
+ '#title' => t('Show Debug Info'),
+ '#options' => array(1 => 'Yes', 0 => 'No'),
+ '#default_value' => variable_get('uc_eway_rapid_show_debug_info', 0),
+ );
+
+ $form['uc_eway_rapid_sandbox_mode'] = array(
+ '#type' => 'select',
+ '#title' => t('Sandbox Mode'),
+ '#options' => array(1 => 'Yes', 0 => 'No'),
+ '#default_value' => variable_get('uc_eway_rapid_sandbox_mode', 1),
+ );
+
+ return $form;
+}
+
+/**
+ * Callback for payment gateway charge.
+ */
+function uc_eway_rapid_charge($order_id, $amount, $data) {
+ global $user;
+
+ // Load order content.
+ $order = uc_order_load($order_id);
+
+ // Include eWayRapid class.
+ module_load_include('inc', 'uc_eway_rapid', 'eWayRapid');
+
+ // Create eWayRapid Service
+ $service = new eWayRapid(
+ variable_get('uc_eway_rapid_payment_username', ''),
+ variable_get('uc_eway_rapid_payment_password', ''),
+ variable_get('uc_eway_rapid_sandbox_mode', 1)
+ );
+
+ $billing_country = uc_get_country_data(array('country_id' => $order->billing_country));
+ $delivery_country = uc_get_country_data(array('country_id' => $order->delivery_country));
+
+ // Create AccessCode Request Object.
+ $request = new CreateAccessCodeRequest();
+
+ // Populate values for Customer Object.
+ $request->Customer->FirstName = $order->billing_first_name;
+ $request->Customer->LastName = $order->billing_last_name;
+ $request->Customer->CompanyName = $order->billing_company;
+ $request->Customer->Street1 = $order->billing_street1;
+ $request->Customer->Street2 = $order->billing_street2;
+ $request->Customer->City = $order->billing_city;
+ $request->Customer->State = uc_get_zone_code($order->billing_zone);
+ $request->Customer->PostalCode = $order->billing_postal_code;
+ $request->Customer->Country = $billing_country[0]['country_iso_code_2'];
+ $request->Customer->Email = $order->primary_email;
+ $request->Customer->Phone = $order->billing_phone;
+
+ // Populate values for ShippingAddress Object.
+ $request->ShippingAddress->FirstName = $order->delivery_first_name;
+ $request->ShippingAddress->LastName = $order->delivery_last_name;
+ $request->ShippingAddress->Street1 = $order->delivery_street1;
+ $request->ShippingAddress->Street2 = $order->delivery_street2;
+ $request->ShippingAddress->City = $order->delivery_city;
+ $request->ShippingAddress->State = uc_get_zone_code($order->delivery_zone);
+ $request->ShippingAddress->Country = $delivery_country[0]['country_iso_code_2'];
+ $request->ShippingAddress->PostalCode = $order->delivery_postal_code;
+ $request->ShippingAddress->Phone = $order->delivery_phone;
+
+ // Populate values for LineItems.
+ $request->Items->LineItem = array();
+ foreach ($order->products as $product) {
+ $item = new LineItem();
+ $item->SKU = $product->model;
+ $item->Description = $product->qty . ' x ' . $product->title;
+
+ $request->Items->LineItem[] = $item;
+ }
+
+ // Populate values for Payment Object.
+ $request->Payment->TotalAmount = $amount * 100;
+ // TODO Fix the "$request->Payment->CurrencyCode" property. At this moment eWAY doesn't accept Ubercart's currency.
+ //$request->Payment->CurrencyCode = $order->currency;
+ $request->Payment->InvoiceReference = $order_id;
+
+ // Method for this request. e.g. ProcessPayment, Create TokenCustomer, Update TokenCustomer & TokenPayment.
+ // TODO Move this to settings and realize other types of payment.
+ $request->Method = 'ProcessPayment';
+
+ // Request access code.
+ $access_code = $service->CreateAccessCode($request);
+
+ // TODO Add this validation to eWayRapid class.
+// // Check if any error returns.
+// if (isset($access_code->Errors)) {
+// // Get Error Messages from Error Code. Error Code Mappings are in the Config.ini file.
+// $error_array = explode(',', $response->Errors);
+//
+// $error_mgs = '';
+// foreach ($error_array as $error) {
+// if (isset($service->APIConfig[$error])) {
+// $error_mgs .= $error . ' ' . $service->APIConfig[$error] . '<br>';
+// }
+// else {
+// $error_mgs .= $error;
+// }
+// }
+//
+// drupal_set_message($error_mgs, 'error');
+// return FALSE;
+// }
+
+ // Populate values for Payment form.
+ $fields = new FormActionURL();
+ $fields->FormActionURL = $access_code->FormActionURL;
+ $fields->AccessCode = $access_code->AccessCode;
+ $fields->CardOwner = $order->payment_details['cc_owner'];
+ $fields->CardNumber = $order->payment_details['cc_number'];
+ $fields->CardExpMonth = $order->payment_details['cc_exp_month'];
+ $fields->CardExpYear = $order->payment_details['cc_exp_year'];
+ $fields->CardIssueNumber = $access_code->Customer->CardIssueNumber;
+ $fields->CardCVV = $order->payment_details['cc_cvv'];
+
+ $response = $service->submitToFormActionURL($fields);
+
+ $data = '';
+
+ if (!empty ($response->TransactionMessage)) {
+ $data .= theme('item_list', array('title' => 'Transaction Message', 'items' => array_values($response->TransactionMessage)));
+ }
+
+ if (!empty($response->BeagleAlertsMessages)) {
+ $data .= theme('item_list', array('title' => 'BeagleAlerts Messages', 'items' => array_values($response->BeagleAlertsMessages)));
+ }
+
+ if (!empty($response->ValidationMessages)) {
+ $data .= theme('item_list', array('title' => 'Validation Messages', 'items' => array_values($response->ValidationMessages)));
+ }
+
+ if ($response->CheckoutStatus == 1) {
+ $return = array(
+ 'success' => TRUE,
+ 'comment' => t('Credit card payment processed successfully') . ': ' . $response->getTransactionMessage(),
+ 'message' => t('Credit card payment processed successfully') . ': ' . $response->getTransactionMessage(),
+ 'uid' => $user->uid,
+ 'data' => $data
+ );
+
+ // Leave a comment for the admin.
+ uc_order_comment_save($order_id, $user->uid, $return['comment']);
+
+ // Leave a comment for the customer.
+ uc_order_comment_save($order_id, $user->uid, $return['comment'], 'order');
+ }
+ else {
+ $return = array(
+ 'success' => FALSE,
+ 'comment' => t('Credit card payment declined') . ': ' . $response->getTransactionMessage(),
+ 'message' => t('Credit card payment declined') . ': ' . $response->getTransactionMessage(),
+ 'uid' => $user->uid,
+ 'data' => $data
+ );
+
+ uc_order_comment_save($order_id, $user->uid, $data);
+ }
+
+ return $return;
+} \ No newline at end of file