Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #46281 pui form. pre-fill birthday and phone #335

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -132,6 +132,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
Loading