Aplazame_Aplazame - Version 0.4.1

Version Notes

* [fixed] Payment method label for narrow boxes

Download this release

Release Info

Developer Aplazame
Extension Aplazame_Aplazame
Version 0.4.1
Comparing to
See all releases


Code changes from version 0.3.3 to 0.4.1

Files changed (52) hide show
  1. app/code/community/Aplazame/Aplazame/Block/AdminHtml/ProductCampaigns.php +1 -11
  2. app/code/community/Aplazame/Aplazame/Block/Checkout/Cart/Widget.php +7 -7
  3. app/code/community/Aplazame/Aplazame/Block/Payment/Form.php +2 -8
  4. app/code/community/Aplazame/Aplazame/Block/Payment/Redirect.php +1 -1
  5. app/code/community/Aplazame/Aplazame/Block/Product/Widget.php +7 -7
  6. app/code/community/Aplazame/Aplazame/Model/Api/Client.php +12 -83
  7. app/code/community/Aplazame/Aplazame/Model/Api/Serializers.php +0 -221
  8. app/code/community/Aplazame/Aplazame/Model/CampaignsObserver.php +2 -3
  9. app/code/community/Aplazame/Aplazame/Model/Observer.php +3 -40
  10. app/code/community/Aplazame/Aplazame/Model/Payment.php +4 -18
  11. app/code/community/Aplazame/Aplazame/controllers/AdminHtml/AplazameController.php +1 -1
  12. app/code/community/Aplazame/Aplazame/controllers/ApiController.php +109 -0
  13. app/code/community/Aplazame/Aplazame/controllers/PaymentController.php +26 -4
  14. app/code/community/Aplazame/Aplazame/etc/config.xml +1 -19
  15. app/code/community/Aplazame/Aplazame/etc/system.xml +1 -1
  16. app/design/adminhtml/default/default/template/aplazame/productCampaigns.phtml +1 -1
  17. app/design/adminhtml/default/default/template/aplazame/productsCampaigns.phtml +1 -1
  18. app/design/frontend/base/default/template/aplazame/checkout/cart/widget.phtml +1 -1
  19. app/design/frontend/base/default/template/aplazame/payment/form.phtml +1 -1
  20. app/design/frontend/base/default/template/aplazame/product/widget.phtml +1 -1
  21. lib/Aplazame/Aplazame.php +0 -4
  22. lib/Aplazame/Aplazame/Api/Article.php +33 -0
  23. lib/Aplazame/Aplazame/Api/BusinessModel/Article.php +22 -0
  24. lib/Aplazame/Aplazame/Api/BusinessModel/HistoricalOrder.php +26 -0
  25. lib/Aplazame/Aplazame/Api/Order.php +38 -0
  26. lib/Aplazame/Aplazame/BusinessModel/Address.php +21 -0
  27. lib/Aplazame/Aplazame/BusinessModel/Article.php +40 -0
  28. lib/Aplazame/Aplazame/BusinessModel/Checkout.php +33 -0
  29. lib/Aplazame/Aplazame/BusinessModel/Customer.php +67 -0
  30. lib/Aplazame/Aplazame/BusinessModel/Order.php +22 -0
  31. lib/Aplazame/Aplazame/BusinessModel/ShippingInfo.php +32 -0
  32. lib/Aplazame/Aplazame/Http/ZendClient.php +36 -0
  33. lib/Aplazame/Aplazame/Util.php +0 -26
  34. lib/Aplazame/Sdk/Api/ApiClientException.php +74 -0
  35. lib/Aplazame/Sdk/Api/ApiCommunicationException.php +17 -0
  36. lib/Aplazame/Sdk/Api/ApiRequest.php +73 -0
  37. lib/Aplazame/Sdk/Api/ApiServerException.php +74 -0
  38. lib/Aplazame/Sdk/Api/AplazameExceptionInterface.php +8 -0
  39. lib/Aplazame/Sdk/Api/Client.php +201 -0
  40. lib/Aplazame/Sdk/Api/DeserializeException.php +8 -0
  41. lib/Aplazame/Sdk/Http/ClientInterface.php +13 -0
  42. lib/Aplazame/Sdk/Http/CurlClient.php +50 -0
  43. lib/Aplazame/Sdk/Http/Request.php +58 -0
  44. lib/Aplazame/Sdk/Http/RequestInterface.php +54 -0
  45. lib/Aplazame/Sdk/Http/Response.php +112 -0
  46. lib/Aplazame/Sdk/Http/ResponseInterface.php +40 -0
  47. lib/Aplazame/Sdk/Serializer/Date.php +47 -0
  48. lib/Aplazame/Sdk/Serializer/Decimal.php +38 -0
  49. lib/Aplazame/Sdk/Serializer/JsonSerializable.php +13 -0
  50. lib/Aplazame/Sdk/Serializer/JsonSerializer.php +43 -0
  51. lib/Aplazame/Sdk/json_polyfill.php +22 -0
  52. package.xml +6 -5
app/code/community/Aplazame/Aplazame/Block/AdminHtml/ProductCampaigns.php CHANGED
@@ -24,17 +24,7 @@ class Aplazame_Aplazame_Block_AdminHtml_ProductCampaigns extends Mage_Adminhtml_
24
  /** @var Mage_Catalog_Model_Product $product */
25
  $product = $products->load($articleId);
26
 
27
- $article = array(
28
- "id" => $product->getId(),
29
- "name" => $product->getName(),
30
- "description" => substr($product->getDescription(), 0, 255),
31
- "url" => $product->getProductUrl(),
32
- );
33
- if (isset($product->_data['media_gallery']['images'][0]['file'])) {
34
- $article["image_url"] = $product->getMediaConfig()->getMediaUrl($product->_data['media_gallery']['images'][0]['file']);
35
- }
36
-
37
- $articles[] = $article;
38
  }
39
 
40
  return $articles;
24
  /** @var Mage_Catalog_Model_Product $product */
25
  $product = $products->load($articleId);
26
 
27
+ $articles[] = Aplazame_Aplazame_Api_BusinessModel_Article::createFromProduct($product);
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
  return $articles;
app/code/community/Aplazame/Aplazame/Block/Checkout/Cart/Widget.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php
2
 
3
- require_once Mage::getBaseDir('lib').DS.'Aplazame'.DS.'Aplazame.php';
4
-
5
  class Aplazame_Aplazame_Block_Checkout_Cart_Widget Extends Mage_Core_Block_Template
