Skip to content

Commit

Permalink
Check 422 fraud exception and bail
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Oct 18, 2023
1 parent e61b17c commit 17bf7e4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Buttons/ApplePayButton/ApplePayDataObjectHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function addressHasRequiredFieldsValues(
sprintf('ApplePay Data Error: Missing value for %s', $requiredField)
);
$this->errors[]
= [
= [
'errorCode' => $errorCode,
'contactField' => $errorValue,
];
Expand Down
25 changes: 25 additions & 0 deletions src/Payment/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ protected function processAsMollieOrder(
}
} catch (ApiException $e) {
$this->handleMollieOutage($e);
//if exception is 422 do not try to create a payment
$this->handleMollieFraudRejection($e);
// Don't try to create a Mollie Payment for Klarna payment methods
$order_payment_method = $order->get_payment_method();
$orderMandatoryPaymentMethods = [
Expand Down Expand Up @@ -873,4 +875,27 @@ public function handleMollieOutage(ApiException $e): void
);
}
}

/**
* Check if the exception is a fraud rejection, if so bail, log and inform user
* @param ApiException $e
* @return void
* @throws ApiException
*/
public function handleMollieFraudRejection(ApiException $e): void
{
$isMollieFraudException = $this->apiHelper->isMollieFraudException($e);
if ($isMollieFraudException) {
$this->logger->debug(
"Creating payment object: The payment was declined due to suspected fraud, stopping process."
);

throw new ApiException(
__(
'Payment failed due to: The payment was declined due to suspected fraud.',
'mollie-payments-for-woocommerce'
)
);
}
}
}
14 changes: 7 additions & 7 deletions src/PaymentMethods/Kbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Kbc extends AbstractPaymentMethod implements PaymentMethodI
{
protected const DEFAULT_ISSUERS_DROPDOWN = 'yes';
protected function getConfig(): array
{
return [
protected const DEFAULT_ISSUERS_DROPDOWN = 'yes';
protected function getConfig(): array
{
return [
'id' => 'kbc',
'defaultTitle' => __('KBC/CBC Payment Button', 'mollie-payments-for-woocommerce'),
'settingsDescription' => '',
Expand All @@ -23,10 +23,10 @@ protected function getConfig(): array
'filtersOnBuild' => false,
'confirmationDelayed' => true,
'SEPA' => true,
];
}
];
}

public function getFormFields($generalFormFields): array
public function getFormFields($generalFormFields): array
{
$paymentMethodFormFieds = [
'issuers_dropdown_shown' => [
Expand Down
11 changes: 11 additions & 0 deletions src/SDK/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ public function isMollieOutageException(\Mollie\Api\Exceptions\ApiException $e):
}
return false;
}

public function isMollieFraudException(\Mollie\Api\Exceptions\ApiException $e): bool
{
$isFraudCode = $e->getCode() === 422;
$isFraudMessage = strpos($e->getMessage(), 'The payment was declined due to suspected fraud') !== false;

if ($isFraudCode && $isFraudMessage) {
return true;
}
return false;
}
}

0 comments on commit 17bf7e4

Please sign in to comment.