-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes the mandatory parameters to update subscription route
It's not mandatory to send all parameters to the update. It's possible to change, for instance, only the plan_id without to alter the card or the payment method. To implement it, we use the "memento pattern" instead to make a new request of the early data subscription. Changes the "plan_id" parameter name. Use "plan_id" instead of "plan" because the body of request with "plan" is not accepted by API in the route PUT /subscriptions/:id. Create methods to load the card, plan and payment method with specific validations to be attached in the body of the request. Changes unit tests and creates behaviour tests.
- Loading branch information
1 parent
6263175
commit c2e2a0d
Showing
8 changed files
with
284 additions
and
83 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
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,102 @@ | ||
<?php | ||
|
||
namespace PagarMe\Sdk\Subscription; | ||
|
||
use PagarMe\Sdk\Card\Card; | ||
use PagarMe\Sdk\Plan\Plan; | ||
|
||
class SubscriptionMemento | ||
{ | ||
/** | ||
* @var int $id | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var Card $card | ||
*/ | ||
private $card; | ||
|
||
/** | ||
* @var Plan $plan | ||
*/ | ||
private $plan; | ||
|
||
/** | ||
* @var string $paymentMethod | ||
*/ | ||
private $paymentMethod; | ||
|
||
/** | ||
* @param Subscription $subscription | ||
*/ | ||
public function __construct(Subscription $subscription) | ||
{ | ||
$this->setCard($subscription); | ||
$this->setPlan($subscription); | ||
$this->setPaymentMethod($subscription); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getId(Subscription $subscription) | ||
{ | ||
$subscription->setId($this->id); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getCard(Subscription $subscription) | ||
{ | ||
$subscription->setCard($this->card); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function setCard(Subscription $subscription) | ||
{ | ||
$this->card = $subscription->getCard(); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getPlan(Subscription $subscription) | ||
{ | ||
$subscription->setPlan($this->plan); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function setPlan(Subscription $subscription) | ||
{ | ||
$this->plan = $subscription->getPlan(); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function getPaymentMethod(Subscription $subscription) | ||
{ | ||
$subscription->setPaymentMethod($this->paymentMethod); | ||
} | ||
|
||
/** | ||
* @param Subscription $subscription | ||
* @codeCoverageIgnore | ||
*/ | ||
public function setPaymentMethod(Subscription $subscription) | ||
{ | ||
$this->paymentMethod = $subscription->getPaymentMethod(); | ||
} | ||
} |
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
Oops, something went wrong.