-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
/** | ||
* This source file is proprietary and part of Rebilly. | ||
* | ||
* (c) Rebilly SRL | ||
* Rebilly Ltd. | ||
* Rebilly Inc. | ||
* | ||
* @see https://www.rebilly.com | ||
*/ | ||
|
||
namespace Rebilly\Entities; | ||
|
||
use DomainException; | ||
use Rebilly\Entities\Subscriptions\PlanItem; | ||
use Rebilly\Rest\Resource; | ||
|
||
class SubscriptionChangeItems extends Resource | ||
{ | ||
public const UNEXPECTED_RENEWAL_POLICY = 'Unexpected renewalPolicy. Only %s are supported'; | ||
|
||
public const RENEWAL_POLICY_RESET = 'reset'; | ||
|
||
public const RENEWAL_POLICY_RETAIN = 'retain'; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function renewalPolicies() | ||
{ | ||
return [ | ||
self::RENEWAL_POLICY_RESET, | ||
self::RENEWAL_POLICY_RETAIN, | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $value | ||
* | ||
* @return $this | ||
*/ | ||
public function setItems(array $value) | ||
{ | ||
return $this->setAttribute('items', $value); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return array|Subscriptions\PlanItem[] | ||
*/ | ||
public function createItems(array $data) | ||
{ | ||
return array_map( | ||
function ($item) { | ||
if ($item instanceof PlanItem) { | ||
return $item; | ||
} | ||
|
||
return new Subscriptions\PlanItem($item); | ||
}, | ||
$data | ||
); | ||
} | ||
|
||
/** | ||
* @param string $value | ||
* | ||
* @throws DomainException | ||
*/ | ||
public function setRenewalPolicy($value) | ||
{ | ||
if (!in_array($value, self::renewalPolicies(), true)) { | ||
throw new DomainException(sprintf(self::UNEXPECTED_RENEWAL_POLICY, implode(', ', self::renewalPolicies()))); | ||
} | ||
$this->setAttribute('renewalPolicy', $value); | ||
} | ||
|
||
/** | ||
* @param bool $value | ||
*/ | ||
public function setProrated($value) | ||
{ | ||
$this->setAttribute('prorated', $value); | ||
} | ||
|
||
/** | ||
* @param string $value | ||
*/ | ||
public function setEffectiveTime($value) | ||
{ | ||
$this->setAttribute('effectiveTime', $value); | ||
} | ||
|
||
/** | ||
* @param bool $value | ||
*/ | ||
public function setPreview($value) | ||
{ | ||
$this->setAttribute('preview', $value); | ||
} | ||
|
||
/** | ||
* @param bool $value | ||
*/ | ||
public function setKeepTrial($value) | ||
{ | ||
$this->setAttribute('keepTrial', $value); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getPreview() | ||
{ | ||
return $this->getAttribute('preview'); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getProrated() | ||
{ | ||
return $this->getAttribute('prorated'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRenewalPolicy() | ||
{ | ||
return $this->getAttribute('renewalPolicy'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEffectiveTime() | ||
{ | ||
return $this->getAttribute('effectiveTime'); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getKeepTrial() | ||
{ | ||
return $this->getAttribute('keepTrial'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters