Apruve_B2B_Payment_Gateway - Version 2.0.0

Version Notes

Stable Version

Download this release

Release Info

Developer Apruve
Extension Apruve_B2B_Payment_Gateway
Version 2.0.0
Comparing to
See all releases


Code changes from version 1.0.15 to 2.0.0

Files changed (27) hide show
  1. app/code/community/Apruve/ApruvePayment/Block/Adminhtml/Sales/Order/View.php +40 -0
  2. app/code/community/Apruve/ApruvePayment/Helper/Data.php +46 -9
  3. app/code/community/Apruve/ApruvePayment/Model/Api/Abstract.php +147 -24
  4. app/code/community/Apruve/ApruvePayment/Model/Api/Payment.php +126 -25
  5. app/code/community/Apruve/ApruvePayment/Model/Api/PaymentRequest.php +0 -211
  6. app/code/community/Apruve/ApruvePayment/Model/Api/Rest.php +24 -129
  7. app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Invoice.php +246 -0
  8. app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Order.php +187 -0
  9. app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Shipment.php +214 -0
  10. app/code/community/Apruve/ApruvePayment/Model/Entity.php +97 -0
  11. app/code/community/Apruve/ApruvePayment/Model/Mode.php +8 -28
  12. app/code/community/Apruve/ApruvePayment/Model/Mysql4/Setup.php +0 -6
  13. app/code/community/Apruve/ApruvePayment/Model/Observer.php +258 -12
  14. app/code/community/Apruve/ApruvePayment/Model/PaymentMethod.php +95 -28
  15. app/code/community/Apruve/ApruvePayment/Model/Resource/Entity.php +31 -0
  16. app/code/community/Apruve/ApruvePayment/Model/Resource/Entity/Collection.php +31 -0
  17. app/code/community/Apruve/ApruvePayment/Model/Sales/Service/Order.php +70 -0
  18. app/code/community/Apruve/ApruvePayment/Model/Version.php +53 -0
  19. app/code/community/Apruve/ApruvePayment/controllers/WebhookController.php +115 -46
  20. app/code/community/Apruve/ApruvePayment/etc/config.xml +136 -88
  21. app/code/community/Apruve/ApruvePayment/etc/system.xml +27 -0
  22. app/code/community/Apruve/ApruvePayment/sql/apruvepayment_setup/install-2.0.0.php +64 -0
  23. app/design/frontend/base/default/layout/apruvepayment.xml +2 -2
  24. app/design/frontend/base/default/template/apruvepayment/payment/form.phtml +33 -12
  25. app/etc/modules/Apruve_ApruvePayment.xml +28 -1
  26. js/Apruve/ApruvePayment.js +13 -5
  27. package.xml +4 -4