6
  {
7
  /**
@@ -25,17 +23,19 @@ class Aplazame_Aplazame_Block_Checkout_Cart_Widget Extends Mage_Core_Block_Templ
25
  }
26
 
27
  /**
28
- * Devuelve el final price del producto, formateado para Aplazame
29
- * @return int
30
  */
31
  public function getTotal()
32
  {
33
  if($this->getQuote() instanceof Mage_Sales_Model_Quote)
34
  {
35
- return Aplazame_Util::formatDecimals($this->getQuote()->getBaseGrandTotal());
 
 
36
  }
37
 
38
- return Aplazame_Util::formatDecimals(0);
39
  }
40
 
41
  /**
@@ -53,4 +53,4 @@ class Aplazame_Aplazame_Block_Checkout_Cart_Widget Extends Mage_Core_Block_Templ
53
  return '';
54
  }
55
 
56
- }
1
  <?php
2
 
 
 
3
  class Aplazame_Aplazame_Block_Checkout_Cart_Widget Extends Mage_Core_Block_Template
4
  {
5
  /**
23
  }
24
 
25
  /**
26
+ * Devuelve el final price del producto
27
+ * @return float
28
  */
29
  public function getTotal()
30
  {
31
  if($this->getQuote() instanceof Mage_Sales_Model_Quote)
32
  {
33
+ $total = $this->getQuote()->getBaseGrandTotal();
34
+ } else {
35
+ $total = 0;
36
  }
37
 
38
+ return $total;
39
  }
40
 
41
  /**
53
  return '';
54
  }
55
 
56
+ }
app/code/community/Aplazame/Aplazame/Block/Payment/Form.php CHANGED
@@ -1,8 +1,5 @@
1
  <?php
2
 
3
- require_once Mage::getBaseDir('lib').DS.'Aplazame'.DS.'Aplazame.php';
4
-
5
-
6
  class Aplazame_Aplazame_Block_Payment_Form extends Mage_Payment_Block_Form
7
  {
8
  protected function _construct()
@@ -16,17 +13,14 @@ class Aplazame_Aplazame_Block_Payment_Form extends Mage_Payment_Block_Form
16
  {
17
  $this->setMethodTitle("");
18
 
19
- $logoSrc = 'https://aplazame.com/static/img/buttons/' . Mage::getStoreConfig('payment/aplazame/button_img') . '.png';
20
- $html = '<img src="' . $logoSrc . '" height="27" class="v-middle" />&nbsp;';
21
- $html.= 'Financia tu compa con Aplazame';
22
 
23
  $this->setMethodLabelAfterHtml($html);
24
  }
25
 
26
  public function getTotal()
27
  {
28
- return Aplazame_Util::formatDecimals(
29
- $this->getMethod()->getCheckout()->getQuote()->getGrandTotal());
30
  }
31
 
32
  /**
1
  <?php
2
 
 
 
 
3
  class Aplazame_Aplazame_Block_Payment_Form extends Mage_Payment_Block_Form
4
  {
5
  protected function _construct()
13
  {
14
  $this->setMethodTitle("");
15
 
16
+ $html = 'Financialo con Aplazame';
 
 
17
 
18
  $this->setMethodLabelAfterHtml($html);
19
  }
20
 
21
  public function getTotal()
22
  {
23
+ return $this->getMethod()->getCheckout()->getQuote()->getGrandTotal();
 
24
  }
25
 
26
  /**
app/code/community/Aplazame/Aplazame/Block/Payment/Redirect.php CHANGED
@@ -26,7 +26,7 @@ class Aplazame_Aplazame_Block_Payment_Redirect extends Mage_Core_Block_Abstract
26
  </script>
27
 
28
  <script>
29
- aplazame.checkout(' . json_encode($payment->getCheckoutSerializer()) . ');
30
  </script>
31
 
32
  <iframe src="'./*Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)*/Mage::getUrl('', array('_secure'=>true)).'" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden;">
26
  </script>
27
 
28
  <script>
29
+ aplazame.checkout(' . json_encode(Aplazame_Sdk_Serializer_JsonSerializer::serializeValue($payment->getCheckoutSerializer())) . ');
30
  </script>
31
 
32
  <iframe src="'./*Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)*/Mage::getUrl('', array('_secure'=>true)).'" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden;">
app/code/community/Aplazame/Aplazame/Block/Product/Widget.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php
2
 
3
- require_once Mage::getBaseDir('lib').DS.'Aplazame'.DS.'Aplazame.php';
4
-
5
  class Aplazame_Aplazame_Block_Product_Widget Extends Mage_Core_Block_Template
6
  {
7
  /**
@@ -25,17 +23,19 @@ class Aplazame_Aplazame_Block_Product_Widget Extends Mage_Core_Block_Template
25
  }
26
 
27
  /**
28
- * Devuelve el final price del producto, formateado para Aplazame
29
- * @return int
30
  */
31
  public function getFinalPrice()
32
  {
33
  if($this->getProduct() instanceof Mage_Catalog_Model_Product)
34
  {
35
- return Aplazame_Util::formatDecimals($this->getProduct()->getFinalPrice());
 
 
36
  }
37
 
38
- return Aplazame_Util::formatDecimals(0);
39
  }
40
 
41
  /**
@@ -54,4 +54,4 @@ class Aplazame_Aplazame_Block_Product_Widget Extends Mage_Core_Block_Template
54
 
55
  return '';
56
  }
57
- }
1
  <?php
2
 
 
 
3
  class Aplazame_Aplazame_Block_Product_Widget Extends Mage_Core_Block_Template
4
  {
5
  /**
23
  }
24
 
25
  /**
26
+ * Devuelve el final price del producto
27
+ * @return float
28
  */
29
  public function getFinalPrice()
30
  {
31
  if($this->getProduct() instanceof Mage_Catalog_Model_Product)
32
  {
33
+ $total = $this->getProduct()->getFinalPrice();
34
+ } else {
35
+ $total = 0;
36
  }
37
 
38
+ return $total;
39
  }
40
 
41
  /**
54
 
55
  return '';
56
  }
57
+ }
app/code/community/Aplazame/Aplazame/Model/Api/Client.php CHANGED
@@ -1,77 +1,20 @@
1
  <?php
2
 
3
- /**
4
- * @method $this setOrder(Mage_Sales_Model_Resource_Order $order)
5
- * @method Mage_Sales_Model_Resource_Order getOrder()
6
- */
7
  class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
8
  {
9
  /**
10
- * @var string
11
  */
12
- public $apiBaseUri;
13
 
14
  public function __construct()
15
  {
16
- $this->apiBaseUri = getenv('APLAZAME_API_BASE_URI') ? getenv('APLAZAME_API_BASE_URI') : 'https://api.aplazame.com';
17
- }
18
-
19
- public function request($method, $path, $data=null)
20
- {
21
- $url = $this->apiBaseUri. $path;
22
- $client = new Zend_Http_Client($url);
23
-
24
- if (in_array($method, array(
25
- Zend_Http_Client::POST, Zend_Http_Client::PUT, 'PATCH')) && $data) {
26
- $client->setHeaders('Content-type: application/json');
27
- $client->setRawData(json_encode($data), 'application/json');
28
- }
29
-
30
- $client->setHeaders('Authorization: Bearer '.
31
- Mage::getStoreConfig('payment/aplazame/secret_api_key'));
32
-
33
- $versions = array(
34
- 'PHP/' . PHP_VERSION,
35
- 'Magento/' . Mage::getVersion(),
36
- 'AplazameMagento/' . Mage::getConfig()->getModuleConfig('Aplazame_Aplazame')->version,
37
  );
38
-
39
- $client->setHeaders('User-Agent: '. implode(', ', $versions));
40
-
41
- $client->setHeaders('Accept: '. 'application/vnd.aplazame.'.
42
- (Mage::getStoreConfig('payment/aplazame/sandbox')?'sandbox.': '') . 'v1+json');
43
-
44
- $response = $client->request($method);
45
- $raw_result = $response->getBody();
46
- $status_code = $response->getStatus();
47
-
48
- if ($status_code >= 500) {
49
- Mage::throwException(Mage::helper('aplazame')->__(
50
- 'Aplazame error code: ' . $status_code));
51
- }
52
-
53
- try {
54
- $ret_json = Zend_Json::decode($raw_result, Zend_Json::TYPE_ARRAY);
55
- } catch (Zend_Json_Exception $e) {
56
- Mage::throwException(Mage::helper('aplazame')->__(
57
- 'Invalid api response: '. $raw_result));
58
- }
59
-
60
- if ($status_code >= 400) {
61
- $errorMsg = Mage::helper('aplazame')->__('Aplazame error code ' . $status_code . ': '
62
- . $ret_json['error']['message']);
63
-
64
- if ($status_code == 403) {
65
- //no tiramos exception, pero informamos de error
66
- Mage::getSingleton('adminhtml/session')->addError($errorMsg);
67
- }
68
-
69
- //para los demás errores mayores de 400 menos el 403
70
- //tiramos exception.
71
- Mage::throwException($errorMsg);
72
- }
73
-
74
- return $ret_json;
75
  }
76
 
77
  /**
@@ -80,21 +23,7 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
80
  */
81
  public function authorize($orderId)
82
  {
83
- return $this->request(Varien_Http_Client::POST, '/orders/' . $orderId . "/authorize");
84
- }
85
-
86
- /**
87
- * @param Mage_Sales_Model_Order $order
88
- * @return array
89
- */
90
- public function updateOrder($order)
91
- {
92
- /** @var Aplazame_Aplazame_Model_Api_Serializers $serializer */
93
- $serializer = Mage::getModel('aplazame/api_serializers');
94
- $data = $serializer->getOrderUpdate($order);
95
-
96
- return $this->request(
97
- 'PATCH', $this->getEndpointForOrder($order), $data);
98
  }
99
 
100
  /**
@@ -103,7 +32,7 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
103
  */
104
  public function cancelOrder($order)
105
  {
106
- return $this->request(
107
  Varien_Http_Client::POST, $this->getEndpointForOrder($order) . "/cancel");
108
  }
109
 
@@ -114,9 +43,9 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
114
  */
115
  public function refundAmount($order, $amount)
116
  {
117
- $data = array('amount'=>Aplazame_Util::formatDecimals($amount));
118
 
119
- return $this->request(
120
  Varien_Http_Client::POST, $this->getEndpointForOrder($order) . "/refund", $data);
121
  }
122
 
@@ -126,6 +55,6 @@ class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
126
  */
127
  protected function getEndpointForOrder($order)
128
  {
129
- return '/orders/' . (int)$order->getIncrementId();
130
  }
131
  }
1
  <?php
2
 
 
 
 
 
3
  class Aplazame_Aplazame_Model_Api_Client extends Varien_Object
4
  {
5
  /**
6
+ * @var Aplazame_Sdk_Api_Client
7
  */
8
+ public $apiClient;
9
 
10
  public function __construct()
11
  {
12
+ $this->apiClient = new Aplazame_Sdk_Api_Client(
13
+ getenv('APLAZAME_API_BASE_URI') ? getenv('APLAZAME_API_BASE_URI') : 'https://api.aplazame.com',
14
+ (Mage::getStoreConfig('payment/aplazame/sandbox') ? Aplazame_Sdk_Api_Client::ENVIRONMENT_SANDBOX : Aplazame_Sdk_Api_Client::ENVIRONMENT_PRODUCTION),
15
+ Mage::getStoreConfig('payment/aplazame/secret_api_key'),
16
+ new Aplazame_Aplazame_Http_ZendClient()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
 
20
  /**
23
  */
24
  public function authorize($orderId)
25
  {
26
+ return $this->apiClient->request(Varien_Http_Client::POST, '/orders/' . $orderId . "/authorize");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
 
29
  /**
32
  */
33
  public function cancelOrder($order)
34
  {
35
+ return $this->apiClient->request(
36
  Varien_Http_Client::POST, $this->getEndpointForOrder($order) . "/cancel");
37
  }
38
 
43
  */
44
  public function refundAmount($order, $amount)
45
  {
46
+ $data = array('amount'=>Aplazame_Sdk_Serializer_Decimal::fromFloat($amount)->jsonSerialize());
47
 
48
+ return $this->apiClient->request(
49
  Varien_Http_Client::POST, $this->getEndpointForOrder($order) . "/refund", $data);
50
  }
51
 
55
  */
56
  protected function getEndpointForOrder($order)
57
  {
58
+ return '/orders/' . $order->getIncrementId();
59
  }
60
  }
app/code/community/Aplazame/Aplazame/Model/Api/Serializers.php DELETED
@@ -1,221 +0,0 @@
1
- <?php
2
-
3
- require_once Mage::getBaseDir('lib').DS.'Aplazame'.DS.'Aplazame.php';
4
-
5
-
6
- class Aplazame_Aplazame_Model_Api_Serializers extends Varien_Object
7
- {
8
- private static function formatDecimals($price)
9
- {
10
- return Aplazame_Util::formatDecimals($price);
11
- }
12
-
13
- private static function _getMetadata()
14
- {
15
- return array(
16
- "module" => array(
17
- "name" => "aplazame:magento",
18
- "version" => Mage::getVersion()
19
- ),
20
- "version" => Mage::getConfig()->getModuleConfig('Aplazame_Aplazame')->version
21
- );
22
- }
23
-
24
- /**
25
- * @param Mage_Sales_Model_Order_Address $addr
26
- * @return array
27
- */
28
- protected function _getAddr($addr)
29
- {
30
- return array(
31
- "first_name"=> $addr->getFirstname(),
32
- "last_name"=> $addr->getLastname(),
33
- "phone"=> $addr->getTelephone(),
34
- "alt_phone"=> $addr->getAltTelephone(),
35
- "street" => $addr->getStreet(1),
36
- "address_addition" => $addr->getStreet(2),
37
- "city" => $addr->getCity(),
38
- "state" => $addr->getRegion(),
39
- "country" => $addr->getCountryModel()->getIso2Code(),
40
- "postcode" => $addr->getPostcode());
41
- }
42
-
43
- /**
44
- * @param Mage_Sales_Model_Order $order
45
- * @return array
46
- */
47
- protected function getCustomer($order)
48
- {
49
- /** @var Mage_Customer_Model_Customer $customer */
50
- $customer = Mage::getSingleton('customer/session')->getCustomer();
51
- $logCustomer = Mage::getModel('log/customer')->load($customer->getId());
52
- $customer_serializer = array("gender"=>0);
53
-
54
- if ($customer->getId()) {
55
- $customer_serializer = array_merge($customer_serializer, array(
56
- "id"=>$customer->getId(),
57
- "type"=>"e",
58
- "email"=>$customer->getEmail(),
59
- "first_name"=>$customer->getFirstname(),
60
- "last_name"=>$customer->getLastname(),
61
- "date_joined"=>date(DATE_ISO8601, $customer->getCreatedAtTimestamp()),
62
- "last_login"=>date(DATE_ISO8601, $logCustomer->getLoginAtTimestamp())));
63
- } else {
64
- $customer_serializer = array_merge($customer_serializer, array(
65
- "type"=>"g",
66
- "email"=>$order->getCustomerEmail(),
67
- "first_name"=>$order->getCustomerFirstname(),
68
- "last_name"=>$order->getCustomerLastname()));
69
- }
70
-
71
- return $customer_serializer;
72
- }
73
-
74
- /**
75
- * @param Mage_Sales_Model_Order $order
76
- * @return array
77
- */
78
- protected function getShipping($order)
79
- {
80
- $shipping = null;
81
- $shipping_address = $order->getShippingAddress();
82
-
83
- if ($shipping_address) {
84
- $shipping = array_merge($this->_getAddr($shipping_address), array(
85
- "price"=> self::formatDecimals($order->getShippingAmount()),
86
- "name"=>$order->getShippingMethod()
87
- ));
88
-
89
- if ($order->getShippingAmount() > 0) {
90
- $shipping["tax_rate"] = 100 * $order->getShippingTaxAmount() / $order->getShippingAmount();
91
- }
92
- }
93
-
94
- return $shipping;
95
- }
96
-
97
- private function getProductTaxRate($product)
98
- {
99
- $store = Mage::app()->getStore();
100
- $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store);
101
- $taxclassid = $product->getData('tax_class_id');
102
- return Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid));
103
- }
104
-
105
- /**
106
- * @param Mage_Sales_Model_Order $order
107
- * @return array
108
- */
109
- protected function getArticles($order)
110
- {
111
- $articles = array();
112
-
113
- /** @var Mage_Sales_Model_Order_Item $order_item */
114
- foreach ($order->getAllVisibleItems() as $order_item) {
115
- $productId = $order_item->getProductId();
116
- /** @var Mage_Catalog_Model_Product $product */
117
- $product = Mage::getModel('catalog/product')->load($productId);
118
- $discounts = $product->getPrice() - $product->getFinalPrice();
119
-
120
- $articles[] = array(
121
- "id" => $productId,
122
- "sku" => $order_item->getSku(),
123
- "name" => $order_item->getName(),
124
- "description" => substr($product->getDescription(), 0, 255),
125
- "url" =>$product->getProductUrl(),
126
- "image_url" => $product->getImageUrl(),
127
- "quantity" => intval($order_item->getQtyOrdered()),
128
- "price" => self::formatDecimals($order_item->getPrice() + $discounts),
129
- "tax_rate" => self::formatDecimals($this->getProductTaxRate($product)),
130
- "discount" => self::formatDecimals($discounts));
131
- }
132
-
133
- return $articles;
134
- }
135
-
136
- /**
137
- * @param Mage_Sales_Model_Order $order
138
- * @return array
139
- */
140
- protected function getRenderOrder($order)
141
- {
142
- $discounts = $order->getDiscountAmount();
143
-
144
- if (is_null($discounts)) {
145
- $discounts = 0;
146
- }
147
-
148
- return array(
149
- "id"=>$order->getIncrementId(),
150
- "articles"=>$this->getArticles($order),
151
- "currency"=>$order->getOrderCurrencyCode(),
152
- "tax_amount"=>self::formatDecimals($order->getTaxAmount()),
153
- "total_amount"=>self::formatDecimals($order->getTotalDue()),
154
- "discount"=>-self::formatDecimals($discounts));
155
- }
156
-
157
- /**
158
- * @param Mage_Sales_Model_Order $order
159
- * @return array
160
- */
161
- public function getHistory($order)
162
- {
163
- /** @var Mage_Sales_Model_Order[] $history_collection */
164
- $history_collection = Mage::getModel('sales/order')
165
- ->getCollection()
166
- ->addAttributeToFilter('customer_id', array('like'=>$order->getCustomerId()));
167
-
168
- $history = array();
169
- foreach ($history_collection as $order_history) {
170
- $history[] = array(
171
- "id"=>$order_history->getIncrementId(),
172
- "amount"=>self::formatDecimals($order_history->getGrandTotal()),
173
- "due"=>self::formatDecimals($order_history->getTotalDue()),
174
- "status"=>$order_history->getStatus(),
175
- "type"=>$order_history->getPayment()->getMethodInstance()->getCode(),
176
- "order_date"=>date(DATE_ISO8601, strtotime($order_history->getCreatedAt())),
177
- "currency"=>$order_history->getOrderCurrencyCode(),
178
- "billing"=>$this->_getAddr($order_history->getBillingAddress()),
179
- "shipping"=>$this->getShipping($order_history));
180
- }
181
-
182
- return $history;
183
- }
184
-
185
- /**
186
- * @param Mage_Sales_Model_Order $order
187
- * @return array
188
- */
189
- public function getOrderUpdate($order)
190
- {
191
- return array(
192
- "order"=>$this->getRenderOrder($order),
193
- "billing"=>$this->_getAddr($order->getBillingAddress()),
194
- "shipping"=>$this->getShipping($order),
195
- "meta"=>self::_getMetadata());
196
- }
197
-
198
- /**
199
- * @param Mage_Sales_Model_Order $order
200
- * @return array
201
- */
202
- public function getCheckout($order)
203
- {
204
- $info = $this->getInfoInstance();
205
-
206
- $merchant = array(
207
- "confirmation_url"=>Mage::getUrl("aplazame/payment/confirm", array('_secure'=>true)),
208
- "cancel_url"=>Mage::getUrl('aplazame/payment/cancel', array('_secure'=>true)) . '?status=error',
209
- "checkout_url"=>Mage::getUrl('aplazame/payment/cancel', array('_secure'=>true)),
210
- "success_url"=>Mage::getUrl('checkout/onepage/success', array('_secure'=>true)));
211
-
212
- return array(
213
- "toc"=>true,
214
- "merchant"=>$merchant,
215
- "customer"=>$this->getCustomer($order),
216
- "order"=>$this->getRenderOrder($order),
217
- "billing"=>$this->_getAddr($order->getBillingAddress()),
218
- "shipping"=>$this->getShipping($order),
219
- "meta"=>self::_getMetadata());
220
- }
221
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Aplazame/Aplazame/Model/CampaignsObserver.php CHANGED
@@ -57,7 +57,7 @@ class Aplazame_Aplazame_Model_CampaignsObserver extends Mage_Core_Model_Abstract
57
  /** @var Mage_Adminhtml_Model_Url $adminUrl */
58
  $adminUrl = Mage::getModel('adminhtml/url');
59
 
60
- $block->addTabAfter(
61
  'aplazameCampaigns',
62
  array(
63
  'label' => $helper->__('Aplazame Campaigns'),
@@ -66,8 +66,7 @@ class Aplazame_Aplazame_Model_CampaignsObserver extends Mage_Core_Model_Abstract
66
  array('id' => $product->getId())
67
  ),
68
  'class' => 'ajax',
69
- ),
70
- 'categories'
71
  );
72
  }
73
 
57
  /** @var Mage_Adminhtml_Model_Url $adminUrl */
58
  $adminUrl = Mage::getModel('adminhtml/url');
59
 
60
+ $block->addTab(
61
  'aplazameCampaigns',
62
  array(
63
  'label' => $helper->__('Aplazame Campaigns'),
66
  array('id' => $product->getId())
67
  ),
68
  'class' => 'ajax',
69
+ )
 
70
  );
