minkasu_smartphone_checkout - Version 1.4.0

Version Notes

- Save logged in customer info to order

Download this release

Release Info

Developer Minkasu Inc
Extension minkasu_smartphone_checkout
Version 1.4.0
Comparing to
See all releases


Code changes from version 1.3.0 to 1.4.0

app/code/community/Minkasu/Wallet/controllers/PaymentController.php CHANGED
@@ -132,10 +132,19 @@ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
132
  Mage::throwException('Required details not provided with payment.');
133
  }
134
 
135
- // Step 2: Set the checkout method as "guest
136
- $quote->setCheckoutMethod('guest')->save();
137
- // Step 2.1:Fill customer name (first name ?)
138
- $quote->setCustomerFirstname($customerDetails['customer_name']);
 
 
 
 
 
 
 
 
 
139
  // Step 3: Fill the address and save it as billing and shipping address
140
  $billingAddressInfo = $this->_prepareBillingAddressInfo($customerDetails);
141
  $shippingAddressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
@@ -444,10 +453,16 @@ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
444
  */
445
  protected function _saveOrder($quote)
446
  {
447
- $quote->setCustomerId(null);
448
- $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
449
- $quote->setCustomerIsGuest(true);
450
- $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
 
 
 
 
 
 
451
 
452
  /** @var $service Mage_Sales_Model_Service_Quote */
453
  $service = Mage::getModel('sales/service_quote', $quote);
132
  Mage::throwException('Required details not provided with payment.');
133
  }
134
 
135
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
136
+ // Step 2: Set the checkout method as "login_in"
137
+ $quote->setCheckoutMethod('login_in')->save();
138
+ // Step 2.1: Customer name will be pulled from customer profile
139
+ } else {
140
+ // Step 2: Set the checkout method as "guest"
141
+ $quote->setCheckoutMethod('guest')->save();
142
+ // Step 2.1: Fill customer name
143
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
144
+ $quote->setCustomerFirstname($customerNameParts[0]);
145
+ $quote->setCustomerLastname(end($customerNameParts));
146
+ }
147
+
148
  // Step 3: Fill the address and save it as billing and shipping address
149
  $billingAddressInfo = $this->_prepareBillingAddressInfo($customerDetails);
150
  $shippingAddressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
453
  */
454
  protected function _saveOrder($quote)
455
  {
456
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
457
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
458
+ Mage::log("Minkasu - Logged in customer id: " . $customerData->getId());
459
+ $quote->setCustomerId($customerData->getId());
460
+ } else {
461
+ $quote->setCustomerId(null);
462
+ $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
463
+ $quote->setCustomerIsGuest(true);
464
+ $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
465
+ }
466
 
467
  /** @var $service Mage_Sales_Model_Service_Quote */
468
  $service = Mage::getModel('sales/service_quote', $quote);
