Skip to content

Commit 82738c5

Browse files
feat: Add ability to know the payment method related to a fee plan (#225)
* feat: Add ability to know the payment method related to a fee plan * feat: refactor interface * feat: add test and more conditions * fix: review * fix: remove unused use --------- Co-authored-by: Benjamin Freoua <benjamin.freoua@getalma.eu>
1 parent f2dab72 commit 82738c5

5 files changed

Lines changed: 28 additions & 25 deletions

File tree

src/Domain/Entity/PaymentPlanTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Alma\API\Domain\Entity;
44

5+
use Alma\API\Domain\ValueObject\PaymentMethod;
6+
57
/**
68
* Trait PaymentPlanTrait
79
*
@@ -24,6 +26,25 @@ public function getPlanKey(): string
2426
);
2527
}
2628

29+
/**
30+
* Get the payment method this payment plan applies to.
31+
*
32+
* @return string
33+
*/
34+
public function getPaymentMethod(): string
35+
{
36+
if ($this->isCredit()) {
37+
$paymentMethod = PaymentMethod::CREDIT;
38+
} elseif ($this->isPnXOnly()) {
39+
$paymentMethod = PaymentMethod::PNX;
40+
} elseif ($this->isPayLaterOnly()) {
41+
$paymentMethod = PaymentMethod::PAY_LATER;
42+
} else {
43+
$paymentMethod = PaymentMethod::PAY_NOW;
44+
}
45+
return $paymentMethod;
46+
}
47+
2748
/**
2849
* Check if a payment plan is "pay later" compliant.
2950
* Warning, a payment plan can be both un-compliant with "pay later" nor "PnX".

src/Domain/Repository/GatewayRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
namespace Alma\API\Domain\Repository;
44

55
interface GatewayRepositoryInterface {
6-
public function findAllAlmaGateways(): array;
6+
public function findOrderedAlmaGateways(): array;
77
}

src/Domain/ValueObject/PaymentMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ final class PaymentMethod
1414
public const PAY_NOW = 'paynow';
1515
public const CREDIT = 'credit';
1616
public const PNX = 'pnx';
17-
}
17+
}

tests/Unit/Infrastructure/CurlClientTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ public function stringToStream(string $string): Stream
8989
return new Stream($resourceFromString);
9090
}
9191

92-
/**
93-
* @throws ClientException
94-
*/
9592
public function testConfig()
9693
{
9794
$client = new CurlClient($this->clientConfiguration);

tests/Unit/Infrastructure/Endpoint/Entity/PaymentPlanTraitTest.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static function paymentPlanProvider(): array
2222
'plan_key' => 'general_4_0_0',
2323
'is_pay_later_only' => false,
2424
'is_pnx_only' => true,
25-
'is_both_pnx_and_pay_later' => false,
2625
'is_pay_now' => false,
26+
'payment_method' => 'pnx',
2727
]
2828
],
2929
'paylater_deferred_months' => [
@@ -37,8 +37,8 @@ public static function paymentPlanProvider(): array
3737
'plan_key' => 'general_1_0_3',
3838
'is_pay_later_only' => true,
3939
'is_pnx_only' => false,
40-
'is_both_pnx_and_pay_later' => false,
4140
'is_pay_now' => false,
41+
'payment_method' => 'paylater',
4242
]
4343
],
4444
'paylater_deferred_days' => [
@@ -52,23 +52,8 @@ public static function paymentPlanProvider(): array
5252
'plan_key' => 'general_1_30_0',
5353
'is_pay_later_only' => true,
5454
'is_pnx_only' => false,
55-
'is_both_pnx_and_pay_later' => false,
56-
'is_pay_now' => false,
57-
]
58-
],
59-
'pnx_and_paylater' => [
60-
'params' => [
61-
'kind' => 'general',
62-
'installments_count' => 3,
63-
'deferred_days' => 15,
64-
'deferred_months' => 0,
65-
],
66-
'expected' => [
67-
'plan_key' => 'general_3_15_0',
68-
'is_pay_later_only' => false,
69-
'is_pnx_only' => false,
70-
'is_both_pnx_and_pay_later' => true,
7155
'is_pay_now' => false,
56+
'payment_method' => 'paylater',
7257
]
7358
],
7459
'pay_now' => [
@@ -82,8 +67,8 @@ public static function paymentPlanProvider(): array
8267
'plan_key' => 'general_1_0_0',
8368
'is_pay_later_only' => false,
8469
'is_pnx_only' => false,
85-
'is_both_pnx_and_pay_later' => false,
8670
'is_pay_now' => true,
71+
'payment_method' => 'paynow',
8772
]
8873
]
8974
];
@@ -135,7 +120,7 @@ public function getDeferredMonths(): int
135120
$this->assertEquals($expected['plan_key'], $paymentPlanImplementation->getPlanKey());
136121
$this->assertEquals($expected['is_pay_later_only'], $paymentPlanImplementation->isPayLaterOnly());
137122
$this->assertEquals($expected['is_pnx_only'], $paymentPlanImplementation->isPnXOnly());
138-
$this->assertEquals($expected['is_both_pnx_and_pay_later'], $paymentPlanImplementation->isBothPnxAndPayLater());
139123
$this->assertEquals($expected['is_pay_now'], $paymentPlanImplementation->isPayNow());
124+
$this->assertEquals($expected['payment_method'], $paymentPlanImplementation->getPaymentMethod());
140125
}
141126
}

0 commit comments

Comments
 (0)