diff --git a/CHANGELOG.md b/CHANGELOG.md index 39f84f806..78cd8e4c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,14 +20,23 @@ _TBD_ ### Added - [x] Added new properties to `Plan`: `pricing`, `recurringInterval`, `trial`, `setup` +- [x] Added new property to `Subscription`: `items` +- [x] Added new property to `LeadSource`: `original` ### Changed - [x] Replaced magic methods like `get`, `post` with explicit defined methods. ### Removed -- [x] Removed deprecated Plan properties: `expiredTime`, `recurringAmount`, `trialAmount`, `setupAmount`, +- [x] Removed deprecated `Plan` properties: `expiredTime`, `recurringAmount`, `trialAmount`, `setupAmount`, `recurringPeriodUnit`, `recurringPeriodLength`, `recurringPeriodLimit`, `trialPeriodUnit`, `trialPeriodLength`, - `contractTermUnit`, `contractTermLength`, `minQuantity`, `maxQuantity` + `contractTermUnit`, `contractTermLength`, `minQuantity`, `maxQuantity` +- [x] Removed `LeadSources` in **Transactions**, **Invoices** and **Subscriptions** +- [x] Removed `LeadSources` endpoint and service. Adding Lead Sources now only possible via **Tokens** and **Customers** +- [x] Removed deprecated `Subscription` properties: `planId`, `quantity`, + `billingContactId`, `billingContact`, `deliveryContactId`, `deliveryContact` +- [x] Removed deprecated `LeadSource` property: `ipAddress` +- [x] Removed `Notification`, `EmailNotification` and `EmailNotificationTracking`. +- [x] Deprecate setting `initialInvoiceId` property when creating a `Subscription`. ## [2.2.0] 2018-08-14 diff --git a/src/Client.php b/src/Client.php index d8569603f..e5e6ed831 100644 --- a/src/Client.php +++ b/src/Client.php @@ -83,8 +83,6 @@ * @method Services\ValuesListService lists() * @method Services\ValuesListTrackingService listsTracking() * @method Services\WebhookTrackingService webhooksTracking() - * @method Services\EmailNotificationService emailNotifications() - * @method Services\EmailNotificationTrackingService emailNotificationsTracking() * @method Services\GatewayAccountDowntimeService gatewayDowntimes() * @method Services\PaymentInstrumentValidationService paymentInstrumentValidation() * @method Services\KycService kycDocuments() @@ -142,8 +140,6 @@ final class Client 'listsTracking' => Services\ValuesListTrackingService::class, 'shippingZones' => Services\ShippingZoneService::class, 'webhooksTracking' => Services\WebhookTrackingService::class, - 'emailNotifications' => Services\EmailNotificationService::class, - 'emailNotificationsTracking' => Services\EmailNotificationTrackingService::class, 'gatewayDowntimes' => Services\GatewayAccountDowntimeService::class, 'paymentInstrumentValidation' => Services\PaymentInstrumentValidationService::class, 'kycDocuments' => Services\KycService::class, diff --git a/src/Entities/Coupons/Restriction.php b/src/Entities/Coupons/Restriction.php index 33b561936..ed1fd36be 100644 --- a/src/Entities/Coupons/Restriction.php +++ b/src/Entities/Coupons/Restriction.php @@ -27,12 +27,18 @@ abstract class Restriction extends Resource const TYPE_RESTRICT_TO_PLANS = 'restrict-to-plans'; const TYPE_RESTRICT_TO_SUBSCRIPTIONS = 'restrict-to-subscriptions'; + const TYPE_TOTAL_REDEMPTIONS = 'total-redemptions'; + + const TYPE_MINIMUM_ORDER_AMOUNT = 'minimum-order-amount'; + protected static $supportedTypes = [ self::TYPE_DISCOUNTS_PER_REDEMPTION, self::TYPE_REDEMPTIONS_PER_CUSTOMER, self::TYPE_RESTRICT_TO_INVOICES, self::TYPE_RESTRICT_TO_PLANS, self::TYPE_RESTRICT_TO_SUBSCRIPTIONS, + self::TYPE_TOTAL_REDEMPTIONS, + self::TYPE_MINIMUM_ORDER_AMOUNT, ]; /** @@ -69,6 +75,14 @@ public static function createFromData(array $data) break; case self::TYPE_RESTRICT_TO_SUBSCRIPTIONS: $restriction = new Restrictions\RestrictToSubscriptions($data); + break; + case self::TYPE_TOTAL_REDEMPTIONS: + $restriction = new Restrictions\TotalRedemptions($data); + + break; + case self::TYPE_MINIMUM_ORDER_AMOUNT: + $restriction = new Restrictions\MinimumOrderAmount($data); + break; default: throw new DomainException( diff --git a/src/Entities/Coupons/Restrictions/MinimumOrderAmount.php b/src/Entities/Coupons/Restrictions/MinimumOrderAmount.php new file mode 100644 index 000000000..84b03302c --- /dev/null +++ b/src/Entities/Coupons/Restrictions/MinimumOrderAmount.php @@ -0,0 +1,61 @@ +getAttribute('quantity'); + } + + /** + * @return string + */ + public function getCurrency() + { + return $this->getAttribute('currency'); + } + + /** + * @param int $value + * + * @return $this + */ + public function setQuantity($value) + { + return $this->setAttribute('quantity', $value); + } + + /** + * @param string $value + * + * @return $this + */ + public function setCurrency($value) + { + return $this->setAttribute('currency', $value); + } + + /** + * @return string + */ + protected function restrictionType() + { + return self::TYPE_MINIMUM_ORDER_AMOUNT; + } +} diff --git a/src/Entities/Coupons/Restrictions/TotalRedemptions.php b/src/Entities/Coupons/Restrictions/TotalRedemptions.php new file mode 100644 index 000000000..1f175ac3a --- /dev/null +++ b/src/Entities/Coupons/Restrictions/TotalRedemptions.php @@ -0,0 +1,43 @@ +getAttribute('quantity'); + } + + /** + * @param int $value + * + * @return $this + */ + public function setQuantity($value) + { + return $this->setAttribute('quantity', $value); + } + + /** + * @return string + */ + protected function restrictionType() + { + return self::TYPE_TOTAL_REDEMPTIONS; + } +} diff --git a/src/Entities/EmailNotifications/EmailNotification.php b/src/Entities/EmailNotifications/EmailNotification.php deleted file mode 100644 index 4c2cdde90..000000000 --- a/src/Entities/EmailNotifications/EmailNotification.php +++ /dev/null @@ -1,184 +0,0 @@ - - * @version 0.1 - */ -final class EmailNotification extends Entity -{ - const MSG_UNEXPECTED_NOTIFICATIONS = 'Unexpected notifications type, it must be an array of Notification'; - const MSG_UNEXPECTED_TAGS = 'Unexpected tags, it must be an array of strings'; - - /** - * @return string - */ - public function getEventType() - { - return $this->getAttribute('eventType'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setEventType($value) - { - return $this->setAttribute('eventType', $value); - } - - /** - * @return string - */ - public function getSubject() - { - return $this->getAttribute('subject'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setSubject($value) - { - return $this->setAttribute('subject', $value); - } - - /** - * @return string - */ - public function getBodyText() - { - return $this->getAttribute('bodyText'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setBodyText($value) - { - return $this->setAttribute('bodyText', $value); - } - - /** - * @return string - */ - public function getBodyHtml() - { - return $this->getAttribute('bodyHtml'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setBodyHtml($value) - { - return $this->setAttribute('bodyHtml', $value); - } - - /** - * @return bool - */ - public function getAttachInvoice() - { - return $this->getAttribute('attachInvoice'); - } - - /** - * @param bool $value - * - * @return $this - */ - public function setAttachInvoice($value) - { - return $this->setAttribute('attachInvoice', $value); - } - - /** - * @return string - */ - public function getStatus() - { - return $this->getAttribute('status'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setStatus($value) - { - return $this->setAttribute('status', $value); - } - - /** - * @return array - */ - public function getNotifications() - { - return $this->getAttribute('notifications'); - } - - /** - * @param array $value - * - * @return $this - */ - public function setNotifications($value) - { - if (!is_array($value)) { - throw new DomainException(self::MSG_UNEXPECTED_NOTIFICATIONS); - } - - return $this->setAttribute('notifications', $value); - } - - /** - * @return string - */ - public function getCreatedTime() - { - return $this->getAttribute('createdTime'); - } - - /** - * @return array - */ - public function getTags() - { - return $this->getAttribute('tags'); - } - - /** - * @param array $value - * - * @return $this - */ - public function setTags($value) - { - if (!is_array($value)) { - throw new DomainException(self::MSG_UNEXPECTED_TAGS); - } - - return $this->setAttribute('tags', $value); - } -} diff --git a/src/Entities/EmailNotifications/EmailNotificationTracking.php b/src/Entities/EmailNotifications/EmailNotificationTracking.php deleted file mode 100644 index a0240383e..000000000 --- a/src/Entities/EmailNotifications/EmailNotificationTracking.php +++ /dev/null @@ -1,115 +0,0 @@ -getAttribute('eventType'); - } - - /** - * @return int - */ - public function getResponseCode() - { - return $this->getAttribute('responseCode'); - } - - /** - * @return string - */ - public function getResponseBody() - { - return $this->getAttribute('responseBody'); - } - - /** - * @return string - */ - public function getBody() - { - return $this->getAttribute('body'); - } - - /** - * @return string - */ - public function getSubject() - { - return $this->getAttribute('subject'); - } - - /** - * @return string - */ - public function getSender() - { - return $this->getAttribute('sender'); - } - - /** - * @return array - */ - public function getRecipients() - { - return $this->getAttribute('recipients'); - } - - /** - * @return string - */ - public function getSentTime() - { - return $this->getAttribute('sentTime'); - } - - /** - * @return string - */ - public function getInitiatedTime() - { - return $this->getAttribute('initiatedTime'); - } - - /** - * @return string - */ - public function getCreatedTime() - { - return $this->getAttribute('createdTime'); - } -} diff --git a/src/Entities/EmailNotifications/Notification.php b/src/Entities/EmailNotifications/Notification.php deleted file mode 100644 index 65eb21bcf..000000000 --- a/src/Entities/EmailNotifications/Notification.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @version 0.1 - */ -final class Notification extends Resource -{ - /** - * @return string - */ - public function getEmail() - { - return $this->getAttribute('email'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setEmail($value) - { - return $this->setAttribute('email', $value); - } - - /** - * @return bool - */ - public function getStatus() - { - return $this->getAttribute('status'); - } - - /** - * @param bool $value - * - * @return $this - */ - public function setStatus($value) - { - return $this->setAttribute('status', $value); - } -} diff --git a/src/Entities/LeadSource.php b/src/Entities/LeadSource.php index 44f92b248..9057dcd10 100644 --- a/src/Entities/LeadSource.php +++ b/src/Entities/LeadSource.php @@ -10,284 +10,13 @@ namespace Rebilly\Entities; -use Rebilly\Rest\Entity; - -/** - * Class LeadSource - * - * ```json - * { - * "customerId" - * "medium" - * "source" - * "campaign" - * "term" - * "content" - * "affiliate" - * "subAffiliate" - * "salesAgent" - * "clickId" - * "path" - * "ipAddress" - * "currency" - * "amount" - * } - * ``` - * - * @author Veaceslav Medvedev - * @version 0.1 - */ -final class LeadSource extends Entity +final class LeadSource extends LeadSourceData { /** - * @return string - */ - public function getCustomerId() - { - return $this->getAttribute('customerId'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setCustomerId($value) - { - return $this->setAttribute('customerId', $value); - } - - /** - * @return string - */ - public function getMedium() - { - return $this->getAttribute('medium'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setMedium($value) - { - return $this->setAttribute('medium', $value); - } - - /** - * @return string - */ - public function getSource() - { - return $this->getAttribute('source'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setSource($value) - { - return $this->setAttribute('source', $value); - } - - /** - * @return string - */ - public function getCampaign() - { - return $this->getAttribute('campaign'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setCampaign($value) - { - return $this->setAttribute('campaign', $value); - } - - /** - * @return string - */ - public function getTerm() - { - return $this->getAttribute('term'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setTerm($value) - { - return $this->setAttribute('term', $value); - } - - /** - * @return string - */ - public function getContent() - { - return $this->getAttribute('content'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setContent($value) - { - return $this->setAttribute('content', $value); - } - - /** - * @return string - */ - public function getAffiliate() - { - return $this->getAttribute('affiliate'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setAffiliate($value) - { - return $this->setAttribute('affiliate', $value); - } - - /** - * @return string - */ - public function getSubAffiliate() - { - return $this->getAttribute('subAffiliate'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setSubAffiliate($value) - { - return $this->setAttribute('subAffiliate', $value); - } - - /** - * @return string - */ - public function getSalesAgent() - { - return $this->getAttribute('salesAgent'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setSalesAgent($value) - { - return $this->setAttribute('salesAgent', $value); - } - - /** - * @return string - */ - public function getClickId() - { - return $this->getAttribute('clickId'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setClickId($value) - { - return $this->setAttribute('clickId', $value); - } - - /** - * @return string - */ - public function getPath() - { - return $this->getAttribute('path'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setPath($value) - { - return $this->setAttribute('path', $value); - } - - /** - * @return string - */ - public function getIpAddress() - { - return $this->getAttribute('ipAddress'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setIpAddress($value) - { - return $this->setAttribute('ipAddress', $value); - } - - /** - * @return string - */ - public function getAmount() - { - return $this->getAttribute('amount'); - } - - /** - * @param string $value - * - * @return $this - */ - public function setAmount($value) - { - return $this->setAttribute('amount', $value); - } - - /** - * @return string - */ - public function getCurrency() - { - return $this->getAttribute('currency'); - } - - /** - * @param string $value - * - * @return $this + * @return LeadSourceData */ - public function setCurrency($value) + public function getOriginal() { - return $this->setAttribute('currency', $value); + return new LeadSourceData((array) $this->getAttribute('original')); } } diff --git a/src/Entities/LeadSourceData.php b/src/Entities/LeadSourceData.php new file mode 100644 index 000000000..6d9c193da --- /dev/null +++ b/src/Entities/LeadSourceData.php @@ -0,0 +1,251 @@ +getAttribute('customerId'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setCustomerId($value) + { + return $this->setAttribute('customerId', $value); + } + + /** + * @return string + */ + public function getMedium() + { + return $this->getAttribute('medium'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setMedium($value) + { + return $this->setAttribute('medium', $value); + } + + /** + * @return string + */ + public function getSource() + { + return $this->getAttribute('source'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setSource($value) + { + return $this->setAttribute('source', $value); + } + + /** + * @return string + */ + public function getCampaign() + { + return $this->getAttribute('campaign'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setCampaign($value) + { + return $this->setAttribute('campaign', $value); + } + + /** + * @return string + */ + public function getTerm() + { + return $this->getAttribute('term'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setTerm($value) + { + return $this->setAttribute('term', $value); + } + + /** + * @return string + */ + public function getContent() + { + return $this->getAttribute('content'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setContent($value) + { + return $this->setAttribute('content', $value); + } + + /** + * @return string + */ + public function getAffiliate() + { + return $this->getAttribute('affiliate'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setAffiliate($value) + { + return $this->setAttribute('affiliate', $value); + } + + /** + * @return string + */ + public function getSubAffiliate() + { + return $this->getAttribute('subAffiliate'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setSubAffiliate($value) + { + return $this->setAttribute('subAffiliate', $value); + } + + /** + * @return string + */ + public function getSalesAgent() + { + return $this->getAttribute('salesAgent'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setSalesAgent($value) + { + return $this->setAttribute('salesAgent', $value); + } + + /** + * @return string + */ + public function getClickId() + { + return $this->getAttribute('clickId'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setClickId($value) + { + return $this->setAttribute('clickId', $value); + } + + /** + * @return string + */ + public function getPath() + { + return $this->getAttribute('path'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setPath($value) + { + return $this->setAttribute('path', $value); + } + + /** + * @return string + */ + public function getAmount() + { + return $this->getAttribute('amount'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setAmount($value) + { + return $this->setAttribute('amount', $value); + } + + /** + * @return string + */ + public function getCurrency() + { + return $this->getAttribute('currency'); + } + + /** + * @param string $value + * + * @return $this + */ + public function setCurrency($value) + { + return $this->setAttribute('currency', $value); + } +} diff --git a/src/Entities/Schema.php b/src/Entities/Schema.php index 8cfae5246..d6ba038c4 100644 --- a/src/Entities/Schema.php +++ b/src/Entities/Schema.php @@ -16,8 +16,6 @@ use IteratorAggregate; use Rebilly\Entities\Coupons\Coupon; use Rebilly\Entities\Coupons\Redemption; -use Rebilly\Entities\EmailNotifications\EmailNotification; -use Rebilly\Entities\EmailNotifications\EmailNotificationTracking; use Rebilly\Entities\KycDocuments\KycDocument; use Rebilly\Entities\Shipping\ShippingZone; use Rebilly\Rest\Collection; @@ -315,18 +313,6 @@ public function __construct() 'tracking/webhooks/{webhookId}' => function (array $content) { return new WebhookTracking($content); }, - 'email-notifications' => function (array $content) { - return new Collection(new EmailNotification(), $content); - }, - 'email-notifications/{notificationId}' => function (array $content) { - return new EmailNotification($content); - }, - 'tracking/email-notifications' => function (array $content) { - return new Collection(new EmailNotificationTracking(), $content); - }, - 'tracking/email-notifications/{trackId}' => function (array $content) { - return new EmailNotificationTracking($content); - }, 'gateway-accounts/{gatewayAccountId}/downtime-schedules' => function (array $content) { return new Collection(new GatewayAccountDowntime(), $content); }, diff --git a/src/Entities/Subscription.php b/src/Entities/Subscription.php index 52b9970c7..14a1a2b1d 100644 --- a/src/Entities/Subscription.php +++ b/src/Entities/Subscription.php @@ -13,24 +13,7 @@ use Rebilly\Rest\Entity; /** - * Class Subscription - * - * ```json - * { - * "id" - * "customerId" - * "planId" - * "websiteId" - * "initialInvoiceId" - * "billingContactId" - * "deliveryContactId" - * "quantity" - * "customFields" - * } - * ``` - * - * @author Veaceslav Medvedev - * @version 0.1 + * Class Subscription. */ final class Subscription extends Entity { @@ -50,18 +33,6 @@ public function getCustomerId() return $this->getAttribute('customerId'); } - /** - * @return null|Customer - */ - public function getCustomer() - { - if ($this->hasEmbeddedResource('customer')) { - return new Customer($this->getEmbeddedResource('customer')); - } else { - return null; - } - } - /** * @param string $value * @@ -80,46 +51,6 @@ public function getInitialInvoiceId() return $this->getAttribute('initialInvoiceId'); } - /** - * @param string $value - * - * @return Subscription - */ - public function setInitialInvoiceId($value) - { - return $this->setAttribute('initialInvoiceId', $value); - } - - /** - * @return string - */ - public function getPlanId() - { - return $this->getAttribute('planId'); - } - - /** - * @return null|Plan - */ - public function getPlan() - { - if ($this->hasEmbeddedResource('plan')) { - return new Plan($this->getEmbeddedResource('plan')); - } else { - return null; - } - } - - /** - * @param string $value - * - * @return Subscription - */ - public function setPlanId($value) - { - return $this->setAttribute('planId', $value); - } - /** * @return string */ @@ -128,18 +59,6 @@ public function getWebsiteId() return $this->getAttribute('websiteId'); } - /** - * @return null|Website - */ - public function getWebsite() - { - if ($this->hasEmbeddedResource('website')) { - return new Website($this->getEmbeddedResource('website')); - } else { - return null; - } - } - /** * @param string $value * @@ -150,92 +69,6 @@ public function setWebsiteId($value) return $this->setAttribute('websiteId', $value); } - /** - * @return int - */ - public function getQuantity() - { - return $this->getAttribute('quantity'); - } - - /** - * @param int $value - * - * @return Subscription - */ - public function setQuantity($value) - { - return $this->setAttribute('quantity', (int) $value); - } - - /** - * @deprecated The method is deprecated and will be removed in next version. - * - * @return string - */ - public function getBillingContactId() - { - return $this->getAttribute('billingContactId'); - } - - /** - * @deprecated The method is deprecated and will be removed in next version. - * - * @return null|Contact - */ - public function getBillingContact() - { - if ($this->hasEmbeddedResource('billingContact')) { - return new Contact($this->getEmbeddedResource('billingContact')); - } else { - return null; - } - } - - /** - * @deprecated The method is deprecated and will be removed in next version. - * @param string $value - * - * @return $this - */ - public function setBillingContactId($value) - { - return $this->setAttribute('billingContactId', $value); - } - - /** - * @return string - */ - public function getDeliveryContactId() - { - return $this->getAttribute('deliveryContactId'); - } - - /** - * @deprecated The method is deprecated and will be removed in next version. - * - * @return null|Contact - */ - public function getDeliveryContact() - { - if ($this->hasEmbeddedResource('deliveryContact')) { - return new Contact($this->getEmbeddedResource('deliveryContact')); - } else { - return null; - } - } - - /** - * @deprecated The method is deprecated and will be removed in next version. - * @param string $value - * - * @return $this - */ - public function setDeliveryContactId($value) - { - return $this->setAttribute('deliveryContactId', $value); - } - /** * @return string */ @@ -268,14 +101,6 @@ public function getRenewalTime() return $this->getAttribute('renewalTime'); } - /** - * @return string - */ - public function getCreatedTime() - { - return $this->getAttribute('createdTime'); - } - /** * @param string $value * @@ -286,6 +111,14 @@ public function setRenewalTime($value) return $this->setAttribute('renewalTime', $value); } + /** + * @return string + */ + public function getCreatedTime() + { + return $this->getAttribute('createdTime'); + } + /** * @return array */ @@ -362,18 +195,6 @@ public function getCancelDescription() return $this->getAttribute('cancelDescription'); } - /** - * @return null|LeadSource - */ - public function getLeadSource() - { - if ($this->hasEmbeddedResource('leadSource')) { - return new LeadSource($this->getEmbeddedResource('leadSource')); - } else { - return null; - } - } - /** * @return Address */ @@ -392,6 +213,16 @@ public function setBillingAddress($value) return $this->setAttribute('billingAddress', $value); } + /** + * @param array $data + * + * @return Address + */ + public function createBillingAddress(array $data) + { + return new Address($data); + } + /** * @return Address */ @@ -410,6 +241,16 @@ public function setDeliveryAddress($value) return $this->setAttribute('deliveryAddress', $value); } + /** + * @param array $data + * + * @return Address + */ + public function createDeliveryAddress(array $data) + { + return new Address($data); + } + /** * @return RiskMetadata */ @@ -429,38 +270,87 @@ public function setRiskMetadata($value) } /** - * @param array $data + * @return array + */ + public function getLineItems() + { + return $this->getAttribute('lineItems'); + } + + /** + * @return float + */ + public function getLineItemSubtotal() + { + return $this->getAttribute('lineItemSubtotal'); + } + + /** + * @return array|Subscriptions\PlanItem[] + */ + public function getItems() + { + return $this->getAttribute('items'); + } + + /** + * @param array $value * - * @return Address + * @return $this */ - public function createBillingAddress(array $data) + public function setItems(array $value) { - return new Address($data); + return $this->setAttribute('items', $value); } /** * @param array $data * - * @return Address + * @return array|Subscriptions\PlanItem[] */ - public function createDeliveryAddress(array $data) + public function createItems(array $data) { - return new Address($data); + return array_map( + function (array $item) { + return new Subscriptions\PlanItem($item); + }, + $data + ); } /** - * @return array + * @return null|Website */ - public function getLineItems() + public function getWebsite() { - return $this->getAttribute('lineItems'); + $data = $this->getEmbeddedResource('website'); + + return $data + ? new Website($data) + : null; } /** - * @return float + * @return null|Customer */ - public function getLineItemSubtotal() + public function getCustomer() { - return $this->getAttribute('lineItemSubtotal'); + $data = $this->getEmbeddedResource('customer'); + + return $data + ? new Customer($data) + : null; + } + + /** + * @return null|LeadSource + */ + public function getLeadSource() + { + $data = $this->getEmbeddedResource('leadSource'); + + return $data + ? new LeadSource($data) + : null; } } diff --git a/src/Entities/Subscriptions/PlanItem.php b/src/Entities/Subscriptions/PlanItem.php new file mode 100644 index 000000000..a831f5262 --- /dev/null +++ b/src/Entities/Subscriptions/PlanItem.php @@ -0,0 +1,53 @@ +getAttribute('planId'); + } + + /** + * @param null|string $value + * + * @return $this + */ + public function setPlanId($value) + { + return $this->setAttribute('planId', $value); + } + + /** + * @return null|int + */ + public function getQuantity() + { + return $this->getAttribute('quantity'); + } + + /** + * @param null|int $value + * + * @return $this + */ + public function setQuantity($value) + { + return $this->setAttribute('quantity', $value); + } +} diff --git a/src/Entities/Transaction.php b/src/Entities/Transaction.php index 954f74424..06cd2d638 100644 --- a/src/Entities/Transaction.php +++ b/src/Entities/Transaction.php @@ -331,4 +331,16 @@ public function getRedirectUrls() { return $this->getAttribute('redirectUrls'); } + + /** + * @return null|Customer + */ + public function getCustomer() + { + if ($this->hasEmbeddedResource('customer')) { + return new Customer($this->getEmbeddedResource('customer')); + } + + return null; + } } diff --git a/src/Services/EmailNotificationService.php b/src/Services/EmailNotificationService.php deleted file mode 100644 index e5e2553df..000000000 --- a/src/Services/EmailNotificationService.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @version 0.1 - */ -final class EmailNotificationService extends Service -{ - /** - * @param array|ArrayObject $params - * - * @return EmailNotification[][]|Collection[]|Paginator - */ - public function paginator($params = []) - { - return new Paginator($this->client(), 'email-notifications', $params); - } - - /** - * @param array|ArrayObject $params - * - * @return EmailNotification[]|Collection - */ - public function search($params = []) - { - return $this->client()->get('email-notifications', $params); - } - - /** - * @param string $notificationId - * @param array|ArrayObject $params - * - * @throws NotFoundException The customer does not exist - * - * @return EmailNotification - */ - public function load($notificationId, $params = []) - { - return $this->client()->get('email-notifications/{notificationId}', ['notificationId' => $notificationId] + (array) $params); - } - - /** - * @param array|JsonSerializable|EmailNotification $data - * @param string $notificationId - * - * @throws UnprocessableEntityException The input data is not valid - * - * @return EmailNotification - */ - public function create($data, $notificationId = null) - { - if (isset($notificationId)) { - return $this->client()->put($data, 'email-notifications/{notificationId}', ['notificationId' => $notificationId]); - } else { - return $this->client()->post($data, 'email-notifications'); - } - } - - /** - * @param string $notificationId - * @param array|JsonSerializable|EmailNotification $data - * - * @throws UnprocessableEntityException The input data is not valid - * - * @return EmailNotification - */ - public function update($notificationId, $data) - { - return $this->client()->put($data, 'email-notifications/{notificationId}', ['notificationId' => $notificationId]); - } - - /** - * @param array $data - */ - public function preview($data) - { - $this->client()->post($data, 'previews/email-notifications/send-notification'); - } -} diff --git a/src/Services/EmailNotificationTrackingService.php b/src/Services/EmailNotificationTrackingService.php deleted file mode 100644 index a3d6f76d1..000000000 --- a/src/Services/EmailNotificationTrackingService.php +++ /dev/null @@ -1,57 +0,0 @@ -client(), 'tracking/email-notifications', $params); - } - - /** - * @param array|ArrayObject $params - * - * @return EmailNotificationTracking[]|Collection - */ - public function search($params = []) - { - return $this->client()->get('tracking/email-notifications', $params); - } - - /** - * @param string $trackId - * @param array|ArrayObject $params - * - * @throws NotFoundException The resource data does exist - * - * @return EmailNotificationTracking - */ - public function load($trackId, $params = []) - { - return $this->client()->get('tracking/email-notifications/{trackId}', ['trackId' => $trackId] + (array) $params); - } -} diff --git a/src/Services/InvoiceService.php b/src/Services/InvoiceService.php index 808e00274..3b25b9819 100644 --- a/src/Services/InvoiceService.php +++ b/src/Services/InvoiceService.php @@ -13,7 +13,6 @@ use ArrayObject; use JsonSerializable; use Rebilly\Entities\Invoice; -use Rebilly\Entities\LeadSource; use Rebilly\Http\Exception\NotFoundException; use Rebilly\Http\Exception\UnprocessableEntityException; use Rebilly\Paginator; @@ -137,33 +136,4 @@ public function loadPdf($invoiceId, $params = []) ['accept' => 'application/pdf'] ); } - - /** - * @param string $invoiceId - * - * @return LeadSource - */ - public function getLeadSource($invoiceId) - { - return $this->client()->get('invoices/{invoiceId}/lead-source', ['invoiceId' => $invoiceId]); - } - - /** - * @param string $invoiceId - * @param array|JsonSerializable|LeadSource $leadSource - * - * @return LeadSource - */ - public function updateLeadSource($invoiceId, $leadSource) - { - return $this->client()->put($leadSource, 'invoices/{invoiceId}/lead-source', ['invoiceId' => $invoiceId]); - } - - /** - * @param string $invoiceId - */ - public function deleteLeadSource($invoiceId) - { - $this->client()->delete('invoices/{invoiceId}/lead-source', ['invoiceId' => $invoiceId]); - } } diff --git a/src/Services/LeadSourceService.php b/src/Services/LeadSourceService.php deleted file mode 100644 index 55cc8e410..000000000 --- a/src/Services/LeadSourceService.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @version 0.1 - */ -final class LeadSourceService extends Service -{ - /** - * @param array|ArrayObject $params - * - * @return LeadSource[][]|Collection[]|Paginator - */ - public function paginator($params = []) - { - return new Paginator($this->client(), 'lead-sources', $params); - } - - /** - * @param array|ArrayObject $params - * - * @return LeadSource[]|Collection - */ - public function search($params = []) - { - return $this->client()->get('lead-sources', $params); - } - - /** - * @param string $leadSourceId - * @param array|ArrayObject $params - * - * @throws NotFoundException The resource data does exist - * - * @return LeadSource - */ - public function load($leadSourceId, $params = []) - { - return $this->client()->get('lead-sources/{leadSourceId}', ['leadSourceId' => $leadSourceId] + (array) $params); - } - - /** - * @param array|JsonSerializable|LeadSource $data - * @param string $leadSourceId - * - * @throws UnprocessableEntityException The input data does not valid - * - * @return LeadSource - */ - public function create($data, $leadSourceId = null) - { - if (isset($leadSourceId)) { - return $this->client()->put($data, 'lead-sources/{leadSourceId}', ['leadSourceId' => $leadSourceId]); - } else { - return $this->client()->post($data, 'lead-sources'); - } - } -} diff --git a/src/Services/SubscriptionService.php b/src/Services/SubscriptionService.php index 37d4f1417..2776f0072 100644 --- a/src/Services/SubscriptionService.php +++ b/src/Services/SubscriptionService.php @@ -13,7 +13,6 @@ use ArrayObject; use JsonSerializable; use Rebilly\Entities\Invoice; -use Rebilly\Entities\LeadSource; use Rebilly\Entities\Subscription; use Rebilly\Entities\SubscriptionCancel; use Rebilly\Entities\SubscriptionChangePlan; @@ -145,33 +144,4 @@ public function issueInterimInvoice($subscriptionId, $data) ['subscriptionId' => $subscriptionId] ); } - - /** - * @param string $subscriptionId - * - * @return LeadSource - */ - public function getLeadSource($subscriptionId) - { - return $this->client()->get('subscriptions/{subscriptionId}/lead-source', ['subscriptionId' => $subscriptionId]); - } - - /** - * @param string $subscriptionId - * @param array|JsonSerializable|LeadSource $leadSource - * - * @return LeadSource - */ - public function updateLeadSource($subscriptionId, $leadSource) - { - return $this->client()->put($leadSource, 'subscriptions/{subscriptionId}/lead-source', ['subscriptionId' => $subscriptionId]); - } - - /** - * @param string $subscriptionId - */ - public function deleteLeadSource($subscriptionId) - { - $this->client()->delete('subscriptions/{subscriptionId}/lead-source', ['subscriptionId' => $subscriptionId]); - } } diff --git a/src/Services/TransactionService.php b/src/Services/TransactionService.php index c044de2f6..76e988300 100644 --- a/src/Services/TransactionService.php +++ b/src/Services/TransactionService.php @@ -11,7 +11,6 @@ namespace Rebilly\Services; use ArrayObject; -use Rebilly\Entities\LeadSource; use Rebilly\Entities\Transaction; use Rebilly\Http\Exception\NotFoundException; use Rebilly\Http\Exception\UnprocessableEntityException; @@ -76,33 +75,4 @@ public function refund($transactionId, $amount) ['transactionId' => $transactionId] ); } - - /** - * @param string $transactionId - * - * @return LeadSource - */ - public function getLeadSource($transactionId) - { - return $this->client()->get('transactions/{transactionId}/lead-source', ['transactionId' => $transactionId]); - } - - /** - * @param string $transactionId - * @param array|JsonSerializable|LeadSource $leadSource - * - * @return LeadSource - */ - public function updateLeadSource($transactionId, $leadSource) - { - return $this->client()->put($leadSource, 'transactions/{transactionId}/lead-source', ['transactionId' => $transactionId]); - } - - /** - * @param string $transactionId - */ - public function deleteLeadSource($transactionId) - { - $this->client()->delete('transactions/{transactionId}/lead-source', ['transactionId' => $transactionId]); - } } diff --git a/tests/Api/ApiTest.php b/tests/Api/ApiTest.php index 2f7db7aad..3e253ae92 100644 --- a/tests/Api/ApiTest.php +++ b/tests/Api/ApiTest.php @@ -143,7 +143,6 @@ public function provideEntityClasses() [Entities\InvoiceItem::class], [Entities\Layout::class], [Entities\LayoutItem::class, null], - [Entities\LeadSource::class], [Entities\Payment::class], [Entities\PaymentMethods\PaymentCardMethod::class, null], [Entities\PaymentCard::class], @@ -188,9 +187,6 @@ public function provideEntityClasses() [Entities\WebhookTracking::class], [Entities\Shipping\ShippingZone::class], [Entities\InvoiceTax::class], - [Entities\EmailNotifications\EmailNotification::class], - [Entities\EmailNotifications\EmailNotificationTracking::class], - [Entities\EmailNotifications\Notification::class], [Entities\SubscriptionChangePlan::class], [Entities\SubscriptionInterimInvoice::class], [Entities\PaymentInstruments\BankAccountPaymentInstrument::class], diff --git a/tests/Api/LeadSourceTest.php b/tests/Api/LeadSourceTest.php new file mode 100644 index 000000000..d0f1be76f --- /dev/null +++ b/tests/Api/LeadSourceTest.php @@ -0,0 +1,123 @@ +setSource('source'); + $leadSource->setCurrency('USD'); + $leadSource->setAmount(10.5); + $leadSource->setAffiliate('affiliate'); + $leadSource->setCampaign('campaign'); + $leadSource->setClickId('123'); + $leadSource->setContent('content'); + $leadSource->setMedium('medium'); + $leadSource->setPath('path'); + $leadSource->setSalesAgent('agent'); + $leadSource->setTerm('term'); + $leadSource->setSubAffiliate('subaffiliate'); + + self::assertSame('source', $leadSource->getSource()); + self::assertSame('USD', $leadSource->getCurrency()); + self::assertSame(10.5, $leadSource->getAmount()); + self::assertSame('affiliate', $leadSource->getAffiliate()); + self::assertSame('campaign', $leadSource->getCampaign()); + self::assertSame('123', $leadSource->getClickId()); + self::assertSame('content', $leadSource->getContent()); + self::assertSame('medium', $leadSource->getMedium()); + self::assertSame('path', $leadSource->getPath()); + self::assertSame('agent', $leadSource->getSalesAgent()); + self::assertSame('term', $leadSource->getTerm()); + self::assertSame('subaffiliate', $leadSource->getSubAffiliate()); + self::assertSame(null, $leadSource->getOriginal()->getSource()); + self::assertSame(null, $leadSource->getOriginal()->getCurrency()); + self::assertSame(null, $leadSource->getOriginal()->getAmount()); + self::assertSame(null, $leadSource->getOriginal()->getAffiliate()); + self::assertSame(null, $leadSource->getOriginal()->getCampaign()); + self::assertSame(null, $leadSource->getOriginal()->getClickId()); + self::assertSame(null, $leadSource->getOriginal()->getContent()); + self::assertSame(null, $leadSource->getOriginal()->getMedium()); + self::assertSame(null, $leadSource->getOriginal()->getPath()); + self::assertSame(null, $leadSource->getOriginal()->getSalesAgent()); + self::assertSame(null, $leadSource->getOriginal()->getTerm()); + } + + /** + * @test + */ + public function leadSourceWithData() + { + $leadSource = new LeadSource([ + 'source' => 'source', + 'currency' => 'USD', + 'amount' => 10.5, + 'affiliate' => 'affiliate', + 'campaign' => 'campaign', + 'clickId' => '123', + 'content' => 'content', + 'medium' => 'medium', + 'path' => 'path', + 'salesAgent' => 'agent', + 'term' => 'term', + 'subAffiliate' => 'subaffiliate', + 'original' => [ + 'source' => 'original-source', + 'currency' => 'EUR', + 'amount' => 12.5, + 'affiliate' => 'original-affiliate', + 'campaign' => 'original-campaign', + 'clickId' => 'original-123', + 'content' => 'original-content', + 'medium' => 'original-medium', + 'path' => 'original-path', + 'salesAgent' => 'original-agent', + 'term' => 'original-term', + 'subAffiliate' => 'original-subaffiliate', + ], + ]); + + self::assertSame('source', $leadSource->getSource()); + self::assertSame('USD', $leadSource->getCurrency()); + self::assertSame(10.5, $leadSource->getAmount()); + self::assertSame('affiliate', $leadSource->getAffiliate()); + self::assertSame('campaign', $leadSource->getCampaign()); + self::assertSame('123', $leadSource->getClickId()); + self::assertSame('content', $leadSource->getContent()); + self::assertSame('medium', $leadSource->getMedium()); + self::assertSame('path', $leadSource->getPath()); + self::assertSame('agent', $leadSource->getSalesAgent()); + self::assertSame('term', $leadSource->getTerm()); + self::assertSame('subaffiliate', $leadSource->getSubAffiliate()); + + self::assertSame('original-source', $leadSource->getOriginal()->getSource()); + self::assertSame('EUR', $leadSource->getOriginal()->getCurrency()); + self::assertSame(12.5, $leadSource->getOriginal()->getAmount()); + self::assertSame('original-affiliate', $leadSource->getOriginal()->getAffiliate()); + self::assertSame('original-campaign', $leadSource->getOriginal()->getCampaign()); + self::assertSame('original-123', $leadSource->getOriginal()->getClickId()); + self::assertSame('original-content', $leadSource->getOriginal()->getContent()); + self::assertSame('original-medium', $leadSource->getOriginal()->getMedium()); + self::assertSame('original-path', $leadSource->getOriginal()->getPath()); + self::assertSame('original-agent', $leadSource->getOriginal()->getSalesAgent()); + self::assertSame('original-term', $leadSource->getOriginal()->getTerm()); + self::assertSame('original-subaffiliate', $leadSource->getOriginal()->getSubAffiliate()); + } +} diff --git a/tests/Api/ServiceTest.php b/tests/Api/ServiceTest.php index 1c0d7178f..2e16dff4e 100644 --- a/tests/Api/ServiceTest.php +++ b/tests/Api/ServiceTest.php @@ -340,38 +340,6 @@ public function invoiceItemService() $this->assertInstanceOf(Entities\InvoiceItem::class, $result); } - /** - * @test - */ - public function invoiceLeadSourcesService() - { - $client = new Client(['apiKey' => 'QWERTY']); - - /** @var CurlHandler|MockObject $handler */ - $handler = $this->getMock(CurlHandler::class); - $handler - ->expects($this->any()) - ->method('__invoke') - ->will($this->returnValue( - $client->createResponse()->withHeader('Location', 'lead-sources/dummy') - )); - - $client = new Client([ - 'apiKey' => 'QWERTY', - 'httpHandler' => $handler, - ]); - - $service = $client->invoices(); - - $result = $service->getLeadSource('dummy'); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $result = $service->updateLeadSource('dummy', []); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $service->deleteLeadSource('dummy'); - } - /** * @test */ @@ -435,38 +403,6 @@ public function subscriptionCancellationService() $this->assertInstanceOf(Entities\SubscriptionCancellation::class, $result); } - /** - * @test - */ - public function subscriptionLeadSourcesService() - { - $client = new Client(['apiKey' => 'QWERTY']); - - /** @var CurlHandler|MockObject $handler */ - $handler = $this->getMock(CurlHandler::class); - $handler - ->expects($this->any()) - ->method('__invoke') - ->will($this->returnValue( - $client->createResponse()->withHeader('Location', 'lead-sources/dummy') - )); - - $client = new Client([ - 'apiKey' => 'QWERTY', - 'httpHandler' => $handler, - ]); - - $service = $client->subscriptions(); - - $result = $service->getLeadSource('dummy'); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $result = $service->updateLeadSource('dummy', []); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $service->deleteLeadSource('dummy'); - } - /** * @test */ @@ -523,38 +459,6 @@ public function transactionService() $this->assertInstanceOf(Entities\Transaction::class, $result); } - /** - * @test - */ - public function transactionLeadSourcesService() - { - $client = new Client(['apiKey' => 'QWERTY']); - - /** @var CurlHandler|MockObject $handler */ - $handler = $this->getMock(CurlHandler::class); - $handler - ->expects($this->any()) - ->method('__invoke') - ->will($this->returnValue( - $client->createResponse()->withHeader('Location', 'lead-sources/dummy') - )); - - $client = new Client([ - 'apiKey' => 'QWERTY', - 'httpHandler' => $handler, - ]); - - $service = $client->transactions(); - - $result = $service->getLeadSource('dummy'); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $result = $service->updateLeadSource('dummy', []); - $this->assertInstanceOf(Entities\LeadSource::class, $result); - - $service->deleteLeadSource('dummy'); - } - /** * @test */ @@ -835,33 +739,6 @@ public function redemptionService() $this->assertInstanceOf(Entities\Coupons\Redemption::class, $result); } - /** - * @test - */ - public function emailNotificationService() - { - $client = new Client(['apiKey' => 'QWERTY']); - - /** @var CurlHandler|MockObject $handler */ - $handler = $this->getMock(CurlHandler::class); - - $handler - ->expects($this->any()) - ->method('__invoke') - ->will($this->returnValue( - $client->createResponse()->withHeader('Location', 'email-notifications/dummy') - )); - - $client = new Client([ - 'apiKey' => 'QWERTY', - 'httpHandler' => $handler, - ]); - - $service = $client->emailNotifications(); - - $service->preview([]); - } - /** * @test */ @@ -1159,11 +1036,6 @@ public function provideServiceClasses() Services\LayoutService::class, Entities\Layout::class, ], - [ - 'leadSources', - Services\LeadSourceService::class, - Entities\LeadSource::class, - ], [ 'paymentCards', Services\PaymentCardService::class, @@ -1324,16 +1196,6 @@ public function provideServiceClasses() Services\RedemptionService::class, Entities\Coupons\Redemption::class, ], - [ - 'emailNotifications', - Services\EmailNotificationService::class, - Entities\EmailNotifications\EmailNotification::class, - ], - [ - 'emailNotificationsTracking', - Services\EmailNotificationTrackingService::class, - Entities\EmailNotifications\EmailNotificationTracking::class, - ], ]; } } diff --git a/tests/Entities/Subscriptions/PlanItemTest.php b/tests/Entities/Subscriptions/PlanItemTest.php new file mode 100644 index 000000000..6cd3d15d6 --- /dev/null +++ b/tests/Entities/Subscriptions/PlanItemTest.php @@ -0,0 +1,26 @@ + 'plan-1', 'quantity' => 2]; + + $value = new PlanItem(); + $value->setPlanId('plan-1'); + $value->setQuantity(2); + self::assertSame($expectedData, $value->jsonSerialize()); + + $value = new PlanItem($expectedData); + self::assertSame($expectedData['planId'], $value->getPlanId()); + self::assertSame($expectedData['quantity'], $value->getQuantity()); + } +} diff --git a/tests/Entities/Subscriptions/SubscriptionTest.php b/tests/Entities/Subscriptions/SubscriptionTest.php new file mode 100644 index 000000000..36c9fec81 --- /dev/null +++ b/tests/Entities/Subscriptions/SubscriptionTest.php @@ -0,0 +1,159 @@ + 'John', + 'lastName' => 'Doe', + ]; + + return [ + 'id' => 'subscription-1', + 'status' => 'draft', + 'customerId' => 'customer-1', + 'websiteId' => 'website-1', + 'initialInvoiceId' => 'invoice-1', + 'autopay' => true, + 'startTime' => $now->modify('+1 day')->format('c'), + 'endTime' => $now->modify('+1 year')->format('c'), + 'renewalTime' => $now->modify('+1 month')->format('c'), + 'createdTime' => $now->format('c'), + 'customFields' => ['foo' => 'bar'], + 'inTrial' => false, + 'rebillNumber' => null, + 'canceledTime' => $now->modify('+1 week')->format('c'), + 'cancelCategory' => 'did-not-want', + 'canceledBy' => 'customer', + 'cancelDescription' => 'Cancelled manually', + 'billingAddress' => $address, + 'deliveryAddress' => $address, + 'riskMetadata' => [ + 'ipAddress' => '127.0.0.1', + ], + 'lineItems' => [], + 'lineItemSubtotal' => 0, + 'items' => [ + ['planId' => 'plan-1', 'quantity' => 1], + ['planId' => 'plan-2', 'quantity' => null], + ['planId' => 'plan-3'], + ], + '_embedded' => [ + 'website' => ['id' => 'website-1'], + 'customer' => ['id' => 'customer-1'], + 'leadSource' => ['id' => 'leadSource-1'], + ], + ]; + } + + /** + * @test + */ + public function buildObjectUsingSetterToSendToServer() + { + $data = self::getDefaultData(); + + $value = new Subscription(); + $value->setCustomerId($data['customerId']); + $value->setWebsiteId($data['websiteId']); + $value->setAutopay(true); + $value->setRenewalTime($data['renewalTime']); + $value->setCustomFields($data['customFields']); + $value->setBillingAddress($data['billingAddress']); + $value->setDeliveryAddress($data['deliveryAddress']); + $value->setRiskMetadata($data['riskMetadata']); + $value->setItems($data['items']); + + $expectedJson = $data; + // Unset read-only properties which we not set. + unset( + $expectedJson['id'], + $expectedJson['status'], + $expectedJson['startTime'], + $expectedJson['endTime'], + $expectedJson['createdTime'], + $expectedJson['inTrial'], + $expectedJson['rebillNumber'], + $expectedJson['canceledTime'], + $expectedJson['cancelCategory'], + $expectedJson['canceledBy'], + $expectedJson['cancelDescription'], + $expectedJson['lineItems'], + $expectedJson['lineItemSubtotal'], + $expectedJson['initialInvoiceId'], + $expectedJson['_embedded'] + ); + + self::assertSame($expectedJson, $value->jsonSerialize()); + } + + /** + * @test + */ + public function populatePlanFromArrayReceivedFromServer() + { + $data = self::getDefaultData(); + + $value = new Subscription($data); + + // Check properties + self::assertSame($data['id'], $value->getId()); + self::assertSame($data['status'], $value->getStatus()); + self::assertSame($data['customerId'], $value->getCustomerId()); + self::assertSame($data['websiteId'], $value->getWebsiteId()); + self::assertSame($data['initialInvoiceId'], $value->getInitialInvoiceId()); + self::assertSame($data['autopay'], $value->getAutopay()); + self::assertSame($data['startTime'], $value->getStartTime()); + self::assertSame($data['endTime'], $value->getEndTime()); + self::assertSame($data['renewalTime'], $value->getRenewalTime()); + self::assertSame($data['createdTime'], $value->getCreatedTime()); + self::assertSame($data['customFields'], $value->getCustomFields()); + self::assertSame($data['inTrial'], $value->getInTrial()); + self::assertSame($data['rebillNumber'], $value->getRebillNumber()); + self::assertSame($data['canceledTime'], $value->getCanceledTime()); + self::assertSame($data['cancelCategory'], $value->getCancelCategory()); + self::assertSame($data['canceledBy'], $value->getCanceledBy()); + self::assertSame($data['cancelDescription'], $value->getCancelDescription()); + self::assertInstanceOf(Address::class, $value->getBillingAddress()); + self::assertSame($data['billingAddress'], $value->getBillingAddress()->jsonSerialize()); + self::assertInstanceOf(Address::class, $value->getDeliveryAddress()); + self::assertSame($data['deliveryAddress'], $value->getDeliveryAddress()->jsonSerialize()); + self::assertSame($data['riskMetadata'], $value->getRiskMetadata()); + self::assertSame($data['lineItems'], $value->getLineItems()); + self::assertSame($data['lineItemSubtotal'], $value->getLineItemSubtotal()); + self::assertInternalType('array', $value->getItems()); + self::assertCount(3, $value->getItems()); + + foreach ($value->getItems() as $i => $item) { + self::assertInstanceOf(PlanItem::class, $item); + self::assertSame($data['items'][$i], $item->jsonSerialize()); + } + + // Check relationship + self::assertInstanceOf(Website::class, $value->getWebsite()); + self::assertInstanceOf(Customer::class, $value->getCustomer()); + self::assertInstanceOf(LeadSource::class, $value->getLeadSource()); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index c05e9e6f8..f38ad3d83 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -333,13 +333,23 @@ protected function getFakeValue($attribute, $class) switch ($class) { case Entities\Layout::class: return [ - new Entities\LayoutItem([ - 'planId' => 'foo', - 'starred' => true, - ]), - new Entities\LayoutItem([ - 'planId' => 'bar', - ]), + new Entities\LayoutItem( + [ + 'planId' => 'foo', + 'starred' => true, + ] + ), + new Entities\LayoutItem( + [ + 'planId' => 'bar', + ] + ), + ]; + case Entities\Subscription::class: + return [ + ['planId' => 'plan-1', 'quantity' => 1], + ['planId' => 'plan-2', 'quantity' => null], + ['planId' => 'plan-3'], ]; default: throw new InvalidArgumentException(