app/code/community/Minkasu/Wallet/controllers/PaymentController.php~ ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Minkasu_Wallet_PaymentController extends Mage_Core_Controller_Front_Action
4
+ {
5
+
6
+ public function getShippingRatesAction()
7
+ {
8
+
9
+ $checkoutSession = Mage::getSingleton('checkout/session');
10
+ $quote = $checkoutSession->getQuote();
11
+ $address = $quote->getShippingAddress();
12
+
13
+ $rates = $address->collectShippingRates()->getGroupedAllShippingRates();
14
+
15
+ $result = array();
16
+
17
+ foreach ($rates as $carrier) {
18
+ foreach ($carrier as $rate) {
19
+ array_push($result, $rate->getData());
20
+ }
21
+ }
22
+
23
+ $this->getResponse()->setHeader('Content-type', 'application/json');
24
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
25
+
26
+ }
27
+
28
+ public function setPaymentMethodToMinkasuAction()
29
+ {
30
+
31
+ $checkoutSession = Mage::getSingleton('checkout/session');
32
+ $quote = $checkoutSession->getQuote();
33
+ /*
34
+ if($quote->isVirtual()) {
35
+ $quote->getBillingAddress()->setPaymentMethod('minkasu_wallet');
36
+ } else {
37
+ $quote->getShippingAddress()->setPaymentMethod('minkasu_wallet');
38
+ }
39
+
40
+ // shipping totals may be affected by payment method
41
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
42
+ $quote->getShippingAddress()->setCollectShippingRates(true);
43
+ }
44
+
45
+ $versionArr = Mage::getVersionInfo();
46
+ $versionStr = $versionArr['major'] . "." . $versionArr['minor'];
47
+ Mage::log("Minkasu - Magento Version: " . $versionStr);
48
+ $versionFlt = floatval($versionStr);
49
+
50
+ if ($versionFlt >= 1.8) {
51
+ Mage::log("Minkasu - Setting Payment Model Method Checks");
52
+ $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
53
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
54
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
55
+ | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
56
+ | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
57
+ }
58
+ */
59
+
60
+ $payment = $quote->getPayment();
61
+ $payment->importData(array('method' => 'minkasu_wallet'));
62
+ $quote->save();
63
+
64
+ $result = ["status" => "success"];
65
+ $this->getResponse()->setHeader('Content-type', 'application/json');
66
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
67
+
68
+ }
69
+
70
+
71
+ public function applyCouponCodeAction()
72
+ {
73
+ $coupon = $this->getRequest()->getParam('coupon_code');
74
+ $remove = $this->getRequest()->getParam('remove');
75
+
76
+ if ($remove == 1) {
77
+ $coupon = '';
78
+ }
79
+
80
+ try {
81
+ Mage::getSingleton('checkout/cart')
82
+ ->getQuote()
83
+ ->setCouponCode($coupon)
84
+ ->collectTotals()
85
+ ->save();
86
+ $applied_coupon = Mage::getSingleton('checkout/cart')
87
+ ->getQuote()
88
+ ->getCouponCode();
89
+ if ($coupon == $applied_coupon) {
90
+ $status = "success";
91
+ } else {
92
+ $status = "failed";
93
+ }
94
+ }
95
+ catch (Exception $e) {
96
+ $status = "failed";
97
+ }
98
+
99
+ $result = ["status" => $status];
100
+ $this->getResponse()->setHeader('Content-type', 'application/json');
101
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
102
+
103
+ }
104
+
105
+ /**
106
+ * Make a payment
107
+ */
108
+ public function paidAction()
109
+ {
110
+ /** @var $coreResource Mage_Core_Model_Resource */
111
+ $coreResource = Mage::getSingleton('core/resource');
112
+ $writeAdapter = $coreResource->getConnection('core_write');
113
+
114
+ // Step 1: Get the current quote object
115
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
116
+ $checkoutSession = Mage::getSingleton('checkout/session');
117
+ $quote = $checkoutSession->getQuote();
118
+
119
+ try {
120
+ $writeAdapter->beginTransaction();
121
+
122
+ $minkasuTransactionId = $checkoutSession->getData('minkasu_txn_id');
123
+ $transactionInfoResponse = $this->_getMinkasuTransaction($minkasuTransactionId);
124
+ if (!isset($transactionInfoResponse['txn_state']) || $transactionInfoResponse['txn_state']
125
+ != Minkasu_Wallet_Model_Api_Type_Transaction::STATE_PREAUTHED
126
+ ) {
127
+ Mage::throwException('This transaction has wrong state.');
128
+ }
129
+
130
+ $customerDetails = $this->_extractCustomerDetails($transactionInfoResponse);
131
+ if (!($customerDetails['customer_details_valid'])) {
132
+ Mage::throwException('Required details not provided with payment.');
133
+ }
134
+
135
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
136
+ $quote->setCheckoutMethod('login_in')->save();
137
+ } else {
138
+ // Step 2: Set the checkout method as "guest
139
+ $quote->setCheckoutMethod('guest')->save();
140
+ // Step 2.1: Fill customer name (first name ?)
141
+ // $quote->setCustomerFirstname($customerDetails['customer_name']);
142
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
143
+ $quote->setCustomerFirstname($customerNameParts[0]);
144
+ $quote->setCustomerLastname(end($customerNameParts));
145
+ }
146
+
147
+ // Step 3: Fill the address and save it as billing and shipping address
148
+ $billingAddressInfo = $this->_prepareBillingAddressInfo($customerDetails);
149
+ $shippingAddressInfo = $this->_prepareCustomerAddressInfo($customerDetails);
150
+ $this->_saveBillingAndShippingAddress($quote, $billingAddressInfo, $shippingAddressInfo);
151
+
152
+ // Step 4: Shipping method should already be set by now.
153
+ $checkoutSession->setStepData('shipping_method', 'complete', true);
154
+
155
+ // Step 5: Set payment method to minkasu wallet
156
+ $this->_savePayment($quote, array('method' => 'minkasu_wallet'));
157
+
158
+ // Calculate shipping rates now
159
+ $quote->getShippingAddress()->collectShippingRates()->save();
160
+ $quote->collectTotals()->save();
161
+
162
+ $writeAdapter->commit();
163
+
164
+ $order = $this->_saveOrder($quote);
165
+
166
+ if ($order->getId()) {
167
+ $this->_updateMinkasuTransactionWithOrderId($minkasuTransactionId, $order->getIncrementId());
168
+ } else {
169
+ Mage::throwException($this->__('Order has not been created.'));
170
+ }
171
+ } catch (Mage_Core_Exception $e) {
172
+ Mage::logException($e);
173
+ $writeAdapter->rollback();
174
+
175
+ try {
176
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
177
+ $client = Mage::getModel('minkasu_wallet/api_client');
178
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
179
+ } catch (Mage_Core_Exception $internalException) {
180
+ Mage::logException($internalException);
181
+ } catch (Exception $internalException) {
182
+ Mage::logException($internalException);
183
+ }
184
+
185
+ $this->_cleanCheckoutSessionParams();
186
+ $this->getResponse()->setHttpResponseCode(500);
187
+ $this->getResponse()->setBody($this->_prepareErrorBody($e->getMessage()));
188
+ $this->getResponse()->sendResponse();
189
+ die;
190
+ } catch (Exception $e) {
191
+ Mage::logException($e);
192
+ $writeAdapter->rollback();
193
+
194
+ try {
195
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
196
+ $client = Mage::getModel('minkasu_wallet/api_client');
197
+ $client->getType('transaction')->voidTransaction($minkasuTransactionId);
198
+ } catch (Mage_Core_Exception $internalException) {
199
+ Mage::logException($internalException);
200
+ } catch (Exception $internalException) {
201
+ Mage::logException($internalException);
202
+ }
203
+
204
+ $this->_cleanCheckoutSessionParams();
205
+ $this->getResponse()->setHttpResponseCode(500);
206
+ $this->getResponse()->setBody(
207
+ $this->_prepareErrorBody('An error has occurred. Please contact store administrator.')
208
+ );
209
+ $this->getResponse()->sendResponse();
210
+ die;
211
+ }
212
+
213
+ $url = Mage::getUrl('checkout/onepage/success');
214
+ $this->getResponse()->setHttpResponseCode(201);
215
+ $this->getResponse()->setBody($this->_prepareBody(array('redirect_url' => $url)));
216
+ $this->getResponse()->sendResponse();
217
+ die;
218
+ }
219
+
220
+ /**
221
+ * @param string $minkasuTransactionId
222
+ *
223
+ * @return array
224
+ */
225
+ protected function _getMinkasuTransaction($minkasuTransactionId)
226
+ {
227
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
228
+ $client = Mage::getModel('minkasu_wallet/api_client');
229
+ $result = $client->getType('transaction')->getTransaction($minkasuTransactionId);
230
+ return $result;
231
+ }
232
+
233
+ /**
234
+ * @param array $response
235
+ *
236
+ * @return array
237
+ */
238
+ protected function _extractCustomerDetails(array $response)
239
+ {
240
+ $result = array();
241
+
242
+ $result['customer_details_valid'] = false;
243
+
244
+ if (!isset($response['customer_address'])
245
+ || (!isset($response['customer_name']))
246
+ || (!isset($response['billing_address']))) {
247
+ return $result;
248
+ }
249
+
250
+ $result['customer_name'] = $response['customer_name'];
251
+ $result['street_1'] = $response['customer_address']['address_line_1'];
252
+ $result['street_2'] = $response['customer_address']['address_line_2'];
253
+ $result['city'] = $response['customer_address']['city'];
254
+ $result['state'] = $response['customer_address']['state'];
255
+ $result['zip'] = $response['customer_address']['zip'];
256
+ $result['phone'] = $response['phone'];
257
+ $result['email'] = $response['email'];
258
+
259
+ $result['billing_address'] = array();
260
+ $result['billing_address']['street_1'] = $response['billing_address']['address_line_1'];
261
+ $result['billing_address']['street_2'] = $response['billing_address']['address_line_2'];
262
+ $result['billing_address']['city'] = $response['billing_address']['city'];
263
+ $result['billing_address']['state'] = $response['billing_address']['state'];
264
+ $result['billing_address']['zip'] = $response['billing_address']['zip'];
265
+
266
+ $result['customer_details_valid'] = true;
267
+
268
+ return $result;
269
+ }
270
+
271
+ /**
272
+ * @param array $customerDetails
273
+ *
274
+ * @return array
275
+ */
276
+ protected function _prepareCustomerAddressInfo(array $customerDetails)
277
+ {
278
+ /** @var $regionModel Mage_Directory_Model_Region */
279
+ $regionModel = Mage::getModel('directory/region');
280
+ $regionModel->loadByCode($customerDetails['state'], 'US');
281
+
282
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
283
+
284
+ $addressInfo = array();
285
+ $addressInfo['firstname'] = $customerNameParts[0];
286
+ $addressInfo['lastname'] = end($customerNameParts);
287
+ $addressInfo['email'] = $customerDetails['email'];
288
+ $addressInfo['street'] = array(0 => $customerDetails['street_1'], 1 => $customerDetails['street_2']);
289
+ $addressInfo['city'] = $customerDetails['city'];
290
+ $addressInfo['region_id'] = $regionModel->getId();
291
+ $addressInfo['postcode'] = $customerDetails['zip'];
292
+ $addressInfo['country_id'] = 'US';
293
+ $addressInfo['telephone'] = $customerDetails['phone'];
294
+ $addressInfo['use_for_shipping'] = 1;
295
+
296
+ // Mage::log('Shipping address info - ' . print_r($addressInfo, true));
297
+
298
+ return $addressInfo;
299
+ }
300
+
301
+ protected function _prepareBillingAddressInfo(array $customerDetails)
302
+ {
303
+
304
+ /** @var $regionModel Mage_Directory_Model_Region */
305
+ $regionModel = Mage::getModel('directory/region');
306
+ $regionModel->loadByCode($customerDetails['billing_address']['state'], 'US');
307
+
308
+ $customerNameParts = explode(' ', $customerDetails['customer_name']);
309
+
310
+ $addressInfo = array();
311
+ $addressInfo['firstname'] = $customerNameParts[0];
312
+ $addressInfo['lastname'] = end($customerNameParts);
313
+ $addressInfo['email'] = $customerDetails['email'];
314
+ $addressInfo['street'] = array(0 => $customerDetails['billing_address']['street_1'], 1 => $customerDetails['billing_address']['street_2']);
315
+ $addressInfo['city'] = $customerDetails['billing_address']['city'];
316
+ $addressInfo['region_id'] = $regionModel->getId();
317
+ $addressInfo['postcode'] = $customerDetails['billing_address']['zip'];
318
+ $addressInfo['country_id'] = 'US';
319
+ $addressInfo['telephone'] = $customerDetails['phone'];
320
+ $addressInfo['use_for_shipping'] = 0;
321
+
322
+ // Mage::log('Billing address info - ' . print_r($addressInfo, true));
323
+
324
+ return $addressInfo;
325
+
326
+
327
+ }
328
+
329
+ /**
330
+ * @param $quote
331
+ * @param array $data
332
+ *
333
+ * @return $this
334
+ */
335
+ protected function _saveBillingAndShippingAddress($quote, $billing_data, $shipping_data)
336
+ {
337
+ $address = $quote->getBillingAddress();
338
+ /** @var $addressForm Mage_Customer_Model_Form */
339
+ $addressForm = Mage::getModel('customer/form');
340
+ $addressForm->setFormCode('customer_address_edit');
341
+ $addressForm->setEntityType('customer_address');
342
+ $addressForm->setEntity($address);
343
+ // emulate request object
344
+ $addressData = $addressForm->extractData($addressForm->prepareRequest($billing_data));
345
+ $addressErrors = $addressForm->validateData($addressData);
346
+ if (true !== $addressErrors) {
347
+ Mage::log("Minkasu - address validation failed");
348
+ }
349
+ $addressForm->compactData($addressData);
350
+ //unset billing address attributes which were not shown in form
351
+ foreach ($addressForm->getAttributes() as $attribute) {
352
+ if (!isset($billing_data[$attribute->getAttributeCode()])) {
353
+ $address->setData($attribute->getAttributeCode(), NULL);
354
+ }
355
+ }
356
+ $address->setCustomerAddressId(null);
357
+ $address->setEmail($billing_data['email']);
358
+ $address->implodeStreetAddress();
359
+
360
+ $billing = clone $address;
361
+ $billing->unsAddressId()->unsAddressType();
362
+
363
+ $shipping = $quote->getShippingAddress();
364
+ $shippingMethod = $shipping->getShippingMethod();
365
+
366
+ // Billing address properties that must be always copied to shipping address
367
+ $requiredBillingAttributes = array('customer_address_id');
368
+
369
+ // don't reset original shipping data, if it was not changed by customer
370
+ foreach ($shipping->getData() as $shippingKey => $shippingValue) {
371
+ if (!is_null($shippingValue) && !is_null($billing->getData($shippingKey))
372
+ && !isset($billing_data[$shippingKey]) && !in_array($shippingKey, $requiredBillingAttributes)
373
+ ) {
374
+ $billing->unsetData($shippingKey);
375
+ }
376
+ }
377
+
378
+ $shipping->addData($shipping_data);
379
+ $shipping->implodeStreetAddress();
380
+ $shipping->setSaveInAddressBook(0);
381
+ $shipping->setShippingMethod($shippingMethod);
382
+ $shipping->setCollectShippingRates(true);
383
+
384
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
385
+ $checkoutSession = Mage::getSingleton('checkout/session');
386
+ $checkoutSession->setStepData('shipping', 'complete', true);
387
+
388
+ $quote->collectTotals();
389
+ $quote->save();
390
+ $quote->getShippingAddress()->setCollectShippingRates(true);
391
+
392
+ $checkoutSession->setStepData('billing', 'allow', true);
393
+ $checkoutSession->setStepData('billing', 'complete', true);
394
+ $checkoutSession->setStepData('shipping', 'allow', true);
395
+
396
+ return $this;
397
+ }
398
+
399
+ /**
400
+ * @param $quote
401
+ * @param array $data
402
+ *
403
+ * @return $this
404
+ */
405
+ protected function _savePayment($quote, array $data)
406
+ {
407
+ try {
408
+ if($quote->isVirtual()) {
409
+ $quote->getBillingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
410
+ } else {
411
+ $quote->getShippingAddress()->setPaymentMethod(isset($data['method']) ? $data['method'] : null);
412
+ }
413
+
414
+ // shipping totals may be affected by payment method
415
+ if (!$quote->isVirtual() && $quote->getShippingAddress()) {
416
+ $quote->getShippingAddress()->setCollectShippingRates(true);
417
+ }
418
+
419
+ $versionArr = Mage::getVersionInfo();
420
+ $versionStr = $versionArr['major'] . "." . $versionArr['minor'];
421
+ Mage::log("Minkasu - Magento Version: " . $versionStr);
422
+ $versionFlt = floatval($versionStr);
423
+
424
+ if ($versionFlt >= 1.8) {
425
+ Mage::log("Minkasu - Setting Payment Model Method Checks");
426
+ $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT
427
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
428
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
429
+ | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
430
+ | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
431
+ }
432
+
433
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
434
+ $checkoutSession = Mage::getSingleton('checkout/session');
435
+ $payment = $quote->getPayment();
436
+ $payment->importData($data);
437
+ $payment->setTransactionId($checkoutSession->getData('minkasu_txn_id'));
438
+ $payment->setTransactionAdditionalInfo('quote-no', $quote->getQuoteId());
439
+
440
+ $quote->save();
441
+ $checkoutSession->setStepData('payment', 'complete', true);
442
+ } catch (Exception $e) {
443
+ Mage::logException($e);
444
+ }
445
+ return $this;
446
+ }
447
+
448
+ /**
449
+ * @param $quote
450
+ *
451
+ * @return Mage_Sales_Model_Order
452
+ */
453
+ protected function _saveOrder($quote)
454
+ {
455
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
456
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
457
+ Mage::log("Minkasu - Logged in customer id: " . $customerData->getId());
458
+ $quote->setCustomerId($customerData->getId());
459
+ } else {
460
+ $quote->setCustomerId(null);
461
+ $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
462
+ $quote->setCustomerIsGuest(true);
463
+ $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
464
+ }
465
+
466
+ /** @var $service Mage_Sales_Model_Service_Quote */
467
+ $service = Mage::getModel('sales/service_quote', $quote);
468
+ $service->submitAll();
469
+
470
+ /** @var $checkoutSession Mage_Checkout_Model_Session */
471
+ $checkoutSession = Mage::getSingleton('checkout/session');
472
+ $checkoutSession->setLastQuoteId($quote->getId());
473
+ $checkoutSession->setLastSuccessQuoteId($quote->getId());
474
+ $checkoutSession->clearHelperData();
475
+
476
+ $order = $service->getOrder();
477
+
478
+ if ($order->getId()) {
479
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$order, 'quote'=>$quote));
480
+
481
+ /**
482
+ * we only want to send to customer about new order when there is no redirect to third party
483
+ */
484
+ if ($order->getCanSendNewEmailFlag()) {
485
+ try {
486
+ $order->sendNewOrderEmail();
487
+ } catch (Exception $e) {
488
+ Mage::logException($e);
489
+ }
490
+ }
491
+
492
+ // add order information to the session
493
+ $checkoutSession->setLastOrderId($order->getId());
494
+ $checkoutSession->setRedirectUrl(null);
495
+ $checkoutSession->setLastRealOrderId($order->getIncrementId());
496
+
497
+ // as well a billing agreement can be created
498
+ $agreement = $order->getPayment()->getBillingAgreement();
499
+ if ($agreement) {
500
+ $checkoutSession->setLastBillingAgreementId($agreement->getId());
501
+ }
502
+ }
503
+
504
+ // add recurring profiles information to the session
505
+ $profiles = $service->getRecurringPaymentProfiles();
506
+ if ($profiles) {
507
+ $ids = array();
508
+ foreach ($profiles as $profile) {
509
+ $ids[] = $profile->getId();
510
+ }
511
+ $checkoutSession->setLastRecurringProfileIds($ids);
512
+ }
513
+
514
+ Mage::dispatchEvent(
515
+ 'checkout_submit_all_after',
516
+ array('order' => $order, 'quote' => $quote, 'recurring_profiles' => $profiles)
517
+ );
518
+
519
+ $quote->save();
520
+ return $order;
521
+ }
522
+
523
+ /**
524
+ * @param string $minkasuTransactionId
525
+ * @param string $orderId
526
+ *
527
+ * @return array
528
+ */
529
+ protected function _updateMinkasuTransactionWithOrderId($minkasuTransactionId, $orderId)
530
+ {
531
+ /** @var $client Minkasu_Wallet_Model_Api_Client */
532
+ $client = Mage::getModel('minkasu_wallet/api_client');
533
+ $result = $client->getType('transaction')->updateTransaction($minkasuTransactionId, array('merchant_bill_number' => $orderId), NULL);
534
+
535
+ return $result;
536
+ }
537
+
538
+ /**
539
+ * @return $this
540
+ */
541
+ protected function _cleanCheckoutSessionParams()
542
+ {
543
+ /** @var $helper Minkasu_Wallet_Helper_Data */
544
+ $helper = Mage::helper('minkasu_wallet');
545
+ $helper->cleanCheckoutSessionParams();
546
+ return $this;
547
+ }
548
+
549
+ /**
550
+ * @param string $error
551
+ *
552
+ * @return string
553
+ */
554
+ protected function _prepareErrorBody($error)
555
+ {
556
+ return $this->_prepareBody(array('error' => $this->__($error)));
557
+ }
558
+
559
+ /**
560
+ * @param array $data
561
+ *
562
+ * @return string
563
+ */
564
+ protected function _prepareBody(array $data)
565
+ {
566
+ /** @var $helper Mage_Core_Helper_Data */
567
+ $helper = Mage::helper('core');
568
+ return $helper->jsonEncode($data);
569
+ }
570
+ }
571
+ ?>
package.xml CHANGED
@@ -1,19 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>minkasu_smartphone_checkout</name>
4
- <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </summary>
10
  <description>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </description>