app/code/community/Apruve/ApruvePayment/Block/Adminhtml/Sales/Order/View.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Apruve
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Apache License, Version 2.0
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/Apache-2.0
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@apruve.com so we can send you a copy immediately.
15
+ *
16
+ * @category Apruve
17
+ * @package Apruve_Payment
18
+ * @copyright Copyright (coffee) 2017 Apruve, Inc. (http://www.apruve.com).
19
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
20
+ * @author Echidna Team
21
+ *
22
+ */
23
+
24
+ /**
25
+ * Adminhtml sales order view
26
+ */
27
+ class Apruve_ApruvePayment_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View
28
+ {
29
+
30
+ protected function _isAllowedAction($action)
31
+ {
32
+ if($action == 'invoice') {
33
+ $order = $this->getOrder();
34
+ if($order->getPayment()->getMethod() == Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE) {
35
+ return false;
36
+ }
37
+ }
38
+ return parent::_isAllowedAction($action);
39
+ }
40
+ }
app/code/community/Apruve/ApruvePayment/Helper/Data.php CHANGED
@@ -21,14 +21,11 @@
21
  class Apruve_ApruvePayment_Helper_Data extends Mage_Core_Helper_Abstract
22
  {
23
  /**
24
- * @return Apruve_ApruvePayment_Model_Api_PaymentRequest
25
  */
26
- public function getPaymentRequestApiModel()
27
  {
28
- return Mage::getModel(
29
- 'apruvepayment/api_paymentRequest',
30
- Mage::getSingleton('checkout/session')->getQuote()
31
- );
32
  }
33
 
34
  public function getMode()
@@ -38,6 +35,11 @@ class Apruve_ApruvePayment_Helper_Data extends Mage_Core_Helper_Abstract
38
  return $sourceArray[Mage::getStoreConfig('payment/apruvepayment/mode')];
39
  }
40
 
 
 
 
 
 
41
  public function isAutoSubmit()
42
  {
43
  return Mage::getStoreConfig('payment/apruvepayment/autosubmit');
@@ -45,8 +47,43 @@ class Apruve_ApruvePayment_Helper_Data extends Mage_Core_Helper_Abstract
45
 
46
  public function getSrc()
47
  {
48
- $sourceModel = Mage::getModel('apruvepayment/mode');
49
- $sourceArray = $sourceModel->toSrcArray();
50
- return $sourceArray[Mage::getStoreConfig('payment/apruvepayment/mode')];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
  }
21
  class Apruve_ApruvePayment_Helper_Data extends Mage_Core_Helper_Abstract
22
  {
23
  /**
24
+ * @return Apruve_ApruvePayment_Model_Api_Payment
25
  */
26
+ public function getPaymentApiModel()
27
  {
28
+ return Mage::getModel('apruvepayment/api_payment');
 
 
 
29
  }
30
 
31
  public function getMode()
35
  return $sourceArray[Mage::getStoreConfig('payment/apruvepayment/mode')];
36
  }
37
 
38
+ public function getApiVersion()
39
+ {
40
+ return Mage::getStoreConfig('payment/apruvepayment/version');
41
+ }
42
+
43
  public function isAutoSubmit()
44
  {
45
  return Mage::getStoreConfig('payment/apruvepayment/autosubmit');
47
 
48
  public function getSrc()
49
  {
50
+ $apruveUrl = Mage::getModel('apruvepayment/api_payment')->getBaseUrl();
51
+ return $apruveUrl . 'js/apruve.js?display=compact';
52
+ }
53
+
54
+ /**
55
+ * Log the messages and data to apruve.log if log is enabled
56
+ *
57
+ * @var string|array|object $data
58
+ * @return void
59
+ */
60
+ public function logException($data)
61
+ {
62
+ $isEnabled = Mage::getStoreConfig('payment/apruvepayment/log');
63
+ if($isEnabled) {
64
+ Mage::log($data, 7, 'apruve.log', true);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Retrieve only the visible items from a item collection for order, invoice and shipment
70
+ *
71
+ * @param Mage_Sales_Model_Abstract $object
72
+ * @return Mage_Core_Model_Abstract[]
73
+ */
74
+ public function getAllVisibleItems($object)
75
+ {
76
+ $items = array();
77
+ foreach ($object->getItemsCollection() as $item) {
78
+ $orderItem = $item->getOrderItem();
79
+ if (!$orderItem->isDeleted() && !$orderItem->getParentItemId()) {
80
+ $qty = (int) $item->getQty();
81
+ $qty = $qty > 0 ? $qty : (int) $item->getQtyOrdered();
82
+ if ($qty) {
83
+ $items[] = $item;
84
+ }
85
+ }
86
+ }
87
+ return $items;
88
  }
89
  }
app/code/community/Apruve/ApruvePayment/Model/Api/Abstract.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * Magento
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -17,6 +16,13 @@
17
  * @package Apruve_Payment
18
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
 
 
 
 
 
 
 
20
  */
21
 
22
  abstract class Apruve_ApruvePayment_Model_Api_Abstract
@@ -24,9 +30,7 @@ abstract class Apruve_ApruvePayment_Model_Api_Abstract
24
  /**
25
  * @var string
26
  */
27
- protected $_version = 'v3';
28
- //protected $_testMode;
29
-
30
 
31
  /**
32
  * Generate headers for rest request
@@ -35,9 +39,107 @@ abstract class Apruve_ApruvePayment_Model_Api_Abstract
35
  protected function getHeaders()
36
  {
37
  return array(
38
- 'Content-type: application/json',
39
- 'Apruve-Api-Key: ' . $this->getApiKey(),
40
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
42
 
43
  /**
@@ -71,33 +173,57 @@ abstract class Apruve_ApruvePayment_Model_Api_Abstract
71
  return Mage::getStoreConfig('payment/apruvepayment/mode');
72
  }
73
 
74
-
75
  /**
76
- * Get Apruve base url based on mode
77
- * @param bool $secure
78
- * @return string
79
  */
80
- public function getBaseUrl($secure = false)
81
  {
82
- $http = $secure ? 'https://' : 'http://';
83
- if($this->getIsTestMode()) {
84
- return $http.'test.apruve.com/';
 
 
 
 
 
 
 
 
 
 
 
85
  } else {
86
- return $http.'app.apruve.com/';
 
 
 
 
 
 
 
 
 
87
  }
88
  }
89
 
90
 
91
  /**
92
- * Get api url part based on version
 
93
  * @return string
94
  */
95
- protected function getApiUrl()
96
  {
97
- return 'api/'.$this->_version.'/';
 
 
 
 
 
98
  }
99
 
100
-
101
  /**
102
  * Convert price to needed value
103
  * As current version supports only USD, convert price to cents
@@ -258,7 +384,4 @@ abstract class Apruve_ApruvePayment_Model_Api_Abstract
258
 
259
  return $result;
260
  }
261
-
262
-
263
-
264
  }
1
  <?php
 
2
  /**
3
+ * Apruve
4
  *
5
  * NOTICE OF LICENSE
6
  *
16
  * @package Apruve_Payment
17
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Class Apruve_ApruvePayment_Model_Api_Abstract
24
+ *
25
+ * This is an abstract for Apruve payment gateway.
26
  */
27
 
28
  abstract class Apruve_ApruvePayment_Model_Api_Abstract
30
  /**
31
  * @var string
32
  */
33
+ const DATE_FORMAT = DateTime::ATOM;
 
 
34
 
35
  /**
36
  * Generate headers for rest request
39
  protected function getHeaders()
40
  {
41
  return array(
42
+ "accept: application/json",
43
+ "apruve-api-key: " . $this->getApiKey(),
44
+ "content-type: application/json"
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Get the API version selected for the store
50
+ * @return string
51
+ */
52
+ protected function getApiVersion()
53
+ {
54
+ return Mage::helper('apruvepayment')->getApiVersion();
55
+ }
56
+
57
+
58
+ /**
59
+ * Get api url part based on version
60
+ * @return string
61
+ */
62
+ protected function getApiUrl()
63
+ {
64
+ return 'api/'.$this->getApiVersion().'/';
65
+ }
66
+
67
+ /**
68
+ * Prepare the response array for the API call
69
+ *
70
+ * @var string|JSON $response
71
+ * @var string $url
72
+ * @var string $err
73
+ * @var string|integer $http_status
74
+ * @var string|[] $curlOptions
75
+ * @return string[] $result
76
+ */
77
+ protected function _prepareResponse($response, $url = '', $err = '', $http_status = '', $curlOptions = '')
78
+ {
79
+ $result = [];
80
+ $success = true;
81
+ $message = '';
82
+ if ($err) {
83
+ $message = "Request Error:" . $err;
84
+ $success = false;
85
+ }
86
+
87
+ if ($http_status < 200 || $http_status >= 300) {
88
+ $message = "Request Error: Request could not be processed";
89
+ $success = false;
90
+ }
91
+
92
+ $result['success'] = $success;
93
+ $result['code'] = $http_status;
94
+ $result['messsage'] = $message;
95
+ $result['response'] = Mage::helper('core')->jsonDecode($response);
96
+ $result['post_data'] = $curlOptions;
97
+ $result['url'] = $url;
98
+ Mage::helper('apruvepayment')->logException($result);
99
+ return $result;
100
+ }
101
+
102
+ /**
103
+ * Returns a formatted date based on the constant DATE_FORMAT
104
+ *
105
+ * @return date
106
+ */
107
+ protected function getDateFormatted($date)
108
+ {
109
+ return date(self::DATE_FORMAT, strtotime($date));
110
+ }
111
+
112
+ /**
113
+ * Returns an expiry date in future for the order items created in apruve
114
+ *
115
+ * @return date
116
+ */
117
+ protected function getExpiryDate()
118
+ {
119
+ return $this->getDateFormatted('+1 week');
120
+ }
121
+
122
+ /**
123
+ * Get the current store currency
124
+ *
125
+ * @return date
126
+ */
127
+ protected function getCurrency()
128
+ {
129
+ return Mage::app()->getStore()->getBaseCurrencyCode();
130
+ }
131
+
132
+ /**
133
+ * Get the order item's vendor/manufacturer data
134
+ *
135
+ * @return string
136
+ */
137
+ protected function getVendor($orderItem)
138
+ {
139
+ $product = $orderItem->getProduct();
140
+ $attributeCode = Mage::getStoreConfig('payment/apruvepayment/product_vendor');
141
+ $vendor = $product->getData($attributeCode);
142
+ return $vendor;
143
  }
144
 
145
  /**
173
  return Mage::getStoreConfig('payment/apruvepayment/mode');
174
  }
175
 
 
176
  /**
177
+ * Build Discount Line item
178
+ * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
179
+ * @return array
180
  */
181
+ protected function _getDiscountItem($object)
182
  {
183
+ $helper = Mage::helper('apruvepayment');
184
+ $discountItem = [];
185
+ $discountItem['quantity'] = 1;
186
+ $discountItem['currency'] = $this->getCurrency();
187
+ $discountItem['description'] = $helper->__('Cart Discount');
188
+ $discountItem['sku'] = $helper->__('Discount');
189
+ $discountItem['title'] = $helper->__('Discount');
190
+
191
+ if($object instanceof Mage_Sales_Model_Quote) {
192
+ $discountAmount = $this->convertPrice($object->getBaseSubtotal() - $object->getBaseSubtotalWithDiscount());
193
+ } elseif($object instanceof Mage_Sales_Model_Order) {
194
+ $discountAmount = $this->convertPrice($object->getBaseDiscountAmount());
195
+ } elseif($object instanceof Mage_Sales_Model_Order_Invoice) {
196
+ $discountAmount = $this->convertPrice($object->getBaseDiscountAmount());
197
  } else {
198
+ return false;
199
+ }
200
+ if($discountAmount) {
201
+ $discountAmount = -1 * abs($discountAmount);
202
+ $discountItem['price_ea_cents'] = $discountAmount;
203
+ $discountItem['price_total_cents'] = $discountAmount;
204
+
205
+ return $discountItem;
206
+ } else {
207
+ return false;
208
  }
209
  }
210
 
211
 
212
  /**
213
+ * Get Apruve base url based on mode
214
+ * @param bool $secure
215
  * @return string
216
  */
217
+ public function getBaseUrl($secure = true)
218
  {
219
+ $http = $secure ? 'https://' : 'http://';
220
+ if($this->getIsTestMode()) {
221
+ return $http . 'test.apruve.com/';
222
+ } else {
223
+ return $http . 'app.apruve.com/';
224
+ }
225
  }
226
 
 
227
  /**
228
  * Convert price to needed value
229
  * As current version supports only USD, convert price to cents
384
 
385
  return $result;
386
  }
 
 
 
387
  }
app/code/community/Apruve/ApruvePayment/Model/Api/Payment.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * Magento
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -17,23 +16,102 @@
17
  * @package Apruve_Payment
18
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
 
20
  */
21
 
22
 
 
 
 
 
 
23
  class Apruve_ApruvePayment_Model_Api_Payment extends Apruve_ApruvePayment_Model_Api_Abstract
24
  {
25
- /** @var Mage_Sales_Model_Order */
26
- private $order;
27
 
28
- /** @var Mage_Sales_Model_Quote */
29
- private $quote;
30
 
31
- private $amounts;
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- function __construct(Mage_Sales_Model_Order $order)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  {
35
- $this->order = $order;
36
- $this->quote = $order->getQuote();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
 
39
  /**
@@ -44,7 +122,7 @@ class Apruve_ApruvePayment_Model_Api_Payment extends Apruve_ApruvePayment_Model_
44
  public function getAmount($key)
45
  {
46
  if (empty($this->amounts)) {
47
- $this->amounts = $this->getAmountsFromOrder($this->order);
48
  }
49
 
50
  if (isset($this->amounts[$key])) {
@@ -55,36 +133,55 @@ class Apruve_ApruvePayment_Model_Api_Payment extends Apruve_ApruvePayment_Model_
55
  }
56
 
57
  /**
58
- * Generate payment request by given order
59
- *
60
  * @return array
61
  */
62
- public function getPayment()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  {
64
- return array(
65
- 'amount_cents' => $this->convertPrice($this->getAmount('amount_cents')),
66
- 'payment_items' => $this->getLineItems($this->order),
67
- 'issue_on_create' => !$this->quote->getIsMultiShipping()
68
- );
 
69
  }
70
 
71
  /**
72
  * Build Line items array
73
- * @param Mage_Sales_Model_Order $itemsParent
74
  * @return array
75
  */
76
  protected function getLineItems($itemsParent)
77
  {
78
  $result = array();
79
- /** @var Mage_Sales_Model_Order_Item[] $visibleItems */
80
  $visibleItems = $itemsParent->getAllVisibleItems();
81
  foreach ($visibleItems as $item) {
82
 
83
  $result[] = array(
84
  'title' => $item->getName(),
85
- 'amount_cents' => $this->convertPrice($item->getPrice()) * $item->getQtyOrdered(),
86
- 'price_ea_cents' => $this->convertPrice($item->getPrice()),
87
- 'quantity' => $item->getQtyOrdered(),
88
  'description' => $this->getShortDescription($item),
89
  'variant_info' => $this->getVariantInfo($item),
90
  'sku' => $item->getSku(),
@@ -92,7 +189,11 @@ class Apruve_ApruvePayment_Model_Api_Payment extends Apruve_ApruvePayment_Model_
92
  );
93
 
94
  }
 
 
 
 
95
 
96
  return $result;
97
  }
98
- }
1
  <?php
 
2
  /**
3
+ * Apruve
4
  *
5
  * NOTICE OF LICENSE
6
  *
16
  * @package Apruve_Payment
17
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
  */
21
 
22
 
23
+ /**
24
+ * Class Apruve_ApruvePayment_Model_Api_Payment
25
+ * Provide methods to build payment
26
+ * @see https://apruvit.atlassian.net/wiki/display/DOCCO/payment_request
27
+ */
28
  class Apruve_ApruvePayment_Model_Api_Payment extends Apruve_ApruvePayment_Model_Api_Abstract
29
  {
30
+ private $_quote;
 
31
 
32
+ private $_amounts;
 
33
 
34
+ /**
35
+ * Post request general fields
36
+ * @var array
37
+ */
38
+ protected $_postFields = array(
39
+ //required
40
+ 'merchant_id',
41
+ 'amount_cents',
42
+ //optional
43
+ 'currency',
44
+ 'tax_cents',
45
+ 'shipping_cents',
46
+ 'line_items' => array(),
47
+ );
48
 
49
+ /**
50
+ * Line Items Fields
51
+ * @var array
52
+ */
53
+ protected $_lineItemFields = array(
54
+ //required
55
+ 'title',
56
+ 'amount_cents', // if qty -> should chanfe
57
+ 'price_ea_cents',
58
+ 'description',
59
+ 'variant_info',
60
+ 'sku',
61
+ 'vendor',
62
+ 'view_product_url',
63
+ );
64
+
65
+ /**
66
+ * @var array
67
+ */
68
+ protected $_paymentRequest;
69
+
70
+ /**
71
+ * Get current quote
72
+ * @return Mage_Sales_Model_Quote
73
+ */
74
+ public function getQuote()
75
+ {
76
+ if($this->_quote == null) {
77
+ $this->_quote = Mage::getSingleton('checkout/session')->getQuote();
78
+ }
79
+
80
+ return $this->_quote;
81
+ }
82
+
83
+ /**
84
+ * Get json encoded payment request
85
+ * @return string
86
+ */
87
+ public function getPaymentRequestJSON()
88
  {
89
+ return json_encode($this->_getPaymentRequest());
90
+ }
91
+
92
+ /**
93
+ * Get secure hash
94
+ * @see https://apruvit.atlassian.net/wiki/display/DOCCO/Checkout+Page+Tutorial#CheckoutPageTutorial-1b:CreatingaSecureHash
95
+ * @return string
96
+ */
97
+ public function getSecureHash()
98
+ {
99
+ $concatString = $this->getApiKey();
100
+
101
+ foreach ($this->_getPaymentRequest() as $val) {
102
+ if (!is_array($val)) {
103
+ $concatString .= $val;
104
+ } else {
105
+ foreach ($val as $v) {
106
+ foreach ($v as $s) {
107
+ $concatString .= $s;
108
+ }
109
+
110
+ }
111
+ }
112
+ }
113
+
114
+ return hash('sha256', $concatString);
115
  }
116
 
117
  /**
122
  public function getAmount($key)
123
  {
124
  if (empty($this->amounts)) {
125
+ $this->amounts = $this->getAmountsFromQuote($this->getQuote());
126
  }
127
 
128
  if (isset($this->amounts[$key])) {
133
  }
134
 
135
  /**
136
+ * Build Payment Request Array
 
137
  * @return array
138
  */
139
+ protected function _getPaymentRequest()
140
+ {
141
+ if($this->_paymentRequest == null) {
142
+ $this->_paymentRequest = array(
143
+ 'merchant_id' => $this->getMerchantKey(),
144
+ 'amount_cents' => $this->convertPrice($this->getAmount('amount_cents')),
145
+ 'currency' => $this->getCurrency(),
146
+ 'tax_cents' => $this->convertPrice($this->getAmount('tax_cents')),
147
+ 'shipping_cents' => $this->convertPrice($this->getAmount('shipping_cents')),
148
+ 'line_items' => $this->getLineItems($this->getQuote())
149
+ );
150
+ }
151
+
152
+ return $this->_paymentRequest;
153
+ }
154
+
155
+ /**
156
+ * @param Mage_Sales_Model_Quote $quote
157
+ */
158
+ public function getShopperInfo($attrName)
159
  {
160
+ $method = 'get' . ucfirst($attrName);
161
+ if ($this->getQuote()->getCustomerIsGuest()) {
162
+ return $this->getQuote()->getBillingAddress()->$method();
163
+ }
164
+
165
+ return $this->getQuote()->getCustomer()->$method();
166
  }
167
 
168
  /**
169
  * Build Line items array
170
+ * @param Mage_Sales_Model_Quote $itemsParent
171
  * @return array
172
  */
173
  protected function getLineItems($itemsParent)
174
  {
175
  $result = array();
176
+ /** @var Mage_Sales_Model_Quote_Item[] $visibleItems */
177
  $visibleItems = $itemsParent->getAllVisibleItems();
178
  foreach ($visibleItems as $item) {
179
 
180
  $result[] = array(
181
  'title' => $item->getName(),
182
+ 'amount_cents' => $this->convertPrice($item->getBaseRowTotal()),
183
+ 'price_ea_cents' => $this->convertPrice($item->getBasePrice()),
184
+ 'quantity' => $item->getQty(),
185
  'description' => $this->getShortDescription($item),
186
  'variant_info' => $this->getVariantInfo($item),
187
  'sku' => $item->getSku(),
189
  );
190
 
191
  }
192
+ // get discount line item
193
+ if(($discountItem = $this->_getDiscountItem($itemsParent))) {
194
+ $result[] = $discountItem;
195
+ }
196
 
197
  return $result;
198
  }
199
+ }
app/code/community/Apruve/ApruvePayment/Model/Api/PaymentRequest.php DELETED
@@ -1,211 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Apache License, Version 2.0
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/Apache-2.0
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@apruve.com so we can send you a copy immediately.
15
- *
16
- * @category Apruve
17
- * @package Apruve_Payment
18
- * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
- * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
20
- */
21
-
22
-
23
- /**
24
- * Class Apruve_ApruvePayment_Model_Api_PaymentRequest
25
- * Provide methods to build paymentRequest
26
- * @see https://apruvit.atlassian.net/wiki/display/DOCCO/payment_request
27
- */
28
- class Apruve_ApruvePayment_Model_Api_PaymentRequest extends Apruve_ApruvePayment_Model_Api_Abstract
29
- {
30
- private $quote;
31
-
32
- private $amounts;
33
-
34
- /**
35
- * Post request general fields
36
- * @var array
37
- */
38
- protected $_postFields = array(
39
- //required
40
- 'merchant_id',
41
- 'amount_cents',
42
- //optional
43
- 'currency',
44
- 'tax_cents',
45
- 'shipping_cents',
46
- 'line_items' => array(),
47
- );
48
-
49
- /**
50
- * Line Items Fields
51
- * @var array
52
- */
53
- protected $_lineItemFields = array(
54
- //required
55
- 'title',
56
- 'amount_cents', // if qty -> should chanfe
57
- 'price_ea_cents',
58
- 'description',
59
- 'variant_info',
60
- 'sku',
61
- 'vendor',
62
- 'view_product_url',
63
- );
64
-
65
- /**
66
- * @var array
67
- */
68
- protected $_paymentRequest;
69
-
70
-
71
- public function __construct(Mage_Sales_Model_Quote $quote)
72
- {
73
- $this->quote = $quote;
74
- $this->_paymentRequest = $this->setPaymentRequest();
75
- }
76
-
77
- /**
78
- * Get json encoded payment request
79
- * @return string
80
- */
81
- public function getPaymentRequestJSON()
82
- {
83
- return json_encode($this->_paymentRequest);
84
- }
85
-
86
- /**
87
- * Get secure hash
88
- * @see https://apruvit.atlassian.net/wiki/display/DOCCO/Checkout+Page+Tutorial#CheckoutPageTutorial-1b:CreatingaSecureHash
89
- * @return string
90
- */
91
- public function getSecureHash()
92
- {
93
- $concatString = $this->getApiKey();
94
-
95
- foreach ($this->_paymentRequest as $val) {
96
- if (!is_array($val)) {
97
- $concatString .= $val;
98
- } else {
99
- foreach ($val as $v) {
100
- foreach ($v as $s) {
101
- $concatString .= $s;
102
- }
103
-
104
- }
105
- }
106
- }
107
-
108
- return hash('sha256', $concatString);
109
- }
110
-
111
- /**
112
- * Return amount_cents, shipping_cents or tax_cents
113
- * @param $key
114
- * @return float | bool
115
- */
116
- public function getAmount($key)
117
- {
118
- if (empty($this->amounts)) {
119
- $this->amounts = $this->getAmountsFromQuote($this->quote);
120
- }
121
-
122
- if (isset($this->amounts[$key])) {
123
- return $this->amounts[$key];
124
- }
125
-
126
- return false;
127
- }
128
-
129
- /**
130
- * Build Payment Request Array
131
- * @return array
132
- */
133
- protected function setPaymentRequest()
134
- {
135
-
136
- $paymentRequest = array(
137
- 'merchant_id' => $this->getMerchantKey(),
138
- 'amount_cents' => $this->convertPrice($this->getAmount('amount_cents')),
139
- 'currency' => 'USD',
140
- 'tax_cents' => $this->convertPrice($this->getAmount('tax_cents')),
141
- 'shipping_cents' => $this->convertPrice($this->getAmount('shipping_cents')),
142
- 'line_items' => $this->getLineItems($this->quote)
143
- );
144
-
145
- return $paymentRequest;
146
- }
147
-
148
- public function updatePaymentRequest($token, $orderId)
149
- {
150
- /** @var Apruve_ApruvePayment_Model_Api_Rest $rest */
151
- $rest = Mage::getModel('apruvepayment/api_rest');
152
- $pRequest = Mage::registry('apruve_request_updated' . $token);
153
- if ($pRequest === null) {
154
-
155
- $pRequest = $rest->updatePaymentRequest(
156
- $token,
157
- $this->getAmount('amount_cents'),
158
- $this->getAmount('shipping_cents'),
159
- $this->getAmount('tax_cents'),
160
- $orderId
161
- );
162
-
163
- Mage::register('apruve_request_updated' . $token, $pRequest);
164
- }
165
- return $pRequest;
166
- }
167
-
168
-
169
- /**
170
- * @param Mage_Sales_Model_Quote $quote
171
- */
172
- public function getShopperInfo($attrName)
173
- {
174
- $method = 'get' . ucfirst($attrName);
175
- if ($this->quote->getCustomerIsGuest()) {
176
- return $this->quote->getBillingAddress()->$method();
177
- }
178
-
179
- return $this->quote->getCustomer()->$method();
180
- }
181
-
182
- /**
183
- * Build Line items array
184
- * @param Mage_Sales_Model_Quote $itemsParent
185
- * @return array
186
- */
187
- protected function getLineItems($itemsParent)
188
- {
189
- $result = array();
190
- /** @var Mage_Sales_Model_Quote_Item[] $visibleItems */
191
- $visibleItems = $itemsParent->getAllVisibleItems();
192
- foreach ($visibleItems as $item) {
193
-
194
- $result[] = array(
195
- 'title' => $item->getName(),
196
- 'amount_cents' => $this->convertPrice($item->getPrice()) * $item->getQty(),
197
- 'price_ea_cents' => $this->convertPrice($item->getPrice()),
198
- 'quantity' => $item->getQty(),
199
- 'description' => $this->getShortDescription($item),
200
- 'variant_info' => $this->getVariantInfo($item),
201
- 'sku' => $item->getSku(),
202
- 'view_product_url' => $item->getProduct()->getProductUrl(false),
203
- );
204
-
205
- }
206
-
207
- return $result;
208
- }
209
-
210
- }
211
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Apruve/ApruvePayment/Model/Api/Rest.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * Magento
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -17,6 +16,7 @@
17
  * @package Apruve_Payment
18
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
 
20
  */
21
 
22
  /**
@@ -27,140 +27,35 @@
27
  class Apruve_ApruvePayment_Model_Api_Rest extends Apruve_ApruvePayment_Model_Api_Abstract
28
  {
29
  /**
30
- * Send Payment object
31
- * @param string $paymentRequestId
32
- * @param array $payment
33
  *
34
- * @return bool
35
- */
36
- public function postPayment($paymentRequestId, $payment)
37
- {
38
- $data = json_encode($payment);
39
-
40
- $c = curl_init($this->getPaymentUrl($paymentRequestId));
41
-
42
- curl_setopt($c, CURLOPT_HTTPHEADER, $this->getHeaders());
43
- curl_setopt($c, CURLOPT_POST, true);
44
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
45
- curl_setopt($c, CURLOPT_POSTFIELDS, $data);
46
- $response = curl_exec($c);
47
- $http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
48
- curl_close($c);
49
-
50
- if ($http_status == '201') {
51
- return json_decode($response);
52
- } else {
53
- return false;
54
- }
55
-
56
- }
57
-
58
- /**
59
- * Update paymentRequest object
60
- * Availible fields to update are: amount_cents, shipping_cents, tax_cents
61
- * @param string $paymentRequestId
62
- * @param float $amount
63
- * @param float $shipping
64
- * @param float $tax
65
- * @return bool
66
  */
67
- public function updatePaymentRequest($paymentRequestId, $amount, $shipping, $tax, $orderIncrementId)
68
  {
69
- $data = json_encode(array(
70
- 'merchant_order_id' => $orderIncrementId,
71
- 'amount_cents' => $this->convertPrice($amount),
72
- 'shipping_cents' => $this->convertPrice($shipping),
73
- 'tax_cents' => $this->convertPrice($tax),
 
 
 
 
 
 
74
  ));
75
 
76
- $c = curl_init($this->getUpdatePaymentRequestUrl($paymentRequestId));
77
-
78
- curl_setopt($c, CURLOPT_HTTPHEADER, $this->getHeaders());
79
- curl_setopt($c, CURLOPT_CUSTOMREQUEST, "PUT");
80
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
81
- curl_setopt($c, CURLOPT_POSTFIELDS, $data);
82
- $response = curl_exec($c);
83
- $http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
84
- curl_close($c);
85
-
86
-
87
- if ($http_status == '200') {
88
- return json_decode($response);
89
- } else {
90
- return false;
91
- }
92
- }
93
-
94
- /**
95
- * Finalize paymentRequest object
96
- *
97
- * @param string $paymentRequestId
98
- *
99
- * @return bool
100
- */
101
- public function finalizePaymentRequest($paymentRequestId)
102
- {
103
- $c = curl_init($this->getFinalizePaymentRequestUrl($paymentRequestId));
104
-
105
- curl_setopt($c, CURLOPT_HTTPHEADER, $this->getHeaders());
106
- curl_setopt($c, CURLOPT_CUSTOMREQUEST, "POST");
107
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
108
- $response = curl_exec($c);
109
- $http_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
110
- curl_close($c);
111
 
 
 
 
112
 
113
- if ($http_status == '200') {
114
- return json_decode($response);
115
- } else {
116
- return false;
117
- }
118
- }
119
 
120
- /**
121
- * GET Apruve Payment Status
122
- * Check whether given status is same as in Apruve.com
123
- * @param $status
124
- * @param $apiUrl
125
- * @return bool
126
- */
127
- public function getApruveOrderStatus($apiUrl, $status)
128
- {
129
- $c = curl_init($apiUrl);
130
- curl_setopt($c, CURLOPT_HTTPHEADER, $this->getHeaders());
131
- curl_setopt($c, CURLOPT_CUSTOMREQUEST, "GET");
132
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
133
- curl_setopt($c, CURLOPT_HEADER, true);
134
- }
135
-
136
- /**
137
- * Get url for send payment
138
- * @param string $paymentRequestId
139
- * @return string
140
- */
141
- protected function getPaymentUrl($paymentRequestId)
142
- {
143
- return $this->getBaseUrl(true) . $this->getApiUrl() . 'payment_requests/' . $paymentRequestId . '/payments';
144
- }
145
-
146
-
147
- /**
148
- * Get url for update paymentRequest
149
- * @param string $paymentRequestId
150
- * @return string
151
- */
152
- protected function getUpdatePaymentRequestUrl($paymentRequestId)
153
- {
154
- return $this->getBaseUrl(true) . $this->getApiUrl() . 'payment_requests/' . $paymentRequestId;
155
- }
156
-
157
- /**
158
- * Get url for paymentRequest finalizing
159
- * @param string $paymentRequestId
160
- * @return string
161
- */
162
- protected function getFinalizePaymentRequestUrl($paymentRequestId)
163
- {
164
- return $this->getBaseUrl(true) . $this->getApiUrl() . 'payment_requests/' . $paymentRequestId . '/finalize';
165
  }
166
  }
1
  <?php
 
2
  /**
3
+ * Apruve
4
  *
5
  * NOTICE OF LICENSE
6
  *
16
  * @package Apruve_Payment
17
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
  */
21
 
22
  /**
27
  class Apruve_ApruvePayment_Model_Api_Rest extends Apruve_ApruvePayment_Model_Api_Abstract
28
  {
29
  /**
30
+ * Executes all the curl requests
 
 
31
  *
32
+ * @param $curlOptions string[]
33
+ * @return $response string
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  */
35
+ public function execCurlRequest($url, $method = 'GET', $curlOptions = [])
36
  {
37
+ $curl = curl_init();
38
+
39
+ curl_setopt_array($curl, array(
40
+ CURLOPT_URL => $url,
41
+ CURLOPT_RETURNTRANSFER => true,
42
+ CURLOPT_ENCODING => "",
43
+ CURLOPT_MAXREDIRS => 10,
44
+ CURLOPT_TIMEOUT => 30,
45
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
46
+ CURLOPT_CUSTOMREQUEST => $method,
47
+ CURLOPT_HTTPHEADER => $this->getHeaders(),
48
  ));
49
 
50
+ curl_setopt_array($curl, $curlOptions);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ $response = curl_exec($curl);
53
+ $err = curl_error($curl);
54
+ $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
55
 
56
+ curl_close($curl);
 
 
 
 
 
57
 
58
+ $result = $this->_prepareResponse($response, $url, $err, $http_status, $curlOptions);
59
+ return $result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
  }
app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Invoice.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Class Apruve_ApruvePayment_Model_Api_Rest_Invoice
24
+ *
25
+ * Provide rest methods to communicate with apruve
26
+ */
27
+ class Apruve_ApruvePayment_Model_Api_Rest_Invoice extends Apruve_ApruvePayment_Model_Api_Rest
28
+ {
29
+ /**
30
+ * Get url for invoice create
31
+ * @param string $apruveOrderId
32
+ * @return string
33
+ */
34
+ protected function _getCreateInvoiceUrl($apruveOrderId)
35
+ {
36
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'orders/' . $apruveOrderId . '/invoices';
37
+ }
38
+
39
+ /**
40
+ * Get url for invoice retrieve
41
+ * @param string $apruveOrderId
42
+ * @return string
43
+ */
44
+ protected function _getInvoiceUrl($apruveInvoiceId)
45
+ {
46
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId;
47
+ }
48
+
49
+ /**
50
+ * Get url for invoice cancel
51
+ * @param string $apruveOrderId
52
+ * @return string
53
+ */
54
+ protected function _getCancelInvoiceUrl($apruveInvoiceId)
55
+ {
56
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId . '/cancel';
57
+ }
58
+
59
+ /**
60
+ * Get url for invoice update
61
+ * @param string $apruveOrderId
62
+ * @return string
63
+ */
64
+ protected function _getUpdateInvoiceUrl($apruveInvoiceId)
65
+ {
66
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId;
67
+ }
68
+
69
+ /**
70
+ * Retrieve an existing invoice by its ID in apruve
71
+ *
72
+ * @param $id string
73
+ * @return $result string
74
+ */
75
+ public function getInvoice($apruveInvoiceId)
76
+ {
77
+ $result = $this->execCurlRequest($this->_getInvoiceUrl($apruveInvoiceId));
78
+ return $result;
79
+ }
80
+
81
+ /**
82
+ * Update Apruve invoice id to it's corresponding invoice in magento
83
+ *
84
+ * @param $id string
85
+ * @param $invoice Mage_Sales_Model_Order_Invoice
86
+ * @return bool
87
+ * @throws Exception
88
+ */
89
+ protected function _updateInvoiceId($apruveInvoiceId, $apruveInvoiceItemIds, $invoice)
90
+ {
91
+ try {
92
+ $apruveInvoiceItemIds = Mage::helper('core')->jsonEncode($apruveInvoiceItemIds);
93
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByInvoiceId($invoice->getIncrementId());
94
+ $apruveEntity->setApruveId($apruveInvoiceId);
95
+ $apruveEntity->setApruveItemId($apruveInvoiceItemIds);
96
+ $apruveEntity->setMagentoId($invoice->getIncrementId());
97
+ $apruveEntity->setEntityType('invoice');
98
+ $apruveEntity->save();
99
+ } catch(Exception $e) {
100
+ Mage::helper('apruvepayment')->logException($e->getMessage());
101
+ Mage::throwException(Mage::helper('apruvepayment')->__('Couldn\'t update invoice.'));
102
+ }
103
+ return true;
104
+ }
105
+
106
+ /**
107
+ * Retrieve the latest comment from magento invoice
108
+ *
109
+ * @param $invoice Mage_Sales_Model_Order_Invoice
110
+ * @return $comment Mage_Sales_Model_Order_Invoice_Comment
111
+ */
112
+ protected function _getInvoiceComment($invoice)
113
+ {
114
+ $comment = Mage::getResourceModel('sales/order_invoice_comment_collection')
115
+ ->setInvoiceFilter($invoice->getId())
116
+ ->setOrder('created_at', 'DESC')
117
+ ->setPageSize(1)
118
+ ->getFirstItem();
119
+
120
+ return $comment;
121
+ }
122
+
123
+ /**
124
+ * Prepare invoice data for Apruve
125
+ *
126
+ * @param $shipment Mage_Sales_Model_Order_Invoice
127
+ * @return $data []
128
+ */
129
+ protected function _getInvoiceData($invoice)
130
+ {
131
+ $invoiceItems = Mage::helper('apruvepayment')->getAllVisibleItems($invoice);
132
+
133
+ $items = [];
134
+ foreach($invoiceItems as $invoiceItem) {
135
+ $orderItem = $invoiceItem->getOrderItem();
136
+ /* create invoice item for apruve */
137
+ $item = [];
138
+ $item['price_ea_cents'] = $this->convertPrice($invoiceItem->getBasePrice());
139
+ $item['quantity'] = $invoiceItem->getQty();
140
+ $item['price_total_cents'] = $this->convertPrice($invoiceItem->getBaseRowTotal());
141
+ $item['currency'] = $this->getCurrency();
142
+ $item['title'] = $invoiceItem->getName();
143
+ $item['merchant_notes'] = $invoiceItem->getAdditionalData();
144
+ $item['description'] = $invoiceItem->getDescription();
145
+ $item['sku'] = $invoiceItem->getSku();
146
+ $item['variant_info'] = $orderItem->getProductOptions();
147
+ $item['vendor'] = $this->getVendor($orderItem);
148
+ /* add invoice item to $items array */
149
+ $items[] = $item;
150
+ }
151
+ // get discount line item
152
+ if(($discountItem = $this->_getDiscountItem($invoice))) {
153
+ $items[] = $discountItem;
154
+ }
155
+
156
+ /* latest shipment comment */
157
+ $comment = $this->_getInvoiceComment($invoice);
158
+
159
+ /* prepare invoice data */
160
+ $data = json_encode([
161
+ 'invoice' => [
162
+ 'amount_cents' => $this->convertPrice($invoice->getBaseGrandTotal()),
163
+ 'currency' => $this->getCurrency(),
164
+ 'shipping_cents' => $this->convertPrice($invoice->getBaseShippingAmount()),
165
+ 'tax_cents' => $this->convertPrice($invoice->getBaseTaxAmount()),
166
+ 'merchant_notes' => $comment->getComment(),
167
+ 'merchant_invoice_id' => $invoice->getIncrementId(),
168
+ //'due_at' => '2016-06-01T13:54:21Z',
169
+ 'invoice_items' => $items,
170
+ 'issue_on_create' => true
171
+ ]
172
+ ]);
173
+
174
+ return $data;
175
+ }
176
+
177
+ /**
178
+ * Create new invoice in Apruve for an order based on invoice created in Magento
179
+ *
180
+ * @param $apruveOrderId string
181
+ * @return $result string[]
182
+ */
183
+ public function createInvoice($apruveOrderId, $invoice)
184
+ {
185
+ $data = $this->_getInvoiceData($invoice);
186
+
187
+ $curlOptions = [];
188
+ $curlOptions[CURLOPT_POSTFIELDS] = $data;
189
+
190
+ $result = $this->execCurlRequest($this->_getCreateInvoiceUrl($apruveOrderId), 'POST', $curlOptions);
191
+ $apruveInvoiceId = isset($result['response']['id']) ? $result['response']['id'] : '';
192
+ $apruveInvoiceItemIds = isset($result['response']['invoice_items']) ? $result['response']['invoice_items'] : '';
193
+ if($result['success'] == true) {
194
+ $this->_updateInvoiceId($apruveInvoiceId, $apruveInvoiceItemIds, $invoice);
195
+ }
196
+
197
+ return $result;
198
+ }
199
+
200
+ /**
201
+ * Update an existing invoice in Apruve
202
+ *
203
+ * @param $id string
204
+ * @return $result string
205
+ */
206
+ public function updateInvoice($apruveInvoiceId, $invoice)
207
+ {
208
+ $data = $this->_getInvoiceData($invoice);
209
+
210
+ $curlOptions = [];
211
+ $curlOptions[CURLOPT_POSTFIELDS] = $data;
212
+
213
+ $result = $this->execCurlRequest($this->_getUpdateInvoiceUrl($apruveInvoiceId), 'PUT', $curlOptions);
214
+
215
+ return $result;
216
+ }
217
+
218
+ /**
219
+ * Retrieve an existing invoice item IDS based on its ID in apruve
220
+ *
221
+ * @param $id string
222
+ * @return $result string
223
+ */
224
+ public function getInvoiceItemIds($apruveInvoiceId)
225
+ {
226
+ $invoice = $this->getInvoice($apruveInvoiceId);
227
+ $invoiceArray = json_decode($invoice);
228
+ $items = [];
229
+ foreach($invoiceArray['invoice_items'] as $item) {
230
+ $items[] = $item['id'];
231
+ }
232
+ return $items;
233
+ }
234
+
235
+ /**
236
+ * cancel an existing invoice by its ID in apruve
237
+ *
238
+ * @param $id string
239
+ * @return $result string
240
+ */
241
+ public function cancelInvoice($apruveInvoiceId)
242
+ {
243
+ $result = $this->execCurlRequest($this->_getCancelInvoiceUrl($apruveInvoiceId), 'POST');
244
+ return $result;
245
+ }
246
+ }
app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Order.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ */
20
+
21
+ /**
22
+ * Class Apruve_ApruvePayment_Model_Api_Rest_Order
23
+ *
24
+ * Provide rest methods to communicate with apruve
25
+ */
26
+ class Apruve_ApruvePayment_Model_Api_Rest_Order extends Apruve_ApruvePayment_Model_Api_Rest
27
+ {
28
+ /**
29
+ * Get url order url
30
+ * @param string $apruveOrderId
31
+ * @return string
32
+ */
33
+ protected function _getOrderUrl($apruveOrderId)
34
+ {
35
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'orders/' . $apruveOrderId;
36
+ }
37
+
38
+
39
+ /**
40
+ * Get url for update order
41
+ * @param string $apruveOrderId
42
+ * @return string
43
+ */
44
+ protected function _getUpdateOrderUrl($apruveOrderId)
45
+ {
46
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'orders/' . $apruveOrderId;
47
+ }
48
+
49
+ /**
50
+ * Get url for order finalizing
51
+ * @param string $apruveOrderId
52
+ * @return string
53
+ */
54
+ protected function _getFinalizeOrderUrl($apruveOrderId)
55
+ {
56
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'orders/' . $apruveOrderId . '/finalize';
57
+ }
58
+
59
+ /**
60
+ * Get url for order cancel
61
+ * @param string $apruveOrderId
62
+ * @return string
63
+ */
64
+ protected function _getCancelOrderUrl($apruveOrderId)
65
+ {
66
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'orders/' . $apruveOrderId . '/cancel';
67
+ }
68
+
69
+ /**
70
+ * Retrieve an existing order by its ID in apruve
71
+ *
72
+ * @param $id string
73
+ * @return $result string
74
+ */
75
+ public function getOrder($apruveOrderId)
76
+ {
77
+ $result = $this->execCurlRequest($this->_getOrderUrl($apruveOrderId));
78
+ return $result;
79
+ }
80
+
81
+ /**
82
+ * Update Apruve order id to it's corresponding order in magento
83
+ *
84
+ * @param $id string
85
+ * @param $order Mage_Sales_Model_Order
86
+ * @return bool
87
+ * @throws Mage_Core_Exception
88
+ */
89
+ protected function _updateOrderId($apruveOrderId, $order)
90
+ {
91
+ try {
92
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByOrderId($order->getIncrementId());
93
+ $apruveEntity->setApruveId($apruveOrderId);
94
+ $apruveEntity->setMagentoId($order->getIncrementId());
95
+ $apruveEntity->setEntityType('order');
96
+ $apruveEntity->save();
97
+ } catch(Exception $e) {
98
+ Mage::helper('apruvepayment')->logException('Couldn\'t update the order: ' . $e->getMessage());
99
+ Mage::throwException(Mage::helper('apruvepayment')->__('Couldn\'t update order.'));
100
+ }
101
+ return true;
102
+ }
103
+
104
+ /**
105
+ * Update an existing order by its ID in apruve
106
+ *
107
+ * @param string $apruveOrderId
108
+ * @param Mage_Sales_Model_Order $order
109
+ * @return string $result
110
+ */
111
+ public function updateOrder($apruveOrderId, $order)
112
+ {
113
+ $lineItems = [];
114
+ // get discount line item
115
+ if(($discountItem = $this->_getDiscountItem($order))) {
116
+ $lineItems[] = $discountItem;
117
+ }
118
+
119
+ $data = json_encode(array(
120
+ 'order' => array(
121
+ 'merchant_order_id' => $order->getIncrementId(),
122
+ 'amount_cents' => $this->convertPrice($order->getBaseGrandTotal()),
123
+ 'shipping_cents' => $this->convertPrice($order->getBaseShippingAmount()),
124
+ 'tax_cents' => $this->convertPrice($order->getBaseTaxAmount()),
125
+ 'invoice_on_create' => 'false',
126
+ 'order_items' => $lineItems
127
+ )
128
+ ));
129
+
130
+ $curlOptions = [];
131
+ $curlOptions[CURLOPT_POSTFIELDS] = $data;
132
+
133
+ $result = $this->execCurlRequest($this->_getUpdateOrderUrl($apruveOrderId), 'PUT', $curlOptions);
134
+ if($result['success'] == true) {
135
+ Mage::helper('apruvepayment')->logException('Order updated successfully...');
136
+ $this->_updateOrderId($apruveOrderId, $order);
137
+ }
138
+ return $result;
139
+ }
140
+
141
+ /**
142
+ * Get order from quote
143
+ *
144
+ * @param $quote Mage_Sales_Model_Quote
145
+ * @return $order Mage_Sales_Model_Order
146
+ * @throws Mage_Core_Exception
147
+ */
148
+ protected function _getOrderFromQuote($quote)
149
+ {
150
+ $orderIncrementId = $quote->getReservedOrderId();
151
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
152
+ if(!$order->getId()) {
153
+ Mage::throwException(Mage::helper('apruvepayment')->__('Couldn\'t load the order.'));
154
+ }
155
+ return $order;
156
+ }
157
+
158
+ /**
159
+ * Finalize an existing order by its ID in apruve
160
+ *
161
+ * @param $apruveOrderId string
162
+ * @param $order Mage_Sales_Model_Order
163
+ * @return $result string
164
+ */
165
+ public function finalizeOrder($apruveOrderId, $order)
166
+ {
167
+ $result = $this->execCurlRequest($this->_getFinalizeOrderUrl($apruveOrderId), 'POST');
168
+ if($result['success'] == true) {
169
+ $this->_updateOrderId($apruveOrderId, $order);
170
+ Mage::helper('apruvepayment')->logException('Order finalized successfully...');
171
+ }
172
+
173
+ return $result;
174
+ }
175
+
176
+ /**
177
+ * Cancel an existing order by its ID in apruve
178
+ *
179
+ * @param $id string
180
+ * @return $result string
181
+ */
182
+ public function cancelOrder($apruveOrderId)
183
+ {
184
+ $result = $this->execCurlRequest($this->_getCancelOrderUrl($apruveOrderId), 'POST');
185
+ return $result;
186
+ }
187
+ }
app/code/community/Apruve/ApruvePayment/Model/Api/Rest/Shipment.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Class Apruve_ApruvePayment_Model_Api_Rest_Shipment
24
+ *
25
+ * Provide rest methods to communicate with apruve
26
+ */
27
+ class Apruve_ApruvePayment_Model_Api_Rest_Shipment extends Apruve_ApruvePayment_Model_Api_Rest
28
+ {
29
+ /**
30
+ * Get url for shipment create
31
+ * @param string $apruveInvoiceId
32
+ * @return string
33
+ */
34
+ protected function _getCreateShipmentUrl($apruveInvoiceId)
35
+ {
36
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId . '/shipments';
37
+ }
38
+
39
+ /**
40
+ * Get url for shipment retrieve
41
+ * @param string $apruveInvoiceId
42
+ * @param string $apruveShipmentId
43
+ * @return string
44
+ */
45
+ protected function _getShipmentUrl($apruveInvoiceId, $apruveShipmentId)
46
+ {
47
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId . '/shipments/' . $apruveShipmentId;
48
+ }
49
+
50
+ /**
51
+ * Get url for shipment update
52
+ * @param string $apruveInvoiceId
53
+ * @param string $apruveShipmentId
54
+ * @return string
55
+ */
56
+ protected function _getUpdateShipmentUrl($apruveInvoiceId, $apruveShipmentId)
57
+ {
58
+ return $this->getBaseUrl(true) . $this->getApiUrl() . 'invoices/' . $apruveInvoiceId . '/shipments/' . $apruveShipmentId;
59
+ }
60
+
61
+ /**
62
+ * Retrieve an existing shipment by its ID in apruve
63
+ *
64
+ * @param $id string
65
+ * @return $result string
66
+ */
67
+ public function getShipment($apruveInvoiceId, $apruveShipmentId)
68
+ {
69
+ $result = $this->execCurlRequest($this->_getShipmentUrl($apruveInvoiceId, $apruveShipmentId));
70
+ return $result;
71
+ }
72
+
73
+ /**
74
+ * Retrieve the latest comment from magento shipment
75
+ *
76
+ * @param $shipment Mage_Sales_Model_Order_Shipment
77
+ * @return $comment Mage_Sales_Model_Order_Shipment_Comment
78
+ */
79
+ protected function _getShipmentComment($shipment)
80
+ {
81
+ $comment = Mage::getResourceModel('sales/order_shipment_comment_collection')
82
+ ->setShipmentFilter($shipment->getId())
83
+ ->setOrder('created_at', 'DESC')
84
+ ->setPageSize(1)
85
+ ->getFirstItem();
86
+
87
+ return $comment;
88
+ }
89
+
90
+ /**
91
+ * Retrieve the latest tracking info from magento shipment
92
+ *
93
+ * @param $shipment Mage_Sales_Model_Order_Shipment
94
+ * @return $comment Mage_Sales_Model_Order_Shipment_Track
95
+ */
96
+ protected function _getShipmentTrack($shipment)
97
+ {
98
+ $track = Mage::getResourceModel('sales/order_shipment_track_collection')
99
+ ->setShipmentFilter($shipment->getId())
100
+ ->setOrder('updated_at', 'DESC')
101
+ ->setPageSize(1)
102
+ ->getFirstItem();
103
+
104
+ return $track;
105
+ }
106
+
107
+ /**
108
+ * Prepare shipment data for Apruve
109
+ *
110
+ * @param $shipment Mage_Sales_Model_Order_Shipment
111
+ * @param $invoice Mage_Sales_Model_Order_Invoice
112
+ * @return $data []
113
+ */
114
+ protected function _getShipmentData($shipment, $invoice)
115
+ {
116
+ $items = [];
117
+
118
+ foreach ($shipment->getAllItems() as $item) {
119
+ $shipmentItem = [];
120
+ $shipmentItem['price_total_cents'] = $this->convertPrice($item->getPriceInclTax() * $item->getQty());
121
+ $shipmentItem['tax_cents'] = $this->convertPrice($item->getTaxAmount());
122
+ $shipmentItem['description'] = $item->getDescription();
123
+ $shipmentItem['title'] = $item->getName();
124
+ $shipmentItem['sku'] = $item->getSku();
125
+ $shipmentItem['price_ea_cents'] = $this->convertPrice($item->getPrice());
126
+ $shipmentItem['quantity'] = $item->getQty();
127
+ $items[] = $shipmentItem;
128
+ }
129
+
130
+ /* latest shipment comment */
131
+ $comment = $this->_getShipmentComment($shipment);
132
+ /* latest shipment tracking */
133
+ $trackingInfo = $this->_getShipmentTrack($shipment);
134
+ /* prepare invoice data */
135
+ $data = json_encode([
136
+ 'amount_cents' => $this->convertPrice($invoice->getBaseGrandTotal()),
137
+ 'tax_cents' => $this->convertPrice($invoice->getTaxAmount()),
138
+ 'shipping_cents' => $this->convertPrice($invoice->getShippingAmount()),
139
+ 'shipper' => $trackingInfo->getTitle(),
140
+ 'tracking_number' => $trackingInfo->getTrackNumber(),
141
+ 'shipped_at' => $this->getDateFormatted($trackingInfo->getCreatedAt()),
142
+ 'delivered_at' => '',
143
+ 'currency' => $this->getCurrency(),
144
+ 'merchant_notes' => $comment->getComment(),
145
+ 'shipment_items' => $items,
146
+ 'status' => 'FULFILLED'
147
+ ]);
148
+
149
+ return $data;
150
+ }
151
+
152
+ /**
153
+ * Update Apruve shipment id to it's corresponding shipment in magento
154
+ *
155
+ * @param $id string
156
+ * @param $shipment Mage_Sales_Model_Order_Shipment
157
+ * @return bool
158
+ * @throws Exception
159
+ */
160
+ protected function _updateShipmentId($apruveShipmentId, $shipment)
161
+ {
162
+ try {
163
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByShipmentId($shipment->getIncrementId(), 'magento_id');
164
+ $apruveEntity->setApruveId($apruveShipmentId);
165
+ $apruveEntity->setMagentoId($shipment->getIncrementId());
166
+ $apruveEntity->setEntityType('shipping');
167
+ $apruveEntity->save();
168
+ } catch(Exception $e) {
169
+ Mage::helper('apruvepayment')->logException($e->getMessage());
170
+ Mage::throwException(Mage::helper('apruvepayment')->__('Couldn\'t update shipment.'));
171
+ }
172
+ return true;
173
+ }
174
+
175
+ /**
176
+ * Create new shipment in Apruve for an invoice based on shipment created in Magento
177
+ *
178
+ * @param string $apruveInvoiceId
179
+ * @param Mage_Sales_Model_Order_Shipment $shipment
180
+ * @param Mage_Sales_Model_Order_Invoice $invoice
181
+ * @return $result string[]
182
+ */
183
+ public function createShipment($apruveInvoiceId, $shipment, $invoice)
184
+ {
185
+ $data = $this->_getShipmentData($shipment, $invoice);
186
+
187
+ $curlOptions = [];
188
+ $curlOptions[CURLOPT_POSTFIELDS] = $data;
189
+
190
+ $result = $this->execCurlRequest($this->_getCreateShipmentUrl($apruveInvoiceId), 'POST', $curlOptions);
191
+ $apruveShipmentId = isset($result['response']['id']) ? $result['response']['id'] : '';
192
+ if($result['success'] == true) {
193
+ $this->_updateShipmentId($apruveShipmentId, $shipment);
194
+ }
195
+ return $result;
196
+ }
197
+
198
+ /**
199
+ * Create new invoice in Apruve for an order based on invoice created in Magento
200
+ *
201
+ * @param $id string
202
+ * @return $result string
203
+ */
204
+ public function updateShipment($apruveInvoiceId, $apruveShipmentId, $shipment, $invoice)
205
+ {
206
+ $data = $this->_getShipmentData($shipment, $invoice);
207
+
208
+ $curlOptions = [];
209
+ $curlOptions[CURLOPT_POSTFIELDS] = $data;
210
+
211
+ $result = $this->execCurlRequest($this->_getUpdateShipmentUrl($apruveInvoiceId, $apruveShipmentId), 'PUT', $curlOptions);
212
+ return $result;
213
+ }
214
+ }
app/code/community/Apruve/ApruvePayment/Model/Entity.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Model to access apruve object ids stored in magento
24
+ */
25
+ class Apruve_ApruvePayment_Model_Entity extends Mage_Core_Model_Abstract
26
+ {
27
+ protected function _construct()
28
+ {
29
+ $this->_init('apruvepayment/entity');
30
+ }
31
+
32
+ /**
33
+ * Get the order item from apruve_entity table based on order id
34
+ *
35
+ * @param string $id
36
+ * @return Apruve_ApruvePayment_Model_Entity
37
+ */
38
+ public function loadByOrderId($id)
39
+ {
40
+ $itemsData = $this->getCollection()->addFieldToFilter('magento_id', $id)->addFieldToFilter('entity_type', 'order')->setPageSize(1)->getData();
41
+ if(isset($itemsData[0])) {
42
+ $this->setData($itemsData[0]);
43
+ }
44
+ return $this;
45
+ }
46
+
47
+ /**
48
+ * Get the invoice item from apruve_entity table based on invoice id
49
+ *
50
+ * @param string $id
51
+ * @return Apruve_ApruvePayment_Model_Entity
52
+ */
53
+ public function loadByInvoiceId($id)
54
+ {
55
+ $itemsData = $this->getCollection()->addFieldToFilter('magento_id', $id)->addFieldToFilter('entity_type', 'invoice')->setPageSize(1)->getData();
56
+ if(isset($itemsData[0])) {
57
+ $this->setData($itemsData[0]);
58
+ }
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Get the shipment item from apruve_entity table based on shipment id
64
+ *
65
+ * @param string $id
66
+ * @return Apruve_ApruvePayment_Model_Entity
67
+ */
68
+ public function loadByShipmentId($id)
69
+ {
70
+ $itemsData = $this->getCollection()->addFieldToFilter('magento_id', $id)->addFieldToFilter('entity_type', 'shipment')->setPageSize(1)->getData();
71
+ if(isset($itemsData[0])) {
72
+ $this->setData($itemsData[0]);
73
+ }
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * Retrieve only the apruve item ids in an array
79
+ *
80
+ * @return []|bool
81
+ */
82
+ public function getItemIds()
83
+ {
84
+ if($this->getId()) {
85
+ $items = Mage::helper('core')->jsonDecode($this->getApruveItemId());
86
+
87
+ $itemIds = [];
88
+ foreach ($items as $item) {
89
+ $itemIds[] = ['id' => $item['id']];
90
+ }
91
+
92
+ return $itemIds;
93
+ }
94
+ return false;
95
+ }
96
+
97
+ }
app/code/community/Apruve/ApruvePayment/Model/Mode.php CHANGED
@@ -1,32 +1,26 @@
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_Adminhtml
23
- * @copyright Copyright (c) 2014 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
  * Used in creating options for Yes|No config value selection
29
- *
30
  */
31
  class Apruve_ApruvePayment_Model_Mode
32
  {
@@ -57,18 +51,4 @@ class Apruve_ApruvePayment_Model_Mode
57
  2 => Mage::helper('apruvepayment')->__('staging'),
58
  );
59
  }
60
-
61
- /**
62
- * Get options' src urls in "key-value" format
63
- *
64
- * @return array
65
- */
66
- public function toSrcArray()
67
- {
68
- return array(
69
- 0 => "https://app.apruve.com/js/apruve.js?display=compact",
70
- 1 => "https://test.apruve.com/js/apruve.js?display=compact",
71
- );
72
- }
73
-
74
  }
1
  <?php
2
  /**
3
+ * Apruve
4
  *
5
  * NOTICE OF LICENSE
6
  *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
  *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
  *
 
 
 
 
 
 
 
 
20
  */
21
 
22
  /**
23
  * Used in creating options for Yes|No config value selection
 
24
  */
25
  class Apruve_ApruvePayment_Model_Mode
26
  {
51
  2 => Mage::helper('apruvepayment')->__('staging'),
52
  );
53
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
app/code/community/Apruve/ApruvePayment/Model/Mysql4/Setup.php DELETED
@@ -1,6 +0,0 @@
1
- <?php
2
-
3
- class Apruve_ApruvePayment_Model_Mysql4_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
4
- {
5
-
6
- }
 
 
 
 
 
 
app/code/community/Apruve/ApruvePayment/Model/Observer.php CHANGED
@@ -1,24 +1,270 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
3
  class Apruve_ApruvePayment_Model_Observer
4
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- public function finalizePayment($observer)
 
 
 
 
 
 
7
  {
8
- /** @var Mage_Sales_Model_Quote $quote */
9
- $quote = $observer->getQuote();
10
- $payment = $quote->getPayment();
11
- if ($quote->getIsMultiShipping()
12
- && $payment->getMethod() == 'apruvepayment'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ) {
14
- $additionalInformation = $payment->getAdditionalInformation();
15
- $token = $additionalInformation['aprt'];
16
- if ($token) {
17
- /** @var Apruve_ApruvePayment_Model_Api_Rest $apiHelper */
18
- $apiHelper = Mage::getModel('apruvepayment/api_rest');
19
- $apiHelper->finalizePaymentRequest($token);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
 
 
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
1
  <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
 
22
+ /**
23
+ * This is an observer created to be triggered based on Magento's event
24
+ * to update Apruve using Apruve's API calls.
25
+ */
26
  class Apruve_ApruvePayment_Model_Observer
27
  {
28
+ /**
29
+ * Get order and payment objects from observer
30
+ *
31
+ * @param Varien_Event_Observer $observer
32
+ * @return []
33
+ */
34
+ protected function _getOrderInfo($observer)
35
+ {
36
+ $order = null;
37
+ $payment = null;
38
+
39
+ if ($order = $observer->getEvent()->getOrder()) {
40
+ $payment = $order->getPayment();
41
+ } elseif ($orders = $observer->getEvent()->getOrders()) {
42
+ if ($order = array_shift($orders)) {
43
+ $payment = $order->getPayment();
44
+ }
45
+ }
46
+ return array($order, $payment);
47
+ }
48
+
49
+ /**
50
+ * Finalize the order in Apruve
51
+ *
52
+ * @param Varien_Event_Observer $observer
53
+ * @return void
54
+ */
55
+ public function finalizeOrder($observer)
56
+ {
57
+ list($order, $payment) = $this->_getOrderInfo($observer);
58
+
59
+ if ($payment->getMethod() == Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE) {
60
+ try {
61
+ /**
62
+ * @var Apruve_ApruvePayment_Helper_Data $apiVersion
63
+ */
64
+ $apiVersion = Mage::helper('apruvepayment')->getApiVersion();
65
+ $additionalInformation = $payment->getAdditionalInformation();
66
+ $token = $additionalInformation['aprt'];
67
+ if ($token && !$order->getApruveOrderId()) {
68
+ /**
69
+ * @var Apruve_ApruvePayment_Model_Api_Rest_Order $orderApi
70
+ */
71
+ $orderApi = Mage::getModel('apruvepayment/api_rest_order');
72
+ $result = $orderApi->finalizeOrder($token, $order);
73
+ if(!$result || !$result['success']) {
74
+ Mage::throwException($result['message']);
75
+ }
76
+ }
77
+ } catch(Exception $e) {
78
+ Mage::throwException($e->getMessage());
79
+ }
80
+ }
81
+
82
+ }
83
 
84
+ /**
85
+ * Cancel the order in Apruve
86
+ *
87
+ * @param Varien_Event_Observer $observer
88
+ * @return void
89
+ */
90
+ public function cancelOrder($observer)
91
  {
92
+ /**
93
+ * @var Mage_Sales_Model_Order $order
94
+ */
95
+ list($order, $payment) = $this->_getOrderInfo($observer);
96
+
97
+ if ($order->getId() && $payment->getMethod() == Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE) {
98
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByOrderId($order->getIncrementId(), 'magento_id');
99
+ $apruveOrderId = $apruveEntity->getApruveId();
100
+
101
+ /**
102
+ * @var Apruve_ApruvePayment_Model_Api_Rest_Order $orderApi
103
+ */
104
+ $orderApi = Mage::getModel('apruvepayment/api_rest_order');
105
+ $result = $orderApi->cancelOrder($apruveOrderId);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Create invoice in Apruve
111
+ *
112
+ * @param Varien_Event_Observer $observer
113
+ * @return void
114
+ */
115
+ public function createInvoice($observer)
116
+ {
117
+ $invoice = $observer->getEvent()->getInvoice();
118
+
119
+ /**
120
+ * @var Mage_Sales_Model_Order $order
121
+ */
122
+ $order = $invoice->getOrder();
123
+ $payment = $order->getPayment();
124
+
125
+ if ($order->getId() && $invoice->getIncrementId()
126
+ && $payment->getMethod() == Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE
127
  ) {
128
+ /**
129
+ * @var Apruve_ApruvePayment_Model_Api_Rest_Invoice $invoiceApi
130
+ */
131
+ $invoiceApi = Mage::getModel('apruvepayment/api_rest_invoice');
132
+
133
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByInvoiceId($invoice->getIncrementId());
134
+ $apruveInvoiceId = $apruveEntity->getApruveId();
135
+ if($apruveInvoiceId && $invoice->getState() != Mage_Sales_Model_Order_Invoice::STATE_CANCELED) {
136
+ $result = $invoiceApi->updateInvoice($apruveInvoiceId, $invoice);
137
+ } elseif($apruveInvoiceId && $invoice->getState() == Mage_Sales_Model_Order_Invoice::STATE_CANCELED) {
138
+ $result = $invoiceApi->cancelInvoice($apruveInvoiceId);
139
+ } else {
140
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByOrderId($order->getIncrementId());
141
+ $apruveOrderId = $apruveEntity->getApruveId();
142
+ $result = $invoiceApi->createInvoice($apruveOrderId, $invoice);
143
+ }
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Get Apruve Invoice from the shipment for an order in magento
149
+ *
150
+ * @param Mage_Sales_Model_Order_Shipment $shipment
151
+ * @return Mage_Sales_Model_Order_Invoice
152
+ */
153
+ protected function _getInvoiceFromShipment($shipment)
154
+ {
155
+ $order = $shipment->getOrder();
156
+
157
+ $shipmentDetails = [];
158
+ foreach ($shipment->getAllItems() as $item) {
159
+ $shipmentDetails[$item->getSku()] = $item->getQty();
160
+ }
161
+
162
+ $hasInvoices = $order->hasInvoices();
163
+ $invoices = $order->getInvoiceCollection();
164
+
165
+ /* if only one invoice is there then return it's apruve id */
166
+ if($hasInvoices && $invoices->getSize() == 1) {
167
+ return $invoices->getFirstItem();
168
+ } elseif($hasInvoices) {
169
+ /* if order has more invoices we have to select a matching invoice for the shipment */
170
+ $apruveInvoice = '';
171
+ foreach($invoices as $invoice) {
172
+ $items = $invoice->getAllItems();
173
+ $apruveInvoice = $invoice;
174
+ foreach($items as $item) {
175
+ if($item->getQty() != $shipmentDetails[$item->getSku()]) {
176
+ $apruveInvoice = '';
177
+ break;
178
+ }
179
+ }
180
+ if($apruveInvoice) return $apruveInvoice;
181
+ }
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Get the list of items shipped with it's qty
187
+ *
188
+ * @param Mage_Sales_Model_Order_Shipment $shipment
189
+ * @return []
190
+ */
191
+ protected function _getShippedItemQty($shipment)
192
+ {
193
+ $qtys = [];
194
+ foreach($shipment->getAllItems() as $item) {
195
+ $orderItem = $item->getOrderItem();
196
+ $qtys[$orderItem->getId()] = $item->getQty();
197
+ }
198
+ return $qtys;
199
+ }
200
+
201
+ /**
202
+ * Create Magento Invoice from the shipment for an order in magento
203
+ *
204
+ * @param Mage_Sales_Model_Order_Shipment $shipment
205
+ * @return Mage_Sales_Model_Order_Invoice
206
+ */
207
+ protected function _createInvoiceFromShipment($shipment)
208
+ {
209
+ $order = $shipment->getOrder();
210
+ $invoice = Mage::getModel('sales/order_invoice');
211
+ try {
212
+ $itemQty = $this->_getShippedItemQty($shipment);
213
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($itemQty);
214
+ if (!$invoice->getTotalQty()) {
215
+ return $invoice;
216
  }
217
+ $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::NOT_CAPTURE);
218
+ $invoice->register();
219
+
220
+ $invoice->getOrder()->setCustomerNoteNotify(false);
221
+ $invoice->getOrder()->setIsInProcess(true);
222
+
223
+ $transactionSave = Mage::getModel('core/resource_transaction')
224
+ ->addObject($invoice)
225
+ ->addObject($invoice->getOrder());
226
+
227
+ $transactionSave->save();
228
+ } catch (Mage_Core_Exception $e) {
229
+ Mage::helper('apruvepayment')->logException($e->getMessage());
230
+ throw new Exception($e->getMessage(), 1);
231
  }
232
+
233
+ return $invoice;
234
  }
235
 
236
+ /**
237
+ * Create shipment in Apruve
238
+ *
239
+ * @param Varien_Event_Observer $observer
240
+ * @return void
241
+ */
242
+ public function createShipment($observer)
243
+ {
244
+ $shipment = $observer->getEvent()->getShipment();
245
+
246
+ /**
247
+ * @var Mage_Sales_Model_Order $order
248
+ */
249
+ $order = $shipment->getOrder();
250
+ $payment = $order->getPayment();
251
+ if ($order->getId() && $shipment->getIncrementId()
252
+ && $payment->getMethod() == Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE
253
+ ) {
254
+ $invoice = $this->_createInvoiceFromShipment($shipment);
255
+ /**
256
+ * @var Apruve_ApruvePayment_Model_Api_Rest_Shipment $shipmentApi
257
+ */
258
+ $shipmentApi = Mage::getModel('apruvepayment/api_rest_shipment');
259
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByInvoiceId($invoice->getIncrementId(), 'magento_id');
260
+ $apruveInvoiceId = $apruveEntity->getApruveId();
261
+ $apruveEntity = Mage::getModel('apruvepayment/entity')->loadByShipmentId($shipment->getIncrementId(), 'magento_id');
262
+ $apruveShipmentId = $apruveEntity->getApruveId();
263
+ if($apruveShipmentId) {
264
+ $result = $shipmentApi->updateShipment($apruveInvoiceId, $apruveShipmentId, $shipment, $invoice);
265
+ } else {
266
+ $result = $shipmentApi->createShipment($apruveInvoiceId, $shipment, $invoice);
267
+ }
268
+ }
269
+ }
270
  }
app/code/community/Apruve/ApruvePayment/Model/PaymentMethod.php CHANGED
@@ -1,7 +1,6 @@
1
  <?php
2
-
3
  /**
4
- * Magento
5
  *
6
  * NOTICE OF LICENSE
7
  *
@@ -17,17 +16,39 @@
17
  * @package Apruve_Payment
18
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
 
 
 
 
 
20
  */
21
  class Apruve_ApruvePayment_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
22
  {
23
- protected $_code = 'apruvepayment';
24
- protected $_formBlockType = 'apruvepayment/payment_form';
25
 
26
- protected $_canAuthorize = true;
27
- protected $_canCapture = true;
28
- protected $_canVoid = true;
29
- protected $_canUseCheckout = true;
30
- protected $_canCreateBillingAgreement = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  /**
33
  * Assign data to info model instance
@@ -37,7 +58,6 @@ class Apruve_ApruvePayment_Model_PaymentMethod extends Mage_Payment_Model_Method
37
  */
38
  public function assignData($data)
39
  {
40
- //$result = parent::assignData($data);
41
  if (is_array($data)) {
42
  $this->getInfoInstance()->setAdditionalInformation('aprt', isset($data['aprt']) ? $data['aprt'] : null);
43
  } elseif ($data instanceof Varien_Object) {
@@ -50,11 +70,14 @@ class Apruve_ApruvePayment_Model_PaymentMethod extends Mage_Payment_Model_Method
50
  /**
51
  * Check whether apruve payment request id(aprt) is exitst
52
  * @return Mage_Payment_Model_Abstract|void
 
53
  */
54
  public function validate()
55
  {
 
 
56
  if (!$this->getInfoInstance()->getAdditionalInformation('aprt')) {
57
- Mage::throwException('Smth going wrong, try again to post order with apruve');
58
  }
59
  }
60
 
@@ -63,43 +86,87 @@ class Apruve_ApruvePayment_Model_PaymentMethod extends Mage_Payment_Model_Method
63
  * @param Varien_Object $payment
64
  * @param float $amount
65
  * @return Mage_Payment_Model_Abstract|void
 
66
  */
67
  public function authorize(Varien_Object $payment, $amount)
68
  {
 
 
 
69
  $additionalInformation = $payment->getAdditionalInformation();
70
  $token = $additionalInformation['aprt'];
71
- /** @var Apruve_ApruvePayment_Model_Api_Rest $rest */
72
- $rest = Mage::getModel('apruvepayment/api_rest');
73
  /** @var Mage_Sales_Model_Order $order */
74
  $order = $payment->getOrder();
75
 
76
- /** @var Apruve_ApruvePayment_Model_Api_Payment $paymentHelper */
77
- $paymentHelper = Mage::getModel('apruvepayment/api_payment', $order);
78
- /** @var Apruve_ApruvePayment_Model_Api_PaymentRequest $paymentRequestHelper */
79
- $paymentRequestHelper = Mage::getModel('apruvepayment/api_paymentRequest', $order->getQuote());
80
 
81
- $updateResult = $paymentRequestHelper->updatePaymentRequest($token, $order->getIncrementId());
82
- if (!$updateResult) {
83
- Mage::throwException('Couldn\'t update order totals to Apruve');
84
- }
85
- $apruvePayment = $rest->postPayment($token, $paymentHelper->getPayment());
86
- if (!$apruvePayment) {
87
- Mage::throwException('Apruve couldn\'t process order information');
88
  }
89
 
90
- $payment->setTransactionId($token . "_" . $apruvePayment->id)
91
- ->setIsTransactionClosed(0);
92
  return $this;
93
  }
94
 
 
 
 
 
 
 
 
95
  public function capture(Varien_Object $payment, $amount)
96
  {
 
 
 
97
  if ($amount <= 0) {
98
  Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
99
  }
100
 
101
- $payment->setAmount($amount)
102
- ->setTransactionId($payment->getParentTransactionId() . '_capture');
103
  return $this;
104
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
1
  <?php
 
2
  /**
3
+ * Apruve
4
  *
5
  * NOTICE OF LICENSE
6
  *
16
  * @package Apruve_Payment
17
  * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
  * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * This is for providing a new payment gateway (Apruve) for checkout.
24
  */
25
  class Apruve_ApruvePayment_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
26
  {
27
+ const PAYMENT_METHOD_CODE = 'apruvepayment';
 
28
 
29
+ protected $_code = self::PAYMENT_METHOD_CODE;
30
+ protected $_formBlockType = 'apruvepayment/payment_form';
31
+
32
+ protected $_canAuthorize = true;
33
+ protected $_canCapture = true;
34
+ protected $_canVoid = true;
35
+ protected $_canUseInternal = false;
36
+ protected $_canUseCheckout = true;
37
+ protected $_canCreateBillingAgreement = true;
38
+ protected $_isGateway = true;
39
+ protected $_canManageRecurringProfiles = false;
40
+ protected $_canUseForMultishipping = false;
41
+ protected $_canReviewPayment = true;
42
+
43
+ /**
44
+ * Can edit order (renew order)
45
+ *
46
+ * @return bool
47
+ */
48
+ public function canEdit()
49
+ {
50
+ return false;
51
+ }
52
 
53
  /**
54
  * Assign data to info model instance
58
  */
59
  public function assignData($data)
60
  {
 
61
  if (is_array($data)) {
62
  $this->getInfoInstance()->setAdditionalInformation('aprt', isset($data['aprt']) ? $data['aprt'] : null);
63
  } elseif ($data instanceof Varien_Object) {
70
  /**
71
  * Check whether apruve payment request id(aprt) is exitst
72
  * @return Mage_Payment_Model_Abstract|void
73
+ * @throws Mage_Core_Exception
74
  */
75
  public function validate()
76
  {
77
+ parent::validate();
78
+
79
  if (!$this->getInfoInstance()->getAdditionalInformation('aprt')) {
80
+ Mage::throwException('Something is going wrong, try again to post order with apruve.');
81
  }
82
  }
83
 
86
  * @param Varien_Object $payment
87
  * @param float $amount
88
  * @return Mage_Payment_Model_Abstract|void
89
+ * @throws Mage_Core_Exception
90
  */
91
  public function authorize(Varien_Object $payment, $amount)
92
  {
93
+ parent::authorize($payment, $amount);
94
+ Mage::helper('apruvepayment')->logException('Authorize...');
95
+
96
  $additionalInformation = $payment->getAdditionalInformation();
97
  $token = $additionalInformation['aprt'];
98
+
 
99
  /** @var Mage_Sales_Model_Order $order */
100
  $order = $payment->getOrder();
101
 
102
+ /** @var Apruve_ApruvePayment_Helper_Data $apiVersion */
103
+ $apiVersion = Mage::helper('apruvepayment')->getApiVersion();
 
 
104
 
105
+ /** @var Apruve_ApruvePayment_Model_Api_Rest_Order $orderApi */
106
+ $orderApi = Mage::getModel('apruvepayment/api_rest_order');
107
+
108
+ $updateResult = $orderApi->updateOrder($token, $order);
109
+ if (!$updateResult || !$updateResult['success']) {
110
+ Mage::throwException('Couldn\'t update order in Apruve.');
 
111
  }
112
 
 
 
113
  return $this;
114
  }
115
 
116
+ /**
117
+ * Captures a payment
118
+ *
119
+ * @param Varien_Object $payment
120
+ * @return bool
121
+ * @throws Mage_Core_Exception
122
+ */
123
  public function capture(Varien_Object $payment, $amount)
124
  {
125
+ parent::capture($payment, $amount);
126
+ Mage::helper('apruvepayment')->logException('Capture...');
127
+
128
  if ($amount <= 0) {
129
  Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
130
  }
131
 
132
+ $payment->setSkipTransactionCreation(true);
 
133
  return $this;
134
  }
135
+
136
+ /**
137
+ * Check void availability
138
+ *
139
+ * @param Varien_Object $payment
140
+ * @return bool
141
+ */
142
+ public function canVoid(Varien_Object $payment)
143
+ {
144
+ if ($payment instanceof Mage_Sales_Model_Order_Invoice
145
+ || $payment instanceof Mage_Sales_Model_Order_Creditmemo
146
+ ) {
147
+ return false;
148
+ }
149
+ if ($payment->getAmountPaid()) {
150
+ $this->_canVoid = false;
151
+ }
152
+
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * Attempt to void the authorization on cancelling
158
+ *
159
+ * @param Varien_Object $payment
160
+ * @return Apruve_ApruvePayment_Model_PaymentMethod | false
161
+ */
162
+ public function cancel(Varien_Object $payment)
163
+ {
164
+ Mage::helper('apruvepayment')->logException('Cancel...');
165
+
166
+ if (!$payment->getOrder()->getInvoiceCollection()->count()) {
167
+ return $this->void($payment);
168
+ }
169
+
170
+ return false;
171
+ }
172
  }
app/code/community/Apruve/ApruvePayment/Model/Resource/Entity.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Resource Model to access apruve entity id in magento
24
+ */
25
+ class Apruve_ApruvePayment_Model_Resource_Entity extends Mage_Core_Model_Resource_Db_Abstract
26
+ {
27
+ protected function _construct()
28
+ {
29
+ $this->_init('apruvepayment/entity', 'id');
30
+ }
31
+ }
app/code/community/Apruve/ApruvePayment/Model/Resource/Entity/Collection.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Collection to access set of apruve entity ids in magento
24
+ */
25
+ class Apruve_ApruvePayment_Model_Resource_Entity_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
26
+ {
27
+ public function _construct()
28
+ {
29
+ $this->_init('apruvepayment/apruvepayment');
30
+ }
31
+ }
app/code/community/Apruve/ApruvePayment/Model/Sales/Service/Order.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Apruve
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Apache License, Version 2.0
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/Apache-2.0
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@apruve.com so we can send you a copy immediately.
15
+ *
16
+ * @category Apruve
17
+ * @package Apruve_Payment
18
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
19
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
20
+ * @author Echidna Team
21
+ *
22
+ */
23
+
24
+ /**
25
+ * Order submit service model
26
+ * Fix for the Magento version < 1.9.2.0
27
+ */
28
+ class Apruve_ApruvePayment_Model_Sales_Service_Order extends Mage_Sales_Model_Service_Order
29
+ {
30
+ /**
31
+ * Prepare order invoice based on order data and requested items qtys. If $qtys is not empty - the function will
32
+ * prepare only specified items, otherwise all containing in the order.
33
+ *
34
+ * @param array $qtys
35
+ * @return Mage_Sales_Model_Order_Invoice
36
+ */
37
+ public function prepareInvoice($qtys = array())
38
+ {
39
+ if (version_compare(Mage::getVersion(), '1.9.2.0', '<')) {
40
+ $invoice = $this->_convertor->toInvoice($this->_order);
41
+ $totalQty = 0;
42
+ foreach ($this->_order->getAllItems() as $orderItem) {
43
+ $qty = 0;
44
+ if (!$this->_canInvoiceItem($orderItem, array())) {
45
+ continue;
46
+ }
47
+ $item = $this->_convertor->itemToInvoiceItem($orderItem);
48
+ if ($orderItem->isDummy()) {
49
+ $qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1;
50
+ } else if (!empty($qtys)) {
51
+ if (isset($qtys[$orderItem->getId()])) {
52
+ $qty = (float) $qtys[$orderItem->getId()];
53
+ }
54
+ } else {
55
+ $qty = $orderItem->getQtyToInvoice();
56
+ }
57
+ $totalQty += $qty;
58
+ $item->setQty($qty);
59
+ $invoice->addItem($item);
60
+ }
61
+ $invoice->setTotalQty($totalQty);
62
+ $invoice->collectTotals();
63
+ $this->_order->getInvoiceCollection()->addItem($invoice);
64
+ } else {
65
+ $invoice = parent::prepareInvoice($qtys);
66
+ }
67
+
68
+ return $invoice;
69
+ }
70
+ }
app/code/community/Apruve/ApruvePayment/Model/Version.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Apruve
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Apache License, Version 2.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/Apache-2.0
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@apruve.com so we can send you a copy immediately.
14
+ *
15
+ * @category Apruve
16
+ * @package Apruve_Payment
17
+ * @copyright Copyright (coffee) 2014 Apruve, Inc. (http://www.apruve.com).
18
+ * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0
19
+ *
20
+ */
21
+
22
+ /**
23
+ * Used in creating options for Version config value selection
24
+ */
25
+ class Apruve_ApruvePayment_Model_Version
26
+ {
27
+
28
+ /**
29
+ * Options getter
30
+ *
31
+ * @return array
32
+ */
33
+ public function toOptionArray()
34
+ {
35
+ return array(
36
+ /*array('value' => 'v3', 'label'=>Mage::helper('apruvepayment')->__('V3')),*/
37
+ array('value' => 'v4', 'label'=>Mage::helper('apruvepayment')->__('V4')),
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Get options in "key-value" format
43
+ *
44
+ * @return array
45
+ */
46
+ public function toArray()
47
+ {
48
+ return array(
49
+ /*'v3' => Mage::helper('apruvepayment')->__('V3'),*/
50
+ 'v4' => Mage::helper('apruvepayment')->__('V4'),
51
+ );
52
+ }
53
+ }
app/code/community/Apruve/ApruvePayment/controllers/WebhookController.php CHANGED
@@ -23,67 +23,135 @@ class Apruve_ApruvePayment_WebhookController extends Mage_Core_Controller_Front_
23
  {
24
  public function updateOrderStatusAction()
25
  {
26
- $q = $this->_getHashedQueryString();
27
 
28
- if(!isset($_GET[$q])) {
29
- //do nothing
30
  header("HTTP/1.1 404 Not Found");
31
  exit;
32
  }
33
 
 
34
  $input = file_get_contents('php://input');
35
  $data = json_decode($input);
36
 
37
- $status = $data->status;
38
- $paymentRequestId = $data->payment_request_id;
39
- $paymentId = $data->payment_id;
40
- Mage::log($data, null, 'webtex.log');
41
 
42
- //todo: compare status by rest request
43
- if($status == 'rejected') {
44
- if(!$this->_cancelOrder($paymentRequestId, $paymentId)) {
45
- header("HTTP/1.1 404 Not Found");
46
- exit;
47
- };
48
- } elseif($status == 'captured' ) {
49
- if(!$this->_addPayed($paymentRequestId, $paymentId)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  header("HTTP/1.1 404 Not Found");
51
  exit;
52
- };
 
 
53
  }
54
 
55
-
56
  header("HTTP/1.1 200");
57
  exit;
58
  }
59
 
60
-
61
- protected function _addPayed($paymentRequestId, $paymentId)
 
 
 
 
 
62
  {
63
- /** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
64
- $transaction = Mage::getModel('sales/order_payment_transaction')->getCollection()
65
- ->addAttributeToFilter('txn_id', array('eq' => $paymentRequestId . "_" . $paymentId))
66
- ->getFirstItem();
67
- if (!$transaction->getId()) {
68
- /** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
69
- $transaction = Mage::getModel('sales/order_payment_transaction')->getCollection()
70
- ->addAttributeToFilter('txn_id', array('eq' => $paymentRequestId))
71
- ->getFirstItem();
72
- }
73
- if ($transaction->getId()) {
74
- $order = $transaction->getOrder();
75
  /** @var Mage_Sales_Model_Order_Invoice_Api $iApi */
76
  $iApi = Mage::getModel('sales/order_invoice_api');
77
- $invoiceId = $iApi->create($order->getIncrementId(), array());
78
  $iApi->capture($invoiceId);
79
  return true;
80
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
 
 
 
 
 
82
  return false;
83
  }
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- protected function _cancelOrder($paymentRequestId, $paymentId)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  {
88
  /** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
89
  $transaction = Mage::getModel('sales/order_payment_transaction')->getCollection()
@@ -96,27 +164,28 @@ class Apruve_ApruvePayment_WebhookController extends Mage_Core_Controller_Front_
96
  ->getFirstItem();
97
  }
98
  if ($transaction->getId()) {
99
- $payment = $transaction->getOrder()->getPayment();
100
- $transaction->setOrderPaymentObject($payment);
101
- $transaction->setIsClosed(true);
102
- $transaction->save();
103
  $order = $transaction->getOrder();
104
- if($order && $order->getId() && !$order->isCanceled()) {
105
- $order->cancel();
106
- $order->save();
107
- return true;
108
- }
109
  }
 
110
  return false;
111
  }
112
 
113
-
 
 
 
 
114
  protected function _getHashedQueryString()
115
  {
116
  $merchantKey = Mage::getStoreConfig('payment/apruvepayment/merchant');
117
  $apiKey = Mage::getStoreConfig('payment/apruvepayment/api');
118
  $data = $apiKey.$merchantKey;
119
- $q = hash('sha256', $data);
120
- return $q;
121
  }
122
- }
23
  {
24
  public function updateOrderStatusAction()
25
  {
26
+ $hash = $this->_getHashedQueryString();
27
 
28
+ // if the hash doesn't match the data sent by Apruve terminate the code
29
+ if(!isset($_GET[$hash])) {
30
  header("HTTP/1.1 404 Not Found");
31
  exit;
32
  }
33
 
34
+ // if the hash matches the data sent by Apruve move forward with the appropriate process
35
  $input = file_get_contents('php://input');
36
  $data = json_decode($input);
37
 
38
+ Mage::helper('apruvepayment')->logException($data);
39
+ try {
40
+ $event = $data->event;
41
+ $entity = $data->entity;
42
 
43
+ // check the event triggered in Apruve to call appropriate action in Magento
44
+ if($event == 'invoice.closed') {
45
+ $invoiceId = $entity->merchant_invoice_id;
46
+ if(!$this->_capturePayment($invoiceId)) {
47
+ header("HTTP/1.1 404 Not Found");
48
+ exit;
49
+ };
50
+ } elseif($event == 'order.accepted' ) {
51
+ exit; // should not be triggering anything in magento
52
+
53
+ $orderId = $entity->merchant_order_id;
54
+ if(!$this->_changeOrderStatus($orderId)) {
55
+ header("HTTP/1.1 404 Not Found");
56
+ exit;
57
+ };
58
+ } elseif($event == 'order.canceled' ) {
59
+ $orderId = $entity->merchant_order_id;
60
+ if(!$this->_cancelOrder($orderId)) {
61
+ header("HTTP/1.1 404 Not Found");
62
+ exit;
63
+ };
64
+ } elseif($event == 'payment_term.accepted' ) {
65
  header("HTTP/1.1 404 Not Found");
66
  exit;
67
+ }
68
+ } catch(Exception $e) {
69
+ Mage::helper('apruvepayment')->logException('Error for transaction UUID: ' . $data->uuid . '. Message: ' . $e->getMessage());
70
  }
71
 
 
72
  header("HTTP/1.1 200");
73
  exit;
74
  }
75
 
76
+ /**
77
+ * Capture payment based on invoice increment ID
78
+ *
79
+ * @param string $orderId
80
+ * @return bool
81
+ */
82
+ protected function _capturePayment($invoiceId)
83
  {
84
+ if($invoiceId) {
 
 
 
 
 
 
 
 
 
 
 
85
  /** @var Mage_Sales_Model_Order_Invoice_Api $iApi */
86
  $iApi = Mage::getModel('sales/order_invoice_api');
 
87
  $iApi->capture($invoiceId);
88
  return true;
89
  }
90
+ return false;
91
+ }
92
+
93
+ /**
94
+ * Change the order status based on the order increment ID
95
+ *
96
+ * @param string $orderId
97
+ * @return bool
98
+ */
99
+ protected function _changeOrderStatus($orderId)
100
+ {
101
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
102
+ Mage::helper('apruvepayment')->logException($order->getData());
103
+ Mage::helper('apruvepayment')->logException($orderId);
104
 
105
+ if($order && $order->getId() && !$order->isCanceled()) {
106
+ Mage::helper('apruvepayment')->logException('creating invoice...');
107
+ $result = $this->_createInvoice($order->getIncrementId());
108
+ return $result;
109
+ }
110
  return false;
111
  }
112
 
113
+ /**
114
+ * Change the order status based on the order increment ID
115
+ *
116
+ * @param string $orderId
117
+ * @return bool
118
+ */
119
+ protected function _createInvoice($orderId)
120
+ {
121
+ if($orderId) {
122
+ /** @var Mage_Sales_Model_Order_Invoice_Api $iApi */
123
+ $iApi = Mage::getModel('sales/order_invoice_api');
124
+ $invoiceId = $iApi->create($orderId, array());
125
+ return true;
126
+ }
127
+ return false;
128
+ }
129
 
130
+ /**
131
+ * cancel and order in magento based on Order Increment Id
132
+ *
133
+ * @param string $orderId
134
+ * @return bool
135
+ */
136
+ protected function _cancelOrder($orderId)
137
+ {
138
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
139
+ if($order && $order->getId() && !$order->isCanceled()) {
140
+ $order->cancel();
141
+ $order->save();
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+
147
+ /**
148
+ * Order and transaction
149
+ *
150
+ * @param string $paymentRequestId
151
+ * @param string $paymentId
152
+ * @return bool
153
+ */
154
+ protected function _addPayed($paymentRequestId, $paymentId)
155
  {
156
  /** @var Mage_Sales_Model_Order_Payment_Transaction $transaction */
157
  $transaction = Mage::getModel('sales/order_payment_transaction')->getCollection()
164
  ->getFirstItem();
165
  }
166
  if ($transaction->getId()) {
 
 
 
 
167
  $order = $transaction->getOrder();
168
+ /** @var Mage_Sales_Model_Order_Invoice_Api $iApi */
169
+ $iApi = Mage::getModel('sales/order_invoice_api');
170
+ $invoiceId = $iApi->create($order->getIncrementId(), array());
171
+ $iApi->capture($invoiceId);
172
+ return true;
173
  }
174
+
175
  return false;
176
  }
177
 
178
+ /**
179
+ * Get the hashed string id based on Apruve merchant id and API key
180
+ *
181
+ * @return string
182
+ */
183
  protected function _getHashedQueryString()
184
  {
185
  $merchantKey = Mage::getStoreConfig('payment/apruvepayment/merchant');
186
  $apiKey = Mage::getStoreConfig('payment/apruvepayment/api');
187
  $data = $apiKey.$merchantKey;
188
+ $hash = hash('sha256', $data);
189
+ return $hash;
190
  }
191
+ }
app/code/community/Apruve/ApruvePayment/etc/config.xml CHANGED
@@ -1,88 +1,136 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Apruve_ApruvePayment>
5
- <version>1.0.15</version>
6
- </Apruve_ApruvePayment>
7
- </modules>
8
- <frontend>
9
- <routers>
10
- <apruvepayment>
11
- <use>standard</use>
12
- <args>
13
- <module>Apruve_ApruvePayment</module>
14
- <frontName>apruvepayment</frontName>
15
- </args>
16
- </apruvepayment>
17
- </routers>
18
- <events>
19
- <checkout_quote_destroy>
20
- <observers>
21
- <module>
22
- <type>singleton</type>
23
- <class>apruvepayment/observer</class>
24
- <method>finalizePayment</method>
25
- </module>
26
- </observers>
27
- </checkout_quote_destroy>
28
- </events>
29
- <layout>
30
- <updates>
31
- <apruvepayment>
32
- <file>apruvepayment.xml</file>
33
- </apruvepayment>
34
- </updates>
35
- </layout>
36
- </frontend>
37
- <global>
38
- <blocks>
39
- <apruvepayment>
40
- <class>Apruve_ApruvePayment_Block</class>
41
- </apruvepayment>
42
- </blocks>
43
- <models>
44
- <apruvepayment>
45
- <class>Apruve_ApruvePayment_Model</class>
46
- </apruvepayment>
47
- </models>
48
- <resources>
49
- <apruvepayment_setup>
50
- <setup>
51
- <module>Apruve_ApruvePayment</module>
52
- <class>Apruve_ApruvePayment_Model_Mysql4_Setup</class>
53
- </setup>
54
- <connection>
55
- <use>core_setup</use>
56
- </connection>
57
- </apruvepayment_setup>
58
- <apruvepayment_write>
59
- <connection>
60
- <use>core_write</use>
61
- </connection>
62
- </apruvepayment_write>
63
- <apruvepayment_read>
64
- <connection>
65
- <use>core_read</use>
66
- </connection>
67
- </apruvepayment_read>
68
- </resources>
69
- <helpers>
70
- <apruvepayment>
71
- <class>Apruve_ApruvePayment_Helper</class>
72
- </apruvepayment>
73
- </helpers>
74
- </global>
75
- <default>
76
- <payment>
77
- <apruvepayment>
78
- <mode>1</mode>
79
- <autosubmit>1</autosubmit>
80
- <active>1</active>
81
- <model>apruvepayment/paymentMethod</model>
82
- <order_status>pending_payment</order_status>
83
- <title>Pay with Apruve</title>
84
- <payment_action>authorize</payment_action>
85
- </apruvepayment>
86
- </payment>
87
- </default>
88
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Apruve_ApruvePayment>
5
+ <version>2.0.0</version>
6
+ </Apruve_ApruvePayment>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <apruvepayment>
11
+ <class>Apruve_ApruvePayment_Model</class>
12
+ <resourceModel>apruvepayment_resource</resourceModel>
13
+ </apruvepayment>
14
+ <apruvepayment_resource>
15
+ <class>Apruve_ApruvePayment_Model_Resource</class>
16
+ <entities>
17
+ <entity>
18
+ <table>apruve_entity</table>
19
+ </entity>
20
+ </entities>
21
+ </apruvepayment_resource>
22
+ <sales>
23
+ <rewrite>
24
+ <service_order>Apruve_ApruvePayment_Model_Sales_Service_Order</service_order>
25
+ </rewrite>
26
+ </sales>
27
+ </models>
28
+ <resources>
29
+ <apruvepayment_setup>
30
+ <setup>
31
+ <module>Apruve_ApruvePayment</module>
32
+ </setup>
33
+ </apruvepayment_setup>
34
+ <apruvepayment_write>
35
+ <connection>
36
+ <use>core_write</use>
37
+ </connection>
38
+ </apruvepayment_write>
39
+ <apruvepayment_read>
40
+ <connection>
41
+ <use>core_read</use>
42
+ </connection>
43
+ </apruvepayment_read>
44
+ </resources>
45
+ <blocks>
46
+ <apruvepayment>
47
+ <class>Apruve_ApruvePayment_Block</class>
48
+ </apruvepayment>
49
+ <adminhtml>
50
+ <rewrite>
51
+ <sales_order_view>Apruve_ApruvePayment_Block_Adminhtml_Sales_Order_View</sales_order_view>
52
+ </rewrite>
53
+ </adminhtml>
54
+ </blocks>
55
+ <helpers>
56
+ <apruvepayment>
57
+ <class>Apruve_ApruvePayment_Helper</class>
58
+ </apruvepayment>
59
+ </helpers>
60
+ <events>
61
+ <checkout_submit_all_after>
62
+ <observers>
63
+ <apruvepayment>
64
+ <class>apruvepayment/observer</class>
65
+ <method>finalizeOrder</method>
66
+ </apruvepayment>
67
+ </observers>
68
+ </checkout_submit_all_after>
69
+ <order_cancel_after>
70
+ <observers>
71
+ <apruvepayment>
72
+ <class>apruvepayment/observer</class>
73
+ <method>cancelOrder</method>
74
+ </apruvepayment>
75
+ </observers>
76
+ </order_cancel_after>
77
+ <sales_order_invoice_save_after>
78
+ <observers>
79
+ <apruvepayment>
80
+ <class>apruvepayment/observer</class>
81
+ <method>createInvoice</method>
82
+ </apruvepayment>
83
+ </observers>
84
+ </sales_order_invoice_save_after>
85
+ <sales_order_shipment_save_after>
86
+ <observers>
87
+ <apruvepayment>
88
+ <class>apruvepayment/observer</class>
89
+ <method>createShipment</method>
90
+ </apruvepayment>
91
+ </observers>
92
+ </sales_order_shipment_save_after>
93
+ <sales_order_shipment_comment_save_after>
94
+ <observers>
95
+ <apruvepayment>
96
+ <class>apruvepayment/observer</class>
97
+ <method>createShipment</method>
98
+ </apruvepayment>
99
+ </observers>
100
+ </sales_order_shipment_comment_save_after>
101
+ </events>
102
+ </global>
103
+ <frontend>
104
+ <routers>
105
+ <apruvepayment>
106
+ <use>standard</use>
107
+ <args>
108
+ <module>Apruve_ApruvePayment</module>
109
+ <frontName>apruvepayment</frontName>
110
+ </args>
111
+ </apruvepayment>
112
+ </routers>
113
+ <layout>
114
+ <updates>
115
+ <apruvepayment>
116
+ <file>apruvepayment.xml</file>
117
+ </apruvepayment>
118
+ </updates>
119
+ </layout>
120
+ </frontend>
121
+ <default>
122
+ <payment>
123
+ <apruvepayment>
124
+ <mode>1</mode>
125
+ <version>v4</version>
126
+ <autosubmit>1</autosubmit>
127
+ <active>1</active>
128
+ <model>apruvepayment/paymentMethod</model>
129
+ <order_status>pending_payment</order_status>
130
+ <title>Pay with Apruve</title>
131
+ <payment_action>authorize</payment_action>
132
+ <log>0</log>
133
+ </apruvepayment>
134
+ </payment>
135
+ </default>
136
+ </config>
app/code/community/Apruve/ApruvePayment/etc/system.xml CHANGED
@@ -28,6 +28,15 @@
28
  <show_in_website>1</show_in_website>
29
  <show_in_store>0</show_in_store>
30
  </mode>
 
 
 
 
 
 
 
 
 
31
  <autosubmit translate="label">
32
  <label>Jump to next step of checkout when Apruve modal window closes</label>
33
  <comment>disabling this option recommended only in case of compatibility issues</comment>
@@ -88,6 +97,24 @@
88
  <show_in_store>0</show_in_store>
89
  <frontend_class>validate-number</frontend_class>
90
  </sort_order>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  </fields>
92
  </apruvepayment>
93
  </groups>
28
  <show_in_website>1</show_in_website>
29
  <show_in_store>0</show_in_store>
30
  </mode>
31
+ <version translate="label">
32
+ <label>Version</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>apruvepayment/version</source_model>
35
+ <sort_order>2</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </version>
40
  <autosubmit translate="label">
41
  <label>Jump to next step of checkout when Apruve modal window closes</label>
42
  <comment>disabling this option recommended only in case of compatibility issues</comment>
97
  <show_in_store>0</show_in_store>
98
  <frontend_class>validate-number</frontend_class>
99
  </sort_order>
100
+ <product_vendor translate="label">
101
+ <label>Product Vendor Attribute</label>
102
+ <frontend_type>text</frontend_type>
103
+ <sort_order>1000</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>0</show_in_store>
107
+ <comment>Optional: Please enter the product vendor/manufacturer attribute_code</comment>
108
+ </product_vendor>
109
+ <log translate="label">
110
+ <label>Enable Log</label>
111
+ <frontend_type>select</frontend_type>
112
+ <source_model>adminhtml/system_config_source_yesno</source_model>
113
+ <sort_order>1</sort_order>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <show_in_store>0</show_in_store>
117
+ </log>
118
  </fields>
119
  </apruvepayment>
120
  </groups>
app/code/community/Apruve/ApruvePayment/sql/apruvepayment_setup/install-2.0.0.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* create apruvepayment tables */
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $connection = $installer->getConnection();
8
+ $entity_table = $installer->getTable('apruvepayment/entity');
9
+ if(!$connection->isTableExists($entity_table)) {
10
+ $table = $connection->newTable($entity_table)
11
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
12
+ 'identity' => true,
13
+ 'unsigned' => true,
14
+ 'nullable' => false,
15
+ 'primary' => true
16
+ ), 'ID')
17
+ ->addColumn('magento_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
18
+ 'nullable' => false
19
+ ), 'Entity\'s ID in Magento')
20
+ ->addColumn('apruve_id', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
21
+ 'nullable' => false
22
+ ), 'Entity\'s ID in Apruve')
23
+ ->addColumn('apruve_item_id', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
24
+ 'nullable' => false
25
+ ), 'Entity Item ID in Apruve')
26
+ ->addColumn('entity_type', Varien_Db_Ddl_Table::TYPE_TEXT, 10, array(
27
+ 'nullable' => false
28
+ ), 'Entity Type')
29
+ ->addIndex(
30
+ $installer->getIdxName(
31
+ 'apruvepayment/entity',
32
+ array(
33
+ 'magento_id',
34
+ 'apruve_id',
35
+ 'entity_type'
36
+ ),
37
+ Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
38
+ ),
39
+ array(
40
+ 'magento_id',
41
+ 'apruve_id',
42
+ 'entity_type'
43
+ ),
44
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE)
45
+ )
46
+ ->addIndex(
47
+ $installer->getIdxName(
48
+ 'apruvepayment/entity',
49
+ array(
50
+ 'magento_id',
51
+ 'apruve_id',
52
+ 'entity_type'
53
+ )
54
+ ),
55
+ array(
56
+ 'magento_id',
57
+ 'apruve_id',
58
+ 'entity_type'
59
+ )
60
+ );
61
+ $installer->getConnection()->createTable($table);
62
+ }
63
+
64
+ $installer->endSetup();
app/design/frontend/base/default/layout/apruvepayment.xml CHANGED
@@ -1,7 +1,7 @@
1
  <layout version="0.1.0">
2
- <default>
3
  <reference name="head">
4
  <block type="core/template" name="apruve_js" template="apruvepayment/head.phtml" output="toHtml" />
5
  </reference>
6
- </default>
7
  </layout>
1
  <layout version="0.1.0">
2
+ <checkout_onepage_index>
3
  <reference name="head">
4
  <block type="core/template" name="apruve_js" template="apruvepayment/head.phtml" output="toHtml" />
5
  </reference>
6
+ </checkout_onepage_index>
7
  </layout>
app/design/frontend/base/default/template/apruvepayment/payment/form.phtml CHANGED
@@ -19,23 +19,44 @@
19
  */
20
  ?>
21
 
22
- <div id="payment_form_apruvepayment">
23
- Press continue to review order.
24
- <input type="hidden" id="aprt" value="" name="payment[aprt]"/>
25
- </div>
26
-
27
  <?php
28
  $helper = Mage::helper('apruvepayment');
29
- $paymentRequestModel = $helper->getPaymentRequestApiModel();
30
  ?>
31
 
 
 
 
 
32
  <script type="text/javascript">
33
- $('p_method_apruvepayment').up().innerHTML += '<div id="apruveDiv" style="display: inline-block; position: absolute; margin-top: -3px; margin-left: 7px;"></div>';
34
- var sh = '<?php echo $paymentRequestModel->getSecureHash();?>';
35
- var pr = <?php echo $paymentRequestModel->getPaymentRequestJSON();?>;
36
- var shopperName = '<?php echo $paymentRequestModel->getShopperInfo('name');?>';
37
- var shopperEmail = '<?php echo $paymentRequestModel->getShopperInfo('email');?>';
38
  var autoSubmit = '<?php echo $helper->isAutoSubmit();?>';
39
- var oApruvePayment = new ApruvePayment(sh, pr, shopperName, shopperEmail, autoSubmit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  </script>
41
 
19
  */
20
  ?>
21
 
 
 
 
 
 
22
  <?php
23
  $helper = Mage::helper('apruvepayment');
24
+ $paymentApiModel = $helper->getPaymentApiModel();
25
  ?>
26
 
27
+ <div id="payment_form_apruvepayment">
28
+ <input type="hidden" id="aprt" value="" name="payment[aprt]"/>
29
+ </div>
30
+
31
  <script type="text/javascript">
32
+ var sh = '<?php echo $paymentApiModel->getSecureHash();?>';
33
+ var pr = <?php echo $paymentApiModel->getPaymentRequestJSON();?>;
34
+ var shopperName = '<?php echo $paymentApiModel->getShopperInfo('name');?>';
35
+ var shopperEmail = '<?php echo $paymentApiModel->getShopperInfo('email');?>';
 
36
  var autoSubmit = '<?php echo $helper->isAutoSubmit();?>';
37
+ var paymentMethodCode = '<?php echo Apruve_ApruvePayment_Model_PaymentMethod::PAYMENT_METHOD_CODE; ?>';
38
+ document.getElementById("aprt").value = aprt;
39
+
40
+ Payment.prototype.save = Payment.prototype.save.wrap(function(save) {
41
+ var validator = new Validation(this.form);
42
+ if (this.validate() && validator.validate()) {
43
+ // DO WHAT YOU WANT TO DO BEFORE SAVE
44
+ var oApruvePayment = new ApruvePayment(sh, pr, shopperName, shopperEmail, autoSubmit, true);
45
+
46
+ var paymentMethod = '';
47
+ for(i in document.getElementsByName('payment[method]')) {
48
+ if(document.getElementsByName('payment[method]').hasOwnProperty(i) && document.getElementsByName('payment[method]')[i].checked) {
49
+ paymentMethod = document.getElementsByName('payment[method]')[i].value;
50
+ }
51
+ }
52
+ if(paymentMethod == paymentMethodCode && document.getElementById("aprt").value == ''){
53
+ apruve.startCheckout();
54
+ }
55
+ if((paymentMethod == paymentMethodCode && document.getElementById("aprt").value !== '') || paymentMethod !== paymentMethodCode){
56
+ aprt = document.getElementById("aprt").value;
57
+ save(); // THIS WILL CALL CORE SAVE THAT WAS WRAPPED
58
+ }
59
+ }
60
+ });
61
  </script>
62
 
app/etc/modules/Apruve_ApruvePayment.xml CHANGED
@@ -1,3 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <config>
2
  <modules>
3
  <Apruve_ApruvePayment>
@@ -5,4 +32,4 @@
5
  <codePool>community</codePool>
6
  </Apruve_ApruvePayment>
7
  </modules>
8
- </config>
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magento.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magento.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Widget
24
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+ -->
28
  <config>
29
  <modules>
30
  <Apruve_ApruvePayment>
32
  <codePool>community</codePool>
33
  </Apruve_ApruvePayment>
34
  </modules>
35
+ </config>
js/Apruve/ApruvePayment.js CHANGED
@@ -1,7 +1,7 @@
1
  var ApruvePayment = Class.create();
2
 
3
  ApruvePayment.prototype = {
4
- initialize: function (hash, pr, shopperName, shopperEmail, autoSubmit) {
5
  if (!apruve) {
6
  return false;
7
  }
@@ -12,15 +12,21 @@ ApruvePayment.prototype = {
12
  apruve.shopperName = shopperName;
13
  apruve.shopperEmail = shopperEmail;
14
  this.autoSubmit = autoSubmit;
 
15
  this._onLoad();
16
  },
17
 
18
  _onLoad: function () {
19
- if ($('apruveDiv') && !$('apruveBtn') && typeof(apruve) == 'object') {
20
- apruve.loadButton();
21
- this._resetApruveRadio();
22
- this._prepareApruve();
23
  this._registerCallbacks();
 
 
 
 
 
 
 
24
  }
25
  },
26
 
@@ -65,3 +71,5 @@ ApruvePayment.prototype = {
65
  }
66
  }
67
  };
 
 
1
  var ApruvePayment = Class.create();
2
 
3
  ApruvePayment.prototype = {
4
+ initialize: function (hash, pr, shopperName, shopperEmail, autoSubmit, onContinue) {
5
  if (!apruve) {
6
  return false;
7
  }
12
  apruve.shopperName = shopperName;
13
  apruve.shopperEmail = shopperEmail;
14
  this.autoSubmit = autoSubmit;
15
+ this.onContinue = onContinue;
16
  this._onLoad();
17
  },
18
 
19
  _onLoad: function () {
20
+ if(this.onContinue) {
21
+ // initiate callback functions
 
 
22
  this._registerCallbacks();
23
+ } else {
24
+ if ($('apruveDiv') && !$('apruveBtn') && typeof(apruve) == 'object') {
25
+ apruve.loadButton();
26
+ this._resetApruveRadio();
27
+ this._prepareApruve();
28
+ this._registerCallbacks();
29
+ }
30
  }
31
  },
32
 
71
  }
72
  }
73
  };
74
+
75
+ var aprt = '';
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Apruve_B2B_Payment_Gateway</name>
4
- <version>1.0.15</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.apache.org/licenses/LICENSE-2.0">Apache License, 2.0</license>
7
  <channel>community</channel>
@@ -10,9 +10,9 @@
10
  <description>Payments designed for business spending. Increase sales and reduce cart abandonment by allowing your shoppers to send purchases directly to their company or client for payment, simply by using an email address instead of a credit card. Learn more and sign up for a free merchant account at http://www.apruve.com.</description>
11
  <notes>Stable Version</notes>
12
  <authors><author><name>Apruve</name><user>Apruve</user><email>magento@apruve.com</email></author></authors>
13
- <date>2016-10-17</date>
14
- <time>12:40:00</time>
15
- <contents><target name="magecommunity"><dir name="Apruve"><dir name="ApruvePayment"><dir name="Block"><dir name="Admin"><file name="Webhook.php" hash="5a4eb68f48306322a973f1f837f53ac8"/></dir><dir name="Payment"><file name="Form.php" hash="c84481487b8a831fc382d90c76eeb962"/></dir></dir><dir name="Helper"><file name="Data.php" hash="a1f14f2f4383ddd39258fe7b2ad3e1e6"/></dir><file name="LICENSE.txt" hash="9b76dd4b62de4f9840b5d462fcb25e39"/><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="8a047f1bdd062ec61162eb44f02c5d43"/><file name="Payment.php" hash="c4d46501092961d448a8592bb2f82abf"/><file name="PaymentRequest.php" hash="54e5e5246c555f50048f7752133074eb"/><file name="Rest.php" hash="36f1519db699ec5c8d45714cbcf35ecb"/></dir><file name="Mode.php" hash="34de37be8b464530151f85caccefe648"/><dir name="Mysql4"><file name="Setup.php" hash="8b3e5b033dac91b47e59c024e16c04ec"/></dir><file name="Observer.php" hash="aa9a79b176f7f0ac580c3c751bd199dd"/><file name="PaymentMethod.php" hash="d094261d4ad6fcbcca063c8bc78c6845"/></dir><dir name="controllers"><file name="WebhookController.php" hash="185f4757d5d289982f55d551d1b4d5ae"/></dir><dir name="etc"><file name="config.xml" hash="3e18308f336f3a5aa6eef550bb3ff47d"/><file name="system.xml" hash="065fd7d1ced76bb5fb2ba4bcb779efb3"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="apruvepayment.xml" hash="a5f41c280270a5fa44212c9d4cfe043a"/></dir><dir name="template"><dir name="apruvepayment"><file name="head.phtml" hash="36809c6a8fa5aad587b03e2107482bdf"/><dir name="payment"><file name="form.phtml" hash="b5497b735afe4257831b005f7aeba199"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apruve_ApruvePayment.xml" hash="b9d4a9486387dce0b7911d46f1ab81c7"/></dir></target><target name="mage"><dir name="js"><dir name="Apruve"><file name="ApruvePayment.js" hash="5b84bf57eb8ae2bb76d99a4ab6844450"/></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Apruve_B2B_Payment_Gateway</name>
4
+ <version>2.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.apache.org/licenses/LICENSE-2.0">Apache License, 2.0</license>
7
  <channel>community</channel>
10
  <description>Payments designed for business spending. Increase sales and reduce cart abandonment by allowing your shoppers to send purchases directly to their company or client for payment, simply by using an email address instead of a credit card. Learn more and sign up for a free merchant account at http://www.apruve.com.</description>
11
  <notes>Stable Version</notes>
12
  <authors><author><name>Apruve</name><user>Apruve</user><email>magento@apruve.com</email></author></authors>
13
+ <date>2017-01-11</date>
14
+ <time>09:17:07</time>
15
+ <contents><target name="magecommunity"><dir name="Apruve"><dir name="ApruvePayment"><dir name="Block"><dir name="Admin"><file name="Webhook.php" hash="5a4eb68f48306322a973f1f837f53ac8"/></dir><dir name="Adminhtml"><dir name="Sales"><dir name="Order"><file name="View.php" hash="517c950361e27545c3ff841cd7bccae4"/></dir></dir></dir><dir name="Payment"><file name="Form.php" hash="c84481487b8a831fc382d90c76eeb962"/></dir></dir><dir name="Helper"><file name="Data.php" hash="c6d29ea8c507e36eae18d1a3491cb7f1"/></dir><file name="LICENSE.txt" hash="9b76dd4b62de4f9840b5d462fcb25e39"/><dir name="Model"><dir name="Api"><file name="Abstract.php" hash="2b93d9f6f9d686271ab2061fbfa6c09e"/><file name="Payment.php" hash="cdc85003d73cf6b9de6f82e0c163b320"/><dir name="Rest"><file name="Invoice.php" hash="7b2f037c9c30218cc379eb551c6f27cf"/><file name="Order.php" hash="d4b128741165c5a2f982b57d2f33f40e"/><file name="Shipment.php" hash="6a8541fa8b19f5bd9d6617c083c4e308"/></dir><file name="Rest.php" hash="c1071949a8dc1229d85cebae150985b7"/></dir><file name="Entity.php" hash="6652836c17449c86c8a599ea63079258"/><file name="Mode.php" hash="95e5f17903661df50f3dea2849adc1bb"/><file name="Observer.php" hash="7c162dfa058e307b9b299d4ed7581f60"/><file name="PaymentMethod.php" hash="dcabe292295d011244421d26a77fc3b7"/><dir name="Resource"><dir name="Entity"><file name="Collection.php" hash="7a8f8115e87d6deaf6d05501e8160863"/></dir><file name="Entity.php" hash="9a2298e1c979f7ce998f867a81728013"/></dir><dir name="Sales"><dir name="Service"><file name="Order.php" hash="807c36c87883a4f01f4f8f7d86b44415"/></dir></dir><file name="Version.php" hash="5d76f8613344d1dfc278add7c2fa3ebf"/></dir><dir name="controllers"><file name="WebhookController.php" hash="ecb19b3c1ce91deaec7e1debcde691af"/></dir><dir name="etc"><file name="config.xml" hash="39b4a1c67ceb27dba4571706284c211c"/><file name="system.xml" hash="5762459db1687ed91c2d855591227c7f"/></dir><dir name="sql"><dir name="apruvepayment_setup"><file name="install-2.0.0.php" hash="eb0b5b2ab790d8710a00a817c52ef2b1"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="apruvepayment.xml" hash="6ade24fa77f4f55ce0bdf4f5c79fd65c"/></dir><dir name="template"><dir name="apruvepayment"><file name="head.phtml" hash="36809c6a8fa5aad587b03e2107482bdf"/><dir name="payment"><file name="form.phtml" hash="d0bff443c44e35201ced6abffdf7ec8f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Apruve_ApruvePayment.xml" hash="8e20101d5c688c8505302df6d73686fb"/></dir></target><target name="mage"><dir name="js"><dir name="Apruve"><file name="ApruvePayment.js" hash="a9fab0a38c6bc2923106e9925462ef3e"/></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>