Skip to content

Commit

Permalink
Merge pull request #34 from paynl/feature/PLUG-3269
Browse files Browse the repository at this point in the history
PLUG-3269 - Make error formatting in checkout user friendly
  • Loading branch information
woutse authored Apr 3, 2024
2 parents d2a94c4 + 148d90f commit 45f67b5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
29 changes: 28 additions & 1 deletion upload/Pay/Controller/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function index()
*/
public function startTransaction()
{
$this->load->language('extension/payment/paynl3');
$this->load->model('extension/payment/' . $this->_paymentMethodName);
$this->load->model('checkout/order');
$modelName = 'model_extension_payment_' . $this->_paymentMethodName;
Expand Down Expand Up @@ -258,7 +259,8 @@ public function startTransaction()

$response['success'] = $result['transaction']['paymentURL'];
} catch (Pay_Api_Exception $e) {
$response['error'] = "De Pay. api gaf de volgende fout: " . $e->getMessage();
$message = $this->getErrorMessage($e->getMessage());
$response['error'] = $this->language->get($message);
} catch (Pay_Exception $e) {
$response['error'] = "Er is een fout opgetreden: " . $e->getMessage();
} catch (Exception $e) {
Expand Down Expand Up @@ -359,4 +361,29 @@ public function isTestMode()
}
return $this->config->get('payment_paynl_general_testmode');
}

/**
* @param $message
* @return string
*/
public function getErrorMessage($message)
{
$message = strtolower(trim($message));

if (
stripos($message, 'minimum amount') !== false
|| stripos($message, 'maximum amount') !== false
|| stripos($message, 'Amount is not allowed') !== false
) {
$errorMessage = 'text_pay_api_error_amount';
} elseif (stripos($message, 'is not activated for this sales location') !== false) {
$errorMessage = 'text_pay_api_error_activated';
} elseif (stripos($message, 'not allowed in country') !== false) {
$errorMessage = 'text_pay_api_error_country';
} else {
$errorMessage = 'text_pay_api_error_general';
}

return $errorMessage;
}
}
4 changes: 4 additions & 0 deletions upload/catalog/language/de-de/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
$_['error_vat'] = 'Um diese Transaktion abzuschließen, ist eine Umsatzsteuer-Identifikationsnummer erforderlich. Bitte geben Sie diese hier ein.';
$_['text_cancel'] = 'Die Zahlung wurde storniert.';
$_['text_denied'] = 'Leider wurde die Zahlung abgelehnt. Bitte versuchen Sie es erneut oder verwenden Sie eine andere Zahlungsmethode.';
$_['text_pay_api_error_amount'] = 'Leider entspricht der Bestellbetrag nicht den Anforderungen für diese Zahlungsart.';
$_['text_pay_api_error_activated'] = 'Die ausgewählte Zahlungsmethode ist nicht aktiviert. Bitte wählen Sie eine andere Zahlungsmethode.';
$_['text_pay_api_error_country'] = 'Diese Währung ist in Kombination mit dieser Zahlungsmethode nicht zulässig. Bitte wählen Sie eine andere Zahlungsmethode.';
$_['text_pay_api_error_general'] = 'Leider ist etwas schief gelaufen.';
5 changes: 5 additions & 0 deletions upload/catalog/language/en-gb/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$_['text_choose_bank'] = 'Choose your bank';
$_['text_dob'] = 'Date of birth';
$_['error_dob'] = 'A date of birth is required to finish this transaction, please fill it in.';
Expand All @@ -8,3 +9,7 @@
$_['error_vat'] = 'A VAT-id is required to finish this transaction, please fill it in.';
$_['text_cancel'] = 'The payment has been canceled, please try again.';
$_['text_denied'] = 'Unfortunately the payment has been denied. Please try again or use another payment method.';
$_['text_pay_api_error_amount'] = 'Unfortunately the order amount does not fit the requirements for this payment method.';
$_['text_pay_api_error_activated'] = 'The selected payment method is not enabled. Please select another payment method.';
$_['text_pay_api_error_country'] = 'This currency is not allowed in combination with this payment method. Please select another payment method.';
$_['text_pay_api_error_general'] = 'Unfortunately something went wrong.';
4 changes: 4 additions & 0 deletions upload/catalog/language/fr-fr/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
$_['error_dob'] = 'Une date de naissance est requise pour finaliser votre transaction. Veuillez le saisir ici.';
$_['text_cancel'] = 'Le paiement a été annulé.';
$_['text_denied'] = 'Malheureusement, le paiement a été rejeté. Veuillez réessayer ou utiliser un autre mode de paiement';
$_['text_pay_api_error_amount'] = "Malheureusement, le montant de la commande ne correspond pas aux exigences de ce mode de paiement.";
$_['text_pay_api_error_activated'] = "Le mode de paiement sélectionné n'est pas activé. Veuillez sélectionner un autre mode de paiement.";
$_['text_pay_api_error_country'] = "Cette devise n'est pas autorisée en combinaison avec ce mode de paiement. Veuillez sélectionner un autre mode de paiement.";
$_['text_pay_api_error_general'] = "Malheureusement, quelque chose s'est mal passé.";
5 changes: 5 additions & 0 deletions upload/catalog/language/nl-nl/extension/payment/paynl3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

$_['text_choose_bank'] = 'Kies uw bank';
$_['text_coc'] = 'KVK nummer';
$_['error_coc'] = 'Een KVK nummer is nodig om deze transactie af te ronden, vul deze aub hier in.';
Expand All @@ -8,3 +9,7 @@
$_['error_dob'] = 'Een geboortedatum is vereist om uw transactie af te ronden. Vul deze aub hier in.';
$_['text_cancel'] = 'De betaling is geannuleerd.';
$_['text_denied'] = 'De betaling is helaas afgewezen. Probeer het opnieuw of gebruik een andere betaalmethode';
$_['text_pay_api_error_amount'] = 'Helaas voldoet het bestelbedrag niet aan de eisen voor deze betaalmethode.';
$_['text_pay_api_error_activated'] = 'De geselecteerde betaalmethode is niet ingeschakeld. Selecteer een andere betaalmethode.';
$_['text_pay_api_error_country'] = 'Deze valuta is niet toegestaan in combinatie met deze betaalmethode. Selecteer een andere betaalmethode.';
$_['text_pay_api_error_general'] = 'Helaas ging er iets mis.';

0 comments on commit 45f67b5

Please sign in to comment.