Skip to content

Commit

Permalink
Merge pull request #17 from Plasma-Platform/features/BIL-34/frontend
Browse files Browse the repository at this point in the history
BIL-34 - add getInvoiceUrl and getTransactionStatusUrl methods
  • Loading branch information
dimanovoseltsev authored Apr 11, 2024
2 parents 2e83ee1 + 758b4cf commit 01a3fe0
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 2 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,40 @@ API2Client\Entities\Order\CustomerPortal Object
)
```

## Get url on invoice url by transaction

```php
// Create API instance
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
$link = $api->getInvoiceUrl('abc12345678');
```
Success response
```php
API2Client\Entities\Order\BillingPortal Object
(
[url:protected] => https://www.domain.com/invoice/a1?token=token
[status:API2Client\Entities\Order\BillingPortal:private] => 1
[messages:API2Client\Entities\Order\BillingPortal:private] => Array()
)
```

## Get url on status page url by transaction

```php
// Create API instance
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
$link = $api->getTransactionStatusUrl('abc12345678');
```
Success response
```php
API2Client\Entities\Order\BillingPortal Object
(
[url:protected] => https://www.domain.com/transaction-statuses/a1?token=token
[status:API2Client\Entities\Order\BillingPortal:private] => 1
[messages:API2Client\Entities\Order\BillingPortal:private] => Array()
)
```

Error Handling
--------------

Expand All @@ -229,4 +263,4 @@ catch (\API2Client\Client\APIException $e)
$e->getMessage ();
}

```
```
58 changes: 57 additions & 1 deletion src/API2Client/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use API2Client\Entities\Order\Status;
use API2Client\Entities\OrderCreated;
use API2Client\Entities\Subscription;
use API2Client\Setters\BillingPortalFactory;
use API2Client\Setters\CustomerPortalFactory;
use API2Client\Setters\OrderCreatedFactory;
use API2Client\Setters\OrderCurrencyFactory;
Expand All @@ -23,7 +24,6 @@
use API2Client\Setters\OrderPaymentFactory;
use API2Client\Setters\OrderStatusesFactory;
use API2Client\Setters\OrderStatusFactory;
use API2Client\Setters\SubscriptionCreatedFactory;
use API2Client\Setters\SubscriptionResultFactory;
use API2Client\Setters\TemplateFactory;
use InvalidArgumentException;
Expand Down Expand Up @@ -415,4 +415,60 @@ public function getCustomerManagementPortalLink($subscriptionId)
$factory = new CustomerPortalFactory();
return $factory->create($response->getResult());
}


/**
* Get url on invoice url by transaction
*
* @return Entities\Order\BillingPortal
* @throws ApiException
*/
public function getInvoiceUrl($transactionId)
{
if (empty($transactionId) || !is_string($transactionId)) {
throw new InvalidArgumentException('Bad Argument');
}

$response = $this->client
->call(
'orders.getInvoiceUrl',
array('transaction_id' => $transactionId),
HttpClient::REQUEST_RAW
);

if (!$response->isSuccess()) {
throw new ApiException ($response->getErrorMessage());
}

$factory = new BillingPortalFactory();
return $factory->create($response->getResult());
}


/**
* Get url on status page url by transaction
*
* @return Entities\Order\BillingPortal
* @throws ApiException
*/
public function getTransactionStatusUrl($transactionId)
{
if (empty($transactionId) || !is_string($transactionId)) {
throw new InvalidArgumentException('Bad Argument');
}

$response = $this->client
->call(
'orders.getTransactionStatusUrl',
array('transaction_id' => $transactionId),
HttpClient::REQUEST_RAW
);

if (!$response->isSuccess()) {
throw new ApiException ($response->getErrorMessage());
}

$factory = new BillingPortalFactory();
return $factory->create($response->getResult());
}
}
71 changes: 71 additions & 0 deletions src/API2Client/Entities/Order/BillingPortal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace API2Client\Entities\Order;

/**
* Class BillingPortal
* @package API2Client\Entities\Order
* @property string $url
* @property array $messages
* @property bool $status
*/
class BillingPortal
{
private $url;
private $status = false;
private $messages = array();

/**
* @return mixed
*/
public function getUrl()
{
return $this->url;
}

/**
* @param mixed $url
* @return BillingPortal
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}

/**
* @return bool
*/
public function isStatus()
{
return $this->status;
}

/**
* @param bool $status
* @return BillingPortal
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}

/**
* @return array
*/
public function getMessages()
{
return $this->messages;
}

/**
* @param array $messages
* @return BillingPortal
*/
public function setMessages($messages)
{
$this->messages = $messages;
return $this;
}
}
28 changes: 28 additions & 0 deletions src/API2Client/Setters/BillingPortalFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace API2Client\Setters;

use API2Client\Entities\Order\BillingPortal;

class BillingPortalFactory extends FactoryAbstract implements FactoryInterface
{
/**
* Create Entity Object from array
*
* @param array $data
* @return BillingPortal
*/
public function create($data)
{
$portal = new BillingPortal();
$portal->setUrl($this->getValue('url', $data, null));
$portal->setStatus((bool)$this->getValue('status', $data, false));
$messages = $this->getValue('messages', $data, array());

if (is_array($messages) && !empty($messages)) {
$portal->setMessages($messages);
}

return $portal;
}
}

0 comments on commit 01a3fe0

Please sign in to comment.