71
  }
72
 
app/code/community/Aplazame/Aplazame/Model/Observer.php CHANGED
@@ -12,48 +12,11 @@ class Aplazame_Aplazame_Model_Observer extends Mage_Core_Model_Abstract
12
  $code = Aplazame_Aplazame_Model_Payment::METHOD_CODE;
13
 
14
  /** @var Mage_Sales_Model_Order $parentOrder */
15
- $parentOrder = Mage::getModel('sales/order')->loadByIncrementId(
16
- (int)$order->getIncrementId());
17
 
18
  return ($code == $parentOrder->getPayment()->getMethod());
19
  }
20
 
21
- /**
22
- * Method for updating the order status after completing a purchase
23
- */
24
- public function salesOrderPlaceAfter($observer)
25
- {
26
- /** @var Mage_Sales_Model_Order|null $order */
27
- $order = $observer->getOrder();
28
-
29
- if (!isset($order)) {
30
- return $this;
31
- }
32
-
33
- $payment = $order->getPayment();
34
- if (!$payment) {
35
- return $this;
36
- }
37
-
38
- if (!$this->is_aplazame_payment($order)) {
39
- return $this;
40
- }
41
-
42
- /** @var Aplazame_Aplazame_Model_Api_Client $client */
43
- $client = Mage::getModel('aplazame/api_client');
44
- $client->updateOrder($order);
45
-
46
- return $this;
47
- }
48
-
49
- /**
50
- * Method after load order edition
51
- */
52
- public function salesOrderLoadAfter($observer)
53
- {
54
- return $this;
55
- }
56
-
57
  /**
58
  * Method used for canceling a Aplazame invoice when a Magento order is canceled
59
  *
@@ -84,8 +47,8 @@ class Aplazame_Aplazame_Model_Observer extends Mage_Core_Model_Abstract
84
  $client = Mage::getModel('aplazame/api_client');
85
  try {
86
  $client->cancelOrder($order);
87
- } catch (Mage_Core_Exception $e) {
88
- if ($e->getMessage() === 'Aplazame error code 404: Not found') {
89
  return $this;
90
  }
91
 
12
  $code = Aplazame_Aplazame_Model_Payment::METHOD_CODE;
13
 
14
  /** @var Mage_Sales_Model_Order $parentOrder */
15
+ $parentOrder = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
 
16
 
17
  return ($code == $parentOrder->getPayment()->getMethod());
18
  }
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  /**
21
  * Method used for canceling a Aplazame invoice when a Magento order is canceled
22
  *
47
  $client = Mage::getModel('aplazame/api_client');
48
  try {
49
  $client->cancelOrder($order);
50
+ } catch (Aplazame_Sdk_Api_ApiClientException $e) {
51
+ if ($e->getStatusCode() == 404) {
52
  return $this;
53
  }
54
 
app/code/community/Aplazame/Aplazame/Model/Payment.php CHANGED
@@ -1,9 +1,5 @@
1
  <?php
2
 
3
-
4
- require_once Mage::getBaseDir('lib').DS.'Aplazame'.DS.'Aplazame.php';
5
-
6
-
7
  class Aplazame_Aplazame_Model_Payment extends Mage_Payment_Model_Method_Abstract
8
  {
9
  const METHOD_CODE = 'aplazame';
@@ -18,6 +14,8 @@ class Aplazame_Aplazame_Model_Payment extends Mage_Payment_Model_Method_Abstract
18
  protected $_isInitializeNeeded = true;
19
  protected $_canUseInternal = false;
20
  protected $_canUseForMultishipping = false;
 
 
21
 
22
 
23
  public function initialize($paymentAction, $stateObject)
@@ -113,7 +111,7 @@ class Aplazame_Aplazame_Model_Payment extends Mage_Payment_Model_Method_Abstract
113
  Mage::throwException(Mage::helper('aplazame')->__('Aplazame charge id not returned from call.'));
114
  }
115
 
116
- $this->_validate_amount_result(Aplazame_Util::formatDecimals($amount), $result);
117
  $payment->setTransactionId($this->getChargeId())->setIsTransactionClosed(0);
118
  return $this;
119
  }
@@ -159,25 +157,13 @@ class Aplazame_Aplazame_Model_Payment extends Mage_Payment_Model_Method_Abstract
159
  return $this;
160
  }
161
 
162
- public function processHistory($order, $checkout_token)
163
- {
164
- /** @var Aplazame_Aplazame_Model_Api_Serializers $serializer */
165
- $serializer = Mage::getModel('aplazame/api_serializers');
166
-
167
- $result = $serializer->getHistory($order);
168
-
169
- return json_encode($result);
170
- }
171
-
172
  public function getCheckoutSerializer()
173
  {
174
  $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
175
 
176
  /** @var Mage_Sales_Model_Order $order */
177
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
178
- /** @var Aplazame_Aplazame_Model_Api_Serializers $serializer */
179
- $serializer = Mage::getModel('aplazame/api_serializers');
180
 
181
- return $serializer->getCheckout($order);
182
  }
183
  }
1
  <?php
2
 
 
 
 
 
3
  class Aplazame_Aplazame_Model_Payment extends Mage_Payment_Model_Method_Abstract
4
  {
5
  const METHOD_CODE = 'aplazame';
14
  protected $_isInitializeNeeded = true;
15
  protected $_canUseInternal = false;
16
  protected $_canUseForMultishipping = false;
17
+ /** @var Aplazame_Aplazame_Model_Config Config */
18
+ private $_config;
19
 
20
 
21
  public function initialize($paymentAction, $stateObject)
111
  Mage::throwException(Mage::helper('aplazame')->__('Aplazame charge id not returned from call.'));
112
  }
113
 
114
+ $this->_validate_amount_result(Aplazame_Sdk_Serializer_Decimal::fromFloat($amount)->jsonSerialize(), $result);
115
  $payment->setTransactionId($this->getChargeId())->setIsTransactionClosed(0);
116
  return $this;
117
  }
157
  return $this;
158
  }
159
 
 
 
 
 
 
 
 
 
 
 
160
  public function getCheckoutSerializer()
161
  {
162
  $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
163
 
164
  /** @var Mage_Sales_Model_Order $order */
165
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
 
 
166
 
167
+ return Aplazame_Aplazame_BusinessModel_Checkout::createFromOrder($order);
168
  }
169
  }
app/code/community/Aplazame/Aplazame/controllers/AdminHtml/AplazameController.php CHANGED
@@ -18,7 +18,7 @@ class Aplazame_Aplazame_AdminHtml_AplazameController extends Mage_Adminhtml_Cont
18
 
19
  $data = json_decode($request->getParam('data'));
20
 
21
- $response = $this->aplazameClient->request(
22
  $request->getParam('method'),
23
  $request->getParam('path'),
24
  $data
18
 
19
  $data = json_decode($request->getParam('data'));
20
 
21
+ $response = $this->aplazameClient->apiClient->request(
22
  $request->getParam('method'),
23
  $request->getParam('path'),
24
  $data
app/code/community/Aplazame/Aplazame/controllers/ApiController.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_ApiController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public static function forbidden()
6
+ {
7
+ return array(
8
+ 'status_code' => 403,
9
+ 'payload' => array(
10
+ 'status' => 403,
11
+ 'type' => 'FORBIDDEN',
12
+ ),
13
+ );
14
+ }
15
+
16
+ public static function not_found()
17
+ {
18
+ return array(
19
+ 'status_code' => 404,
20
+ 'payload' => array(
21
+ 'status' => 404,
22
+ 'type' => 'NOT_FOUND',
23
+ ),
24
+ );
25
+ }
26
+
27
+ public static function collection($page, $page_size, array $elements)
28
+ {
29
+ return array(
30
+ 'status_code' => 200,
31
+ 'payload' => array(
32
+ 'query' => array(
33
+ 'page' => $page,
34
+ 'page_size' => $page_size,
35
+ ),
36
+ 'elements' => $elements,
37
+ ),
38
+ );
39
+ }
40
+
41
+ public function indexAction()
42
+ {
43
+ $request = $this->getRequest();
44
+ $path = $request->getParam('path', '');
45
+ $pathArguments = json_decode($request->getParam('path_arguments', '[]'), true);
46
+ $queryArguments = json_decode($request->getParam('query_arguments', '[]'), true);
47
+
48
+ $result = $this->route($path, $pathArguments, $queryArguments);
49
+
50
+ $response = $this->getResponse();
51
+ $response->setHttpResponseCode($result['status_code']);
52
+ $response->setHeader('Content-type', 'application/json');
53
+ $response->setBody(json_encode(Aplazame_Sdk_Serializer_JsonSerializer::serializeValue($result['payload'])));
54
+ }
55
+
56
+ /**
57
+ * @param string $path
58
+ * @param array $pathArguments
59
+ * @param array $queryArguments
60
+ *
61
+ * @return array
62
+ */
63
+ public function route($path, array $pathArguments, array $queryArguments)
64
+ {
65
+ if (!$this->verifyAuthentication()) {
66
+ return self::forbidden();
67
+ }
68
+
69
+ switch ($path) {
70
+ case '/article/':
71
+ $controller = new Aplazame_Aplazame_Api_Article(Mage::getModel('catalog/product'));
72
+
73
+ return $controller->articles($queryArguments);
74
+ case '/order/{order_id}/history/':
75
+ $controller = new Aplazame_Aplazame_Api_Order(Mage::getModel('sales/order'));
76
+
77
+ return $controller->history($pathArguments, $queryArguments);
78
+ default:
79
+ return self::not_found();
80
+ }
81
+ }
82
+
83
+ /**
84
+ * @return bool
85
+ */
86
+ private function verifyAuthentication()
87
+ {
88
+ $privateKey = Mage::getStoreConfig('payment/aplazame/secret_api_key');
89
+
90
+ $authorization = $this->getHeaderAuthorization();
91
+ if (!$authorization || empty($privateKey)) {
92
+ return false;
93
+ }
94
+
95
+ return ($authorization === $privateKey);
96
+ }
97
+
98
+ private function getHeaderAuthorization()
99
+ {
100
+ $request = $this->getRequest();
101
+
102
+ $header = $request->getHeader('authorization');
103
+ if (!$header) {
104
+ return false;
105
+ }
106
+
107
+ return trim(str_replace('Bearer', '', $header));
108
+ }
109
+ }
app/code/community/Aplazame/Aplazame/controllers/PaymentController.php CHANGED
@@ -56,7 +56,12 @@ class Aplazame_Aplazame_PaymentController extends Mage_Core_Controller_Front_Act
56
  if ($session->getLastRealOrderId()) {
57
  /** @var Mage_Sales_Model_Order $order */
58
  $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
59
- $order->getPayment()->getMethodInstance()->processConfirmOrder($order, $checkout_token);
 
 
 
 
 
60
 
61
  // TODO: add a boolean configuration option
62
  $order->sendNewOrderEmail();
@@ -67,6 +72,11 @@ class Aplazame_Aplazame_PaymentController extends Mage_Core_Controller_Front_Act
67
  }
68
 
69
  public function cancelAction()
 
 
 
 
 
70
  {
71
  $session = $this->_getCheckoutSession();
72
  $orderId = $session->getLastRealOrderId();
@@ -75,7 +85,9 @@ class Aplazame_Aplazame_PaymentController extends Mage_Core_Controller_Front_Act
75
  /** @var Mage_Sales_Model_Order $order */
76
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
77
  if ($order->getId() && $order->getState() === Mage_Sales_Model_Order::STATE_NEW) {
78
- Mage::helper('aplazame/cart')->resuscitateCartFromOrder($order, $this);
 
 
79
  }
80
  }
81
 
@@ -93,6 +105,10 @@ class Aplazame_Aplazame_PaymentController extends Mage_Core_Controller_Front_Act
93
  /** @var Mage_Sales_Model_Order $order */
94
  $order = Mage::getModel('sales/order')->loadByIncrementId($checkout_token);
95
  $payment = $order->getPayment()->getMethodInstance();
 
 
 
 
96
  $code = Aplazame_Aplazame_Model_Payment::METHOD_CODE;
97
 
98
  if (!$payment or $code !== $payment->getCode()) {
@@ -103,9 +119,15 @@ class Aplazame_Aplazame_PaymentController extends Mage_Core_Controller_Front_Act
103
  Mage::throwException($this->__('You don\'t have permissions.'));
104
  }
105
 
106
- $result = $payment->processHistory($order, $checkout_token);
 
 
 
 
 
 
107
 
108
  $this->getResponse()->setHeader('Content-type', 'application/json');
109
- $this->getResponse()->setBody($result);
110
  }
