Skip to content

Commit 0b1e1a1

Browse files
authored
Merge pull request #1 from aplazame/serializer
[bc break] BusinessModel removal, Serializer addition
2 parents 5b205bf + cc68fc9 commit 0b1e1a1

25 files changed

+264
-883
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased]
88
### Added
99
- [Api] Add `getHttpStatusCode` to `ApiClientException` and `ApiServerException`. This method returns the response HTTP status code.
10+
- [Serializer] New component focused only in assist the conversion of PHP types to JSON compatible types.
1011

1112
### Changed
12-
- [BusinessModel] Remove constructors
13+
- [BusinessModel] This component has been replaced by [Serializer]
1314
- [Api] Change in `ApiClientException` and `ApiServerException` constructor signature.
1415

1516
### Deprecated
1617

1718
### Removed
19+
- [BusinessModel] This component has been replaced by [Serializer]
1820

1921
### Fixed
2022

README.md

+54-54
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This SDK provides a tree of objects for guide you about to craft the checkout mo
2626
/*
2727
* Merchant model
2828
*/
29-
$merchant = new Aplazame\BusinessModel\Merchant();
29+
$merchant = new stdClass();
3030
$merchant->confirmation_url = "/confirm"; // url that the JS client sent to confirming the order.
3131
$merchant->cancel_url = "/cancel"; // url that the customer is sent to if there is an error in the checkout.
3232
$merchant->success_url = "/success"; // url that the customer is sent to after confirming their order.
@@ -36,17 +36,17 @@ $merchant->checkout_url = "/checkout"; // url that the customer is sent to if
3636
/*
3737
* Article model
3838
*/
39-
$article = new Aplazame\BusinessModel\Article();
40-
$article->id = "89793238462643383279"; // The article ID.
41-
$article->name = "Reloj en oro blanco de 18 quilates y diamantes"; // Article name.
42-
$article->url = "http://shop.example.com/product.html"; // Article url.
43-
$article->image_url = "http://shop.example.com/product_image.png"; // Article image url.
44-
$article->quantity = 2; // Article quantity.
45-
$article->price = Aplazame\BusinessModel\Decimal::fromFloat(4020.00); // Article price (tax is not included). (4,020.00 €)
46-
$article->description = "Movimiento de cuarzo de alta precisión"; // Article description.
47-
$article->tax_rate = Aplazame\BusinessModel\Decimal::fromFloat(21.00); // Article tax rate. (21.00%)
48-
$article->discount = Aplazame\BusinessModel\Decimal::fromFloat(5.00); // The discount amount of the article. (5.00 €)
49-
$article->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the article. (2.00 %)
39+
$article = new stdClass();
40+
$article->id = "89793238462643383279"; // The article ID.
41+
$article->name = "Reloj en oro blanco de 18 quilates y diamantes"; // Article name.
42+
$article->url = "http://shop.example.com/product.html"; // Article url.
43+
$article->image_url = "http://shop.example.com/product_image.png"; // Article image url.
44+
$article->quantity = 2; // Article quantity.
45+
$article->price = Aplazame\Serializer\Decimal::fromFloat(4020.00); // Article price (tax is not included). (4,020.00 €)
46+
$article->description = "Movimiento de cuarzo de alta precisión"; // Article description.
47+
$article->tax_rate = Aplazame\Serializer\Decimal::fromFloat(21.00); // Article tax rate. (21.00%)
48+
$article->discount = Aplazame\Serializer\Decimal::fromFloat(5.00); // The discount amount of the article. (5.00 €)
49+
$article->discount_rate = Aplazame\Serializer\Decimal::fromFloat(2.00); // The rate discount of the article. (2.00 %)
5050

5151
// ... rest of articles in the shopping cart.
5252

@@ -59,21 +59,21 @@ $articles = array( $article, ... );
5959
/*
6060
* Order model
6161
*/
62-
$order = new Aplazame\BusinessModel\Order();
63-
$order->id = "28475648233786783165"; // Your order ID.
64-
$order->currency = "EUR"; // Currency code of the order.
65-
$order->tax_rate = Aplazame\BusinessModel\Decimal::fromFloat(21.00); // Order tax rate. (21.00%)
66-
$order->total_amount = Aplazame\BusinessModel\Decimal::fromFloat(4620.00); // Order total amount. (4,620.00 €)
67-
$order->articles = $articles; // Articles in cart.
68-
$order->discount = Aplazame\BusinessModel\Decimal::fromFloat(160.00); // The discount amount of the order. (160.00 €)
69-
$order->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the order. (2.00 %)
70-
$order->cart_discount = Aplazame\BusinessModel\Decimal::fromFloat(0.50); // The discount amount of the cart. (0.50 €)
71-
$order->cart_discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(3.00); // The rate discount of the cart. (3.00 %)
62+
$order = new stdClass();
63+
$order->id = "28475648233786783165"; // Your order ID.
64+
$order->currency = "EUR"; // Currency code of the order.
65+
$order->tax_rate = Aplazame\Serializer\Decimal::fromFloat(21.00); // Order tax rate. (21.00%)
66+
$order->total_amount = Aplazame\Serializer\Decimal::fromFloat(4620.00); // Order total amount. (4,620.00 €)
67+
$order->articles = $articles; // Articles in cart.
68+
$order->discount = Aplazame\Serializer\Decimal::fromFloat(160.00); // The discount amount of the order. (160.00 €)
69+
$order->discount_rate = Aplazame\Serializer\Decimal::fromFloat(2.00); // The rate discount of the order. (2.00 %)
70+
$order->cart_discount = Aplazame\Serializer\Decimal::fromFloat(0.50); // The discount amount of the cart. (0.50 €)
71+
$order->cart_discount_rate = Aplazame\Serializer\Decimal::fromFloat(3.00); // The rate discount of the cart. (3.00 %)
7272

7373
/*
7474
* Customer address model
7575
*/
76-
$customerAddress = new Aplazame\BusinessModel\Address();
76+
$customerAddress = new stdClass();
7777
$customerAddress->first_name = "John"; // Address first name.
7878
$customerAddress->last_name = "Coltrane"; // Address last name.
7979
$customerAddress->street = "Plaza del Angel nº10"; // Address street.
@@ -88,24 +88,24 @@ $customerAddress->address_addition = "Cerca de la plaza Santa Ana"; // Address a
8888
/*
8989
* Customer model
9090
*/
91-
$customer = new Aplazame\BusinessModel\Customer();
92-
$customer->id = "1618"; // Customer ID.
93-
$customer->email = "[email protected]"; // The customer email.
94-
$customer->type = Aplazame\BusinessModel\Customer::TYPE_EXISTING; // Customer type. Other options are: TYPE_GUEST and TYPE_NEW.
95-
$customer->gender = Aplazame\BusinessModel\Customer::GENDER_UNKNOWN; // Customer gender. Other options are: GENDER_MALE, GENDER_FEMALE and GENDER_NOT_APPLICABLE.
96-
$customer->first_name = "John"; // Customer first name.
97-
$customer->last_name = "Coltrane"; // Customer last name.
98-
$customer->birthday = DateTime::createFromFormat(DateTime::ISO8601, "1990-08-21T13:56:45+0000"); // Customer birthday.
99-
$customer->language = "es"; // Customer language preferences.
100-
$customer->date_joined = DateTime::createFromFormat(DateTime::ISO8601, "2014-08-21T13:56:45+0000"); // A datetime designating when the customer account was created.
101-
$customer->last_login = DateTime::createFromFormat(DateTime::ISO8601, "2014-08-27T19:57:56+0000"); // A datetime of the customer last login.
102-
$customer->address = $customerAddress; // Customer address.
91+
$customer = new stdClass();
92+
$customer->id = "1618"; // Customer ID.
93+
$customer->email = "[email protected]"; // The customer email.
94+
$customer->type = 'e'; // Customer type, the choices are g:guest, n:new, e:existing.
95+
$customer->gender = 0; // Customer gender, the choices are 0: not known, 1: male, 2:female, 3: not applicable.
96+
$customer->first_name = "John"; // Customer first name.
97+
$customer->last_name = "Coltrane"; // Customer last name.
98+
$customer->birthday = Aplazame\Serializer\Date::fromDateTime(new DateTime("1990-08-21 13:56:45")); // Customer birthday.
99+
$customer->language = "es"; // Customer language preferences.
100+
$customer->date_joined = Aplazame\Serializer\Date::fromDateTime(new DateTime("2014-08-21 13:56:45")); // A datetime designating when the customer account was created.
101+
$customer->last_login = Aplazame\Serializer\Date::fromDateTime(new DateTime("2014-08-27 19:57:56")); // A datetime of the customer last login.
102+
$customer->address = $customerAddress; // Customer address.
103103

104104

