diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7eeb2b3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [1.1.0] - 2025-02-07 +### Added +- Add parameters discounts, products and cartId list in subscriptions + +## [1.0.9] - 2025-02-06 +### Added +- Add trackers + +## [1.0.8] - 2025-02-05 +### Added +- Add membership and support products for order + +## [1.0.7] - 2024-04-11 +### Added +- Billing portal links + +## [1.0.6] - 2022-10-14 +### Added +- Get customer management portal link + +## [1.0.5] - 2022-02-14 +### Added +- Added cancel order + +## [1.0.4] - 2021-10-06 +### Added +- Google & Apple pay. + +## [1.0.3] - 2020-05-09 +### Fixed +- fix screenshots + +## [1.0.0] - 2019-02-19 +### Added +- Payment Subscriptions + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). diff --git a/README.md b/README.md index 6e37f1f..8abc2fa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ TemplateMonster API2 Client =========================== +[![version][version-badge]][CHANGELOG] ![php-version] + Installation ------------ @@ -267,3 +269,8 @@ catch (\API2Client\Client\APIException $e) } ``` + +[CHANGELOG]: ./CHANGELOG.md + +[version-badge]: https://img.shields.io/badge/version-1.1.0-green.svg +[php-version]:https://img.shields.io/static/v1?label=php&message=>=5.3&color=green diff --git a/composer.json b/composer.json index 606b078..b6d5214 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,26 @@ { - "name": "templatemonster/api2-client", - "description": "TemplateMonster API client", - "license": "Apache License, Version 2.0", - "authors": [ - { - "name": "kolomiets", - "email": "kolomiets.dev@gmail.com" - } - ], - "minimum-stability": "dev", - "require": { - "php": ">=5.3.0" - }, - "autoload": { - "psr-0": { - "NewRelic": "src/" - }, - "classmap": [ - "./" - ] + "name": "templatemonster/api2-client", + "description": "TemplateMonster API client", + "version": "1.1.0", + "license": "Apache License, Version 2.0", + "authors": [ + { + "name": "kolomiets", + "email": "kolomiets.dev@gmail.com" } + ], + "minimum-stability": "dev", + "require": { + "php": ">=5.3.0", + "ext-curl": "*", + "ext-json": "*" + }, + "autoload": { + "psr-0": { + "NewRelic": "src/" + }, + "classmap": [ + "./" + ] + } } diff --git a/src/API2Client/Entities/Order.php b/src/API2Client/Entities/Order.php index 11d8df0..39f02dd 100644 --- a/src/API2Client/Entities/Order.php +++ b/src/API2Client/Entities/Order.php @@ -69,10 +69,15 @@ class Order */ protected $paymentOptions; + /** + * @var string + */ + protected $cartId; + /** * @param float $amount */ - public function setAmount ($amount) + public function setAmount($amount) { $this->amount = $amount; } @@ -80,31 +85,31 @@ public function setAmount ($amount) /** * @return float */ - public function getAmount () + public function getAmount() { return $this->amount; } /** - * @param \API2Client\Entities\Order\BillingInfo $billingInfo + * @param BillingInfo $billingInfo */ - public function setBillingInfo (BillingInfo $billingInfo) + public function setBillingInfo(BillingInfo $billingInfo) { $this->billingInfo = $billingInfo; } /** - * @return \API2Client\Entities\Order\BillingInfo + * @return BillingInfo */ - public function getBillingInfo () + public function getBillingInfo() { - return $this->billingInfo ? $this->billingInfo : new BillingInfo (); + return $this->billingInfo ? $this->billingInfo : new BillingInfo(); } /** * @param float $bonusesAmount */ - public function setBonusesAmount ($bonusesAmount) + public function setBonusesAmount($bonusesAmount) { $this->bonusesAmount = $bonusesAmount; } @@ -112,7 +117,7 @@ public function setBonusesAmount ($bonusesAmount) /** * @return float */ - public function getBonusesAmount () + public function getBonusesAmount() { return $this->bonusesAmount; } @@ -120,7 +125,7 @@ public function getBonusesAmount () /** * @param $discountInfo */ - public function addDiscountInfo ($discountInfo) + public function addDiscountInfo($discountInfo) { $this->discountInfoList [] = $discountInfo; } @@ -128,23 +133,23 @@ public function addDiscountInfo ($discountInfo) /** * @return array */ - public function getDiscountInfoList () + public function getDiscountInfoList() { return $this->discountInfoList; } /** - * @param \API2Client\Entities\Order\PaymentInfo $paymentInfo + * @param PaymentInfo $paymentInfo */ - public function setPaymentInfo ($paymentInfo) + public function setPaymentInfo($paymentInfo) { $this->paymentInfo = $paymentInfo; } /** - * @return \API2Client\Entities\Order\PaymentInfo + * @return PaymentInfo */ - public function getPaymentInfo () + public function getPaymentInfo() { return $this->paymentInfo; } @@ -152,7 +157,7 @@ public function getPaymentInfo () /** * @param ProductInfo $productInfo */ - public function addProductInfo (ProductInfo $productInfo) + public function addProductInfo(ProductInfo $productInfo) { $this->productInfoList[] = $productInfo; } @@ -160,7 +165,7 @@ public function addProductInfo (ProductInfo $productInfo) /** * @return array */ - public function getProductInfoList () + public function getProductInfoList() { return $this->productInfoList; } @@ -168,7 +173,7 @@ public function getProductInfoList () /** * @param int $projectId */ - public function setProjectId ($projectId) + public function setProjectId($projectId) { $this->projectId = $projectId; } @@ -176,7 +181,7 @@ public function setProjectId ($projectId) /** * @return float */ - public function getProjectId () + public function getProjectId() { return $this->projectId; } @@ -184,7 +189,7 @@ public function getProjectId () /** * @param mixed TrackingInfo $trackingInfo */ - public function setTrackingInfo (TrackingInfo $trackingInfo) + public function setTrackingInfo(TrackingInfo $trackingInfo) { $this->trackingInfo = $trackingInfo; } @@ -192,7 +197,7 @@ public function setTrackingInfo (TrackingInfo $trackingInfo) /** * @return TrackingInfo */ - public function getTrackingInfo () + public function getTrackingInfo() { return $this->trackingInfo ? $this->trackingInfo : new TrackingInfo (); } @@ -200,7 +205,7 @@ public function getTrackingInfo () /** * @return boolean */ - public function isGift () + public function isGift() { return $this->gift; } @@ -208,7 +213,7 @@ public function isGift () /** * @param boolean $gift */ - public function setGift ($gift) + public function setGift($gift) { $this->gift = $gift; } @@ -216,54 +221,52 @@ public function setGift ($gift) /** * @return array */ - protected function getPaymentWithGift () + protected function getPaymentWithGift() { - if ($this->isGift () === true) - { + if ($this->isGift() === true) { $paymentData = new PaymentInfo (); return $paymentData - ->setCurrencyId (0) - ->setCurrencyRate (1) - ->setPaymentId (Payment::GIFT_METHOD) - ->toArray (); + ->setCurrencyId(0) + ->setCurrencyRate(1) + ->setPaymentId(Payment::GIFT_METHOD) + ->toArray(); } - return $this->getPaymentInfo ()->toArray (); + return $this->getPaymentInfo()->toArray(); } /** * @return array */ - public function toArray () + public function toArray() { - $data = array( - 'projectId' => $this->getProjectId (), - 'amount' => $this->getAmount (), - 'bonusesAmount' => $this->getBonusesAmount (), - 'billingInfo' => $this->getBillingInfo ()->toArray (), - 'paymentInfo' => $this->getPaymentWithGift (), - 'trackingInfo' => $this->getTrackingInfo ()->toArray (), - 'discountInfoList' => array (), - 'payment_options' => $this->getPaymentOptions(), + $data = array( + 'projectId' => $this->getProjectId(), + 'amount' => $this->getAmount(), + 'bonusesAmount' => $this->getBonusesAmount(), + 'billingInfo' => $this->getBillingInfo()->toArray(), + 'paymentInfo' => $this->getPaymentWithGift(), + 'trackingInfo' => $this->getTrackingInfo()->toArray(), + 'discountInfoList' => array(), + 'payment_options' => $this->getPaymentOptions(), + 'cartId' => $this->getCartId() ); - $data['productInfoList'] = array (); + $data['productInfoList'] = array(); /** * @var ProductInfo $productInfo */ - foreach ($this->getProductInfoList () as $productInfo) - { - $data['productInfoList'][] = $productInfo->toArray (); + foreach ($this->getProductInfoList() as $productInfo) { + $data['productInfoList'][] = $productInfo->toArray(); } - $discountList = array (); + $discountList = array(); /** @var DiscountInfo $discount */ - foreach ($this->getDiscountInfoList () as $discount) - { - $discountList = array_merge ($discountList, $discount->toArray ()); + foreach ($this->getDiscountInfoList() as $discount) { + $discountList = array_merge($discountList, $discount->toArray()); } $data['discountInfoList'] = $discountList; @@ -286,6 +289,20 @@ public function setPaymentOptions($paymentOptions) { $this->paymentOptions = $paymentOptions; } - - -} \ No newline at end of file + + /** + * @param string $cartId + */ + public function setCartId($cartId) + { + $this->cartId = $cartId; + } + + /** + * @return string + */ + public function getCartId() + { + return $this->cartId; + } +} diff --git a/src/API2Client/Entities/Order/ProductInfo.php b/src/API2Client/Entities/Order/ProductInfo.php index 191188a..d71a18c 100644 --- a/src/API2Client/Entities/Order/ProductInfo.php +++ b/src/API2Client/Entities/Order/ProductInfo.php @@ -14,10 +14,16 @@ class ProductInfo { + const PRODUCT_TYPE_OFFER = "offer"; + const PRODUCT_TYPE_EXTERNAL = "external"; + const PRODUCT_TYPE_SUPPORT = "support"; + const PRODUCT_TYPE_MEMBERSHIP = "membership"; + const PRODUCT_TYPE_TEMPLATE = "template"; + /** * @var array */ - protected $discountCodeList = array (); + protected $discountCodeList = array(); /** * @var float @@ -60,7 +66,7 @@ class ProductInfo /** * @param string $discountCode */ - public function addDiscountCode ($discountCode) + public function addDiscountCode($discountCode) { $this->discountCodeList[] = $discountCode; } @@ -68,7 +74,7 @@ public function addDiscountCode ($discountCode) /** * @return array */ - public function getDiscountCodeList () + public function getDiscountCodeList() { return $this->discountCodeList; } @@ -76,7 +82,7 @@ public function getDiscountCodeList () /** * @param AdditionalInfoInterface $additionalInfo */ - public function setAdditionalInfo (AdditionalInfoInterface $additionalInfo) + public function setAdditionalInfo(AdditionalInfoInterface $additionalInfo) { $this->additionalInfo = $additionalInfo; } @@ -84,7 +90,7 @@ public function setAdditionalInfo (AdditionalInfoInterface $additionalInfo) /** * @return AdditionalInfoInterface */ - public function getAdditionalInfo () + public function getAdditionalInfo() { return $this->additionalInfo; } @@ -92,7 +98,7 @@ public function getAdditionalInfo () /** * @param float $finalPrice */ - public function setFinalPrice ($finalPrice) + public function setFinalPrice($finalPrice) { $this->finalPrice = $finalPrice; } @@ -100,15 +106,15 @@ public function setFinalPrice ($finalPrice) /** * @return float */ - public function getFinalPrice () + public function getFinalPrice() { - return $this->finalPrice != null ? $this->finalPrice : $this->getPrice() ; + return $this->finalPrice != null ? $this->finalPrice : $this->getPrice(); } /** * @param float $price */ - public function setPrice ($price) + public function setPrice($price) { $this->price = $price; } @@ -116,7 +122,7 @@ public function setPrice ($price) /** * @return float */ - public function getPrice () + public function getPrice() { return $this->price; } @@ -124,7 +130,7 @@ public function getPrice () /** * @return boolean */ - public function isExclusive () + public function isExclusive() { return $this->exclusive; } @@ -140,7 +146,7 @@ public function setExclusive($exclusive) /** * @param int $productId */ - public function setProductId ($productId) + public function setProductId($productId) { $this->productId = $productId; } @@ -148,7 +154,7 @@ public function setProductId ($productId) /** * @return int */ - public function getProductId () + public function getProductId() { return $this->productId; } @@ -156,7 +162,7 @@ public function getProductId () /** * @param string $type */ - public function setType ($type) + public function setType($type) { $this->type = $type; } @@ -164,7 +170,7 @@ public function setType ($type) /** * @return string */ - public function getType () + public function getType() { return $this->type; } @@ -172,7 +178,7 @@ public function getType () /** * @return mixed */ - public function getName () + public function getName() { return $this->name; } @@ -180,7 +186,7 @@ public function getName () /** * @param mixed $name */ - public function setName ($name) + public function setName($name) { $this->name = $name; } @@ -188,7 +194,7 @@ public function setName ($name) /** * @return string */ - public function getDescription () + public function getDescription() { return $this->description; } @@ -196,29 +202,28 @@ public function getDescription () /** * @param string $description */ - public function setDescription ($description) + public function setDescription($description) { $this->description = $description; } - public function toArray () + public function toArray() { - $additional = $this->getAdditionalInfo () ? $this->getAdditionalInfo ()->toArray () : array (); + $additional = $this->getAdditionalInfo() ? $this->getAdditionalInfo()->toArray() : array(); - if ($this->isExclusive ()) - { - $additional ['exclusivePrice'] = $this->isExclusive (); + if ($this->isExclusive()) { + $additional ['exclusivePrice'] = $this->isExclusive(); } - return array ( - 'additionalInfo' => $additional, - 'description' => $this->getDescription (), - 'discountCodeList' => $this->getDiscountCodeList (), - 'name' => $this->getName (), - 'price' => $this->getPrice (), - 'finalPrice' => $this->getFinalPrice (), - 'productId' => $this->getProductId () ? $this->getProductId () : 0, - 'type' => $this->getType (), + return array( + 'additionalInfo' => $additional, + 'description' => $this->getDescription(), + 'discountCodeList' => $this->getDiscountCodeList(), + 'name' => $this->getName(), + 'price' => $this->getPrice(), + 'finalPrice' => $this->getFinalPrice(), + 'productId' => $this->getProductId() ? $this->getProductId() : 0, + 'type' => $this->getType(), ); } -} \ No newline at end of file +} diff --git a/src/API2Client/Entities/Subscription.php b/src/API2Client/Entities/Subscription.php index 9fbaff5..a8d4bee 100644 --- a/src/API2Client/Entities/Subscription.php +++ b/src/API2Client/Entities/Subscription.php @@ -2,6 +2,8 @@ namespace API2Client\Entities; +use API2Client\Entities\Order\DiscountInfo; +use API2Client\Entities\Order\ProductInfo; class Subscription { @@ -138,6 +140,21 @@ class Subscription */ protected $paymentOptions; + /** + * @var DiscountInfo[] + */ + protected $discountInfoList = array(); + + /** + * @var ProductInfo[] + */ + protected $productInfoList = array(); + + /** + * @var string + */ + protected $cartId; + /** * @return string */ @@ -159,9 +176,9 @@ public function setAffiliateName($affiliate_name) /** * @return array */ - public function getAllowedPeriods () + public function getAllowedPeriods() { - return array ( + return array( self::PERIOD_DAYS, self::PERIOD_WEEK, self::PERIOD_MONT, @@ -325,7 +342,7 @@ public function getPeriod() * @param mixed $period * @return $this */ - public function setPeriod ($period) + public function setPeriod($period) { $this->period = $period; return $this; @@ -599,16 +616,63 @@ public function setPaymentOptions($paymentOptions) $this->paymentOptions = $paymentOptions; } + /** + * @param $discountInfo + */ + public function addDiscountInfo($discountInfo) + { + $this->discountInfoList [] = $discountInfo; + } + + /** + * @return DiscountInfo[] + */ + public function getDiscountInfoList() + { + return $this->discountInfoList; + } + + /** + * @param ProductInfo $productInfo + */ + public function addProductInfo(ProductInfo $productInfo) + { + $this->productInfoList[] = $productInfo; + } + + /** + * @return ProductInfo[] + */ + public function getProductInfoList() + { + return $this->productInfoList; + } + + /** + * @param string $cartId + */ + public function setCartId($cartId) + { + $this->cartId = $cartId; + } + + /** + * @return string + */ + public function getCartId() + { + return $this->cartId; + } /** * @return array */ - public function toArray () + public function toArray() { - return array ( + $data = array( 'id' => $this->getId(), 'project_id' => $this->getProjectId(), - 'payment_system_id' => $this->getPaymentSystemId (), + 'payment_system_id' => $this->getPaymentSystemId(), 'currency_id' => $this->getCurrencyId(), 'title' => $this->getTitle(), 'period' => $this->getPeriod(), @@ -623,12 +687,29 @@ public function toArray () 'customer_state_code' => $this->getCustomerStateCode(), 'customer_city' => $this->getCustomerCity(), 'customer_zip' => $this->getCustomerZip(), - 'customer_phone' => $this->getCustomerPhone (), + 'customer_phone' => $this->getCustomerPhone(), 'customer_user_agent' => $this->getCustomerUserAgent(), 'customer_ip_address' => $this->getCustomerIpAddress(), 'customer_local_time' => $this->getCustomerLocalTime(), 'affiliate_name' => $this->getAffiliateName(), - 'payment_options' => $this->getPaymentOptions(), + 'payment_options' => $this->getPaymentOptions(), + 'cartId' => $this->getCartId(), + 'discountInfoList' => array(), + 'productInfoList' => array(), ); + + foreach ($this->getProductInfoList() as $productInfo) { + $data['productInfoList'][] = $productInfo->toArray(); + } + + $discountList = array(); + + foreach ($this->getDiscountInfoList() as $discount) { + $discountList = array_merge($discountList, $discount->toArray()); + } + + $data['discountInfoList'] = $discountList; + + return $data; } -} \ No newline at end of file +}