111
  }
56
  if ($session->getLastRealOrderId()) {
57
  /** @var Mage_Sales_Model_Order $order */
58
  $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
59
+ $payment = $order->getPayment()->getMethodInstance();
60
+ if (!$payment instanceof Aplazame_Aplazame_Model_Payment) {
61
+ Mage::throwException($this->__('Unexpected payment method.'));
62
+ }
63
+
64
+ $payment->processConfirmOrder($order, $checkout_token);
65
 
66
  // TODO: add a boolean configuration option
67
  $order->sendNewOrderEmail();
72
  }
73
 
74
  public function cancelAction()
75
+ {
76
+ $this->_redirectUrl(Mage::getUrl('aplazame/payment/cart'));
77
+ }
78
+
79
+ public function cartAction()
80
  {
81
  $session = $this->_getCheckoutSession();
82
  $orderId = $session->getLastRealOrderId();
85
  /** @var Mage_Sales_Model_Order $order */
86
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
87
  if ($order->getId() && $order->getState() === Mage_Sales_Model_Order::STATE_NEW) {
88
+ /** @var Aplazame_Aplazame_Helper_Cart $cart */
89
+ $cart = Mage::helper('aplazame/cart');
90
+ $cart->resuscitateCartFromOrder($order, $this);
91
  }
92
  }
93
 
105
  /** @var Mage_Sales_Model_Order $order */
106
  $order = Mage::getModel('sales/order')->loadByIncrementId($checkout_token);
107
  $payment = $order->getPayment()->getMethodInstance();
108
+ if (!$payment instanceof Aplazame_Aplazame_Model_Payment) {
109
+ Mage::throwException($this->__('Unexpected payment method.'));
110
+ }
111
+
112
  $code = Aplazame_Aplazame_Model_Payment::METHOD_CODE;
113
 
114
  if (!$payment or $code !== $payment->getCode()) {
119
  Mage::throwException($this->__('You don\'t have permissions.'));
120
  }
121
 
122
+ /** @var Mage_Sales_Model_Order[] $history_collection */
123
+ $history_collection = Mage::getModel('sales/order')
124
+ ->getCollection()
125
+ ->addAttributeToFilter('customer_id', array('like'=> $order->getCustomerId()))
126
+ ;
127
+
128
+ $historyOrders = array_map(array('Aplazame_Aplazame_Api_BusinessModel_HistoricalOrder', 'createFromOrder'), $history_collection);
129
 
130
  $this->getResponse()->setHeader('Content-type', 'application/json');
131
+ $this->getResponse()->setBody(json_encode(Aplazame_Sdk_Serializer_JsonSerializer::serializeValue($historyOrders)));
132
  }
133
  }
app/code/community/Aplazame/Aplazame/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Aplazame_Aplazame>
5
- <version>0.3.2</version>
6
  </Aplazame_Aplazame>
7
  </modules>
8
  <global>
@@ -59,24 +59,6 @@
59
  </modules>
60
  </translate>
61
  <events>
62
- <sales_order_place_after>
63
- <observers>
64
- <Aplazame>
65
- <type>singleton</type>
66
- <class>aplazame/observer</class>
67
- <method>salesOrderPlaceAfter</method>
68
- </Aplazame>
69
- </observers>
70
- </sales_order_place_after>
71
- <sales_order_load_after>
72
- <observers>
73
- <Aplazame>
74
- <type>singleton</type>
75
- <class>aplazame/observer</class>
76
- <method>salesOrderLoadAfter</method>
77
- </Aplazame>
78
- </observers>
79
- </sales_order_load_after>
80
  <order_cancel_after>
81
  <observers>
82
  <Aplazame>
2
  <config>
3
  <modules>
4
  <Aplazame_Aplazame>
5
+ <version>0.4.0</version>
6
  </Aplazame_Aplazame>
7
  </modules>
8
  <global>
59
  </modules>
60
  </translate>
61
  <events>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  <order_cancel_after>
63
  <observers>
64
  <Aplazame>
app/code/community/Aplazame/Aplazame/etc/system.xml CHANGED
@@ -32,7 +32,7 @@
32
  </sandbox>
33
  <secret_api_key translate="label">
34
  <label>Private API Key</label>
35
- <frontend_type>obscure</frontend_type>
36
  <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
37
  <sort_order>30</sort_order>
38
  <show_in_default>1</show_in_default>
32
  </sandbox>
33
  <secret_api_key translate="label">
34
  <label>Private API Key</label>
35
+ <frontend_type>text</frontend_type>
36
  <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
37
  <sort_order>30</sort_order>
38
  <show_in_default>1</show_in_default>
app/design/adminhtml/default/default/template/aplazame/productCampaigns.phtml CHANGED
@@ -27,7 +27,7 @@
27
  var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
28
  var campaignsContainer = document.getElementById("aplazame_campaigns_container");
29
 
30
- var articles = <?php echo json_encode($this->getArticles()) ?>;
31
 