105105
/*
106106
* Billing address model
107107
*/
108-
$billingAddress = new Aplazame\BusinessModel\Address();
108+
$billingAddress = new stdClass();
109109
$billingAddress->first_name = "Bill"; // Billing first name.
110110
$billingAddress->last_name = "Evans"; // Billing last name.
111111
$billingAddress->street = "Calle de Las Huertas 22"; // Billing street.
@@ -121,28 +121,28 @@ $billingAddress->address_addition = "Cerca de la pizzería"; // Billing address
121121
/*
122122
* Shipping info model
123123
*/
124-
$shippingInfo = new Aplazame\BusinessModel\Address();
125-
$shippingInfo->first_name = "Django"; // Shipping first name.
126-
$shippingInfo->last_name = "Reinhard"; // Shipping last name.
127-
$shippingInfo->street = "Plaza del Angel nº10"; // Shipping street.
128-
$shippingInfo->city = "Madrid"; // Shipping city.
129-
$shippingInfo->state = "Madrid"; // Shipping state.
130-
$shippingInfo->country = "ES"; // Shipping country code.
131-
$shippingInfo->postcode = "28012"; // Shipping postcode.
132-
$shippingInfo->name = "Planet Express"; // Shipping name.
133-
$shippingInfo->price = Aplazame\BusinessModel\Decimal::fromFloat(5.00); // Shipping price (tax is not included). (5.00 €)
134-
$shippingInfo->phone = "616123456"; // Shipping phone number.
135-
$shippingInfo->alt_phone = "+34917909930"; // Shipping alternative phone.
136-
$shippingInfo->address_addition = "Cerca de la plaza Santa Ana"; // Shipping address addition.
137-
$shippingInfo->tax_rate = Aplazame\BusinessModel\Decimal::fromFloat(21.00); // Shipping tax rate. (21.00%)
138-
$shippingInfo->discount = Aplazame\BusinessModel\Decimal::fromFloat(1.00); // The discount amount of the shipping. (1.00 €)
139-
$shippingInfo->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the shipping. (2.00 %)
124+
$shippingInfo = new stdClass();
125+
$shippingInfo->first_name = "Django"; // Shipping first name.
126+
$shippingInfo->last_name = "Reinhard"; // Shipping last name.
127+
$shippingInfo->street = "Plaza del Angel nº10"; // Shipping street.
128+
$shippingInfo->city = "Madrid"; // Shipping city.
129+
$shippingInfo->state = "Madrid"; // Shipping state.
130+
$shippingInfo->country = "ES"; // Shipping country code.
131+
$shippingInfo->postcode = "28012"; // Shipping postcode.
132+
$shippingInfo->name = "Planet Express"; // Shipping name.
133+
$shippingInfo->price = Aplazame\Serializer\Decimal::fromFloat(5.00); // Shipping price (tax is not included). (5.00 €)
134+
$shippingInfo->phone = "616123456"; // Shipping phone number.
135+
$shippingInfo->alt_phone = "+34917909930"; // Shipping alternative phone.
136+
$shippingInfo->address_addition = "Cerca de la plaza Santa Ana"; // Shipping address addition.
137+
$shippingInfo->tax_rate = Aplazame\Serializer\Decimal::fromFloat(21.00); // Shipping tax rate. (21.00%)
138+
$shippingInfo->discount = Aplazame\Serializer\Decimal::fromFloat(1.00); // The discount amount of the shipping. (1.00 €)
139+
$shippingInfo->discount_rate = Aplazame\Serializer\Decimal::fromFloat(2.00); // The rate discount of the shipping. (2.00 %)
140140

141141

142142
/*
143143
* Checkout model
144144
*/
145-
$checkout = new Aplazame\BusinessModel\Checkout();
145+
$checkout = new stdClass();
146146
$checkout->toc = true;
147147
$checkout->merchant = $merchant;
148148
$checkout->order = $order;
@@ -154,7 +154,7 @@ $checkout->shipping = $shippingInfo;
154154
In your view you will need to put an snippet similar to this one.
155155
```html
156156
<script>
157-
aplazame.checkout( <?php echo json_encode($checkout->jsonSerialize()); ?> );
157+
aplazame.checkout( <?php echo json_encode(Aplazame\Serializer\JsonSerializer::serializeValue($checkout)); ?> );
158158
</script>
159159
```
160160

src/BusinessModel/AbstractModel.php

-64
This file was deleted.

src/BusinessModel/Address.php

-76
This file was deleted.

0 commit comments

Comments
 (0)