|
| 1 | +# Aplazame PHP SDK |
| 2 | + |
| 3 | +[](https://aplazame.com) |
| 4 | + |
| 5 | +[Aplazame](https://aplazame.com), a consumer credit company, offers a payment system that can be |
| 6 | +used by online buyers to receive funding for their purchases. |
| 7 | + |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +You can use [Composer](https://getcomposer.org): |
| 12 | + |
| 13 | +```bash |
| 14 | +composer require aplazame/aplazame-api-sdk |
| 15 | +``` |
| 16 | + |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | + |
| 21 | +### Checkout |
| 22 | + |
| 23 | +This SDK provides a tree of objects for guide you about to craft the checkout model. |
| 24 | + |
| 25 | +```php |
| 26 | +/* |
| 27 | + * Merchant model |
| 28 | + */ |
| 29 | +$merchant = new Aplazame\BusinessModel\Merchant( |
| 30 | + "/confirm", // url that the JS client sent to confirming the order. |
| 31 | + "/cancel", // url that the customer is sent to if there is an error in the checkout. |
| 32 | + "/success" // url that the customer is sent to after confirming their order. |
| 33 | +); |
| 34 | +$merchant->checkout_url = "/checkout"; // url that the customer is sent to if the customer chooses to back to the e-commerce, by default is /. |
| 35 | + |
| 36 | + |
| 37 | +/* |
| 38 | + * Article model |
| 39 | + */ |
| 40 | +$article = new Aplazame\BusinessModel\Article( |
| 41 | + "89793238462643383279", // The article ID. |
| 42 | + "Reloj en oro blanco de 18 quilates y diamantes", // Article name. |
| 43 | + "http://shop.example.com/product.html", // Article url. |
| 44 | + "http://shop.example.com/product_image.png", // Article image url. |
| 45 | + 2, // Article quantity. |
| 46 | + Aplazame\BusinessModel\Decimal::fromFloat(4020.00) // Article price (tax is not included). (4,020.00 €) |
| 47 | +); |
| 48 | +$article->description = "Movimiento de cuarzo de alta precisión"; // Article description. |
| 49 | +$article->tax_rate = Aplazame\BusinessModel\Decimal::fromFloat(21.00); // Article tax rate. (21.00%) |
| 50 | +$article->discount = Aplazame\BusinessModel\Decimal::fromFloat(5.00); // The discount amount of the article. (5.00 €) |
| 51 | +$article->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the article. (2.00 %) |
| 52 | + |
| 53 | +// ... rest of articles in the shopping cart. |
| 54 | + |
| 55 | +/* |
| 56 | + * Articles collection |
| 57 | + */ |
| 58 | +$articles = array( $article, ... ); |
| 59 | + |
| 60 | + |
| 61 | +/* |
| 62 | + * Order model |
| 63 | + */ |
| 64 | +$order = new Aplazame\BusinessModel\Order( |
| 65 | + "28475648233786783165", // Your order ID. |
| 66 | + "EUR", // Currency code of the order. |
| 67 | + Aplazame\BusinessModel\Decimal::fromFloat(21.00), // Order tax rate. (21.00%) |
| 68 | + Aplazame\BusinessModel\Decimal::fromFloat(4620.00), // Order total amount. (4,620.00 €) |
| 69 | + $articles // Articles in cart. |
| 70 | +); |
| 71 | +$order->discount = Aplazame\BusinessModel\Decimal::fromFloat(160.00); // The discount amount of the order. (160.00 €) |
| 72 | +$order->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the order. (2.00 %) |
| 73 | +$order->cart_discount = Aplazame\BusinessModel\Decimal::fromFloat(0.50); // The discount amount of the cart. (0.50 €) |
| 74 | +$order->cart_discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(3.00); // The rate discount of the cart. (3.00 %) |
| 75 | + |
| 76 | +/* |
| 77 | + * Customer address model |
| 78 | + */ |
| 79 | +$customerAddress = new Aplazame\BusinessModel\Address( |
| 80 | + "John", // Address first name. |
| 81 | + "Coltrane", // Address last name. |
| 82 | + "Plaza del Angel nº10", // Address street. |
| 83 | + "Madrid", // Address city. |
| 84 | + "Madrid", // Address state. |
| 85 | + "ES", // Address country code. |
| 86 | + "28012" // Address postcode. |
| 87 | +); |
| 88 | +$customerAddress->phone = "616123456"; // Address phone number. |
| 89 | +$customerAddress->alt_phone = "+34917909930"; // Address alternative phone. |
| 90 | +$customerAddress->address_addition = "Cerca de la plaza Santa Ana"; // Address addition. |
| 91 | + |
| 92 | +/* |
| 93 | + * Customer model |
| 94 | + */ |
| 95 | +$customer = new Aplazame\BusinessModel\Customer( |
| 96 | + "1618", // Customer ID. |
| 97 | + " [email protected]", // The customer email. |
| 98 | + Aplazame\BusinessModel\Customer::TYPE_EXISTING, // Customer type. Other options are: TYPE_GUEST and TYPE_NEW. |
| 99 | + Aplazame\BusinessModel\Customer::GENDER_UNKNOWN, // Customer gender. Other options are: GENDER_MALE, GENDER_FEMALE and GENDER_NOT_APPLICABLE. |
| 100 | +); |
| 101 | +$customer->first_name = "John"; // Customer first name. |
| 102 | +$customer->last_name = "Coltrane"; // Customer last name. |
| 103 | +$customer->birthday = DateTime::createFromFormat(DateTime::ISO8601, "1990-08-21T13:56:45+0000"); // Customer birthday. |
| 104 | +$customer->language = "es"; // Customer language preferences. |
| 105 | +$customer->date_joined = DateTime::createFromFormat(DateTime::ISO8601, "2014-08-21T13:56:45+0000"); // A datetime designating when the customer account was created. |
| 106 | +$customer->last_login = DateTime::createFromFormat(DateTime::ISO8601, "2014-08-27T19:57:56+0000"); // A datetime of the customer last login. |
| 107 | +$customer->address = $customerAddress; // Customer address. |
| 108 | + |
| 109 | + |
| 110 | +/* |
| 111 | + * Billing address model |
| 112 | + */ |
| 113 | +$billingBilling = new Aplazame\BusinessModel\Address( |
| 114 | + "Bill", // Billing first name. |
| 115 | + "Evans", // Billing last name. |
| 116 | + "Calle de Las Huertas 22", // Billing street. |
| 117 | + "Madrid", // Billing city. |
| 118 | + "Madrid", // Billing state. |
| 119 | + "ES", // Billing country code. |
| 120 | + "28014" // Billing postcode. |
| 121 | +); |
| 122 | +$billingAddress->phone = "+34914298407"; // Billing phone number. |
| 123 | +$billingAddress->alt_phone = null; // Billing alternative phone. |
| 124 | +$billingAddress->address_addition = "Cerca de la pizzería"; // Billing address addition. |
| 125 | + |
| 126 | + |
| 127 | +/* |
| 128 | + * Shipping info model |
| 129 | + */ |
| 130 | +$shippingInfo = new Aplazame\BusinessModel\Address( |
| 131 | + "Django", // Shipping first name. |
| 132 | + "Reinhard", // Shipping last name. |
| 133 | + "Plaza del Angel nº10", // Shipping street. |
| 134 | + "Madrid", // Shipping city. |
| 135 | + "Madrid", // Shipping state. |
| 136 | + "ES", // Shipping country code. |
| 137 | + "28012", // Shipping postcode. |
| 138 | + "Planet Express", // Shipping name. |
| 139 | + Aplazame\BusinessModel\Decimal::fromFloat(5.00), // Shipping price (tax is not included). (5.00 €) |
| 140 | +); |
| 141 | +$shippingInfo->phone = "616123456"; // Shipping phone number. |
| 142 | +$shippingInfo->alt_phone = "+34917909930"; // Shipping alternative phone. |
| 143 | +$shippingInfo->address_addition = "Cerca de la plaza Santa Ana"; // Shipping address addition. |
| 144 | +$shippingInfo->tax_rate = Aplazame\BusinessModel\Decimal::fromFloat(21.00); // Shipping tax rate. (21.00%) |
| 145 | +$shippingInfo->discount = Aplazame\BusinessModel\Decimal::fromFloat(1.00); // The discount amount of the shipping. (1.00 €) |
| 146 | +$shippingInfo->discount_rate = Aplazame\BusinessModel\Decimal::fromFloat(2.00); // The rate discount of the shipping. (2.00 %) |
| 147 | + |
| 148 | + |
| 149 | +/* |
| 150 | + * Checkout model |
| 151 | + */ |
| 152 | +$checkout = new Aplazame\BusinessModel\Checkout( |
| 153 | + true, // TOC |
| 154 | + $merchant, |
| 155 | + $order, |
| 156 | + $customer |
| 157 | +); |
| 158 | +$checkout->billing = $billingAddress; |
| 159 | +$checkout->shipping = $shippingInfo; |
| 160 | +``` |
| 161 | + |
| 162 | +In your view you will need to put an snippet similar to this one. |
| 163 | +```html |
| 164 | +<script> |
| 165 | + aplazame.checkout( <?php echo $checkout->jsonSerialize(); ?> ); |
| 166 | +</script> |
| 167 | +``` |
| 168 | +
|
| 169 | +### API Calls |
| 170 | +
|
| 171 | +This SDK assist you for craft a well formatted API request and decode the response back to PHP. |
| 172 | +
|
| 173 | +```php |
| 174 | +$apiBaseUri = 'http://api.aplazame.com'; |
| 175 | +$environment = Aplazame\Api\Client::ENVIRONMENT_SANDBOX; // When you are ready use Aplazame\Api\Client::ENVIRONMENT_PRODUCTION |
| 176 | +$accessToken = 'api private key'; |
| 177 | +
|
| 178 | +$aplazameApiClient = new Aplazame\Api\Client($apiBaseUri, $environment, $accessToken); |
| 179 | +try { |
| 180 | + $result = $aplazameApiClient->get('/me'); |
| 181 | +} catch (Aplazame\Api\ApiCommunicationException $apiCommunicationException) { |
| 182 | + // A network error has occurred while sending the request or receiving the response. |
| 183 | +
|
| 184 | + // Retry |
| 185 | +} catch (Aplazame\Api\DeserializeException $deserializationException) { |
| 186 | + // Nobody knows when this happen, may an HTTP Proxy on our side or on your side started to return HTML responses with errors. |
| 187 | +
|
| 188 | + // Retry |
| 189 | +} catch (Aplazame\Api\ApiServerException $apiServerException) { |
| 190 | + // Our server has crashed. We promise to fix it ASAP. |
| 191 | +
|
| 192 | + echo 'Error type', $apiServerException->getType(), PHP_EOL; |
| 193 | + echo 'Error message', $apiServerException->getMessage(), PHP_EOL; |
| 194 | +
|
| 195 | + $rawErrorWithErrorDetails = $apiServerException->getError(); |
| 196 | +
|
| 197 | +} catch (Aplazame\Api\ApiClientException $apiClientException) { |
| 198 | + // Your client has sent an invalid request. Please check your code. |
| 199 | +
|
| 200 | + echo 'Error type', $apiClientException->getType(), PHP_EOL; |
| 201 | + echo 'Error message', $apiClientException->getMessage(), PHP_EOL; |
| 202 | +
|
| 203 | + $rawErrorWithErrorDetails = $apiClientException->getError(); |
| 204 | +} |
| 205 | +print_r($result); |
| 206 | +``` |
| 207 | +
|
| 208 | +
|
| 209 | +## Documentation |
| 210 | +
|
| 211 | +Documentation is available at http://docs.aplazame.com. |
0 commit comments