np3455key - Version 0.1.0

Version Notes

Launched a new extension for our clients using Magento as their ecommerce platform with facilities that will offer its implementation through NextPay

Download this release

Release Info

Developer NextPay
Extension np3455key
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Mage/Nextpay/Block/Form.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Mage_Nextpay_Block_Form extends Mage_Payment_Block_Form
10
+ {
11
+ /**
12
+ * @var Mage_Sales_Model_Quote
13
+ */
14
+ protected $_quote;
15
+
16
+ protected function _construct()
17
+ {
18
+ parent::_construct();
19
+ $this->setTemplate('nextpay/form.phtml');
20
+ }
21
+
22
+ /**
23
+ * Get quote
24
+ *
25
+ * @return Mage_Sales_Model_Quote
26
+ */
27
+ public function getQuote() {
28
+ if(!$this->_quote) {
29
+ $this->_quote = $this->getMethod()->getInfoInstance()->getQuote();
30
+ }
31
+
32
+ return $this->_quote;
33
+ }
34
+
35
+ }
app/code/local/Mage/Nextpay/Block/Info.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Tritac
4
+ * @package Tritac_Capayable
5
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
6
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
7
+ */
8
+
9
+ class Mage_Nextpay_Block_Info extends Mage_Payment_Block_Info
10
+ {
11
+
12
+ /**
13
+ * @var Mage_Sales_Model_Quote
14
+ */
15
+ protected $_quote;
16
+
17
+ /**
18
+ * Set block template
19
+ */
20
+ protected function _construct()
21
+ {
22
+ parent::_construct();
23
+ $this->setTemplate('nextpay/info.phtml');
24
+ }
25
+
26
+ /**
27
+ * Get quote
28
+ *
29
+ * @return Mage_Sales_Model_Quote
30
+ */
31
+ public function getQuote() {
32
+ if(!$this->_quote) {
33
+ $this->_quote = $this->getMethod()->getInfoInstance()->getQuote();
34
+ }
35
+
36
+ return $this->_quote;
37
+ }
38
+
39
+ }
app/code/local/Mage/Nextpay/Helper/Data.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Nextpay_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ /**
5
+ * Get current extension environment
6
+ *
7
+ * @return int
8
+ */
9
+ public function getMode() {
10
+ $configMode = Mage::getStoreConfig('payment/nextpay/test_mode');
11
+ return $configMode;
12
+ }
13
+
14
+ public function getGatewayUrl() {
15
+ $configMode = Mage::getStoreConfig('payment/nextpay/test_mode');
16
+
17
+ $gateway_url = "https://gateway.nextpay.com/interface/process.do";
18
+ if ($configMode) {
19
+ $gateway_url = "https://gateway.nextpay.com/testing/process.do";
20
+ }
21
+
22
+ return $gateway_url;
23
+ }
24
+
25
+ public function getRedirectUrl() {
26
+ return Mage::getUrl('nextpay/index/index', array('_secure' => true));
27
+ }
28
+
29
+ public function getReturnUrl() {
30
+ return Mage::getUrl('nextpay/index/return', array('_secure' => true));
31
+ }
32
+
33
+ public function getDynamicReturnUrl() {
34
+ return Mage::getUrl('nextpay/index/dynamicreturn', array('_secure' => true));
35
+ }
36
+
37
+ public function getIdCommerce() {
38
+ return Mage::getStoreConfig('payment/nextpay/idcom');
39
+ }
40
+
41
+ public function getTransactionType() {
42
+ return Mage::getStoreConfig('payment/nextpay/transaction_type');
43
+ }
44
+
45
+ public function get3DigitCountryCode($country_code) {
46
+ $data = array(
47
+ "AA"=>"AAA",
48
+ "AD"=>"AND",
49
+ "AE"=>"ARE",
50
+ "AF"=>"AFG",
51
+ "AG"=>"ATG",
52
+ "AI"=>"AIA",
53
+ "AL"=>"ALB",
54
+ "AM"=>"ARM",
55
+ "AN"=>"ANT",
56
+ "AO"=>"AGO",
57
+ "AQ"=>"ATA",
58
+ "AR"=>"ARG",
59
+ "AS"=>"ASM",
60
+ "AT"=>"AUT",
61
+ "AU"=>"AUS",
62
+ "AW"=>"ABW",
63
+ "AX"=>"ALA",
64
+ "AZ"=>"AZE",
65
+ "BA"=>"BIH",
66
+ "BB"=>"BRB",
67
+ "BD"=>"BGD",
68
+ "BE"=>"BEL",
69
+ "BF"=>"BFA",
70
+ "BG"=>"BGR",
71
+ "BH"=>"BHR",
72
+ "BI"=>"BDI",
73
+ "BJ"=>"BEN",
74
+ "BL"=>"BLM",
75
+ "BM"=>"BMU",
76
+ "BN"=>"BRN",
77
+ "BO"=>"BOL",
78
+ "BR"=>"BRA",
79
+ "BS"=>"BHS",
80
+ "BT"=>"BTN",
81
+ "BU"=>"BUR",
82
+ "BV"=>"BVT",
83
+ "BW"=>"BWA",
84
+ "BY"=>"BLR",
85
+ "BZ"=>"BLZ",
86
+ "CA"=>"CAN",
87
+ "CC"=>"CCK",
88
+ "CD"=>"COD",
89
+ "CF"=>"CAF",
90
+ "CG"=>"COG",
91
+ "CH"=>"CHE",
92
+ "CI"=>"CIV",
93
+ "CK"=>"COK",
94
+ "CL"=>"CHL",
95
+ "CM"=>"CMR",
96
+ "CN"=>"CHN",
97
+ "CO"=>"COL",
98
+ "CR"=>"CRI",
99
+ "CS"=>"SCG",
100
+ "CU"=>"CUB",
101
+ "CV"=>"CPV",
102
+ "CX"=>"CXR",
103
+ "CY"=>"CYP",
104
+ "CZ"=>"CZE",
105
+ "DD"=>"DDR",
106
+ "DE"=>"DEU",
107
+ "DJ"=>"DJI",
108
+ "DK"=>"DNK",
109
+ "DM"=>"DMA",
110
+ "DO"=>"DOM",
111
+ "DZ"=>"DZA",
112
+ "EC"=>"ECU",
113
+ "EE"=>"EST",
114
+ "EG"=>"EGY",
115
+ "EH"=>"ESH",
116
+ "ER"=>"ERI",
117
+ "ES"=>"ESP",
118
+ "ET"=>"ETH",
119
+ "FI"=>"FIN",
120
+ "FJ"=>"FJI",
121
+ "FK"=>"FLK",
122
+ "FM"=>"FSM",
123
+ "FO"=>"FRO",
124
+ "FR"=>"FRA",
125
+ "FX"=>"FXX",
126
+ "GA"=>"GAB",
127
+ "GB"=>"GBR",
128
+ "GD"=>"GRD",
129
+ "GE"=>"GEO",
130
+ "GF"=>"GUF",
131
+ "GG"=>"GGY",
132
+ "GH"=>"GHA",
133
+ "GI"=>"GIB",
134
+ "GL"=>"GRL",
135
+ "GM"=>"GMB",
136
+ "GN"=>"GIN",
137
+ "GP"=>"GLP",
138
+ "GQ"=>"GNQ",
139
+ "GR"=>"GRC",
140
+ "GS"=>"SGS",
141
+ "GT"=>"GTM",
142
+ "GU"=>"GUM",
143
+ "GW"=>"GNB",
144
+ "GY"=>"GUY",
145
+ "HK"=>"HKG",
146
+ "HM"=>"HMD",
147
+ "HN"=>"HND",
148
+ "HR"=>"HRV",
149
+ "HT"=>"HTI",
150
+ "HU"=>"HUN",
151
+ "ID"=>"IDN",
152
+ "IE"=>"IRL",
153
+ "IL"=>"ISR",
154
+ "IM"=>"IMN",
155
+ "IN"=>"IND",
156
+ "IO"=>"IOT",
157
+ "IQ"=>"IRQ",
158
+ "IR"=>"IRN",
159
+ "IS"=>"ISL",
160
+ "IT"=>"ITA",
161
+ "JE"=>"JEY",
162
+ "JM"=>"JAM",
163
+ "JO"=>"JOR",
164
+ "JP"=>"JPN",
165
+ "KE"=>"KEN",
166
+ "KG"=>"KGZ",
167
+ "KH"=>"KHM",
168
+ "KI"=>"KIR",
169
+ "KM"=>"COM",
170
+ "KN"=>"KNA",
171
+ "KP"=>"PRK",
172
+ "KR"=>"KOR",
173
+ "KW"=>"KWT",
174
+ "KY"=>"CYM",
175
+ "KZ"=>"KAZ",
176
+ "LA"=>"LAO",
177
+ "LB"=>"LBN",
178
+ "LC"=>"LCA",
179
+ "LI"=>"LIE",
180
+ "LK"=>"LKA",
181
+ "LR"=>"LBR",
182
+ "LS"=>"LSO",
183
+ "LT"=>"LTU",
184
+ "LU"=>"LUX",
185
+ "LV"=>"LVA",
186
+ "LY"=>"LBY",
187
+ "MA"=>"MAR",
188
+ "MC"=>"MCO",
189
+ "MD"=>"MDA",
190
+ "ME"=>"MNE",
191
+ "MG"=>"MDG",
192
+ "MF"=>"MAF",
193
+ "MH"=>"MHL",
194
+ "MK"=>"MKD",
195
+ "ML"=>"MLI",
196
+ "MM"=>"MMR",
197
+ "MN"=>"MNG",
198
+ "MO"=>"MAC",
199
+ "MP"=>"MNP",
200
+ "MQ"=>"MTQ",
201
+ "MR"=>"MRT",
202
+ "MS"=>"MSR",
203
+ "MT"=>"MLT",
204
+ "MU"=>"MUS",
205
+ "MV"=>"MDV",
206
+ "MW"=>"MWI",
207
+ "MX"=>"MEX",
208
+ "MY"=>"MYS",
209
+ "MZ"=>"MOZ",
210
+ "NA"=>"NAM",
211
+ "NC"=>"NCL",
212
+ "NE"=>"NER",
213
+ "NF"=>"NFK",
214
+ "NG"=>"NGA",
215
+ "NI"=>"NIC",
216
+ "NL"=>"NLD",
217
+ "NO"=>"NOR",
218
+ "NP"=>"NPL",
219
+ "NR"=>"NRU",
220
+ "NT"=>"NTZ",
221
+ "NU"=>"NIU",
222
+ "NZ"=>"NZL",
223
+ "OM"=>"OMN",
224
+ "PA"=>"PAN",
225
+ "PE"=>"PER",
226
+ "PF"=>"PYF",
227
+ "PG"=>"PNG",
228
+ "PH"=>"PHL",
229
+ "PK"=>"PAK",
230
+ "PL"=>"POL",
231
+ "PM"=>"SPM",
232
+ "PN"=>"PCN",
233
+ "PR"=>"PRI",
234
+ "PS"=>"PSE",
235
+ "PT"=>"PRT",
236
+ "PW"=>"PLW",
237
+ "PY"=>"PRY",
238
+ "QA"=>"QAT",
239
+ "QM"=>"QMM",
240
+ "QN"=>"QNN",
241
+ "QO"=>"QOO",
242
+ "QP"=>"QPP",
243
+ "QQ"=>"QQQ",
244
+ "QR"=>"QRR",
245
+ "QS"=>"QSS",
246
+ "QT"=>"QTT",
247
+ "QU"=>"QUU",
248
+ "QV"=>"QVV",
249
+ "QW"=>"QWW",
250
+ "QX"=>"QXX",
251
+ "QY"=>"QYY",
252
+ "QZ"=>"QZZ",
253
+ "RE"=>"REU",
254
+ "RO"=>"ROU",
255
+ "RS"=>"SRB",
256
+ "RU"=>"RUS",
257
+ "RW"=>"RWA",
258
+ "SA"=>"SAU",
259
+ "SB"=>"SLB",
260
+ "SC"=>"SYC",
261
+ "SD"=>"SDN",
262
+ "SE"=>"SWE",
263
+ "SG"=>"SGP",
264
+ "SH"=>"SHN",
265
+ "SI"=>"SVN",
266
+ "SJ"=>"SJM",
267
+ "SK"=>"SVK",
268
+ "SL"=>"SLE",
269
+ "SM"=>"SMR",
270
+ "SN"=>"SEN",
271
+ "SO"=>"SOM",
272
+ "SR"=>"SUR",
273
+ "ST"=>"STP",
274
+ "SU"=>"SUN",
275
+ "SV"=>"SLV",
276
+ "SY"=>"SYR",
277
+ "SZ"=>"SWZ",
278
+ "TC"=>"TCA",
279
+ "TD"=>"TCD",
280
+ "TF"=>"ATF",
281
+ "TG"=>"TGO",
282
+ "TH"=>"THA",
283
+ "TJ"=>"TJK",
284
+ "TK"=>"TKL",
285
+ "TL"=>"TLS",
286
+ "TM"=>"TKM",
287
+ "TN"=>"TUN",
288
+ "TO"=>"TON",
289
+ "TP"=>"TMP",
290
+ "TR"=>"TUR",
291
+ "TT"=>"TTO",
292
+ "TV"=>"TUV",
293
+ "TW"=>"TWN",
294
+ "TZ"=>"TZA",
295
+ "UA"=>"UKR",
296
+ "UG"=>"UGA",
297
+ "UM"=>"UMI",
298
+ "US"=>"USA",
299
+ "UY"=>"URY",
300
+ "UZ"=>"UZB",
301
+ "VA"=>"VAT",
302
+ "VC"=>"VCT",
303
+ "VE"=>"VEN",
304
+ "VG"=>"VGB",
305
+ "VI"=>"VIR",
306
+ "VN"=>"VNM",
307
+ "VU"=>"VUT",
308
+ "WF"=>"WLF",
309
+ "WS"=>"WSM",
310
+ "XA"=>"XAA",
311
+ "XB"=>"XBB",
312
+ "XC"=>"XCC",
313
+ "XD"=>"XDD",
314
+ "XE"=>"XEE",
315
+ "XF"=>"XFF",
316
+ "XG"=>"XGG",
317
+ "XH"=>"XHH",
318
+ "XI"=>"XII",
319
+ "XJ"=>"XJJ",
320
+ "XK"=>"XKK",
321
+ "XL"=>"XLL",
322
+ "XM"=>"XMM",
323
+ "XN"=>"XNN",
324
+ "XO"=>"XOO",
325
+ "XP"=>"XPP",
326
+ "XQ"=>"XQQ",
327
+ "XR"=>"XRR",
328
+ "XS"=>"XSS",
329
+ "XT"=>"XTT",
330
+ "XU"=>"XUU",
331
+ "XV"=>"XVV",
332
+ "XW"=>"XWW",
333
+ "XX"=>"XXX",
334
+ "XY"=>"XYY",
335
+ "XZ"=>"XZZ",
336
+ "YD"=>"YMD",
337
+ "YE"=>"YEM",
338
+ "YT"=>"MYT",
339
+ "YU"=>"YUG",
340
+ "ZA"=>"ZAF",
341
+ "ZM"=>"ZMB",
342
+ "ZR"=>"ZAR",
343
+ "ZW"=>"ZWE",
344
+ "ZZ"=>"ZZZ"
345
+ );
346
+ return $data[$country_code];
347
+ }
348
+
349
+
350
+ /**
351
+ * Convert price to cents.
352
+ *
353
+ * @param $amount
354
+ * @return int
355
+ */
356
+ public function convertToCents($amount) {
357
+ return (int) ($amount * 100);
358
+ }
359
+ }
app/code/local/Mage/Nextpay/Model/Payment.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Capayable payment method model
4
+ *
5
+ * @category Tritac
6
+ * @package Tritac_Capayable
7
+ * @copyright Copyright (c) 2014 Tritac (http://www.tritac.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ class Mage_Nextpay_Model_Payment extends Mage_Payment_Model_Method_Abstract
12
+ {
13
+ /**
14
+ * Unique internal payment method identifier
15
+ */
16
+ protected $_code = 'nextpay';
17
+ protected $_paymentMethod = 'Nextpay';
18
+ protected $_formBlockType = 'nextpay/form';
19
+ protected $_infoBlockType = 'nextpay/info';
20
+
21
+ /**
22
+ * Availability options
23
+ */
24
+ protected $_isGateway = true;
25
+ protected $_canOrder = true;
26
+ protected $_canAuthorize = true;
27
+ protected $_canCapture = true;
28
+ protected $_canCapturePartial = false;
29
+ protected $_canRefundInvoicePartial = false;
30
+ protected $_canVoid = false;
31
+
32
+ /**
33
+ * Extension helper
34
+ */
35
+ protected $_helper = null;
36
+
37
+ public function __construct()
38
+ {
39
+ $this->_helper = Mage::helper('nextpay');
40
+ // $public_key = $this->getConfigData('public_key');
41
+
42
+
43
+ parent::__construct();
44
+ }
45
+
46
+ /**
47
+ * Get capayable helper
48
+ *
49
+ * @return Mage_Core_Helper_Abstract|Mage_Payment_Helper_Data|null
50
+ */
51
+ public function getHelper() {
52
+ return $this->_helper;
53
+ }
54
+
55
+ /**
56
+ * Check customer credit via capayable
57
+ *
58
+ * @param Varien_Object $payment
59
+ * @param float $amount
60
+ * @return $this|Mage_Payment_Model_Abstract
61
+ * @throws Mage_Payment_Model_Info_Exception
62
+ */
63
+ public function authorize(Varien_Object $payment, $amount) {
64
+ return parent::authorize($payment, $amount);
65
+ }
66
+
67
+ /**
68
+ * Assign data to info model instance
69
+ * Save capayable customer
70
+ *
71
+ * @param mixed $data
72
+ * @return Mage_Payment_Model_Info
73
+ */
74
+ public function assignData($data)
75
+ {
76
+ $quote = $this->getInfoInstance()->getQuote();
77
+ $billing_address = $quote->getBillingAddress();
78
+
79
+ if ($billing_address->getRegion() == "") {
80
+ throw new Mage_Payment_Model_Info_Exception("Client state can't be empty");
81
+ }
82
+
83
+ return parent::assignData($data);
84
+ }
85
+
86
+ public function getOrderPlaceRedirectUrl()
87
+ {
88
+ if((int)$this->_getOrderAmount() > 0){
89
+ return Mage::helper('nextpay')->getRedirectUrl();
90
+ }else{
91
+ return false;
92
+ }
93
+ }
94
+ private function _getOrderAmount()
95
+ {
96
+ $info = $this->getInfoInstance();
97
+ if ($this->_isPlacedOrder()) {
98
+ return (double)$info->getOrder()->getQuoteBaseGrandTotal();
99
+ } else {
100
+ return (double)$info->getQuote()->getBaseGrandTotal();
101
+ }
102
+ }
103
+ private function _isPlacedOrder()
104
+ {
105
+ $info = $this->getInfoInstance();
106
+ if ($info instanceof Mage_Sales_Model_Quote_Payment) {
107
+ return false;
108
+ } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
109
+ return true;
110
+ }
111
+ }
112
+ }
app/code/local/Mage/Nextpay/Model/Source/Transactiontype.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Nextpay_Model_Source_Transactiontype
3
+ {
4
+
5
+ /**
6
+ * Options getter
7
+ *
8
+ * @return array
9
+ */
10
+ public function toOptionArray()
11
+ {
12
+ return array(
13
+ array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('Sale')),
14
+ array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Pre-Authorization')),
15
+ );
16
+ }
17
+
18
+ /**
19
+ * Get options in "key-value" format
20
+ *
21
+ * @return array
22
+ */
23
+ public function toArray()
24
+ {
25
+ return array(
26
+ 0 => Mage::helper('adminhtml')->__('Sale'),
27
+ 1 => Mage::helper('adminhtml')->__('Pre-Authorization'),
28
+ );
29
+ }
30
+
31
+ }
app/code/local/Mage/Nextpay/controllers/IndexController.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mage_Nextpay_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+ $this->loadLayout();
7
+ $this->renderLayout();
8
+ }
9
+
10
+ public function dynamicreturnAction()
11
+ {
12
+ $order = Mage::getModel('sales/order')->loadByIncrementId($_REQUEST['order']);
13
+
14
+ try{
15
+ $payment_status = $_REQUEST['payment_status'];
16
+ if($payment_status == 10){
17
+ $payment = $order->getPayment();
18
+ $grandTotal = $order->getBaseGrandTotal();
19
+ if(isset($request['nextpay_order_id'])){
20
+ $tid = $request['nextpay_order_id'];
21
+ }
22
+ else {
23
+ $tid = -1 ;
24
+ }
25
+
26
+ $payment->setTransactionId($tid)
27
+ ->setPreparedMessage("Payment Sucessfull Result:")
28
+ ->setIsTransactionClosed(0)
29
+ ->registerAuthorizationNotification($grandTotal);
30
+
31
+ $order->setStatus("payment_approved");
32
+ $order->save();
33
+ }
34
+ }
35
+ catch(Exception $e)
36
+ {
37
+ Mage::logException($e);
38
+ }
39
+ }
40
+
41
+ public function returnAction()
42
+ {
43
+ $order = Mage::getModel('sales/order')->loadByIncrementId($_REQUEST['order']);
44
+
45
+ try{
46
+ $payment_status = $_REQUEST['payment_status'];
47
+ if($payment_status == 2){
48
+ $comment = $order->addStatusHistoryComment('Declined, the order been declined')
49
+ ->setIsCustomerNotified(false)
50
+ ->save();
51
+
52
+ $this->_forward('error');
53
+ }
54
+ elseif($payment_status == 10){
55
+ $comment = $order->sendNewOrderEmail()->addStatusHistoryComment('Approved, the order been approved')
56
+ ->setIsCustomerNotified(false)
57
+ ->save();
58
+
59
+ $url = Mage::getUrl('checkout/onepage/success', array('_secure'=>true));
60
+ Mage::register('redirect_url',$url);
61
+ $this->_redirectUrl($url);
62
+ }
63
+ }
64
+ catch(Exception $e)
65
+ {
66
+ Mage::logException($e);
67
+ }
68
+ }
69
+
70
+ protected function _getCheckout()
71
+ {
72
+ return Mage::getSingleton('checkout/session');
73
+ }
74
+
75
+ public function errorAction()
76
+ {
77
+ $request = $_REQUEST;
78
+
79
+ $gotoSection = false;
80
+ $session = $this->_getCheckout();
81
+ if ($session->getLastRealOrderId()) {
82
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
83
+ if ($order->getId()) {
84
+ //Cancel order
85
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_CANCELED) {
86
+ $order->registerCancellation($errorMsg)->save();
87
+ }
88
+ $quote = Mage::getModel('sales/quote')
89
+ ->load($order->getQuoteId());
90
+ //Return quote
91
+ if ($quote->getId()) {
92
+ $quote->setIsActive(1)
93
+ ->setReservedOrderId(NULL)
94
+ ->save();
95
+ $session->replaceQuote($quote);
96
+ }
97
+
98
+ //Unset data
99
+ $session->unsLastRealOrderId();
100
+ //Redirect to payment step
101
+ $gotoSection = 'payment';
102
+ $url = Mage::getUrl('checkout/onepage/index', array('_secure'=>true));
103
+ Mage::register('redirect_url',$url);
104
+ $this->_redirectUrl($url);
105
+ }
106
+ }
107
+
108
+ return $gotoSection;
109
+ }
110
+ }
app/code/local/Mage/Nextpay/etc/config.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Nextpay>
5
+ <version>0.1.0</version>
6
+ </Mage_Nextpay>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <nextpay>
11
+ <class>Mage_Nextpay_Block</class>
12
+ </nextpay>
13
+ </blocks>
14
+ <helpers>
15
+ <nextpay>
16
+ <class>Mage_Nextpay_Helper</class>
17
+ </nextpay>
18
+ </helpers>
19
+ <models>
20
+ <nextpay>
21
+ <class>Mage_Nextpay_Model</class>
22
+ </nextpay>
23
+ </models>
24
+ <resources>
25
+ <nextpay_setup>
26
+ <setup>
27
+ <module>Mage_Nextpay</module>
28
+ </setup>
29
+ </nextpay_setup>
30
+ </resources>
31
+ </global>
32
+ <frontend>
33
+ <routers>
34
+ <nextpay>
35
+ <use>standard</use>
36
+ <args>
37
+ <module>Mage_Nextpay</module>
38
+ <frontName>nextpay</frontName>
39
+ </args>
40
+ </nextpay>
41
+ </routers>
42
+ <layout>
43
+ <updates>
44
+ <nextpay>
45
+ <file>nextpay.xml</file>
46
+ </nextpay>
47
+ </updates>
48
+ </layout>
49
+ </frontend>
50
+ <default>
51
+ <payment>
52
+ <nextpay>
53
+ <active>1</active>
54
+ <model>nextpay/payment</model>
55
+ <title>Nextpay</title>
56
+ <email_customer>1</email_customer>
57
+ <payment_action>authorize</payment_action>
58
+ <order_status>pending</order_status>
59
+ <sort_order>1</sort_order>
60
+ </nextpay>
61
+ </payment>
62
+ </default>
63
+ </config>
app/code/local/Mage/Nextpay/etc/system.xml ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment translate="label" module="nextpay">
5
+ <groups>
6
+ <nextpay translate="label">
7
+ <label>NextPay</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>3</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <active translate="label">
15
+ <label>Active</label>
16
+ <frontend_type>select</frontend_type>
17
+ <source_model>adminhtml/system_config_source_yesno</source_model>
18
+ <sort_order>10</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>1</show_in_store>
22
+ </active>
23
+ <title translate="label">
24
+ <label>Title</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>20</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ </title>
31
+ <idcom translate="label">
32
+ <label>NextPay Merchant Key</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>30</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ </idcom>
39
+ <transaction_type translate="label">
40
+ <label>Transaction Type</label>
41
+ <frontend_type>select</frontend_type>
42
+ <source_model>nextpay/source_transactiontype</source_model>
43
+ <sort_order>40</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </transaction_type>
48
+ <allowspecific translate="label">
49
+ <label>Payment from Applicable Countries</label>
50
+ <frontend_type>allowspecific</frontend_type>
51
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
52
+ <sort_order>50</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </allowspecific>
57
+ <specificcountry translate="label">
58
+ <label>Payment from Specific Countries</label>
59
+ <frontend_type>multiselect</frontend_type>
60
+ <source_model>adminhtml/system_config_source_country</source_model>
61
+ <sort_order>60</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>1</show_in_website>
64
+ <show_in_store>1</show_in_store>
65
+ </specificcountry>
66
+ <order_status translate="label">
67
+ <label>New Order Status</label>
68
+ <frontend_type>select</frontend_type>
69
+ <source_model>adminhtml/system_config_source_order_status_new</source_model>
70
+ <sort_order>70</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>1</show_in_store>
74
+ </order_status>
75
+ <test_mode translate="label">
76
+ <label>Test Mode</label>
77
+ <frontend_type>select</frontend_type>
78
+ <source_model>adminhtml/system_config_source_yesno</source_model>
79
+ <sort_order>80</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ </test_mode>
84
+ <sort_order translate="label">
85
+ <label>Sort Order</label>
86
+ <frontend_type>text</frontend_type>
87
+ <sort_order>90</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ </sort_order>
92
+ </fields>
93
+ </nextpay>
94
+ </groups>
95
+ </payment>
96
+ </sections>
97
+ </config>
app/code/local/Mage/Nextpay/sql/nextpay_setup/install-0.1.0.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ // Required tables
6
+ $statusTable = $installer->getTable('sales/order_status');
7
+ $statusStateTable = $installer->getTable('sales/order_status_state');
8
+
9
+ // Insert statuses
10
+ $installer->getConnection()->insertArray(
11
+ $statusTable,
12
+ array(
13
+ 'status',
14
+ 'label'
15
+ ),
16
+ array(
17
+ array('status' => 'payment_approved', 'label' => 'Payment Approved'),
18
+ )
19
+ );
20
+
21
+ // Insert states and mapping of statuses to states
22
+ $installer->getConnection()->insertArray(
23
+ $statusStateTable,
24
+ array(
25
+ 'status',
26
+ 'state',
27
+ 'is_default'
28
+ ),
29
+ array(
30
+ array(
31
+ 'status' => 'payment_approved',
32
+ 'state' => 'new',
33
+ 'is_default' => 0
34
+ )
35
+ )
36
+ );
app/design/frontend/base/default/layout/nextpay.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ </default>
5
+ <nextpay_index_index>
6
+ <reference name="root">
7
+ <action method="setTemplate"><template>page/empty.phtml</template></action>
8
+ </reference>
9
+ <reference name="content">
10
+ <block type="core/template" template="nextpay/nextpay.phtml" />
11
+ </reference>
12
+ </nextpay_index_index>
13
+ </layout>
app/design/frontend/base/default/template/nextpay/form.phtml ADDED
File without changes
app/design/frontend/base/default/template/nextpay/info.phtml ADDED
@@ -0,0 +1 @@
 