11
- <notes>-addition for estimate shipping and tax&#xD;
12
  </notes>
13
  <authors><author><name>Minkasu Inc</name><user>it-admin</user><email>it-admin@minkasu.com</email></author></authors>
14
- <date>2015-09-09</date>
15
- <time>23:44:40</time>
16
- <contents><target name="magecommunity"><dir name="Minkasu"><dir name="Wallet"><dir name="Block"><dir name="Adminhtml"><dir name="Merchant"><dir name="Create"><file name="Form.php" hash="77e288884729c197292d3799b2094d7b"/><file name="Success.php" hash="d1ed1419a27fed884c9d8d83eef9546c"/></dir><file name="Create.php" hash="108bac82be521ce9a98ffdcd716c7b4c"/><dir name="Edit"><file name="Form.php" hash="6d98746a2004442e70d6fa1e0c243723"/></dir><file name="Edit.php" hash="2c0b329a6f6df4af99da5c6407c280c8"/></dir><dir name="System"><dir name="Config"><dir name="Frontend"><file name="Cctype.php" hash="e236b1263378f894b7becf3852b1027e"/><file name="MinkasuGroup.php" hash="2fb103ce6e246972636dbfc4dd77bc42"/><file name="MinkasuMode.php" hash="f877b4be92ee3f869b6e42f0e1916a1b"/><file name="Paymentaction.php" hash="91420a5a4f610bf48821d51d688bc079"/></dir></dir></dir></dir><file name="Pay.php" hash="6545b86f80ab7a1aa43ddaaecce48112"/></dir><dir name="Helper"><dir name="Api"><file name="Merchant.php" hash="8192234ddd243022df5298171349321c"/></dir><file name="Api.php" hash="a38dd4f9af37b6131d18b7d78b2eb802"/><file name="Data.php" hash="004ff5e827b9a2981019f421c7be01a9"/></dir><dir name="Model"><dir name="Api"><dir name="Adapter"><file name="Abstract.php" hash="2c35170bc831f3884c9351716ca55030"/><file name="Curl.php" hash="0f64beb2ed75a3cadcb9b264b7c10eb9"/></dir><file name="Client.php" hash="8575b8b0d52635b0ec5942d2ace4dba6"/><dir name="Format"><file name="Abstract.php" hash="011af2c9cd958efffbba03e411cc1627"/><file name="Json.php" hash="f32759fe608158aede8c39d4816b8236"/></dir><dir name="Type"><file name="Abstract.php" hash="df9ed9fa6e616f233c7e01d7943ee709"/><file name="Merchant.php" hash="96e782e3756f5753c46a36f1aa6970f8"/><file name="Transaction.php" hash="3365045471a509166827e7a86eb9e4ab"/></dir></dir><file name="Observer.php" hash="3911f50f92812a588c343206e4834d05"/><file name="Payment.php" hash="61aeb4f7d7e5872401de43c87711d3f3"/><dir name="Source"><dir name="Api"><file name="Mode.php" hash="0e479fee542ff543ad1e3a2206b74acf"/></dir><file name="Cctype.php" hash="833ab97e39326b25cf13c644866493fb"/><file name="Paymentaction.php" hash="04bb331b86110d118254d49bd96aa33d"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="AddressPoBoxEnabled.php" hash="9795465148b90b598fe811809ca591c0"/><file name="Cctype.php" hash="08fbfe643918fad60eb5fc1140616f85"/><file name="Double.php" hash="a9fc25c67caf2db75af89a85b188ad80"/><file name="MinkasuStatus.php" hash="3d1b41d010c4ec15311beebce2e88ae5"/><file name="Mode.php" hash="8f5e497d6dceff432ce5b6dc11400bb9"/><file name="Paymentaction.php" hash="fc061be2e85fd8303bcd1da95198a3e2"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Minkasu"><dir name="Wallet"><file name="MerchantController.php" hash="c892302a1883c417b56628ec43172a27"/></dir></dir></dir><file name="PaymentController.php" hash="7b02b386678b7e4be640b3842f043ac9"/><file name="TransactionController.php" hash="361617e656a59979d886fe54cf2328a5"/></dir><dir name="etc"><file name="config.xml" hash="eb43346e15eceddab9805a0b0bc8a075"/><file name="system.xml" hash="38091c8cba513d1464115e5483e71558"/></dir><dir name="sql"><dir name="minkasu_wallet_setup"><file name="install-0.0.0.1.php" hash="ccbed051e0d98bf2fa167ea7b13edb4f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Minkasu_Wallet.xml" hash="a8daca594f8108b5fd5f28b04842fa91"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="95ca0132f2696fd91c0a67922030c8a2"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><dir name="merchant"><dir name="create"><file name="success.phtml" hash="fec665badf6dc1032514ac0dd3b31996"/></dir><file name="popup.phtml" hash="5e4050fa03cee52c263d259383ae0308"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="383412265ce51df29662f23f1e3accea"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="pay.phtml" hash="93c0a87a9fef5bb09a49370436325f9a"/><file name="estimate_box.phtml" hash="1bc7aab3113f038a805c13d553a22297"/></dir></dir></dir></dir></dir><dir name="gravdept"><dir name="acumen"><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="estimate_box.phtml" hash="7c839278df79b217ad5f53a24ad8b32d"/></dir></dir></dir></dir></dir><dir name="ultimo"><dir name="default"><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="estimate_box.phtml" hash="721b46be864fa8d29b5583dcc17478cc"/></dir></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>minkasu_smartphone_checkout</name>
4
+ <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </summary>
10
  <description>Enjoy higher conversion and greater security by offering a smartphone checkout option for your customers </description>
