Skip to content

Commit

Permalink
BP-3322 Change new required fields for Riverty DE (#35)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivascu Madalin <[email protected]>
  • Loading branch information
harli91 and Ivascu Madalin committed Jan 17, 2024
1 parent 7e06607 commit 726186a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
39 changes: 39 additions & 0 deletions Controllers/Frontend/BuckarooAfterpayNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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');
Expand Down
34 changes: 18 additions & 16 deletions PaymentMethods/AfterPayNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -66,7 +67,7 @@ public function getImageName()
*/
public function validCountries()
{
return [ 'BE', 'NL' ];
return [ 'BE', 'NL', "DE" ];
}

/**
Expand Down Expand Up @@ -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 [
Expand All @@ -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 [
Expand All @@ -225,12 +232,7 @@ public function getValidations()
]
];

} else {

return [];
}



return [];
}
}
8 changes: 5 additions & 3 deletions Views/frontend/checkout/confirm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,17 @@
<li class="block-group row--tos">
{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}
<input type="hidden" name="payment" value="{$paymentId}">
{/if}
Expand Down

0 comments on commit 726186a

Please sign in to comment.