Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117755177
D1804.1775202502.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D1804.1775202502.diff
View Options
diff --git a/src/app/Providers/Payment/Mollie.php b/src/app/Providers/Payment/Mollie.php
--- a/src/app/Providers/Payment/Mollie.php
+++ b/src/app/Providers/Payment/Mollie.php
@@ -6,6 +6,7 @@
use App\Utils;
use App\Wallet;
use Illuminate\Support\Facades\DB;
+use Mollie\Api\Exceptions\ApiException;
class Mollie extends \App\Providers\PaymentProvider
{
@@ -417,21 +418,21 @@
// Get the manadate reference we already have
if ($customer_id && $mandate_id) {
- $mandate = mollie()->mandates()->getForId($customer_id, $mandate_id);
- if ($mandate) {// && ($mandate->isValid() || $mandate->isPending())) {
- return $mandate;
- }
- }
+ try {
+ return mollie()->mandates()->getForId($customer_id, $mandate_id);
+ } catch (ApiException $e) {
+ // FIXME: What about 404?
+ if ($e->getCode() == 410) {
+ // The mandate is gone, remove the reference
+ $wallet->setSetting('mollie_mandate_id', null);
+ return null;
+ }
- // Get all mandates from Mollie and find the active one
- /*
- foreach ($customer->mandates() as $mandate) {
- if ($mandate->isValid() || $mandate->isPending()) {
- $wallet->setSetting('mollie_mandate_id', $mandate->id);
- return $mandate;
+ // TODO: Maybe we shouldn't always throw? It make sense in the job
+ // but for example when we're just fetching wallet info...
+ throw $e;
}
}
- */
}
/**
diff --git a/src/tests/Feature/Controller/PaymentsMollieTest.php b/src/tests/Feature/Controller/PaymentsMollieTest.php
--- a/src/tests/Feature/Controller/PaymentsMollieTest.php
+++ b/src/tests/Feature/Controller/PaymentsMollieTest.php
@@ -213,7 +213,7 @@
$this->assertSame($mandate_id, $json['id']);
$this->assertFalse($json['isDisabled']);
- $wallet = $user->wallets()->first();
+ $wallet->refresh();
$this->assertEquals(30.10, $wallet->getSetting('mandate_amount'));
$this->assertEquals(1, $wallet->getSetting('mandate_balance'));
@@ -272,6 +272,34 @@
$mandate = mollie()->mandates()->getForId($customer_id, $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'));
}
/**
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 3, 7:48 AM (32 m, 23 s ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823075
Default Alt Text
D1804.1775202502.diff (3 KB)
Attached To
Mode
D1804: Handle "410 Gone" response when fetching mandate from Mollie (T385223)
Attached
Detach File
Event Timeline