From 4596bea48020b91237153793ee5e713ed62acc45 Mon Sep 17 00:00:00 2001 From: "dima.novoseltsev" Date: Thu, 17 Nov 2022 10:35:58 +0200 Subject: [PATCH] QUASAR-3835 - add get customer portal link --- README.md | 49 ++++++++++++++++--- .../Entities/Order/CustomerPortal.php | 44 +++++++++++++++++ .../Setters/CustomerPortalFactory.php | 6 +++ 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cf9f366..c23d4db 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ TemplateMonster API2 Client Installation ------------ -### Using Composer (recommended) + Using Composer (recommended) Add the dependency in your `composer.json` @@ -25,7 +25,7 @@ Add the dependency in your `composer.json` Usage ----- -### Templates +# Templates ```php // Create API instance @@ -58,9 +58,9 @@ $template = $api->getTemplate ($template_id); ``` -### Orders +# Orders -Receive a status of Order +## Receive a status of Order ``` php @@ -72,7 +72,7 @@ echo $status->getStatusName (); ``` -Get all Statuses +## Get all Statuses ```php @@ -87,7 +87,7 @@ foreach ($statuses as $status) ``` -Create an Order +## Create an Order ``` php @@ -164,7 +164,7 @@ $result = $api->createOrder ($order); ``` -Get customer management portal link +## Get customer management portal link ```php // Create API instance @@ -172,6 +172,41 @@ $api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserTok $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 diff --git a/src/API2Client/Entities/Order/CustomerPortal.php b/src/API2Client/Entities/Order/CustomerPortal.php index 1840ba2..42b09a4 100644 --- a/src/API2Client/Entities/Order/CustomerPortal.php +++ b/src/API2Client/Entities/Order/CustomerPortal.php @@ -11,6 +11,16 @@ class CustomerPortal { protected $link; + /** + * @var bool + */ + private $status = false; + + /** + * @var array + */ + private $messages = array(); + /** * @return string */ @@ -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; + } } \ No newline at end of file diff --git a/src/API2Client/Setters/CustomerPortalFactory.php b/src/API2Client/Setters/CustomerPortalFactory.php index e57bf88..82310dc 100644 --- a/src/API2Client/Setters/CustomerPortalFactory.php +++ b/src/API2Client/Setters/CustomerPortalFactory.php @@ -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; }