Skip to content

Commit

Permalink
Merge pull request #16 from Plasma-Platform/feature/QUASAR-3835/custo…
Browse files Browse the repository at this point in the history
…mer-portal

QUASAR-3835 - add get customer portal link
  • Loading branch information
dimanovoseltsev authored Nov 17, 2022
2 parents a498ddc + 4596bea commit 2e83ee1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TemplateMonster API2 Client
Installation
------------

### Using Composer (recommended)
Using Composer (recommended)

Add the dependency in your `composer.json`

Expand All @@ -25,7 +25,7 @@ Add the dependency in your `composer.json`
Usage
-----

### Templates
# Templates

```php
// Create API instance
Expand Down Expand Up @@ -58,9 +58,9 @@ $template = $api->getTemplate ($template_id);

```

### Orders
# Orders

Receive a status of Order
## Receive a status of Order

``` php

Expand All @@ -72,7 +72,7 @@ echo $status->getStatusName ();

```

Get all Statuses
## Get all Statuses

```php

Expand All @@ -87,7 +87,7 @@ foreach ($statuses as $status)

```

Create an Order
## Create an Order

``` php

Expand Down Expand Up @@ -164,14 +164,49 @@ $result = $api->createOrder ($order);

```

Get customer management portal link
## Get customer management portal link

```php
// Create API instance
$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken');
$subscriptionId = 'abc12345678';
$link = $api->getCustomerManagementPortalLink($subscriptionId);

```
Success response
```php
API2Client\Entities\Order\CustomerPortal Object
(
[link:protected] => https://billing.stripe.com/p/session/test_YWNjdF8VGb1NE
[status:API2Client\Entities\Order\CustomerPortal:private] => 1
[messages:API2Client\Entities\Order\CustomerPortal:private] => Array()
)
```

Response if not exist subscriptions
```php
API2Client\Entities\Order\CustomerPortal Object
(
[link:protected] =>
[status:API2Client\Entities\Order\CustomerPortal:private] =>
[messages:API2Client\Entities\Order\CustomerPortal:private] => Array
(
[0] => Subscription does not exists
)
)
```

Response if payment method not supported customer management portal
```php
API2Client\Entities\Order\CustomerPortal Object
(
[link:protected] =>
[status:API2Client\Entities\Order\CustomerPortal:private] =>
[messages:API2Client\Entities\Order\CustomerPortal:private] => Array
(
[0] => Payment method not supported customer management portal
)
)
```

Error Handling
Expand Down
44 changes: 44 additions & 0 deletions src/API2Client/Entities/Order/CustomerPortal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ class CustomerPortal
{
protected $link;

/**
* @var bool
*/
private $status = false;

/**
* @var array
*/
private $messages = array();

/**
* @return string
*/
Expand All @@ -26,4 +36,38 @@ public function setLink($link)
{
$this->link = $link;
}

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

/**
* @param array $messages
*/
public function setMessages($messages)
{
$this->messages = $messages;
}

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

/**
* @param boolean $status
* @return $this
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
}
6 changes: 6 additions & 0 deletions src/API2Client/Setters/CustomerPortalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public function create($data)
{
$portal = new CustomerPortal();
$portal->setLink($this->getValue('link', $data, null));
$portal->setStatus($this->getValue('status', $data, false));
$messages = $this->getValue('messages', $data, array());

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

return $portal;
}
Expand Down

0 comments on commit 2e83ee1

Please sign in to comment.