11
+ <notes>- Save logged in customer info to order&#xD;
12
  </notes>
13
  <authors><author><name>Minkasu Inc</name><user>it-admin</user><email>it-admin@minkasu.com</email></author></authors>
14
+ <date>2015-10-08</date>
15
+ <time>01:21:43</time>
16
+ <contents><target name="magecommunity"><dir name="Minkasu"><dir name="Wallet"><dir name="Block"><dir name="Adminhtml"><dir name="Merchant"><dir name="Create"><file name="Form.php" hash="77e288884729c197292d3799b2094d7b"/><file name="Success.php" hash="d1ed1419a27fed884c9d8d83eef9546c"/></dir><file name="Create.php" hash="108bac82be521ce9a98ffdcd716c7b4c"/><dir name="Edit"><file name="Form.php" hash="6d98746a2004442e70d6fa1e0c243723"/></dir><file name="Edit.php" hash="2c0b329a6f6df4af99da5c6407c280c8"/></dir><dir name="System"><dir name="Config"><dir name="Frontend"><file name="Cctype.php" hash="e236b1263378f894b7becf3852b1027e"/><file name="MinkasuGroup.php" hash="2fb103ce6e246972636dbfc4dd77bc42"/><file name="MinkasuMode.php" hash="f877b4be92ee3f869b6e42f0e1916a1b"/><file name="Paymentaction.php" hash="91420a5a4f610bf48821d51d688bc079"/></dir></dir></dir></dir><file name="Pay.php" hash="6545b86f80ab7a1aa43ddaaecce48112"/></dir><dir name="Helper"><dir name="Api"><file name="Merchant.php" hash="8192234ddd243022df5298171349321c"/></dir><file name="Api.php" hash="a38dd4f9af37b6131d18b7d78b2eb802"/><file name="Data.php" hash="004ff5e827b9a2981019f421c7be01a9"/></dir><dir name="Model"><dir name="Api"><dir name="Adapter"><file name="Abstract.php" hash="2c35170bc831f3884c9351716ca55030"/><file name="Curl.php" hash="0f64beb2ed75a3cadcb9b264b7c10eb9"/></dir><file name="Client.php" hash="8575b8b0d52635b0ec5942d2ace4dba6"/><dir name="Format"><file name="Abstract.php" hash="011af2c9cd958efffbba03e411cc1627"/><file name="Json.php" hash="f32759fe608158aede8c39d4816b8236"/></dir><dir name="Type"><file name="Abstract.php" hash="df9ed9fa6e616f233c7e01d7943ee709"/><file name="Merchant.php" hash="96e782e3756f5753c46a36f1aa6970f8"/><file name="Transaction.php" hash="3365045471a509166827e7a86eb9e4ab"/></dir></dir><file name="Observer.php" hash="3911f50f92812a588c343206e4834d05"/><file name="Payment.php" hash="61aeb4f7d7e5872401de43c87711d3f3"/><dir name="Source"><dir name="Api"><file name="Mode.php" hash="0e479fee542ff543ad1e3a2206b74acf"/></dir><file name="Cctype.php" hash="833ab97e39326b25cf13c644866493fb"/><file name="Paymentaction.php" hash="04bb331b86110d118254d49bd96aa33d"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="AddressPoBoxEnabled.php" hash="9795465148b90b598fe811809ca591c0"/><file name="Cctype.php" hash="08fbfe643918fad60eb5fc1140616f85"/><file name="Double.php" hash="a9fc25c67caf2db75af89a85b188ad80"/><file name="MinkasuStatus.php" hash="3d1b41d010c4ec15311beebce2e88ae5"/><file name="Mode.php" hash="8f5e497d6dceff432ce5b6dc11400bb9"/><file name="Paymentaction.php" hash="fc061be2e85fd8303bcd1da95198a3e2"/></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Minkasu"><dir name="Wallet"><file name="MerchantController.php" hash="c892302a1883c417b56628ec43172a27"/></dir></dir></dir><file name="PaymentController.php" hash="60e90774a133f691c0e28a84faa31ea6"/><file name="PaymentController.php~" hash="c1782a2bf123da888631e29acf418c39"/><file name="TransactionController.php" hash="361617e656a59979d886fe54cf2328a5"/></dir><dir name="etc"><file name="config.xml" hash="eb43346e15eceddab9805a0b0bc8a075"/><file name="system.xml" hash="38091c8cba513d1464115e5483e71558"/></dir><dir name="sql"><dir name="minkasu_wallet_setup"><file name="install-0.0.0.1.php" hash="ccbed051e0d98bf2fa167ea7b13edb4f"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Minkasu_Wallet.xml" hash="a8daca594f8108b5fd5f28b04842fa91"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="95ca0132f2696fd91c0a67922030c8a2"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><dir name="merchant"><dir name="create"><file name="success.phtml" hash="fec665badf6dc1032514ac0dd3b31996"/></dir><file name="popup.phtml" hash="5e4050fa03cee52c263d259383ae0308"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="minkasu_wallet.xml" hash="383412265ce51df29662f23f1e3accea"/></dir><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="pay.phtml" hash="93c0a87a9fef5bb09a49370436325f9a"/><file name="estimate_box.phtml" hash="1bc7aab3113f038a805c13d553a22297"/></dir></dir></dir></dir></dir><dir name="gravdept"><dir name="acumen"><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="estimate_box.phtml" hash="7c839278df79b217ad5f53a24ad8b32d"/></dir></dir></dir></dir></dir><dir name="ultimo"><dir name="default"><dir name="template"><dir name="minkasu"><dir name="wallet"><file name="estimate_box.phtml" hash="721b46be864fa8d29b5583dcc17478cc"/></dir></dir></dir></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>5.6.0</max></php></required></dependencies>
19
  </package>