Skip to content

Commit

Permalink
Merge pull request #335 from 202ecommerce/feature/46281-pui_form_birt…
Browse files Browse the repository at this point in the history
…hday

refs #46281 pui form. pre-fill birthday and phone
  • Loading branch information
bogdan202 authored Jun 14, 2024
2 parents 8380ae2 + 10810fd commit 750075a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
13 changes: 11 additions & 2 deletions classes/PUI/DataUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

namespace PaypalAddons\classes\PUI;

use DateTime;
use PayPal;

if (!defined('_PS_VERSION_')) {
exit;
}
Expand Down Expand Up @@ -131,9 +134,15 @@ public function setEmail($email)
/**
* @return string
*/
public function getBirth()
public function getBirth($format = PayPal::PS_CUSTOMER_DATE_FORMAT)
{
return (string) $this->birth;
$date = DateTime::createFromFormat(PayPal::PS_CUSTOMER_DATE_FORMAT, (string) $this->birth);

if (!$date) {
return '';
}

return $date->format($format);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions classes/PUI/FraudNetForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use Address;
use Context;
use Customer;
use Exception;
use PaypalAddons\classes\AbstractMethodPaypal;
use Throwable;
Expand Down Expand Up @@ -83,12 +84,15 @@ protected function getSourceId()
protected function getUserData()
{
$billingAddress = new Address($this->context->cart->id_address_invoice);
$customer = new Customer($billingAddress->id_customer);
$userData = new DataUserForm();

$userData->setFirstName($this->context->customer->firstname);
$userData->setLastName($this->context->customer->lastname);
$userData->setEmail($this->context->customer->email);
$userData->setPhone($billingAddress->phone);
$userData->setBirth($customer->birthday);
$userData->setPhone($billingAddress->phone);

return $userData;
}
Expand Down
2 changes: 2 additions & 0 deletions paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class PayPal extends \PaymentModule implements WidgetInterface

const SCA_ALWAYS = 'SCA_ALWAYS';

const PS_CUSTOMER_DATE_FORMAT = 'Y-m-d';

public static $dev = true;
public $express_checkout;
public $message;
Expand Down
10 changes: 9 additions & 1 deletion views/templates/pui/fraudNetForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
required
class="form-control"
type="date"
data-date={l s='DD.MM.YYYY' mod='paypal'}
data-date={if isset($userData) && $userData->getBirth('d.m.Y')}{$userData->getBirth('d.m.Y')}{else}{l s='DD.MM.YYYY' mod='paypal'}{/if}
max="{$currentDate nofilter}"
name="paypal_pui_birhday"
id="paypal_pui_birhday"
Expand Down Expand Up @@ -167,7 +167,9 @@
class="form-control"
type="tel"
name="paypal_pui_phone"
value="{if isset($userData)}{$userData->getPhone()}{/if}"
id="paypal_pui_phone">

</div>
</div>

Expand Down Expand Up @@ -204,6 +206,12 @@
separateDialCode: true
}
);

if (paypalPuiPhone.getSelectedCountryData().iso2 !== 'de') {
paypalPuiPhone.telInput.value = null;
paypalPuiPhone.setCountry('de');
}

document.querySelector('form[pui-form]').addEventListener('submit', function(e) {
if (paypalPuiPhone.getValidationError() == 0) {
return;
Expand Down

0 comments on commit 750075a

Please sign in to comment.