Skip to content

Commit

Permalink
fix: Fix extending happening on non subscription payments
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Feb 2, 2021
1 parent 1117d2d commit 1cab844
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function complete($request)
$payment_dao->save($payment);

$account = $payment->account();
if ($account) {
if ($account && $payment->type === 'subscription') {
$account->extendSubscription($payment->frequency);
$account_dao->save($account);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/cli/PaymentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testCompleteExtendsSubscriptionIfAccountIsAttached($frequency)
'expired_at' => \Minz\Time::now()->format(\Minz\Model::DATETIME_FORMAT),
]);
$payment_id = $this->create('payment', [
'type' => 'subscription',
'completed_at' => null,
'is_paid' => 1,
'account_id' => $account_id,
Expand All @@ -71,6 +72,29 @@ public function testCompleteExtendsSubscriptionIfAccountIsAttached($frequency)
$this->assertSame($expected_expired_at->getTimestamp(), $account->expired_at->getTimestamp());
}

public function testCompleteDontExtendsSubscriptionIfNotSubscription()
{
$now = $this->fake('dateTime');
$this->freeze($now);
$account_dao = new models\dao\Account();
$expired_at = \Minz\Time::now();
$account_id = $this->create('account', [
'expired_at' => $expired_at->format(\Minz\Model::DATETIME_FORMAT),
]);
$type = $this->fake('randomElement', ['common_pot', 'credit']);
$payment_id = $this->create('payment', [
'type' => $type,
'completed_at' => null,
'is_paid' => 1,
'account_id' => $account_id,
]);

$response = $this->appRun('CLI', '/payments/complete');

$account = new models\Account($account_dao->find($account_id));
$this->assertSame($expired_at->getTimestamp(), $account->expired_at->getTimestamp());
}

public function testCompleteCreatesAnInvoice()
{
$payment_dao = new models\dao\Payment();
Expand Down

0 comments on commit 1cab844

Please sign in to comment.