Skip to content

Commit c2512b4

Browse files
BIL-34 - add getInvoiceUrl and getTransactionStatusUrl methods
1 parent 2e83ee1 commit c2512b4

File tree

4 files changed

+357
-2
lines changed

4 files changed

+357
-2
lines changed

README.md

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,206 @@ API2Client\Entities\Order\CustomerPortal Object
209209
)
210210
```
211211

212+
TemplateMonster API2 Client
213+
===========================
214+
215+
Installation
216+
------------
217+
218+
Using Composer (recommended)
219+
220+
Add the dependency in your `composer.json`
221+
222+
``` json
223+
{
224+
"repositories": [
225+
{
226+
"type": "vcs",
227+
"url": "https://github.com/M0nsterLabs/api2client.git"
228+
}
229+
],
230+
"require": {
231+
"templatemonster/api2-client":"dev-master"
232+
}
233+
}
234+
235+
```
236+
Usage
237+
-----
238+
239+
# Templates
240+
241+
```php
242+
// Create API instance
243+
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
244+
245+
246+
// Receive a count of all Templates
247+
$templatesCount = $api->getTemplatesCount ()
248+
249+
// Receive a list of Templates
250+
$offset = 0;
251+
$limit = 20;
252+
253+
$templates = $api->getTemplatesList ($offset, $limit);
254+
255+
/** @var API2Client\Entities\Template $template */
256+
foreach ($templates as $template)
257+
{
258+
// Template pages
259+
$templatePages = $template->getPages ();
260+
}
261+
262+
263+
// Receive a single Template
264+
$template_id = 30506;
265+
266+
/** @var API2Client\Entities\Template $template */
267+
$template = $api->getTemplate ($template_id);
268+
269+
270+
```
271+
272+
# Orders
273+
274+
## Receive a status of Order
275+
276+
``` php
277+
278+
/** @var \API2Client\Entities\Order\Status $status */
279+
$status = $api->getOrderStatus ('rgRvuzZQP9OoALyEKGKA');
280+
281+
// print status title
282+
echo $status->getStatusName ();
283+
284+
```
285+
286+
## Get all Statuses
287+
288+
```php
289+
290+
$statuses = $api->getOrderStatuses ();
291+
292+
/** @var \API2Client\Entities\Order\Status $status */
293+
foreach ($statuses as $status)
294+
{
295+
echo $status->getStatusCode ();
296+
echo $status->getStatusName ();
297+
}
298+
299+
```
300+
301+
## Create an Order
302+
303+
``` php
304+
305+
$order = new \API2Client\Entities\Order ();
306+
307+
$order->setProjectId (0);
308+
$order->setAmount (174);
309+
$order->setBonusesAmount (0);
310+
311+
$billingInfo = new \API2Client\Entities\Order\BillingInfo ();
312+
313+
$billingInfo->setAccountSId ('u03e9b361c607ju37707iyo8s273sibh9z8lka2e6kt3276e41g11e7f6ozjm0cv7c4a40piorf408bb203of6wnbx2v24xfo61nwr4o7960tu898w50u4bu51zn2fa1');
314+
$billingInfo->setAddress ('Torenplein Str');
315+
$billingInfo->setCityName ('Hasselt');
316+
$billingInfo->setContactPhone (74933242323);
317+
$billingInfo->setEmail ('[email protected]');
318+
$billingInfo->setCountryISO2 ('BE');
319+
$billingInfo->setFullName ('Mark Twain');
320+
$billingInfo->setPhone (74933242323);
321+
$billingInfo->setPostalCode (12123);
322+
$billingInfo->setStateISO2 ('XX');
323+
324+
$order->setBillingInfo ($billingInfo);
325+
326+
$productInfo1 = new \API2Client\Entities\Order\ProductInfo ();
327+
328+
$productInfo1->setProductId (49334);
329+
$productInfo1->setPrice (69);
330+
$productInfo1->setType ('template');
331+
332+
$order->addProductInfo ($productInfo1);
333+
334+
$productInfo2 = new \API2Client\Entities\Order\ProductInfo ();
335+
336+
$productInfo2->setProductId (49334);
337+
$productInfo2->setPrice (75);
338+
$productInfo2->setType ('template');
339+
340+
$order->addProductInfo ($productInfo2);
341+
342+
343+
$externalProduct = new \API2Client\Entities\Order\ProductInfo ();
344+
345+
$externalProduct->setProductId (0);
346+
$externalProduct->setPrice (33);
347+
$externalProduct->setFinalPrice (30);
348+
$externalProduct->setName ('Headspace Journey Subscription');
349+
$externalProduct->setType ('external');
350+
351+
$order->addProductInfo ($externalProduct);
352+
353+
$trackingInfo = new \API2Client\Entities\Order\TrackingInfo ();
354+
355+
$trackingInfo->setRmsLocale ('EN');
356+
$trackingInfo->setRefererUrl ('http://localhost:8081/');
357+
$trackingInfo->setUserAgent ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36');
358+
$trackingInfo->setUserIPAddress ('10.0.2.2');
359+
$trackingInfo->setUserLanguage ('en-US,en;q=0.8,uk;q=0.6,ru;q=0.4');
360+
$trackingInfo->setUserLocalTime ('Tue May 27 2014 10:31:05 GMT+0300 (EEST)');
361+
362+
$order->setTrackingInfo ($trackingInfo);
363+
364+
$paymentInfo = new \API2Client\Entities\Order\PaymentInfo ();
365+
366+
$paymentInfo->setCurrencyId (0);
367+
$paymentInfo->setCurrencyRate (1);
368+
$paymentInfo->setPaymentId (2);
369+
370+
$order->setPaymentInfo ($paymentInfo);
371+
372+
/** @var \API2Client\Entities\OrderCreated $result */
373+
$result = $api->createOrder ($order);
374+
375+
376+
```
377+
378+
## Get url on invoice url by transaction
379+
380+
```php
381+
// Create API instance
382+
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
383+
$link = $api->getInvoiceUrl('abc12345678');
384+
```
385+
Success response
386+
```php
387+
API2Client\Entities\Order\BillingPortal Object
388+
(
389+
[url:protected] => https://www.domain.com/invoice/a1?token=token
390+
[status:API2Client\Entities\Order\BillingPortal:private] => 1
391+
[messages:API2Client\Entities\Order\BillingPortal:private] => Array()
392+
)
393+
```
394+
395+
## Get url on status page url by transaction
396+
397+
```php
398+
// Create API instance
399+
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
400+
$link = $api->getTransactionStatusUrl('abc12345678');
401+
```
402+
Success response
403+
```php
404+
API2Client\Entities\Order\BillingPortal Object
405+
(
406+
[url:protected] => https://www.domain.com/transaction-statuses/a1?token=token
407+
[status:API2Client\Entities\Order\BillingPortal:private] => 1
408+
[messages:API2Client\Entities\Order\BillingPortal:private] => Array()
409+
)
410+
```
411+
212412
Error Handling
213413
--------------
214414

@@ -229,4 +429,4 @@ catch (\API2Client\Client\APIException $e)
229429
$e->getMessage ();
230430
}
231431

232-
```
432+
```

src/API2Client/Api.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use API2Client\Entities\Order\Status;
1616
use API2Client\Entities\OrderCreated;
1717
use API2Client\Entities\Subscription;
18+
use API2Client\Setters\BillingPortalFactory;
1819
use API2Client\Setters\CustomerPortalFactory;
1920
use API2Client\Setters\OrderCreatedFactory;
2021
use API2Client\Setters\OrderCurrencyFactory;
@@ -23,7 +24,6 @@
2324
use API2Client\Setters\OrderPaymentFactory;
2425
use API2Client\Setters\OrderStatusesFactory;
2526
use API2Client\Setters\OrderStatusFactory;
26-
use API2Client\Setters\SubscriptionCreatedFactory;
2727
use API2Client\Setters\SubscriptionResultFactory;
2828
use API2Client\Setters\TemplateFactory;
2929
use InvalidArgumentException;
@@ -415,4 +415,60 @@ public function getCustomerManagementPortalLink($subscriptionId)
415415
$factory = new CustomerPortalFactory();
416416
return $factory->create($response->getResult());
417417
}
418+
419+
420+
/**
421+
* Get url on invoice url by transaction
422+
*
423+
* @return Entities\Order\BillingPortal
424+
* @throws ApiException
425+
*/
426+
public function getInvoiceUrl($transactionId)
427+
{
428+
if (empty($transactionId) || !is_string($transactionId)) {
429+
throw new InvalidArgumentException('Bad Argument');
430+
}
431+
432+
$response = $this->client
433+
->call(
434+
'orders.getInvoiceUrl',
435+
array('transaction_id' => $transactionId),
436+
HttpClient::REQUEST_RAW
437+
);
438+
439+
if (!$response->isSuccess()) {
440+
throw new ApiException ($response->getErrorMessage());
441+
}
442+
443+
$factory = new BillingPortalFactory();
444+
return $factory->create($response->getResult());
445+
}
446+
447+
448+
/**
449+
* Get url on status page url by transaction
450+
*
451+
* @return Entities\Order\BillingPortal
452+
* @throws ApiException
453+
*/
454+
public function getTransactionStatusUrl($transactionId)
455+
{
456+
if (empty($transactionId) || !is_string($transactionId)) {
457+
throw new InvalidArgumentException('Bad Argument');
458+
}
459+
460+
$response = $this->client
461+
->call(
462+
'orders.getTransactionStatusUrl',
463+
array('transaction_id' => $transactionId),
464+
HttpClient::REQUEST_RAW
465+
);
466+
467+
if (!$response->isSuccess()) {
468+
throw new ApiException ($response->getErrorMessage());
469+
}
470+
471+
$factory = new BillingPortalFactory();
472+
return $factory->create($response->getResult());
473+
}
418474
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace API2Client\Entities\Order;
4+
5+
/**
6+
* Class BillingPortal
7+
* @package API2Client\Entities\Order
8+
* @property string $url
9+
* @property array $messages
10+
* @property bool $status
11+
*/
12+
class BillingPortal
13+
{
14+
private $url;
15+
private $status = false;
16+
private $messages = array();
17+
18+
/**
19+
* @return mixed
20+
*/
21+
public function getUrl()
22+
{
23+
return $this->url;
24+
}
25+
26+
/**
27+
* @param mixed $url
28+
* @return BillingPortal
29+
*/
30+
public function setUrl($url)
31+
{
32+
$this->url = $url;
33+
return $this;
34+
}
35+
36+
/**
37+
* @return bool
38+
*/
39+
public function isStatus()
40+
{
41+
return $this->status;
42+
}
43+
44+
/**
45+
* @param bool $status
46+
* @return BillingPortal
47+
*/
48+
public function setStatus($status)
49+
{
50+
$this->status = $status;
51+
return $this;
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
public function getMessages()
58+
{
59+
return $this->messages;
60+
}
61+
62+
/**
63+
* @param array $messages
64+
* @return BillingPortal
65+
*/
66+
public function setMessages($messages)
67+
{
68+
$this->messages = $messages;
69+
return $this;
70+
}
71+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace API2Client\Setters;
4+
5+
use API2Client\Entities\Order\BillingPortal;
6+
7+
class BillingPortalFactory extends FactoryAbstract implements FactoryInterface
8+
{
9+
/**
10+
* Create Entity Object from array
11+
*
12+
* @param array $data
13+
* @return BillingPortal
14+
*/
15+
public function create($data)
16+
{
17+
$portal = new BillingPortal();
18+
$portal->setUrl($this->getValue('url', $data, null));
19+
$portal->setStatus((bool)$this->getValue('status', $data, false));
20+
$messages = $this->getValue('messages', $data, array());
21+
22+
if (is_array($messages) && !empty($messages)) {
23+
$portal->setMessages($messages);
24+
}
25+
26+
return $portal;
27+
}
28+
}

0 commit comments

Comments
 (0)