forked from mollie/laravel-cashier-mollie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManageChargesTest.php
More file actions
61 lines (52 loc) · 2.04 KB
/
Copy pathManageChargesTest.php
File metadata and controls
61 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Laravel\Cashier\Tests\Charge;
use Laravel\Cashier\Charge\ChargeItem;
use Laravel\Cashier\Charge\FirstPaymentChargeBuilder;
use Laravel\Cashier\Charge\MandatedChargeBuilder;
use Laravel\Cashier\Exceptions\MandateIsNotYetFinalizedException;
use Laravel\Cashier\Tests\BaseTestCase;
use Laravel\Cashier\Tests\Fixtures\User;
use Money\Currency;
use Money\Money;
use PHPUnit\Framework\Attributes\Test;
class ManageChargesTest extends BaseTestCase
{
#[Test]
public function usingMandatedChargeBuilderWhenValidMandate()
{
$owner = User::factory()->create();
$this->assertInstanceOf(FirstPaymentChargeBuilder::class, $owner->newCharge());
}
#[Test]
public function useNewMandatedCharge()
{
$this->withMockedGetMollieCustomer(2);
$this->withMockedGetMollieMandateAccepted(2);
$owner = $this->getMandatedUser(true, [
'mollie_mandate_id' => 'mdt_unique_mandate_id',
'mollie_customer_id' => 'cst_unique_customer_id',
]);
$this->assertInstanceOf(MandatedChargeBuilder::class, $owner->newCharge());
}
#[Test]
public function mandatedChargeStillRejectsPendingMandate()
{
// Regression test for issue #289: while the first-payment flow accepts
// a pending mandate (Mollie has already collected that payment),
// off-session/recurring charges must remain strict — a pending mandate
// offers no payment guarantee for charges initiated by the merchant.
$this->expectException(MandateIsNotYetFinalizedException::class);
$this->withMockedGetMollieCustomer();
$this->withMockedGetMollieMandatePending();
$owner = $this->getMandatedUser(true, [
'mollie_mandate_id' => 'mdt_unique_mandate_id',
'mollie_customer_id' => 'cst_unique_customer_id',
]);
$builder = new MandatedChargeBuilder($owner);
$builder->addItem(new ChargeItem(
$owner,
new Money(1000, new Currency('EUR')),
'Test charge'
))->create();
}
}