From c2512b4d45076f5dfd781bf3fa0c226006cf6b03 Mon Sep 17 00:00:00 2001 From: "dima.novoseltsev" Date: Thu, 28 Mar 2024 14:32:34 +0200 Subject: [PATCH 1/2] BIL-34 - add getInvoiceUrl and getTransactionStatusUrl methods --- README.md | 202 +++++++++++++++++- src/API2Client/Api.php | 58 ++++- .../Entities/Order/BillingPortal.php | 71 ++++++ .../Setters/BillingPortalFactory.php | 28 +++ 4 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 src/API2Client/Entities/Order/BillingPortal.php create mode 100644 src/API2Client/Setters/BillingPortalFactory.php diff --git a/README.md b/README.md index c23d4db..969dc58 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,206 @@ API2Client\Entities\Order\CustomerPortal Object ) ``` +TemplateMonster API2 Client +=========================== + +Installation +------------ + +Using Composer (recommended) + +Add the dependency in your `composer.json` + +``` json +{ + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/M0nsterLabs/api2client.git" + } + ], + "require": { + "templatemonster/api2-client":"dev-master" + } +} + +``` +Usage +----- + +# Templates + +```php +// Create API instance +$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken'); + + +// Receive a count of all Templates +$templatesCount = $api->getTemplatesCount () + +// Receive a list of Templates +$offset = 0; +$limit = 20; + +$templates = $api->getTemplatesList ($offset, $limit); + +/** @var API2Client\Entities\Template $template */ +foreach ($templates as $template) +{ + // Template pages + $templatePages = $template->getPages (); +} + + +// Receive a single Template +$template_id = 30506; + +/** @var API2Client\Entities\Template $template */ +$template = $api->getTemplate ($template_id); + + +``` + +# Orders + +## Receive a status of Order + +``` php + +/** @var \API2Client\Entities\Order\Status $status */ +$status = $api->getOrderStatus ('rgRvuzZQP9OoALyEKGKA'); + +// print status title +echo $status->getStatusName (); + +``` + +## Get all Statuses + +```php + +$statuses = $api->getOrderStatuses (); + +/** @var \API2Client\Entities\Order\Status $status */ +foreach ($statuses as $status) +{ + echo $status->getStatusCode (); + echo $status->getStatusName (); +} + +``` + +## Create an Order + +``` php + +$order = new \API2Client\Entities\Order (); + +$order->setProjectId (0); +$order->setAmount (174); +$order->setBonusesAmount (0); + +$billingInfo = new \API2Client\Entities\Order\BillingInfo (); + +$billingInfo->setAccountSId ('u03e9b361c607ju37707iyo8s273sibh9z8lka2e6kt3276e41g11e7f6ozjm0cv7c4a40piorf408bb203of6wnbx2v24xfo61nwr4o7960tu898w50u4bu51zn2fa1'); +$billingInfo->setAddress ('Torenplein Str'); +$billingInfo->setCityName ('Hasselt'); +$billingInfo->setContactPhone (74933242323); +$billingInfo->setEmail ('mark.twain@mail.com'); +$billingInfo->setCountryISO2 ('BE'); +$billingInfo->setFullName ('Mark Twain'); +$billingInfo->setPhone (74933242323); +$billingInfo->setPostalCode (12123); +$billingInfo->setStateISO2 ('XX'); + +$order->setBillingInfo ($billingInfo); + +$productInfo1 = new \API2Client\Entities\Order\ProductInfo (); + +$productInfo1->setProductId (49334); +$productInfo1->setPrice (69); +$productInfo1->setType ('template'); + +$order->addProductInfo ($productInfo1); + +$productInfo2 = new \API2Client\Entities\Order\ProductInfo (); + +$productInfo2->setProductId (49334); +$productInfo2->setPrice (75); +$productInfo2->setType ('template'); + +$order->addProductInfo ($productInfo2); + + +$externalProduct = new \API2Client\Entities\Order\ProductInfo (); + +$externalProduct->setProductId (0); +$externalProduct->setPrice (33); +$externalProduct->setFinalPrice (30); +$externalProduct->setName ('Headspace Journey Subscription'); +$externalProduct->setType ('external'); + +$order->addProductInfo ($externalProduct); + +$trackingInfo = new \API2Client\Entities\Order\TrackingInfo (); + +$trackingInfo->setRmsLocale ('EN'); +$trackingInfo->setRefererUrl ('http://localhost:8081/'); +$trackingInfo->setUserAgent ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36'); +$trackingInfo->setUserIPAddress ('10.0.2.2'); +$trackingInfo->setUserLanguage ('en-US,en;q=0.8,uk;q=0.6,ru;q=0.4'); +$trackingInfo->setUserLocalTime ('Tue May 27 2014 10:31:05 GMT+0300 (EEST)'); + +$order->setTrackingInfo ($trackingInfo); + +$paymentInfo = new \API2Client\Entities\Order\PaymentInfo (); + +$paymentInfo->setCurrencyId (0); +$paymentInfo->setCurrencyRate (1); +$paymentInfo->setPaymentId (2); + +$order->setPaymentInfo ($paymentInfo); + +/** @var \API2Client\Entities\OrderCreated $result */ +$result = $api->createOrder ($order); + + +``` + +## 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 -------------- @@ -229,4 +429,4 @@ catch (\API2Client\Client\APIException $e) $e->getMessage (); } -``` \ No newline at end of file +``` diff --git a/src/API2Client/Api.php b/src/API2Client/Api.php index 7a3ee42..cd4d6b4 100644 --- a/src/API2Client/Api.php +++ b/src/API2Client/Api.php @@ -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; @@ -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; @@ -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()); + } } diff --git a/src/API2Client/Entities/Order/BillingPortal.php b/src/API2Client/Entities/Order/BillingPortal.php new file mode 100644 index 0000000..cddf654 --- /dev/null +++ b/src/API2Client/Entities/Order/BillingPortal.php @@ -0,0 +1,71 @@ +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; + } +} diff --git a/src/API2Client/Setters/BillingPortalFactory.php b/src/API2Client/Setters/BillingPortalFactory.php new file mode 100644 index 0000000..97a0c36 --- /dev/null +++ b/src/API2Client/Setters/BillingPortalFactory.php @@ -0,0 +1,28 @@ +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; + } +} From 758b4cf052860d8bd84b6496957274ffdbda147c Mon Sep 17 00:00:00 2001 From: "dima.novoseltsev" Date: Thu, 28 Mar 2024 14:35:13 +0200 Subject: [PATCH 2/2] BIL-34 - add getInvoiceUrl and getTransactionStatusUrl methods --- README.md | 166 ------------------------------------------------------ 1 file changed, 166 deletions(-) diff --git a/README.md b/README.md index 969dc58..bb9ba73 100644 --- a/README.md +++ b/README.md @@ -209,172 +209,6 @@ API2Client\Entities\Order\CustomerPortal Object ) ``` -TemplateMonster API2 Client -=========================== - -Installation ------------- - -Using Composer (recommended) - -Add the dependency in your `composer.json` - -``` json -{ - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/M0nsterLabs/api2client.git" - } - ], - "require": { - "templatemonster/api2-client":"dev-master" - } -} - -``` -Usage ------ - -# Templates - -```php -// Create API instance -$api = new \API2Client\Api ('api2.templatemonster.com', 'myUserName', 'myUserToken'); - - -// Receive a count of all Templates -$templatesCount = $api->getTemplatesCount () - -// Receive a list of Templates -$offset = 0; -$limit = 20; - -$templates = $api->getTemplatesList ($offset, $limit); - -/** @var API2Client\Entities\Template $template */ -foreach ($templates as $template) -{ - // Template pages - $templatePages = $template->getPages (); -} - - -// Receive a single Template -$template_id = 30506; - -/** @var API2Client\Entities\Template $template */ -$template = $api->getTemplate ($template_id); - - -``` - -# Orders - -## Receive a status of Order - -``` php - -/** @var \API2Client\Entities\Order\Status $status */ -$status = $api->getOrderStatus ('rgRvuzZQP9OoALyEKGKA'); - -// print status title -echo $status->getStatusName (); - -``` - -## Get all Statuses - -```php - -$statuses = $api->getOrderStatuses (); - -/** @var \API2Client\Entities\Order\Status $status */ -foreach ($statuses as $status) -{ - echo $status->getStatusCode (); - echo $status->getStatusName (); -} - -``` - -## Create an Order - -``` php - -$order = new \API2Client\Entities\Order (); - -$order->setProjectId (0); -$order->setAmount (174); -$order->setBonusesAmount (0); - -$billingInfo = new \API2Client\Entities\Order\BillingInfo (); - -$billingInfo->setAccountSId ('u03e9b361c607ju37707iyo8s273sibh9z8lka2e6kt3276e41g11e7f6ozjm0cv7c4a40piorf408bb203of6wnbx2v24xfo61nwr4o7960tu898w50u4bu51zn2fa1'); -$billingInfo->setAddress ('Torenplein Str'); -$billingInfo->setCityName ('Hasselt'); -$billingInfo->setContactPhone (74933242323); -$billingInfo->setEmail ('mark.twain@mail.com'); -$billingInfo->setCountryISO2 ('BE'); -$billingInfo->setFullName ('Mark Twain'); -$billingInfo->setPhone (74933242323); -$billingInfo->setPostalCode (12123); -$billingInfo->setStateISO2 ('XX'); - -$order->setBillingInfo ($billingInfo); - -$productInfo1 = new \API2Client\Entities\Order\ProductInfo (); - -$productInfo1->setProductId (49334); -$productInfo1->setPrice (69); -$productInfo1->setType ('template'); - -$order->addProductInfo ($productInfo1); - -$productInfo2 = new \API2Client\Entities\Order\ProductInfo (); - -$productInfo2->setProductId (49334); -$productInfo2->setPrice (75); -$productInfo2->setType ('template'); - -$order->addProductInfo ($productInfo2); - - -$externalProduct = new \API2Client\Entities\Order\ProductInfo (); - -$externalProduct->setProductId (0); -$externalProduct->setPrice (33); -$externalProduct->setFinalPrice (30); -$externalProduct->setName ('Headspace Journey Subscription'); -$externalProduct->setType ('external'); - -$order->addProductInfo ($externalProduct); - -$trackingInfo = new \API2Client\Entities\Order\TrackingInfo (); - -$trackingInfo->setRmsLocale ('EN'); -$trackingInfo->setRefererUrl ('http://localhost:8081/'); -$trackingInfo->setUserAgent ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36'); -$trackingInfo->setUserIPAddress ('10.0.2.2'); -$trackingInfo->setUserLanguage ('en-US,en;q=0.8,uk;q=0.6,ru;q=0.4'); -$trackingInfo->setUserLocalTime ('Tue May 27 2014 10:31:05 GMT+0300 (EEST)'); - -$order->setTrackingInfo ($trackingInfo); - -$paymentInfo = new \API2Client\Entities\Order\PaymentInfo (); - -$paymentInfo->setCurrencyId (0); -$paymentInfo->setCurrencyRate (1); -$paymentInfo->setPaymentId (2); - -$order->setPaymentInfo ($paymentInfo); - -/** @var \API2Client\Entities\OrderCreated $result */ -$result = $api->createOrder ($order); - - -``` - ## Get url on invoice url by transaction ```php