Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/PaymentsMollieTest.php
Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | public function testMandates(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('The auto-payment has been updated.', $json['message']); | $this->assertSame('The auto-payment has been updated.', $json['message']); | ||||
$this->assertSame($mandate_id, $json['id']); | $this->assertSame($mandate_id, $json['id']); | ||||
$this->assertFalse($json['isDisabled']); | $this->assertFalse($json['isDisabled']); | ||||
$wallet = $user->wallets()->first(); | $wallet->refresh(); | ||||
$this->assertEquals(30.10, $wallet->getSetting('mandate_amount')); | $this->assertEquals(30.10, $wallet->getSetting('mandate_amount')); | ||||
$this->assertEquals(1, $wallet->getSetting('mandate_balance')); | $this->assertEquals(1, $wallet->getSetting('mandate_balance')); | ||||
// Test updating a disabled mandate (invalid input) | // Test updating a disabled mandate (invalid input) | ||||
$wallet->setSetting('mandate_disabled', 1); | $wallet->setSetting('mandate_disabled', 1); | ||||
$wallet->balance = -2000; | $wallet->balance = -2000; | ||||
$wallet->save(); | $wallet->save(); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function testMandates(): void | ||||
// Confirm with Mollie the mandate does not exist | // Confirm with Mollie the mandate does not exist | ||||
$customer_id = $wallet->getSetting('mollie_id'); | $customer_id = $wallet->getSetting('mollie_id'); | ||||
$this->expectException(\Mollie\Api\Exceptions\ApiException::class); | $this->expectException(\Mollie\Api\Exceptions\ApiException::class); | ||||
$this->expectExceptionMessageMatches('/410: Gone/'); | $this->expectExceptionMessageMatches('/410: Gone/'); | ||||
$mandate = mollie()->mandates()->getForId($customer_id, $mandate_id); | $mandate = mollie()->mandates()->getForId($customer_id, $mandate_id); | ||||
$this->assertNull($wallet->fresh()->getSetting('mollie_mandate_id')); | $this->assertNull($wallet->fresh()->getSetting('mollie_mandate_id')); | ||||
// Test Mollie's "410 Gone" response handling when fetching the mandate info | |||||
// It is expected to remove the mandate reference | |||||
$mollie_response = [ | |||||
'status' => 410, | |||||
'title' => "Gone", | |||||
'detail' => "You are trying to access an object, which has previously been deleted", | |||||
'_links' => [ | |||||
'documentation' => [ | |||||
'href' => "https://docs.mollie.com/errors", | |||||
'type' => "text/html" | |||||
] | |||||
] | |||||
]; | |||||
$responseStack = $this->mockMollie(); | |||||
$responseStack->append(new Response(410, [], json_encode($mollie_response))); | |||||
$wallet->fresh()->setSetting('mollie_mandate_id', '123'); | |||||
$response = $this->actingAs($user)->get("api/v4/payments/mandate"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertFalse(array_key_exists('id', $json)); | |||||
$this->assertFalse(array_key_exists('method', $json)); | |||||
$this->assertNull($wallet->fresh()->getSetting('mollie_mandate_id')); | |||||
} | } | ||||
/** | /** | ||||
* Test creating a payment and receiving a status via webhook | * Test creating a payment and receiving a status via webhook | ||||
* | * | ||||
* @group mollie | * @group mollie | ||||
*/ | */ | ||||
public function testStoreAndWebhook(): void | public function testStoreAndWebhook(): void | ||||
▲ Show 20 Lines • Show All 476 Lines • Show Last 20 Lines |