32
  function associateArticlesToCampaign(articles, campaignId) {
33
  apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
27
  var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
28
  var campaignsContainer = document.getElementById("aplazame_campaigns_container");
29
 
30
+ var articles = <?php echo json_encode(Aplazame_Sdk_Serializer_JsonSerializer::serializeValue($this->getArticles())) ?>;
31
 
32
  function associateArticlesToCampaign(articles, campaignId) {
33
  apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
app/design/adminhtml/default/default/template/aplazame/productsCampaigns.phtml CHANGED
@@ -35,7 +35,7 @@
35
  var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
36
  var campaignsContainer = document.getElementById("aplazame_campaigns_container");
37
 
38
- var articles = <?php echo json_encode($this->getArticles()) ?>;
39
 
40
  function associateArticlesToCampaign(articles, campaignId) {
41
  apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
35
  var apiProxyEndpoint = "<?php echo $this->getUrl('adminhtml/aplazame/proxy') ?>";
36
  var campaignsContainer = document.getElementById("aplazame_campaigns_container");
37
 
38
+ var articles = <?php echo json_encode(Aplazame_Sdk_Serializer_JsonSerializer::serializeValue($this->getArticles())) ?>;
39
 
40
  function associateArticlesToCampaign(articles, campaignId) {
41
  apiRequest("POST", "/me/campaigns/" + campaignId + "/articles", articles, function() {});
app/design/frontend/base/default/template/aplazame/checkout/cart/widget.phtml CHANGED
@@ -1,5 +1,5 @@
1
  <div
2
  data-aplazame-simulator=""
3
  data-view="cart"
4
- data-amount="<?php echo $this->getTotal(); ?>">
5
  </div>
1
  <div
2
  data-aplazame-simulator=""
3
  data-view="cart"
4
+ data-amount="<?php echo Aplazame_Sdk_Serializer_Decimal::fromFloat($this->getTotal())->jsonSerialize(); ?>">
5
  </div>
app/design/frontend/base/default/template/aplazame/payment/form.phtml CHANGED
@@ -15,7 +15,7 @@
15
  <script>
16
  aplazame.button({
17
  selector: "<?php echo Mage::getStoreConfig('payment/aplazame/button') ?>",
18
- amount: <?php echo $this->getTotal() ?>,
19
  currency: "EUR",
20
  country: "<?php echo $this->getCountry(); ?>"
21
  });
15
  <script>
16
  aplazame.button({
17
  selector: "<?php echo Mage::getStoreConfig('payment/aplazame/button') ?>",
18
+ amount: <?php echo Aplazame_Sdk_Serializer_Decimal::fromFloat($this->getTotal())->jsonSerialize() ?>,
19
  currency: "EUR",
20
  country: "<?php echo $this->getCountry(); ?>"
21
  });
app/design/frontend/base/default/template/aplazame/product/widget.phtml CHANGED
@@ -1,5 +1,5 @@
1
  <div
2
  data-aplazame-simulator=""
3
  data-view="product"
4
- data-amount="<?php echo $this->getFinalPrice(); ?>">
5
  </div>
1
  <div
2
  data-aplazame-simulator=""
3
  data-view="product"
4
+ data-amount="<?php echo Aplazame_Sdk_Serializer_Decimal::fromFloat($this->getFinalPrice())->jsonSerialize(); ?>">
5
  </div>
lib/Aplazame/Aplazame.php DELETED
@@ -1,4 +0,0 @@
1
- <?php
2
-
3
- // Utilities
4
- require(dirname(__FILE__) . '/Aplazame/Util.php');
 
 
 
 
lib/Aplazame/Aplazame/Api/Article.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ final class Aplazame_Aplazame_Api_Article
4
+ {
5
+ /** @var Mage_Catalog_Model_Product */
6
+ private $productModel;
7
+
8
+ public function __construct(Mage_Catalog_Model_Product $productModel)
9
+ {
10
+ $this->productModel = $productModel;
11
+ }
12
+
13
+ public function articles(array $queryArguments)
14
+ {
15
+ $page = (isset($queryArguments['page'])) ? $queryArguments['page'] : 1;
16
+ $page_size = (isset($queryArguments['page_size'])) ? $queryArguments['page_size'] : 10;
17
+
18
+ /** @var Mage_Catalog_Model_Resource_Product_Collection|Mage_Catalog_Model_Product[] $products */
19
+ $products = $this->productModel
20
+ ->getCollection()
21
+ ->addAttributeToSelect(array(
22
+ 'name',
23
+ 'description'
24
+ ))
25
+ ->addAttributeToFilter('visibility', array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds()))
26
+ ->setPage($page, $page_size)
27
+ ;
28
+
29
+ $articles = array_map(array('Aplazame_Aplazame_Api_BusinessModel_Article', 'createFromProduct'), $products);
30
+
31
+ return Aplazame_Aplazame_ApiController::collection($page, $page_size, $articles);
32
+ }
33
+ }
lib/Aplazame/Aplazame/Api/BusinessModel/Article.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_Api_BusinessModel_Article
4
+ {
5
+ /**
6
+ * @param Mage_Catalog_Model_Product $product
7
+ *
8
+ * @return array
9
+ */
10
+ public static function createFromProduct(Mage_Catalog_Model_Product $product)
11
+ {
12
+ $article = array(
13
+ 'id' => $product->getId(),
14
+ 'name' => $product->getName(),
15
+ 'description' => substr($product->getDescription(), 0, 255),
16
+ 'url' => $product->getProductUrl(),
17
+ 'image_url' => $product->getImageUrl(),
18
+ );
19
+
20
+ return $article;
21
+ }
22
+ }
lib/Aplazame/Aplazame/Api/BusinessModel/HistoricalOrder.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_Api_BusinessModel_HistoricalOrder
4
+ {
5
+ /**
6
+ * @param Mage_Sales_Model_Order $order
7
+ *
8
+ * @return array
9
+ */
10
+ public static function createFromOrder(Mage_Sales_Model_Order $order)
11
+ {
12
+ $serialized = array(
13
+ 'id' => $order->getIncrementId(),
14
+ 'amount' => Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getGrandTotal()),
15
+ 'due' => Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getTotalDue()),
16
+ 'status' => $order->getStatus(),
17
+ 'type' => $order->getPayment()->getMethodInstance()->getCode(),
18
+ 'order_date' => date(DATE_ISO8601, strtotime($order->getCreatedAt())),
19
+ 'currency' => $order->getOrderCurrencyCode(),
20
+ 'billing' => Aplazame_Aplazame_BusinessModel_Address::createFromAddress($order->getBillingAddress()),
21
+ 'shipping' => Aplazame_Aplazame_BusinessModel_ShippingInfo::createFromOrder($order),
22
+ );
23
+
24
+ return $serialized;
25
+ }
26
+ }
lib/Aplazame/Aplazame/Api/Order.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ final class Aplazame_Aplazame_Api_Order
4
+ {
5
+ /** @var Mage_Sales_Model_Order */
6
+ private $orderModel;
7
+
8
+ public function __construct(Mage_Sales_Model_Order $orderModel)
9
+ {
10
+ $this->orderModel = $orderModel;
11
+ }
12
+
13
+ public function history(array $params, array $queryArguments)
14
+ {
15
+ if (!isset($params['order_id'])) {
16
+ return Aplazame_Aplazame_ApiController::not_found();
17
+ }
18
+
19
+ $order = $this->orderModel->loadByIncrementId($params['order_id']);
20
+ if (!$order->getId()) {
21
+ return Aplazame_Aplazame_ApiController::not_found();
22
+ }
23
+
24
+ $page = (isset($queryArguments['page'])) ? $queryArguments['page'] : 1;
25
+ $page_size = (isset($queryArguments['page_size'])) ? $queryArguments['page_size'] : 10;
26
+
27
+ /** @var Mage_Sales_Model_Order[] $history_collection */
28
+ $orders = $this->orderModel
29
+ ->getCollection()
30
+ ->addAttributeToFilter('customer_id', array('like'=>$order->getCustomerId()))
31
+ ->setPage($page, $page_size)
32
+ ;
33
+
34
+ $historyOrders = array_map(array('Aplazame_Aplazame_Api_BusinessModel_HistoricalOrder', 'createFromOrder'), $orders);
35
+
36
+ return Aplazame_Aplazame_ApiController::collection($page, $page_size, $historyOrders);
37
+ }
38
+ }
lib/Aplazame/Aplazame/BusinessModel/Address.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_BusinessModel_Address
4
+ {
5
+ public static function createFromAddress(Mage_Sales_Model_Order_Address $address)
6
+ {
7
+ $aAddress = new self();
8
+ $aAddress->first_name = $address->getFirstname();
9
+ $aAddress->last_name = $address->getLastname();
10
+ $aAddress->street = $address->getStreet(1);
11
+ $aAddress->city = $address->getCity();
12
+ $aAddress->state = $address->getRegion();
13
+ $aAddress->country = $address->getCountryModel()->getIso2Code();
14
+ $aAddress->postcode = $address->getPostcode();
15
+ $aAddress->phone = $address->getTelephone();
16
+ $aAddress->alt_phone = $address->getAltTelephone();
17
+ $aAddress->address_addition = $address->getStreet(2);
18
+
19
+ return $aAddress;
20
+ }
21
+ }
lib/Aplazame/Aplazame/BusinessModel/Article.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Article.
5
+ */
6
+ class Aplazame_Aplazame_BusinessModel_Article
7
+ {
8
+ public static function crateFromOrderItem(Mage_Sales_Model_Order_Item $orderItem)
9
+ {
10
+ $productId = $orderItem->getProductId();
11
+ /** @var Mage_Catalog_Model_Product $product */
12
+ $product = Mage::getModel('catalog/product')->load($productId);
13
+ $discounts = $product->getPrice() - $product->getFinalPrice();
14
+
15
+ $aArticle = new self();
16
+ $aArticle->id = $productId;
17
+ $aArticle->name = $orderItem->getName();
18
+ $aArticle->url = $product->getProductUrl();
19
+ $aArticle->image_url = $product->getImageUrl();
20
+ $aArticle->quantity = intval($orderItem->getQtyOrdered());
21
+ $aArticle->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($orderItem->getPrice() + $discounts);
22
+ $aArticle->description = substr($product->getDescription(), 0, 255);
23
+ $aArticle->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(self::getProductTaxRate($product));
24
+ $aArticle->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($discounts);
25
+
26
+ return $aArticle;
27
+ }
28
+
29
+ private static function getProductTaxRate(Mage_Catalog_Model_Product $product)
30
+ {
31
+ /** @var Mage_Tax_Model_Calculation $taxCalculation */
32
+ $taxCalculation = Mage::getSingleton('tax/calculation');
33
+
34
+ $store = Mage::app()->getStore();
35
+ $request = $taxCalculation->getRateRequest(null, null, null, $store);
36
+ $taxClassId = $product->getData('tax_class_id');
37
+
38
+ return $taxCalculation->getRate($request->setProductClassId($taxClassId));
39
+ }
40
+ }
lib/Aplazame/Aplazame/BusinessModel/Checkout.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Checkout.
5
+ */
6
+ class Aplazame_Aplazame_BusinessModel_Checkout
7
+ {
8
+ public static function createFromOrder(Mage_Sales_Model_Order $order)
9
+ {
10
+ $merchant = new stdClass();
11
+ $merchant->confirmation_url = Mage::getUrl("aplazame/payment/confirm", array('_secure' => true));
12
+ $merchant->cancel_url = Mage::getUrl('aplazame/payment/cancel', array('_secure' => true));
13
+ $merchant->success_url = Mage::getUrl('checkout/onepage/success', array('_secure' => true));
14
+ $merchant->checkout_url = Mage::getUrl('aplazame/payment/cart');
15
+
16
+ $checkout = new self();
17
+ $checkout->toc = true;
18
+ $checkout->merchant = $merchant;
19
+ $checkout->order = Aplazame_Aplazame_BusinessModel_Order::crateFromOrder($order);
20
+ $checkout->customer = Aplazame_Aplazame_BusinessModel_Customer::createFromOrder($order);
21
+ $checkout->billing = Aplazame_Aplazame_BusinessModel_Address::createFromAddress($order->getBillingAddress());
22
+ $checkout->shipping = Aplazame_Aplazame_BusinessModel_ShippingInfo::createFromOrder($order);
23
+ $checkout->meta = array(
24
+ "module" => array(
25
+ "name" => "aplazame:magento",
26
+ "version" => Mage::getVersion(),
27
+ ),
28
+ "version" => Mage::getConfig()->getModuleConfig('Aplazame_Aplazame')->version,
29
+ );
30
+
31
+ return $checkout;
32
+ }
33
+ }
lib/Aplazame/Aplazame/BusinessModel/Customer.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Customer.
5
+ */
6
+ class Aplazame_Aplazame_BusinessModel_Customer
7
+ {
8
+ public static function createFromOrder(Mage_Sales_Model_Order $order)
9
+ {
10
+ /** @var Mage_Customer_Model_Customer $customer */
11
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
12
+ if ($customer->getId()) {
13
+ return self::createFromCustomer($customer);
14
+ }
15
+
16
+ return self::createGuessCustomerFromOrder($order);
17
+ }
18
+
19
+ public static function createFromCustomer(Mage_Customer_Model_Customer $customer)
20
+ {
21
+ /** @var Mage_Log_Model_Customer $logCustomer */
22
+ $logCustomer = Mage::getModel('log/customer')->loadByCustomer($customer->getId());
23
+
24
+ switch ($customer->getGender()) {
25
+ case '1':
26
+ $gender = 1;
27
+ break;
28
+ case '2':
29
+ $gender = 2;
30
+ break;
31
+ default:
32
+ $gender = 0;
33
+ }
34
+
35
+ $aCustomer = new self();
36
+ $aCustomer->email = $customer->getEmail();
37
+ $aCustomer->type = 'e';
38
+ $aCustomer->gender = $gender;
39
+ $aCustomer->id = $customer->getId();
40
+ $aCustomer->first_name = $customer->getFirstname();
41
+ $aCustomer->last_name = $customer->getLastname();
42
+ if (($birthday = $customer->getDob()) !== null) {
43
+ $aCustomer->birthday = Aplazame_Sdk_Serializer_Date::fromDateTime(new DateTime($birthday));
44
+ }
45
+ if (($document_id = $customer->getTaxvat()) !== null) {
46
+ $aCustomer->document_id = $document_id;
47
+ }
48
+ $aCustomer->date_joined = Aplazame_Sdk_Serializer_Date::fromDateTime(new DateTime('@' . $customer->getCreatedAtTimestamp()));
49
+ if (($lastLogin = $logCustomer->getLoginAtTimestamp()) != null) {
50
+ $aCustomer->last_login = Aplazame_Sdk_Serializer_Date::fromDateTime(new DateTime('@' . $lastLogin));
51
+ }
52
+
53
+ return $aCustomer;
54
+ }
55
+
56
+ public static function createGuessCustomerFromOrder(Mage_Sales_Model_Order $order)
57
+ {
58
+ $aCustomer = new self();
59
+ $aCustomer->email = $order->getCustomerEmail();
60
+ $aCustomer->type = 'g';
61
+ $aCustomer->gender = 0;
62
+ $aCustomer->first_name = $order->getCustomerFirstname();
63
+ $aCustomer->last_name = $order->getCustomerLastname();
64
+
65
+ return $aCustomer;
66
+ }
67
+ }
lib/Aplazame/Aplazame/BusinessModel/Order.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Order.
5
+ */
6
+ class Aplazame_Aplazame_BusinessModel_Order
7
+ {
8
+ public static function crateFromOrder(Mage_Sales_Model_Order $order)
9
+ {
10
+ $aOrder = new self();
11
+ $aOrder->id = $order->getIncrementId();
12
+ $aOrder->currency = $order->getOrderCurrencyCode();
13
+ $aOrder->total_amount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getTotalDue());
14
+ $aOrder->articles = array_map(array('Aplazame_Aplazame_BusinessModel_Article', 'crateFromOrderItem'), $order->getAllVisibleItems());
15
+
16
+ if (($discounts = $order->getDiscountAmount()) !== null) {
17
+ $aOrder->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat(-$discounts);
18
+ }
19
+
20
+ return $aOrder;
21
+ }
22
+ }
lib/Aplazame/Aplazame/BusinessModel/ShippingInfo.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Shipping info.
5
+ */
6
+ class Aplazame_Aplazame_BusinessModel_ShippingInfo
7
+ {
8
+ public static function createFromOrder(Mage_Sales_Model_Order $order)
9
+ {
10
+ $address = $order->getShippingAddress();
11
+
12
+ $shippingInfo = new self();
13
+ $shippingInfo->first_name = $address->getFirstname();
14
+ $shippingInfo->last_name = $address->getLastname();
15
+ $shippingInfo->street = $address->getStreet(1);
16
+ $shippingInfo->city = $address->getCity();
17
+ $shippingInfo->state = $address->getRegion();
18
+ $shippingInfo->country = $address->getCountryModel()->getIso2Code();
19
+ $shippingInfo->postcode = $address->getPostcode();
20
+ $shippingInfo->name = $order->getShippingMethod();
21
+ $shippingInfo->price = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingAmount());
22
+ $shippingInfo->phone = $address->getTelephone();
23
+ $shippingInfo->alt_phone = $address->getAltTelephone();
24
+ $shippingInfo->address_addition = $address->getStreet(2);
25
+ if ($order->getShippingAmount() > 0) {
26
+ $shippingInfo->tax_rate = Aplazame_Sdk_Serializer_Decimal::fromFloat(100 * $order->getShippingTaxAmount() / $order->getShippingAmount());
27
+ }
28
+ $shippingInfo->discount = Aplazame_Sdk_Serializer_Decimal::fromFloat($order->getShippingDiscountAmount());
29
+
30
+ return $shippingInfo;
31
+ }
32
+ }
lib/Aplazame/Aplazame/Http/ZendClient.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Aplazame_Http_ZendClient implements Aplazame_Sdk_Http_ClientInterface
4
+ {
5
+ public function send(Aplazame_Sdk_Http_RequestInterface $request)
6
+ {
7
+ $rawHeaders = array();
8
+ foreach ($request->getHeaders() as $header => $value) {
9
+ $rawHeaders[] = sprintf('%s:%s', $header, implode(', ', $value));
10
+ }
11
+
12
+ $client = new Zend_Http_Client($request->getUri());
13
+ $client->setHeaders($rawHeaders);
14
+ $client->setMethod($request->getMethod());
15
+
16
+ $body = $request->getBody();
17
+ if (!empty($body)) {
18
+ $client->setRawData($body);
19
+ }
20
+
21
+ try {
22
+ $zendResponse = $client->request();
23
+ } catch (Exception $e) {
24
+ throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
25
+ }
26
+
27
+ $responseBody = $zendResponse->getBody();
28
+
29
+ $response = new Aplazame_Sdk_Http_Response(
30
+ $zendResponse->getStatus(),
31
+ $responseBody
32
+ );
33
+
34
+ return $response;
35
+ }
36
+ }
lib/Aplazame/Aplazame/Util.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- class Aplazame_Util
4
- {
5
- public static function formatDecimals($amount = 0)
6
- {
7
- $ret = '';
8
- $str = sprintf('%.2f', $amount);
9
-
10
- if (strcmp($str[0], '-') === 0) {
11
- $str = substr($str, 1);
12
- $ret = '-';
13
- }
14
-
15
- $parts = explode('.', $str, 2);
16
-
17
- if (($parts === false) || (empty($parts)) ||
18
- (strcmp($parts[0], 0) === 0 && strcmp($parts[1], '00') === 0)) {
19
-
20
- return 0;
21
- }
22
-
23
- $ret .= ltrim($parts[0] . substr($parts[1], 0, 2), '0');
24
- return intval($ret);
25
- }
26
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/Aplazame/Sdk/Api/ApiClientException.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Exception thrown for HTTP 4xx client errors.
5
+ */
6
+ class Aplazame_Sdk_Api_ApiClientException extends LogicException implements Aplazame_Sdk_Api_AplazameExceptionInterface
7
+ {
8
+ /**
9
+ * @param Aplazame_Sdk_Http_ResponseInterface $response
10
+ *
11
+ * @return Aplazame_Sdk_Api_ApiClientException
12
+ */
13
+ public static function fromResponse(Aplazame_Sdk_Http_ResponseInterface $response)
14
+ {
15
+ $responseBody = (string) $response->getBody();
16
+ if (empty($responseBody)) {
17
+ return new self($response->getStatusCode(), $response->getReasonPhrase());
18
+ }
19
+
20
+ $decodedBody = json_decode($responseBody, true);
21
+ if (!isset($decodedBody['error'])) {
22
+ return new self($response->getStatusCode(), $response->getReasonPhrase());
23
+ }
24
+
25
+ $error = $decodedBody['error'];
26
+
27
+ return new self($response->getStatusCode(), $error['message'], $error['type'], $error);
28
+ }
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ private $type;
34
+
35
+ /**
36
+ * @var array
37
+ */
38
+ private $error;
39
+
40
+ /**
41
+ * @param string $statusCode
42
+ * @param string $message
43
+ * @param string $type
44
+ * @param array $error
45
+ */
46
+ public function __construct($statusCode, $message, $type = '', array $error = array())
47
+ {
48
+ parent::__construct($message, $statusCode);
49
+
50
+ $this->type = $type;
51
+ $this->error = $error;
52
+ }
53
+
54
+ public function getStatusCode()
55
+ {
56
+ return $this->getCode();
57
+ }
58
+
59
+ /**
60
+ * @return string
61
+ */
62
+ public function getType()
63
+ {
64
+ return $this->type;
65
+ }
66
+
67
+ /**
68
+ * @return array
69
+ */
70
+ public function getError()
71
+ {
72
+ return $this->error;
73
+ }
74
+ }
lib/Aplazame/Sdk/Api/ApiCommunicationException.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Exception thrown when there is communication possible with the API.
5
+ */
6
+ class Aplazame_Sdk_Api_ApiCommunicationException extends RuntimeException implements Aplazame_Sdk_Api_AplazameExceptionInterface
7
+ {
8
+ /**
9
+ * @param Exception $exception
10
+ *
11
+ * @return Aplazame_Sdk_Api_ApiCommunicationException
12
+ */
13
+ public static function fromException(Exception $exception)
14
+ {
15
+ return new self($exception->getMessage(), $exception->getCode(), $exception);
16
+ }
17
+ }
lib/Aplazame/Sdk/Api/ApiRequest.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Sdk_Api_ApiRequest extends Aplazame_Sdk_Http_Request
4
+ {
5
+ const SDK_VERSION = '0.2.1';
6
+ const FORMAT_JSON = 'json';
7
+ const FORMAT_XML = 'xml';
8
+ const FORMAT_YAML = 'yaml';
9
+
10
+ /**
11
+ * @param string $accessToken
12
+ *
13
+ * @return string
14
+ */
15
+ public static function createAuthorizationHeader($accessToken)
16
+ {
17
+ return 'Bearer ' . $accessToken;
18
+ }
19
+
20
+ /**
21
+ * @param bool $useSandbox
22
+ * @param int $apiVersion
23
+ * @param string $format
24
+ *
25
+ * @return string
26
+ */
27
+ public static function createAcceptHeader($useSandbox, $apiVersion, $format)
28
+ {
29
+ $header = 'application/vnd.aplazame';
30
+ if ($useSandbox) {
31
+ $header .= '.sandbox';
32
+ }
33
+ $header .= sprintf('.v%d+%s', $apiVersion, $format);
34
+
35
+ return $header;
36
+ }
37
+
38
+ /**
39
+ * @param bool $useSandbox
40
+ * @param string $accessToken The Access Token of the request (Public API key or Private API key)
41
+ * @param string $method The HTTP method of the request.
42
+ * @param string $uri The URI of the request.
43
+ * @param mixed $data The data of the request.
44
+ */
45
+ public function __construct(
46
+ $useSandbox,
47
+ $accessToken,
48
+ $method,
49
+ $uri,
50
+ $data = null
51
+ ) {
52
+ $headers = array(
53
+ 'Accept' => array(self::createAcceptHeader($useSandbox, 1, self::FORMAT_JSON)),
54
+ 'Authorization' => array(self::createAuthorizationHeader($accessToken)),
55
+ 'User-Agent' => array(
56
+ 'Sdk/' . self::SDK_VERSION,
57
+ 'PHP/' . PHP_VERSION,
58
+ 'Magento/' . Mage::getVersion(),
59
+ 'AplazameMagento/' . Mage::getConfig()->getModuleConfig('Aplazame_Aplazame')->version,
60
+ ),
61
+ );
62
+
63
+ if ($data && !is_string($data)) {
64
+ $data = json_encode($data);
65
+ if (json_last_error() !== JSON_ERROR_NONE) {
66
+ throw new DomainException(json_last_error_msg(), json_last_error());
67
+ }
68
+ $headers['Content-Type'] = array('application/json');
69
+ }
70
+
71
+ parent::__construct($method, $uri, $headers, $data);
72
+ }
73
+ }
lib/Aplazame/Sdk/Api/ApiServerException.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Exception thrown for HTTP 5xx client errors.
5
+ */
6
+ class Aplazame_Sdk_Api_ApiServerException extends RuntimeException implements Aplazame_Sdk_Api_AplazameExceptionInterface
7
+ {
8
+ /**
9
+ * @param Aplazame_Sdk_Http_ResponseInterface $response
10
+ *
11
+ * @return Aplazame_Sdk_Api_ApiServerException
12
+ */
13
+ public static function fromResponse(Aplazame_Sdk_Http_ResponseInterface $response)
14
+ {
15
+ $responseBody = (string) $response->getBody();
16
+ if (empty($responseBody)) {
17
+ return new self($response->getStatusCode(), $response->getReasonPhrase());
18
+ }
19
+
20
+ $decodedBody = json_decode($responseBody, true);
21
+ if (!isset($decodedBody['error'])) {
22
+ return new self($response->getStatusCode(), $response->getReasonPhrase());
23
+ }
24
+
25
+ $error = $decodedBody['error'];
26
+
27
+ return new self($response->getStatusCode(), $error['message'], $error['type'], $error);
28
+ }
29
+
30
+ /**
31
+ * @var string
32
+ */
33
+ private $type;
34
+
35
+ /**
36
+ * @var array
37
+ */
38
+ private $error;
39
+
40
+ /**
41
+ * @param string $statusCode
42
+ * @param string $message
43
+ * @param string $type
44
+ * @param array $error
45
+ */
46
+ public function __construct($statusCode, $message, $type = '', array $error = array())
47
+ {
48
+ parent::__construct($message, $statusCode);
49
+
50
+ $this->type = $type;
51
+ $this->error = $error;
52
+ }
53
+
54
+ public function getStatusCode()
55
+ {
56
+ return $this->getCode();
57
+ }
58
+
59
+ /**
60
+ * @return string
61
+ */
62
+ public function getType()
63
+ {
64
+ return $this->type;
65
+ }
66
+
67
+ /**
68
+ * @return array
69
+ */
70
+ public function getError()
71
+ {
72
+ return $this->error;
73
+ }
74
+ }
lib/Aplazame/Sdk/Api/AplazameExceptionInterface.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Common interface for custom exceptions.
5
+ */
6
+ interface Aplazame_Sdk_Api_AplazameExceptionInterface
7
+ {
8
+ }
lib/Aplazame/Sdk/Api/Client.php ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!function_exists('json_last_error_msg')) {
4
+ include __DIR__ . '/../json_polyfill.php';
5
+ }
6
+
7
+ class Aplazame_Sdk_Api_Client
8
+ {
9
+ const ENVIRONMENT_PRODUCTION = 'production';
10
+ const ENVIRONMENT_SANDBOX = 'sandbox';
11
+
12
+ /**
13
+ * @var string
14
+ */
15
+ private $apiBaseUri;
16
+
17
+ /**
18
+ * @var bool
19
+ */
20
+ private $useSandbox;
21
+
22
+ /**
23
+ * @var string
24
+ */
25
+ private $accessToken;
26
+
27
+ /**
28
+ * @var Aplazame_Sdk_Http_ClientInterface
29
+ */
30
+ private $httpClient;
31
+
32
+ /**
33
+ * @param string $apiBaseUri The API base URI.
34
+ * @param string $environment Destination of the request.
35
+ * @param string $accessToken The Access Token of the request (Public API key or Private API key)
36
+ * @param Aplazame_Sdk_Http_ClientInterface|null $httpClient
37
+ */
38
+ public function __construct(
39
+ $apiBaseUri,
40
+ $environment,
41
+ $accessToken,
42
+ Aplazame_Sdk_Http_ClientInterface $httpClient = null
43
+ ) {
44
+ $this->apiBaseUri = $apiBaseUri;
45
+ $this->useSandbox = ($environment === self::ENVIRONMENT_SANDBOX) ? true : false;
46
+ $this->accessToken = $accessToken;
47
+ $this->httpClient = $httpClient ? $httpClient : new Aplazame_Sdk_Http_CurlClient();
48
+ }
49
+
50
+ /**
51
+ * Performs a DELETE request.
52
+ *
53
+ * @param string $path The path of the request.
54
+ *
55
+ * @return array The data of the response.
56
+ *
57
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
58
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
59
+ * @throws Aplazame_Sdk_Api_ApiServerException if an I/O error occurs.
60
+ * @throws Aplazame_Sdk_Api_ApiClientException if request is invalid.
61
+ */
62
+ public function delete($path)
63
+ {
64
+ return $this->request('DELETE', $path);
65
+ }
66
+
67
+ /**
68
+ * Performs a GET request.
69
+ *
70
+ * @param string $path The path of the request.
71
+ * @param array $query The filters of the request.
72
+ *
73
+ * @return array The data of the response.
74
+ *
75
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
76
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
77
+ * @throws Aplazame_Sdk_Api_ApiServerException if an I/O error occurs.
78
+ * @throws Aplazame_Sdk_Api_ApiClientException if request is invalid.
79
+ */
80
+ public function get($path, array $query = array())
81
+ {
82
+ if (!empty($query)) {
83
+ $query = http_build_query($query);
84
+ $path .= '?' . $query;
85
+ }
86
+
87
+ return $this->request('GET', $path);
88
+ }
89
+
90
+ /**
91
+ * Performs a POST request.
92
+ *
93
+ * @param string $path The path of the request.
94
+ * @param array $data The data of the request.
95
+ *
96
+ * @return array The data of the response.
97
+ *
98
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
99
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
100
+ * @throws Aplazame_Sdk_Api_ApiServerException if an I/O error occurs.
101
+ * @throws Aplazame_Sdk_Api_ApiClientException if request is invalid.
102
+ */
103
+ public function patch($path, array $data)
104
+ {
105
+ return $this->request('PATCH', $path, $data);
106
+ }
107
+
108
+ /**
109
+ * Performs a POST request.
110
+ *
111
+ * @param string $path The path of the request.
112
+ * @param array $data The data of the request.
113
+ *
114
+ * @return array The data of the response.
115
+ *
116
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
117
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
118
+ * @throws Aplazame_Sdk_Api_ApiServerException if an I/O error occurs.
119
+ * @throws Aplazame_Sdk_Api_ApiClientException if request is invalid.
120
+ */
121
+ public function post($path, array $data)
122
+ {
123
+ return $this->request('POST', $path, $data);
124
+ }
125
+
126
+ /**
127
+ * Performs a PUT request.
128
+ *
129
+ * @param string $path The path of the request.
130
+ * @param array $data The data of the request.
131
+ *
132
+ * @return array The data of the response.
133
+ *
134
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
135
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
136
+ * @throws Aplazame_Sdk_Api_ApiServerException if an I/O error occurs.
137
+ * @throws Aplazame_Sdk_Api_ApiClientException if request is invalid.
138
+ */
139
+ public function put($path, array $data)
140
+ {
141
+ return $this->request('PUT', $path, $data);
142
+ }
143
+
144
+ /**
145
+ * @param string $method The HTTP method of the request.
146
+ * @param string $path The path of the request.
147
+ * @param array|null $data The data of the request.
148
+ *
149
+ * @return array The data of the response.
150
+ *
151
+ * @throws Aplazame_Sdk_Api_ApiCommunicationException if an I/O error occurs.
152
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
153
+ * @throws Aplazame_Sdk_Api_ApiClientException if an I/O error occurs.
154
+ * @throws Aplazame_Sdk_Api_ApiServerException if request is invalid.
155
+ */
156
+ public function request($method, $path, array $data = null)
157
+ {
158
+ $uri = $this->apiBaseUri . '/' . ltrim($path, '/');
159
+
160
+ $request = new Aplazame_Sdk_Api_ApiRequest($this->useSandbox, $this->accessToken, $method, $uri, $data);
161
+ try {
162
+ $response = $this->httpClient->send($request);
163
+ } catch (RuntimeException $e) {
164
+ throw Aplazame_Sdk_Api_ApiCommunicationException::fromException($e);
165
+ }
166
+
167
+ if ($response->getStatusCode() >= 500) {
168
+ throw Aplazame_Sdk_Api_ApiClientException::fromResponse($response);
169
+ }
170
+
171
+ if ($response->getStatusCode() >= 400) {
172
+ throw Aplazame_Sdk_Api_ApiServerException::fromResponse($response);
173
+ }
174
+
175
+ $payload = $this->decodeResponseBody((string) $response->getBody());
176
+
177
+ return $payload;
178
+ }
179
+
180
+ /**
181
+ * @param string $responseBody The HTTP response body.
182
+ *
183
+ * @return array Decoded payload.
184
+ *
185
+ * @throws Aplazame_Sdk_Api_DeserializeException if response cannot be deserialized.
186
+ */
187
+ protected function decodeResponseBody($responseBody)
188
+ {
189
+ // Response body is empty for HTTP 204 and 304 status code.
190
+ if (empty($responseBody)) {
191
+ return array();
192
+ }
193
+
194
+ $responseBody = json_decode($responseBody, true);
195
+ if (json_last_error() !== JSON_ERROR_NONE) {
196
+ throw new Aplazame_Sdk_Api_DeserializeException('Unable to deserialize JSON data: ' . json_last_error_msg(), json_last_error());
197
+ }
198
+
199
+ return $responseBody;
200
+ }
201
+ }
lib/Aplazame/Sdk/Api/DeserializeException.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This exception is thrown when the data cannot be deserialized/unmarshalled.
5
+ */
6
+ class Aplazame_Sdk_Api_DeserializeException extends UnexpectedValueException implements Aplazame_Sdk_Api_AplazameExceptionInterface
7
+ {
8
+ }
lib/Aplazame/Sdk/Http/ClientInterface.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ interface Aplazame_Sdk_Http_ClientInterface
4
+ {
5
+ /**
6
+ * @param Aplazame_Sdk_Http_RequestInterface $request
7
+ *
8
+ * @return Aplazame_Sdk_Http_ResponseInterface
9
+ *
10
+ * @throws RuntimeException If requests cannot be performed due network issues.
11
+ */
12
+ public function send(Aplazame_Sdk_Http_RequestInterface $request);
13
+ }
lib/Aplazame/Sdk/Http/CurlClient.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Sdk_Http_CurlClient implements Aplazame_Sdk_Http_ClientInterface
4
+ {
5
+ public function __construct()
6
+ {
7
+ if (!function_exists('curl_init')) {
8
+ throw new \LogicException('cURL extension is not loaded');
9
+ }
10
+ }
11
+
12
+ public function send(Aplazame_Sdk_Http_RequestInterface $request)
13
+ {
14
+ $rawHeaders = array();
15
+ foreach ($request->getHeaders() as $header => $value) {
16
+ $rawHeaders[] = sprintf('%s:%s', $header, implode(', ', $value));
17
+ }
18
+
19
+ $ch = curl_init();
20
+ curl_setopt($ch, CURLOPT_URL, $request->getUri());
21
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
22
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod());
23
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $rawHeaders);
24
+
25
+ $body = $request->getBody();
26
+ if (!empty($body)) {
27
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
28
+ }
29
+
30
+ $responseBody = curl_exec($ch);
31
+
32
+ if (false === $responseBody) {
33
+ $message = curl_error($ch);
34
+ $code = curl_errno($ch);
35
+
36
+ curl_close($ch);
37
+
38
+ throw new RuntimeException($message, $code);
39
+ }
40
+
41
+ $response = new Aplazame_Sdk_Http_Response(
42
+ curl_getinfo($ch, CURLINFO_HTTP_CODE),
43
+ $responseBody
44
+ );
45
+
46
+ curl_close($ch);
47
+
48
+ return $response;
49
+ }
50
+ }
lib/Aplazame/Sdk/Http/Request.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Sdk_Http_Request implements Aplazame_Sdk_Http_RequestInterface
4
+ {
5
+ /**
6
+ * @var string
7
+ */
8
+ private $method;
9
+
10
+ /**
11
+ * @var string
12
+ */
13
+ private $uri;
14
+
15
+ /**
16
+ * @var array
17
+ */
18
+ private $headers;
19
+
20
+ /**
21
+ * @var string
22
+ */
23
+ private $body;
24
+
25
+ /**
26
+ * @param string $method The HTTP method of the request.
27
+ * @param string $uri The URI of the request.
28
+ * @param array $headers The headers of the request.
29
+ * @param string $body The body of the message.
30
+ */
31
+ public function __construct($method, $uri, array $headers = array(), $body = '')
32
+ {
33
+ $this->method = strtoupper($method);
34
+ $this->uri = $uri;
35
+ $this->headers = $headers;
36
+ $this->body = $body;
37
+ }
38
+
39
+ public function getMethod()
40
+ {
41
+ return $this->method;
42
+ }
43
+
44
+ public function getHeaders()
45
+ {
46
+ return $this->headers;
47
+ }
48
+
49
+ public function getUri()
50
+ {
51
+ return $this->uri;
52
+ }
53
+
54
+ public function getBody()
55
+ {
56
+ return $this->body;
57
+ }
58
+ }
lib/Aplazame/Sdk/Http/RequestInterface.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ interface Aplazame_Sdk_Http_RequestInterface
4
+ {
5
+ /**
6
+ * Retrieves the HTTP method of the request.
7
+ *
8
+ * @return string Returns the request method. The return value must use uppercase letters.
9
+ */
10
+ public function getMethod();
11
+
12
+ /**
13
+ * Retrieves all message header values.
14
+ *
15
+ * The keys represent the header name as it will be sent over the wire, and
16
+ * each value is an array of strings associated with the header.
17
+ *
18
+ * // Represent the headers as a string
19
+ * foreach ($message->getHeaders() as $name => $values) {
20
+ * echo $name . ": " . implode(", ", $values);
21
+ * }
22
+ *
23
+ * // Emit headers iteratively:
24
+ * foreach ($message->getHeaders() as $name => $values) {
25
+ * foreach ($values as $value) {
26
+ * header(sprintf('%s: %s', $name, $value), false);
27
+ * }
28
+ * }
29
+ *
30
+ * While header names are not case-sensitive, getHeaders() will preserve the
31
+ * exact case in which headers were originally specified.
32
+ *
33
+ * @return array Returns an associative array of the message's headers. Each
34
+ * key MUST be a header name, and each value MUST be an array of strings
35
+ * for that header.
36
+ */
37
+ public function getHeaders();
38
+
39
+ /**
40
+ * Retrieves the URI instance.
41
+ *
42
+ * @link http://tools.ietf.org/html/rfc3986#section-4.3
43
+ *
44
+ * @return string Returns the URI of the request.
45
+ */
46
+ public function getUri();
47
+
48
+ /**
49
+ * Gets the body of the message.
50
+ *
51
+ * @return string Returns the body of the request.
52
+ */
53
+ public function getBody();
54
+ }
lib/Aplazame/Sdk/Http/Response.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Aplazame_Sdk_Http_Response implements Aplazame_Sdk_Http_ResponseInterface
4
+ {
5
+ /** @var array Map of standard HTTP status code/reason phrases */
6
+ private static $phrases = array(
7
+ 100 => 'Continue',
8
+ 101 => 'Switching Protocols',
9
+ 102 => 'Processing',
10
+ 200 => 'OK',
11
+ 201 => 'Created',
12
+ 202 => 'Accepted',
13
+ 203 => 'Non-Authoritative Information',
14
+ 204 => 'No Content',
15
+ 205 => 'Reset Content',
16
+ 206 => 'Partial Content',
17
+ 207 => 'Multi-status',
18
+ 208 => 'Already Reported',
19
+ 300 => 'Multiple Choices',
20
+ 301 => 'Moved Permanently',
21
+ 302 => 'Found',
22
+ 303 => 'See Other',
23
+ 304 => 'Not Modified',
24
+ 305 => 'Use Proxy',
25
+ 306 => 'Switch Proxy',
26
+ 307 => 'Temporary Redirect',
27
+ 400 => 'Bad Request',
28
+ 401 => 'Unauthorized',
29
+ 402 => 'Payment Required',
30
+ 403 => 'Forbidden',
31
+ 404 => 'Not Found',
32
+ 405 => 'Method Not Allowed',
33
+ 406 => 'Not Acceptable',
34
+ 407 => 'Proxy Authentication Required',
35
+ 408 => 'Request Time-out',
36
+ 409 => 'Conflict',
37
+ 410 => 'Gone',
38
+ 411 => 'Length Required',
39
+ 412 => 'Precondition Failed',
40
+ 413 => 'Request Entity Too Large',
41
+ 414 => 'Request-URI Too Large',
42
+ 415 => 'Unsupported Media Type',
43
+ 416 => 'Requested range not satisfiable',
44
+ 417 => 'Expectation Failed',
45
+ 418 => "'I'm a teapot'",
46
+ 422 => 'Unprocessable Entity',
47
+ 423 => 'Locked',
48
+ 424 => 'Failed Dependency',
49
+ 425 => 'Unordered Collection',
50
+ 426 => 'Upgrade Required',
51
+ 428 => 'Precondition Required',
52
+ 429 => 'Too Many Requests',
53
+ 431 => 'Request Header Fields Too Large',
54
+ 451 => 'Unavailable For Legal Reasons',
55
+ 500 => 'Internal Server Error',
56
+ 501 => 'Not Implemented',
57
+ 502 => 'Bad Gateway',
58
+ 503 => 'Service Unavailable',
59
+ 504 => 'Gateway Time-out',
60
+ 505 => 'HTTP Version not supported',
61
+ 506 => 'Variant Also Negotiates',
62
+ 507 => 'Insufficient Storage',
63
+ 508 => 'Loop Detected',
64
+ 511 => 'Network Authentication Required',
65
+ );
66
+
67
+ /**
68
+ * @var int
69
+ */
70
+ private $statusCode;
71
+
72
+ /**
73
+ * @var string
74
+ */
75
+ private $reasonPhrase = '';
76
+
77
+ /**
78
+ * @var string
79
+ */
80
+ private $body;
81
+
82
+ /**
83
+ * @param int $statusCode
84
+ * @param string $body
85
+ */
86
+ public function __construct($statusCode, $body)
87
+ {
88
+ $this->statusCode = $statusCode;
89
+ $this->body = $body;
90
+
91
+ if (isset(self::$phrases[$this->statusCode])) {
92
+ $this->reasonPhrase = self::$phrases[$statusCode];
93
+ } else {
94
+ $this->reasonPhrase = '';
95
+ }
96
+ }
97
+
98
+ public function getStatusCode()
99
+ {
100
+ return $this->statusCode;
101
+ }
102
+
103
+ public function getReasonPhrase()
104
+ {
105
+ return $this->reasonPhrase;
106
+ }
107
+
108
+ public function getBody()
109
+ {
110
+ return $this->body;
111
+ }
112
+ }
lib/Aplazame/Sdk/Http/ResponseInterface.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Representation of an outgoing, server-side response.
5
+ */
6
+ interface Aplazame_Sdk_Http_ResponseInterface
7
+ {
8
+ /**
9
+ * Gets the response status code.
10
+ *
11
+ * The status code is a 3-digit integer result code of the server's attempt
12
+ * to understand and satisfy the request.
13
+ *
14
+ * @return int Status code.
15
+ */
16
+ public function getStatusCode();
17
+
18
+ /**
19
+ * Gets the response reason phrase associated with the status code.
20
+ *
21
+ * Because a reason phrase is not a required element in a response
22
+ * status line, the reason phrase value MAY be null. Implementations MAY
23
+ * choose to return the default RFC 7231 recommended reason phrase (or those
24
+ * listed in the IANA HTTP Status Code Registry) for the response's
25
+ * status code.
26
+ *
27
+ * @link http://tools.ietf.org/html/rfc7231#section-6
28
+ * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
29
+ *
30
+ * @return string Reason phrase; must return an empty string if none present.
31
+ */
32
+ public function getReasonPhrase();
33
+
34
+ /**
35
+ * Gets the body of the message.
36
+ *
37
+ * @return string
38
+ */
39
+ public function getBody();
40
+ }
lib/Aplazame/Sdk/Serializer/Date.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use DateTime;
4
+
5
+ /**
6
+ * DateTime Type.
7
+ */
8
+ class Aplazame_Sdk_Serializer_Date implements Aplazame_Sdk_Serializer_JsonSerializable
9
+ {
10
+ /**
11
+ * @param DateTime $value
12
+ *
13
+ * @return Aplazame_Sdk_Serializer_Date
14
+ */
15
+ public static function fromDateTime($value)
16
+ {
17
+ return new self($value->format(DateTime::ISO8601));
18
+ }
19
+
20
+ /**
21
+ * @var null|string
22
+ */
23
+ public $value;
24
+
25
+ /**
26
+ * @param string $value
27
+ */
28
+ public function __construct($value)
29
+ {
30
+ $this->value = $value;
31
+ }
32
+
33
+ /**
34
+ * @return DateTime
35
+ */
36
+ public function asDateTime()
37
+ {
38
+ $dateTime = DateTime::createFromFormat(DateTime::ISO8601, $this->value);
39
+
40
+ return $dateTime;
41
+ }
42
+
43
+ public function jsonSerialize()
44
+ {
45
+ return $this->value;
46
+ }
47
+ }
lib/Aplazame/Sdk/Serializer/Decimal.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Decimal Type.
5
+ */
6
+ class Aplazame_Sdk_Serializer_Decimal implements Aplazame_Sdk_Serializer_JsonSerializable
7
+ {
8
+ public static function fromFloat($value)
9
+ {
10
+ return new self((int) number_format($value, 2, '', ''));
11
+ }
12
+
13
+ /**
14
+ * @var null|int
15
+ */
16
+ public $value;
17
+
18
+ /**
19
+ * @param int $value
20
+ */
21
+ public function __construct($value)
22
+ {
23
+ $this->value = $value;
24
+ }
25
+
26
+ /**
27
+ * @return float
28
+ */
29
+ public function asFloat()
30
+ {
31
+ return $this->value / 100;
32
+ }
33
+
34
+ public function jsonSerialize()
35
+ {
36
+ return $this->value;
37
+ }
38
+ }
lib/Aplazame/Sdk/Serializer/JsonSerializable.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ interface Aplazame_Sdk_Serializer_JsonSerializable
4
+ {
5
+ /**
6
+ * Serializes the object to a value that can be serialized natively by json_encode().
7
+ *
8
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
9
+ *
10
+ * @return mixed data which can be serialized by json_encode(), which is a value of any type other than a resource.
11
+ */
12
+ public function jsonSerialize();
13
+ }
lib/Aplazame/Sdk/Serializer/JsonSerializer.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This class assist to compose API models serializable as JSON for PHP versions prior to v5.4.
5
+ */
6
+ class Aplazame_Sdk_Serializer_JsonSerializer
7
+ {
8
+ /**
9
+ * Important: This method does not return a JSON string, the return of this method must be encoded with `json_encode()`.
10
+ *
11
+ * @param mixed $value
12
+ *
13
+ * @return mixed a value valid for to be used with native `json_encode()` function
14
+ */
15
+ public static function serializeValue($value)
16
+ {
17
+ if ($value instanceof Aplazame_Sdk_Serializer_JsonSerializable || $value instanceof \JsonSerializable) {
18
+ return $value->jsonSerialize();
19
+ }
20
+
21
+ if (is_object($value)) {
22
+ $value = (array) $value;
23
+ }
24
+
25
+ if (is_array($value)) {
26
+ foreach ($value as &$nestedValue) {
27
+ $nestedValue = self::serializeValue($nestedValue);
28
+ }
29
+
30
+ return $value;
31
+ }
32
+
33
+ if ($value instanceof DateTime || $value instanceof \DateTimeInterface) {
34
+ throw new DomainException('Please wrap your DateTime objects with Aplazame_Sdk_Serializer_Date::fromDateTime');
35
+ }
36
+
37
+ if (is_float($value)) {
38
+ throw new DomainException('Please wrap your float values with Aplazame_Sdk_Serializer_Decimal::fromFloat');
39
+ }
40
+
41
+ return $value;
42
+ }
43
+ }
lib/Aplazame/Sdk/json_polyfill.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * json_last_error_msg is available since PHP 5.5.0
5
+ */
6
+ if (!function_exists('json_last_error_msg')) {
7
+ function json_last_error_msg()
8
+ {
9
+ static $ERRORS = array(
10
+ JSON_ERROR_NONE => 'No error',
11
+ JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
12
+ JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
13
+ JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
14
+ JSON_ERROR_SYNTAX => 'Syntax error',
15
+ JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
16
+ );
17
+
18
+ $error = json_last_error();
19
+
20
+ return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
21
+ }
22
+ }
package.xml CHANGED
@@ -1,18 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aplazame_Aplazame</name>
4
- <version>0.3.3</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</summary>
10
  <description>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</description>
