<?php

namespace litle\sdk;

require_once realpath(__DIR__) . '/../../vendor/autoload.php';
#Authorization
$auth_info = array('orderId' => '1', 'amount' => '10010', 'id' => '456', 'orderSource' => 'ecommerce', 'billToAddress' => array('name' => 'John Smith', 'addressLine1' => '1 Main St.', 'city' => 'Burlington', 'state' => 'MA', 'zip' => '01803-3747', 'country' => 'US'), 'card' => array('number' => '4457010000000009', 'expDate' => '0112', 'cardValidationNum' => '349', 'type' => 'VI'));
$initilaize = new LitleOnlineRequest();
$authResponse = $initilaize->authorizationRequest($auth_info);
#display results
echo "Response: " . XmlParser::getNode($authResponse, 'response') . "<br>";
echo "Message: " . XmlParser::getNode($authResponse, 'message') . "<br>";
echo "Litle Transaction ID: " . XmlParser::getNode($authResponse, 'litleTxnId');
if (XmlParser::getNode($authResponse, 'message') != 'Approved') {
    throw new \Exception('LitleAuthorizationTransaction does not get the right response');
}
Exemple #2
0
 /**
  * this method is called if we are just authorising a transaction
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     // What about this?   Mage::app()->getStore()->isAdmin()
     // @TODO This is the wrong way to do this.
     if (preg_match('/sales_order_create/i', $_SERVER['REQUEST_URI']) && $this->getConfigData('paypage_enable') == '1') {
         $payment->setStatus('N/A')->setCcTransId('Litle VT')->setLastTransId('Litle VT')->setTransactionId('Litle VT')->setIsTransactionClosed(0)->setCcType('Litle VT');
     } else {
         $order = $payment->getOrder();
         $orderId = $order->getIncrementId();
         $amountToPass = Mage::helper('creditcard')->formatAmount($amount, true);
         if (!empty($order)) {
             $orderSource = "ecommerce";
             if ($orderId > 200000000) {
                 $orderSource = "recurring";
             }
             $info = $this->getInfoInstance();
             if (!$info->getAdditionalInformation('orderSource')) {
                 $info->setAdditionalInformation('orderSource', $orderSource);
             }
             $hash_in = $this->generateAuthorizationHash($orderId, $amountToPass, $info, $payment);
             $litleRequest = new LitleOnlineRequest();
             $litleResponse = $litleRequest->authorizationRequest($hash_in);
             $this->processResponse($payment, $litleResponse);
             Mage::helper('palorus')->saveCustomerInsight($payment, $litleResponse);
             if (!is_null($info->getAdditionalInformation('cc_should_save'))) {
                 $this->_saveToken($payment, $litleResponse);
             }
         }
     }
     return $this;
 }
 public function send()
 {
     $this->load->model('checkout/order');
     $orderId = $this->session->data['order_id'];
     $order_info = $this->model_checkout_order->getOrder($orderId);
     $orderAmountToInsert = $this->getAmountInCorrectFormat($order_info['total']);
     $litle_order_info = array('orderId' => $order_info['order_id'], 'customerId' => $order_info['customer_id'], 'amount' => $orderAmountToInsert, 'orderSource' => "ecommerce", 'billToAddress' => $this->getAddressInfo($order_info, "payment"), 'shipToAddress' => $this->getAddressInfo($order_info, "shipping"), 'card' => $this->getCreditCardInfo());
     $hash_in = array_merge($this->merchantDataFromOC(), $litle_order_info);
     $litleResponseMessagePrefix = "";
     $litleRequest = new LitleOnlineRequest($treeResponse = true);
     $doingAuth = $this->config->get('litle_transaction') == "auth";
     if ($doingAuth) {
         //auth txn
         $response = $litleRequest->authorizationRequest($hash_in);
         $litleResponseMessagePrefix = "LitleAuthTxn: ";
         $code = strval($response->authorizationResponse->response);
         $litleTxnId = strval($response->authorizationResponse->litleTxnId);
         $avsResponse = strval($response->authorizationResponse->fraudResult->avsResult);
         $cvvResponse = strval($response->authorizationResponse->fraudResult->cardValidationResult);
         $authCode = strval($response->authorizationResponse->authCode);
     } else {
         //sale txn
         $response = $litleRequest->saleRequest($hash_in);
         $litleResponseMessagePrefix = "LitleSaleTxn: ";
         $code = strval($response->saleResponse->response);
         $litleTxnId = strval($response->saleResponse->litleTxnId);
         $avsResponse = strval($response->saleResponse->fraudResult->avsResult);
         $cvvResponse = strval($response->saleResponse->fraudResult->cardValidationResult);
         $authCode = strval($response->saleResponse->authCode);
     }
     $cvvResponseMap = array("M" => "Match", "N" => "No Match", "P" => "Not Processed", "S" => "CVV2/CVC2/CID should be on the card, but the merchant has indicated CVV2/CVC2/CID is not present", "U" => "Issuer is not certified for CVV2/CVC2/CID processing", "" => "Check was not done for an unspecified reason");
     $cvvResponse = $cvvResponse . " - " . $cvvResponseMap[$cvvResponse];
     $avsResponseMap = array("00" => "5-Digit zip and address match", "01" => "9-Digit zip and address match", "02" => "Postal code and address match", "10" => "5-Digit zip matches, address does not match", "11" => "9-Digit zip matches, address does not match", "12" => "Zip does not match, address matches", "13" => "Postal code does not match, address matches", "14" => "Postal code matches, address not verified", "20" => "Neither zip nor address match", "30" => "AVS service not supported by issuer", "31" => "AVS system not available", "32" => "Address unavailable", "33" => "General error", "34" => "AVS not performed", "40" => "Address failed Litle & Co. edit checks");
     if (array_key_exists($avsResponse, $avsResponseMap)) {
         $avsResponse = $avsResponse . " - " . $avsResponseMap[$avsResponse];
     }
     $litleValidationMessage = $response->message;
     $softDeclineCodes = array("100", "101", "102", "110", "120", "349", "350", "356", "368", "372", "601", "602");
     $genericErrorSoftDecline = "This method of payment has been declined.  Please try another method of payment or contact us for further help";
     $genericErrorHardDecline = "This method of payment has been declined.  Please try another method of payment or contact us for further help";
     $json = array();
     if ($code == "000") {
         //Success
         if ($doingAuth) {
             $orderStatusId = 1;
             //Pending
         } else {
             $orderStatusId = 2;
             //Processing
         }
         $message = "Approval\n" . $litleResponseMessagePrefix . $litleValidationMessage . " \n Litle Response Code: " . $code . "\n  Litle Transaction ID: " . $litleTxnId . " \nAVS Response: " . $avsResponse . "\nCard Validation Response: " . $cvvResponse . "\nAuthCode: " . $authCode;
         $json['success'] = $this->url->link('checkout/success', '', 'SSL');
         $this->model_checkout_order->confirm($order_info['order_id'], $orderStatusId, $message, true);
     } else {
         if (in_array($code, $softDeclineCodes)) {
             //Soft decline
             $orderStatusId = 8;
             //Denied
             $message = "Soft Decline\n" . $litleResponseMessagePrefix . $litleValidationMessage . " \n Litle Response Code: " . $code . "\n  Litle Transaction ID: " . $litleTxnId . " \nAVS Response: " . $avsResponse . "\nCard Validation Response: " . $cvvResponse . "\nAuthCode: " . $authCode;
             $json['error'] = $genericErrorSoftDecline;
             $this->model_checkout_order->update($order_info['order_id'], $orderStatusId, $message, false);
         } else {
             //Do we have a code, if so, hard decline
             $orderStatusId = 8;
             //Denied
             $json['error'] = $genericErrorHardDecline;
             if (!empty($code)) {
                 $message = $litleResponseMessagePrefix . $litleValidationMessage . " \n Litle Response Code: " . $code . "\n  Litle Transaction ID: " . $litleTxnId . " \nAVS Response: " . $avsResponse . "\nCard Validation Response: " . $cvvResponse . "\nAuthCode: " . $authCode;
             } else {
                 //The xml is invalid, incorrect username/password, or other configuration error
                 //scrub the card number and password
                 $hash_in['password'] = preg_replace("/./", "*", $hash_in['password']);
                 $hash_in['card']['number'] = preg_replace("/./", "*", $hash_in['card']['number'], strlen($hash_in['card']['number']) - 4);
                 $message = "The xml sent to Litle failed.\nRequest XML:\n" . print_r($hash_in, TRUE) . "\nResponse XML:\n" . htmlentities($response->asXML());
             }
             $this->model_checkout_order->update($order_info['order_id'], $orderStatusId, $message, false);
         }
     }
     $this->response->setOutput(json_encode($json));
 }