diff --git a/Controllers/Frontend/BuckarooAfterpayNew.php b/Controllers/Frontend/BuckarooAfterpayNew.php index f78506d..0442881 100755 --- a/Controllers/Frontend/BuckarooAfterpayNew.php +++ b/Controllers/Frontend/BuckarooAfterpayNew.php @@ -51,6 +51,21 @@ public function indexAction() } + /** + * Action to create a payment + * And redirect to Buckaroo + */ + public function payAction() + { + + $validationMessage = $this->validateHouseNumbers(); + + if ($validationMessage !== null && strlen($validationMessage) > 0) { + return $this->redirectBackToCheckout()->addMessage($validationMessage); + } + return parent::payAction(); + } + /** * Action to reserve a payment */ @@ -60,6 +75,11 @@ public function authorizeAction() $em = $this->container->get('models'); $transaction = null; + $validationMessage = $this->validateHouseNumbers(); + + if ($validationMessage !== null && strlen($validationMessage) > 0) { + return $this->redirectBackToCheckout()->addMessage($validationMessage); + } try { $request = $this->createRequest(); @@ -140,6 +160,23 @@ public function authorizeAction() } } + private function validateHouseNumbers() { + $userData = Shopware()->Container()->get('session')->sOrderVariables['sUserData']; + if (!isset($userData['billingaddress']) || !$this->isValidHouseNumber($userData['billingaddress'])) { + return 'Invalid billing address, a house number is required for this payment method'; + } + + if (!isset($userData['shippingaddress']) || !$this->isValidHouseNumber($userData['shippingaddress'])) { + return 'Invalid shipping address, a house number is required for this payment method'; + } + return null; + } + + private function isValidHouseNumber($address) { + $parts = Helpers::stringSplitStreet($address['street']); + return is_string($parts['number']) && !empty(trim($parts['number'])); + } + /** * Add paymentmethod specific fields to request * @@ -368,6 +405,8 @@ protected function addShippingCustomerParameters($request, $birthDay, $user, $pa $request->setServiceParameter($typeBelgiumPhone, Helpers::stringFormatPhone($shipping['phone']), 'ShippingCustomer'); } + } else if ($shippingCountryIso == "DE"){ + $request->setServiceParameter('BirthDate', $birthDay, 'ShippingCustomer'); } else if ($shippingCountryIso == "FI"){ // Finland required field: $request->setServiceParameter('IdentificationNumber', $paymentMethod->getUserUserIdentification(), 'ShippingCustomer'); diff --git a/PaymentMethods/AfterPayNew.php b/PaymentMethods/AfterPayNew.php index 3f30bb9..a49ccac 100755 --- a/PaymentMethods/AfterPayNew.php +++ b/PaymentMethods/AfterPayNew.php @@ -2,12 +2,13 @@ namespace BuckarooPayment\PaymentMethods; +use BuckarooPayment\Components\Helpers; +use BuckarooPayment\Components\Validation\Validator; use BuckarooPayment\Components\Base\AbstractPaymentMethod; use BuckarooPayment\Components\JsonApi\Payload\DataRequest; use BuckarooPayment\Components\JsonApi\Payload\DataResponse; use BuckarooPayment\Components\JsonApi\Payload\TransactionRequest; use BuckarooPayment\Components\JsonApi\Payload\TransactionResponse; -use BuckarooPayment\Components\Validation\Validator; class AfterPayNew extends AbstractPaymentMethod { @@ -66,7 +67,7 @@ public function getImageName() */ public function validCountries() { - return [ 'BE', 'NL' ]; + return [ 'BE', 'NL', "DE" ]; } /** @@ -194,6 +195,15 @@ public function getValidations() $billingCountryIso = empty($billingCountry) ? '' : $billingCountry->getIso(); } + $birthDayValidation = [ + [ + 'birthday', + 'notEmpty', + $validationMessages->get('ValidationUserBirthdayRequired', 'User should have an birthday'), + 'ValidationUserBirthdayRequired' + ], + ]; + if(in_array($billingCountryIso, ["NL", "BE"])){ return [ @@ -204,15 +214,12 @@ public function getValidations() $validationMessages->get('ValidationBillingPhoneRequired', 'Billingaddress has no phone'), 'ValidationBillingPhoneRequired' ], ], - 'user' => [ - [ - 'birthday', - 'notEmpty', - $validationMessages->get('ValidationUserBirthdayRequired', 'User should have an birthday'), - 'ValidationUserBirthdayRequired' ], - ] + 'user' => $birthDayValidation + ]; + } else if ($billingCountryIso == "DE"){ + return [ + 'user' => $birthDayValidation ]; - } else if ($billingCountryIso == "FI"){ return [ @@ -225,12 +232,7 @@ public function getValidations() ] ]; - } else { - - return []; } - - - + return []; } } diff --git a/Views/frontend/checkout/confirm.tpl b/Views/frontend/checkout/confirm.tpl index c427d1c..5dbaf05 100755 --- a/Views/frontend/checkout/confirm.tpl +++ b/Views/frontend/checkout/confirm.tpl @@ -171,15 +171,17 @@
  • - {if $paymentName|strstr:"buckaroo_afterpaynew" ne false && ($billingCountryIso eq 'NL' || $billingCountryIso eq 'BE')} + {if $paymentName|strstr:"buckaroo_afterpaynew" ne false && ($billingCountryIso eq 'NL' || $billingCountryIso eq 'BE' || $billingCountryIso eq 'DE')} {assign var="name" value="afterpaynew"} {include file='frontend/_includes/fields/user_id.tpl' name=$name} {include file='frontend/_includes/fields/user_birthday.tpl' name=$name} - {include file='frontend/_includes/fields/billing_id.tpl' name=$name} - {include file='frontend/_includes/fields/billing_phone.tpl' name=$name} + {if $billingCountryIso ne 'DE'} + {include file='frontend/_includes/fields/billing_id.tpl' name=$name} + {include file='frontend/_includes/fields/billing_phone.tpl' name=$name} + {/if} {/if}