1
+ nextpay info block
app/design/frontend/base/default/template/nextpay/nextpay.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $session = Mage::getSingleton('checkout/session');
3
+ $orderIncrementId = $session->getLastRealOrderId();
4
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
5
+ $billingaddress = $order->getBillingAddress();
6
+ // $shippingaddress = $order->getShippingAddress();
7
+ $currencyDesc = Mage::app()->getStore()->getCurrentCurrencyCode();
8
+ $totals = number_format($order->getGrandTotal(), 2, '.', '');
9
+ $address = $billingaddress->getStreet();
10
+ // $address1 = $shippingaddress->getStreet();
11
+
12
+ $data = array(
13
+ 'id_commerce'=> Mage::helper('nextpay')->getIdCommerce(),
14
+ 'order'=> $order->getIncrementId(),
15
+ 'amount'=> $totals,
16
+ 'urlreturn'=> Mage::helper('nextpay')->getReturnUrl(),
17
+ 'client_name'=> $order->getCustomerFirstname(),
18
+ 'client_lastname'=> $order->getCustomerLastname(),
19
+ 'client_address'=> $address[0] . ' '.$address[1],
20
+ 'client_city'=> $billingaddress->getCity(),
21
+ 'client_state'=> $billingaddress->getRegion(),
22
+ 'client_country'=> Mage::helper('nextpay')->get3DigitCountryCode($billingaddress->getCountryId()),
23
+ 'client_postcode'=> $billingaddress->getPostcode(),
24
+ 'client_phone'=> $billingaddress->getTelephone(),
25
+ 'client_email'=> $order->getCustomerEmail(),
26
+ 'currency'=>'USD',
27
+ 'trans_type'=> Mage::helper('nextpay')->getTransactionType(),
28
+ );
29
+
30
+ $gateway_url = Mage::helper('nextpay')->getGatewayUrl();
31
+ ?>
32
+ <form action="<?php echo $gateway_url; ?>" method="post" id="redirect_nextpay">
33
+ <?php foreach($data as $key => $value): ?>
34
+ <input type='hidden' name='<?php echo $key?>' value='<?php echo $value;?>' />
35
+ <?php endforeach;?>
36
+ <input type="submit" value='Buy Now'/>
37
+ </form>
38
+
39
+ <?php echo $this->__('If Page Doesn\'t Redirect In 5 Sectonds, Please press Buy button');?>
40
+ <script type="text/javascript">
41
+ function myfunc () {
42
+ var frm = document.getElementById("redirect_nextpay");
43
+ frm.submit();
44
+ }
45
+ window.onload = myfunc;
46
+ </script>
47
+
48
+
app/etc/modules/Mage_Nextpay.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Nextpay>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Mage_Nextpay>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>np3455key</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>New Extension Release</summary>
10
+ <description>Launched a new extension for our clients using Magento as their ecommerce platform with facilities that will offer its implementation through NextPay</description>
11
+ <notes>Launched a new extension for our clients using Magento as their ecommerce platform with facilities that will offer its implementation through NextPay</notes>
12
+ <authors><author><name>NextPay</name><user>erick</user><email>erick@nextpay.com</email></author></authors>
13
+ <date>2014-10-01</date>
14
+ <time>17:10:41</time>
15
+ <contents><target name="magelocal"><dir><dir name="Mage"><dir name="Nextpay"><dir name="Block"><file name="Form.php" hash="8f1216de1fe18493c9eb79ecea8012d1"/><file name="Info.php" hash="5bb74b09d9657be71451b021ee81c064"/></dir><dir name="Helper"><file name="Data.php" hash="44df12aeb93477aa3ca4a3ece0824b3d"/></dir><dir name="Model"><file name="Payment.php" hash="7332c73fce96486e9431fd93474e8f9f"/><dir name="Source"><file name="Transactiontype.php" hash="dfcd84fab9614b0b4748b02ce0a6604e"/></dir></dir><dir name="controllers"><file name="IndexController.php" hash="5525dbe618e3546e6f80c09f5a6dcbef"/></dir><dir name="etc"><file name="config.xml" hash="53cf5eef44c603327a410f170a5ea5b0"/><file name="system.xml" hash="41c8017840027b14ec21e3bb915827b6"/></dir><dir name="sql"><dir name="nextpay_setup"><file name="install-0.1.0.php" hash="99d074929112e387114a50cc8e321743"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="nextpay.xml" hash="f4f1a5feaa5c8c52482da534ed291a4f"/></dir><dir name="template"><dir name="nextpay"><file name="form.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="info.phtml" hash="26a5203ec241f08c53c55a64c24df0cb"/><file name="nextpay.phtml" hash="afe56eb54362d4bf3ea0d0d58e61c436"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mage_Nextpay.xml" hash="4d29b014a9e261d7ceb0a66c8520a247"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>