Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F16222908
D4980.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D4980.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
@@ -34,11 +34,11 @@
}
/**
- * Validates that mollie available.
- *
- * @throws \Mollie\Api\Exceptions\ApiException on failure
- * @return bool true on success
- */
+ * Validates that mollie available.
+ *
+ * @throws ApiException on failure
+ * @return bool true on success
+ */
public static function healthcheck()
{
mollie()->methods()->allActive();
@@ -87,7 +87,12 @@
];
// Create the payment in Mollie
- $response = mollie()->payments()->create($request);
+ try {
+ $response = mollie()->payments()->create($request);
+ } catch (ApiException $e) {
+ self::logRequestError($request, $e, "Failed to create mandate");
+ throw $e;
+ }
if ($response->mandateId) {
$wallet->setSetting('mollie_mandate_id', $response->mandateId);
@@ -219,7 +224,12 @@
// billingAddress (it is a structured field not just text)
// Create the payment in Mollie
- $response = mollie()->payments()->create($request);
+ try {
+ $response = mollie()->payments()->create($request);
+ } catch (ApiException $e) {
+ self::logRequestError($request, $e, "Failed to create payment");
+ throw $e;
+ }
// Store the payment reference in database
$payment['status'] = $response->status;
@@ -266,7 +276,7 @@
// Check if there's a valid mandate
$mandate = self::mollieMandate($wallet);
- if (empty($mandate) || !$mandate->isValid() || $mandate->isPending()) {
+ if (empty($mandate) || !$mandate->isValid()) {
\Log::debug("Recurring payment for {$wallet->id}: no valid Mollie mandate");
return null;
}
@@ -295,7 +305,12 @@
\Log::debug("Recurring payment for {$wallet->id}: " . json_encode($request));
// Create the payment in Mollie
- $response = mollie()->payments()->create($request);
+ try {
+ $response = mollie()->payments()->create($request);
+ } catch (ApiException $e) {
+ self::logRequestError($request, $e, "Failed to create payment");
+ throw $e;
+ }
// Store the payment reference in database
$payment['status'] = $response->status;
@@ -443,8 +458,8 @@
if (!empty($notify)) {
\App\Jobs\PaymentEmail::dispatch($payment);
}
- } catch (\Mollie\Api\Exceptions\ApiException $e) {
- \Log::warning(sprintf('Mollie api call failed (%s)', $e->getMessage()));
+ } catch (ApiException $e) {
+ \Log::error(sprintf('Mollie API call failed (%s)', $e->getMessage()));
}
return 200;
@@ -499,6 +514,7 @@
// TODO: Maybe we shouldn't always throw? It make sense in the job
// but for example when we're just fetching wallet info...
+ self::logRequestError($settings['mollie_mandate_id'], $e, "Failed to get mandate");
throw $e;
}
}
@@ -627,4 +643,18 @@
'checkoutUrl' => $payment->getCheckoutUrl()
];
}
+
+ /**
+ * Log an error on API request exception
+ */
+ protected static function logRequestError($request, $exception, $msg)
+ {
+ \Log::error(sprintf("%s. [%d] %s (%s). Request: %s",
+ $msg,
+ $exception->getCode(),
+ $exception->getMessage(),
+ $exception->getField() ?? '',
+ json_encode($request),
+ ));
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 19, 1:22 PM (22 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9861048
Default Alt Text
D4980.diff (3 KB)
Attached To
Mode
D4980: Improve logging Mollie errors
Attached
Detach File
Event Timeline
Log In to Comment