Skip to content

Commit

Permalink
Change Subscription Cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
viceromag committed Jan 27, 2017
1 parent e671ce6 commit 508e1fd
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ public function getRebillNumber()
return $this->getAttribute('rebillNumber');
}

/**
* @return string
*/
public function getCancelCategory()
{
return $this->getAttribute('cancelCategory');
}

/**
* @return string
*/
public function getCanceledBy()
{
return $this->getAttribute('canceledBy');
}

/**
* @return null|LeadSource
*/
Expand Down
92 changes: 92 additions & 0 deletions src/Entities/SubscriptionCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@
class SubscriptionCancel extends Resource
{
const MSG_UNEXPECTED_POLICY = 'Unexpected type. Only %s types support';
const UNEXPECTED_CATEGORY = 'Unexpected cancel category. Only %s categories are supported';
const UNEXPECTED_CANCEL_SOURCE = 'Unexpected cancel source. Only %s cancel sources are supported';

const AT_NEXT_RENEWAL = 'at-next-renewal';
const NOW = 'now';
const NOW_WITH_PRORATA_CREDIT = 'now-with-prorata-credit';

const CATEGORY_OTHER = 'other';
const CATEGORY_BILLING_FAILURE = 'billing-failure';
const CATEGORY_DID_NOT_USE = 'did-not-use';
const CATEGORY_DID_NOT_WANT = 'did-not-want';
const CATEGORY_MISSING_FEATURES = 'missing-features';
const CATEGORY_BUGS_OR_PROBLEMS = 'bugs-or-problems';
const CATEGORY_DO_NOT_REMEMBER = 'suspected-fraud';
const CATEGORY_RISK_WARNING = 'contract-expired';
const CATEGORY_TOO_EXPENSIVE = 'too-expensive';

const SOURCE_MERCHANT = 'merchant';
const SOURCE_CUSTOMER = 'customer';

/**
* @return array
*/
Expand All @@ -39,6 +54,35 @@ public static function policies()
];
}

/**
* @return array
*/
public static function cancelCategories()
{
return [
self::CATEGORY_OTHER,
self::CATEGORY_BILLING_FAILURE,
self::CATEGORY_DID_NOT_USE,
self::CATEGORY_DID_NOT_WANT,
self::CATEGORY_MISSING_FEATURES,
self::CATEGORY_BUGS_OR_PROBLEMS,
self::CATEGORY_DO_NOT_REMEMBER,
self::CATEGORY_RISK_WARNING,
self::CATEGORY_TOO_EXPENSIVE,
];
}

/**
* @return array
*/
public static function canceledBySources()
{
return [
self::SOURCE_MERCHANT,
self::SOURCE_CUSTOMER,
];
}

/**
* @return string
*/
Expand All @@ -47,6 +91,22 @@ public function getPolicy()
return $this->getAttribute('policy');
}

/**
* @return string
*/
public function getCancelCategory()
{
return $this->getAttribute('cancelCategory');
}

/**
* @return string
*/
public function getCanceledBy()
{
return $this->getAttribute('cancelledBy');
}

/**
* @param string $value
*
Expand All @@ -62,4 +122,36 @@ public function setPolicy($value)

return $this->setAttribute('policy', $value);
}

/**
* @param string $value
*
* @throws DomainException
*
* @return SubscriptionCancel
*/
public function setCancelCategory($value)
{
if (!in_array($value, self::cancelCategories())) {
throw new DomainException(sprintf(self::UNEXPECTED_CATEGORY, implode(', ', self::cancelCategories())));
}

return $this->setAttribute('category', $value);
}

/**
* @param string $value
*
* @throws DomainException
*
* @return SubscriptionCancel
*/
public function setCanceledBy($value)
{
if (!in_array($value, self::getCanceledBy())) {
throw new DomainException(sprintf(self::UNEXPECTED_CATEGORY, implode(', ', self::getCanceledBy())));
}

return $this->setAttribute('by', $value);
}
}

0 comments on commit 508e1fd

Please sign in to comment.