11
- <notes>* Prevent order cancellation after confirm.</notes>
 
12
  <authors><author><name>Aplazame</name><user>aplazame</user><email>dev@aplazame.com</email></author></authors>
13
- <date>2016-10-17</date>
14
- <time>11:07:01</time>
15
- <contents><target name="magecommunity"><dir name="Aplazame"><dir name="Aplazame"><dir name="Block"><dir name="AdminHtml"><file name="ProductCampaigns.php" hash="c2cb087af982d7ed40cecc1cba48db00"/><file name="ProductsCampaigns.php" hash="4e654f2a4b65979229e2adcedda2f287"/></dir><dir name="Checkout"><dir name="Cart"><file name="Widget.php" hash="3942489d065d22d356ce3ffcef1a801f"/></dir><dir name="Onepage"><file name="Billing.php" hash="d908bf39c8555f436f8841ff30b520f1"/><file name="Shipping.php" hash="8968979cc9140f2f6236ee9f2fbafc98"/></dir></dir><dir name="Payment"><file name="Form.php" hash="d23f592da9ed9ac11b4432f49c2783ac"/><file name="Info.php" hash="eeadafff816256593595d261c9e3b5f8"/><file name="Redirect.php" hash="094164989ca58ada9669722608b6bc7c"/></dir><dir name="Product"><file name="Widget.php" hash="672f3ce4f644fa93206bbbf908a38b15"/></dir></dir><dir name="Helper"><file name="Cart.php" hash="f95a90db86fb4732f7d3ef1fb6a2322a"/><file name="Data.php" hash="35cc7eb331ff48912492cce397918270"/></dir><dir name="Model"><dir name="Api"><file name="Client.php" hash="a6ac5731d75daee8d2e96a1c052778c5"/><file name="Serializers.php" hash="564d5ee885e3bbb9d2c623ed57dba52e"/></dir><file name="CampaignsObserver.php" hash="8fad045c72f366897e41d571ac9290f5"/><file name="Config.php" hash="ecff6c7d937b86802dc6c98139b1d7c4"/><file name="Observer.php" hash="1d418013ae7fc2c68cdd99c931b2c7e6"/><file name="Payment.php" hash="5026810ce6ccb7a44ac682af899e3d51"/></dir><dir name="controllers"><dir name="AdminHtml"><file name="AplazameController.php" hash="455ef1ac99ae9b43902ad65f408a95ef"/></dir><file name="PaymentController.php" hash="0f70591e7533cf9fcb4648938602c84e"/></dir><dir name="etc"><file name="config.xml" hash="26ad10bf4bc5f12ae998a27318ad793b"/><file name="system.xml" hash="714e49e7b52a305c7f8ceebefe34adcb"/></dir></dir></dir></target><target name="magelib"><dir name="Aplazame"><dir name="Aplazame"><file name="Util.php" hash="039c093cbf8c1859cd7e159829ec8e82"/></dir><file name="Aplazame.php" hash="e67f083f4079693da19cd634d7e5bae9"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="79024c230729c2757d9b372278411308"/></dir><dir name="template"><dir name="aplazame"><file name="productCampaigns.phtml" hash="9d9f685a918b8f7a7042ba531332991a"/><file name="productsCampaigns.phtml" hash="25e22d4540ebbb7cbb87a516b66393c6"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="e56ae75dc4088c1590d986904ecee676"/></dir><dir name="template"><dir name="aplazame"><dir name="checkout"><dir name="cart"><file name="widget.phtml" hash="d81d7b50e0289f54bd653f9c865712c5"/></dir></dir><dir name="payment"><file name="common.phtml" hash="128898cf9895997954ea62da3ce091c9"/><file name="form.phtml" hash="47d03cc30037d3136790a7e88942c8b9"/></dir><dir name="product"><file name="widget.phtml" hash="381b9f5d90cfe4eb5394a862838d7993"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="es_ES"><file name="Aplazame_Aplazame.csv" hash="2bbbffece8ee09579e94c8e810bfde6a"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aplazame_Aplazame.xml" hash="d816c618a1829401ca0314c3406482a1"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Aplazame_Aplazame</name>
4
+ <version>0.4.1</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</summary>
10
  <description>Aplazame, a consumer credit company, offers a payment system that can be used by online buyers to receive funding for their purchases.</description>
11
+ <notes>* [fixed] Payment method label for narrow boxes&#xD;
12
+ </notes>
13
  <authors><author><name>Aplazame</name><user>aplazame</user><email>dev@aplazame.com</email></author></authors>
14
+ <date>2016-11-24</date>
15
+ <time>14:37:46</time>
16
+ <contents><target name="magecommunity"><dir name="Aplazame"><dir name="Aplazame"><dir name="Block"><dir name="AdminHtml"><file name="ProductCampaigns.php" hash="cc4007bf8a21b0beee3f26fb7a50291b"/><file name="ProductsCampaigns.php" hash="4e654f2a4b65979229e2adcedda2f287"/></dir><dir name="Checkout"><dir name="Cart"><file name="Widget.php" hash="1224204293d067c0d3de3e63f2e7bdf9"/></dir><dir name="Onepage"><file name="Billing.php" hash="d908bf39c8555f436f8841ff30b520f1"/><file name="Shipping.php" hash="8968979cc9140f2f6236ee9f2fbafc98"/></dir></dir><dir name="Payment"><file name="Form.php" hash="25e50d6cc49b8cb14f5a2406cdc7d2c3"/><file name="Info.php" hash="eeadafff816256593595d261c9e3b5f8"/><file name="Redirect.php" hash="b585f3542b421e1034a1593a49541bd3"/></dir><dir name="Product"><file name="Widget.php" hash="a0963da7d957f0d022665ebf851cbd46"/></dir></dir><dir name="Helper"><file name="Cart.php" hash="f95a90db86fb4732f7d3ef1fb6a2322a"/><file name="Data.php" hash="35cc7eb331ff48912492cce397918270"/></dir><dir name="Model"><dir name="Api"><file name="Client.php" hash="c5e1ed86d81e7b5dcddad6e928411e5e"/></dir><file name="CampaignsObserver.php" hash="a24df9a5b2c241a25c5c2578e04c2aab"/><file name="Config.php" hash="ecff6c7d937b86802dc6c98139b1d7c4"/><file name="Observer.php" hash="44825f169bd6c5c85d284cf1fd0fdf28"/><file name="Payment.php" hash="f550b95a9e582424ffff6876d5aec94d"/></dir><dir name="controllers"><dir name="AdminHtml"><file name="AplazameController.php" hash="31a80d33439c5c2d36701347556ea2e9"/></dir><file name="ApiController.php" hash="3d37b650de9731d8e2b6556dadb63e98"/><file name="PaymentController.php" hash="d62bacd625b4cc9a4d2ae0af28d447a4"/></dir><dir name="etc"><file name="config.xml" hash="0736b27c56fca3f1f9ab48155c3071cc"/><file name="system.xml" hash="b595707d4b03ec4f29f82c77968ad438"/></dir></dir></dir></target><target name="magelib"><dir name="Aplazame"><dir name="Aplazame"><dir name="Api"><file name="Article.php" hash="f88b4e4d0e472f5e70f10df77d923504"/><dir name="BusinessModel"><file name="Article.php" hash="b2620ae2f806f61feb94a29ffa0f8ef9"/><file name="HistoricalOrder.php" hash="5c86021841845c3af4b8e20b06310989"/></dir><file name="Order.php" hash="2f73b330a8df3a41f925c6b721f69957"/></dir><dir name="BusinessModel"><file name="Address.php" hash="0d59592092e08dfb4d3a8fd08de4ac57"/><file name="Article.php" hash="a34660c185b9808ae84488031b4ef504"/><file name="Checkout.php" hash="97b13eb130bdf15a38a4aeb04e239034"/><file name="Customer.php" hash="4e3b255e589bde0ca6f97c3b35fac80c"/><file name="Order.php" hash="e66fa54a1ca4203abef33be1c7712076"/><file name="ShippingInfo.php" hash="e5f1b9a91b0839094a30c04ec9d8ed86"/></dir><dir name="Http"><file name="ZendClient.php" hash="605e0739e74ad75540c0cb8963a64e88"/></dir></dir><dir name="Sdk"><dir name="Api"><file name="ApiClientException.php" hash="96792d448d909366049192c2a37556ae"/><file name="ApiCommunicationException.php" hash="2f46d905ad859291aa204bdbef4153bc"/><file name="ApiRequest.php" hash="c060290dfa790d2b2b38d120e7abf534"/><file name="ApiServerException.php" hash="90821aed9204104da1983137129bbb16"/><file name="AplazameExceptionInterface.php" hash="ed0cfbeda38fd29403c916418716eb02"/><file name="Client.php" hash="c8bcd8d2a0c410e0b82ea4c0359f308c"/><file name="DeserializeException.php" hash="155f2f9c7af08c89401bd74fd4d95c56"/></dir><dir name="Http"><file name="ClientInterface.php" hash="ea3fe4fa5fe82da131521d84ab4fea22"/><file name="CurlClient.php" hash="28150b98ff950b2e1fcc1b048d637bdc"/><file name="Request.php" hash="a910df86e3c92328b59e7922a4bb1481"/><file name="RequestInterface.php" hash="deb097c359796fdbb08e8a3041728f33"/><file name="Response.php" hash="85e49bf8b02fc7f0174db3bf4dcace94"/><file name="ResponseInterface.php" hash="f21ac2bb3969a54015089718c3652e15"/></dir><dir name="Serializer"><file name="Date.php" hash="ef81948d05ea2982d88cbeb5643904d4"/><file name="Decimal.php" hash="677664df2610ad6e0374d8629ea6d68a"/><file name="JsonSerializable.php" hash="baf92f09f79e92bf9c1df90b324be5b0"/><file name="JsonSerializer.php" hash="95f308cad5cab0a7765246bd156ffe50"/></dir><file name="json_polyfill.php" hash="8472b84afc7fc1c7ea4e1d9c2b5d0343"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="79024c230729c2757d9b372278411308"/></dir><dir name="template"><dir name="aplazame"><file name="productCampaigns.phtml" hash="8d3cd85e3ad212720153277225db9859"/><file name="productsCampaigns.phtml" hash="03450bb464b6bf48716322183641e57b"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="aplazame.xml" hash="e56ae75dc4088c1590d986904ecee676"/></dir><dir name="template"><dir name="aplazame"><dir name="checkout"><dir name="cart"><file name="widget.phtml" hash="59a69ab5025d94adf08994c35bf68979"/></dir></dir><dir name="payment"><file name="common.phtml" hash="128898cf9895997954ea62da3ce091c9"/><file name="form.phtml" hash="beb98d1ff353008154dc873bfabdb366"/></dir><dir name="product"><file name="widget.phtml" hash="7fb0f731092beeac8d82969df2f0bbfc"/></dir></dir></dir></dir></dir></dir></target><target name="magelocale"><dir><dir name="es_ES"><file name="Aplazame_Aplazame.csv" hash="2bbbffece8ee09579e94c8e810bfde6a"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aplazame_Aplazame.xml" hash="d816c618a1829401ca0314c3406482a1"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
19
  </package>