Skip to content

Commit

Permalink
Merge pull request #4 from 202-ecommerce/develop
Browse files Browse the repository at this point in the history
v 1.1.2
  • Loading branch information
202-ecommerce authored Nov 28, 2019
2 parents 46f613a + 24ecc2d commit 806f12f
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 20 deletions.
2 changes: 1 addition & 1 deletion 202/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="src-dir" value="${basedir}" />
<property name="TARGETNAME" value="braintreeofficial" />
<property name="TARGETBRANCH" value="${env.GIT_BRANCH}" />
<property name="TARGETVERSION" value="1.1.1" />
<property name="TARGETVERSION" value="1.1.2" />
<property name="PHPVERSION" value="5.6" />
<property name="PSVERSION" value="1.7.5.x" />

Expand Down
41 changes: 41 additions & 0 deletions _dev/js/payment_bt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {selectOption} from './functions.js';
$(document).ready(() => {
if ($('#checkout-payment-step').hasClass('js-current-step')) {
initBraintreeCard();
if (use3dVerification) {
initBraintreeCvvField();
}
}

$('.js-payment-option-form').each((i) => {
Expand All @@ -33,6 +36,22 @@ $(document).ready(() => {
let bt_hosted_fileds;
let bt_client_instance;

const initBraintreeCvvField = () => {
let cardSelect = $('[data-bt-vaulting-token="bt"]');
let cardForm = $('[data-form-cvv-field]');
$(document).on('input', '#btCvvField', maxLengthCheck)
if (cardSelect.length) {
toggleCvv(cardSelect, cardForm);
}
}

const maxLengthCheck = (event) => {
let object = event.target;
if (object.value.length > 4) {
object.value = object.value.slice(0, 4);
}
}

const initBraintreeCard = () => {
braintree.client.create({
authorization,
Expand Down Expand Up @@ -152,6 +171,20 @@ const initBraintreeCard = () => {
});
}

const toggleCvv = (select, el) => {
if (select) {
select.on('change', (e) => {
const index = e.target.selectedIndex;

if (index === 0) {
el.hide();
} else {
el.show();
}
});
}
};



const removeErrorMsg = (el) => {
Expand All @@ -178,10 +211,12 @@ const setErrorMsg = (el, field) => {
}
}


const BraintreeSubmitPayment = () => {
const bt_form = $('[data-braintree-card-form]');
const vaultToken = $('[data-bt-vaulting-token="bt"]').val(); // use vaulted card
const btnConfirmation = $('#payment-confirmation button');
const cvvField = $('[name = "btCvvField"]');

getOrderInformation(vaultToken).then(
response => {
Expand All @@ -190,6 +225,12 @@ const BraintreeSubmitPayment = () => {
let use3dVerification = response["use3dVerification"];

if (use3dVerification) {
if (vaultToken && (cvvField.length == 0 || cvvField.val() == '')) {
btnConfirmation.prop('disabled', false);
$('[data-bt-cvv-error-msg]').show().text(bt_translations_cvv);
return false;
}

braintree.threeDSecure.create({
version: 2, //Using 3DS 2
client: bt_client_instance,
Expand Down
1 change: 1 addition & 0 deletions _dev/js/payment_pbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const initPaypalBraintree = (flow) => {

$('[data-braintree-button]').html('');
paypal.Button.render({
locale: envLocale,
env: paypal_braintree_mode, // 'production' or 'sandbox'
style: {
tagline: false
Expand Down
13 changes: 12 additions & 1 deletion _dev/scss/helpers/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@
padding-left: 10px;
}

}
&__number-field::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}

&__number-field::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

}

30 changes: 15 additions & 15 deletions braintreeofficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,20 +479,6 @@ public function hookActionOrderStatusUpdate(&$params)
$ex_detailed_message = '';
if ($params['newOrderStatus']->id == Configuration::get('PS_OS_CANCELED')) {
$braintreeCapture = $this->serviceBraintreeOfficialCapture->loadByOrderBraintreeId($orderBraintree->id);
if (Validate::isLoadedObject($braintreeCapture) && !$braintreeCapture->id_capture) {
ProcessLoggerHandler::openLogger();
ProcessLoggerHandler::logError(
$this->l('You couldn\'t refund order, it\'s not payed yet.'),
null,
$orderBraintree->id_order,
$orderBraintree->id_cart,
$this->context->shop->id,
$orderBraintree->payment_tool,
$orderBraintree->sandbox
);
ProcessLoggerHandler::closeLogger();
Tools::redirect($_SERVER['HTTP_REFERER'].'&not_payed_capture=1');
}

try {
$response_void = $this->methodBraintreeOfficial->void($orderBraintree);
Expand Down Expand Up @@ -1050,6 +1036,7 @@ public function addJsVarsPB()
'paypal_braintree_amount' => $this->context->cart->getOrderTotal(),
'paypal_braintree_mode' => $this->methodBraintreeOfficial->mode == 'SANDBOX' ? Tools::strtolower($this->methodBraintreeOfficial->mode) : 'production',
'paypal_braintree_currency' => $this->context->currency->iso_code,
'envLocale' => str_replace("-", "_", $this->context->language->locale)
));
}

Expand Down Expand Up @@ -1091,13 +1078,26 @@ public function generateFormBT()
public function addJsVarsBT()
{
$clientToken = $this->methodBraintreeOfficial->init();
$use3dVerification = $this->use3dVerification();

Media::addJsDef(array(
'authorization' => $clientToken,
'controllerValidation' => $this->context->link->getModuleLink($this->name, 'validation', array(), true)
'controllerValidation' => $this->context->link->getModuleLink($this->name, 'validation', array(), true),
'use3dVerification' => $use3dVerification
));
}

/**
* @return bool
* */
public function use3dVerification()
{
$use3dVerification = (int)Configuration::get('BRAINTREEOFFICIAL_3DSECURE');
$use3dVerification &= (int)Configuration::get('BRAINTREEOFFICIAL_3DSECURE_AMOUNT') <= $this->context->cart->getOrderTotal(true, Cart::BOTH);

return $use3dVerification;
}

/**
* Check if we need convert currency
* @return boolean|integer currency id
Expand Down
26 changes: 26 additions & 0 deletions classes/MethodBraintreeOfficial.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class MethodBraintreeOfficial extends AbstractMethodBraintreeOfficial
/* @var ServiceBraintreeOfficialOrder*/
protected $serviceBraintreeOfficialOrder;

protected $cvv_field;

public function __construct()
{
$this->serviceBraintreeOfficialCapture = new ServiceBraintreeOfficialCapture();
Expand Down Expand Up @@ -731,6 +733,30 @@ public function sale($cart, $token_payment)
if ($vaultExists && $this->payment_method_bt == 'paypal-braintree') {
$data['paymentMethodToken'] = $vault_token;
} elseif ($vaultExists) {
if ($module->use3dVerification()) {
if (empty($this->cvv_field)) {
$error_msg = $module->l('Card verification failed.', get_class($this));

throw new Exception($error_msg, '00000');
}

$params = array(
'cvv' => $this->cvv_field,
'options' => [
'verifyCard' => true
]
);
$payment_method = $this->gateway->paymentMethod()->update($vault_token, $params);

if ((isset($payment_method->verification) && $payment_method->verification == null) ||
(isset($payment_method->verification) && $payment_method->verification->status != 'verified')) {
$error_msg = $module->l('Card verification failed.', get_class($this));
$error_msg .= $module->l('The reason : ', get_class($this)).' '.$payment_method->message;

throw new Exception($error_msg, '00000');
}
}

$data['paymentMethodNonce'] = $token_payment;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function init()
$this->values['pbt_vaulting_token'] = Tools::getvalue('pbt_vaulting_token');
$this->values['save_card_in_vault'] = Tools::getvalue('save_card_in_vault');
$this->values['save_account_in_vault'] = Tools::getvalue('save_account_in_vault');
$this->values['cvv_field'] = Tools::getValue('btCvvField');
}

public function postProcess()
Expand Down Expand Up @@ -84,8 +85,7 @@ public function displayAjaxGetOrderInformation()
$customer = new Customer($this->context->cart->id_customer);
$address = new Address($this->context->cart->id_address_delivery);
$country = new Country($address->id_country);
$use3dVerification = (int)Configuration::get('BRAINTREEOFFICIAL_3DSECURE');
$use3dVerification &= (int)Configuration::get('BRAINTREEOFFICIAL_3DSECURE_AMOUNT') <= $this->context->cart->getOrderTotal();
$use3dVerification = $this->module->use3dVerification();
$iso = '';

if ($address->id_state) {
Expand Down
2 changes: 1 addition & 1 deletion views/templates/admin/help.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{l s='Discover module ducumentation before configuration' mod='braintreeofficial'}
</p>
<p>
<a target="_blank" href="https://help.202-ecommerce.com/wp-content/uploads/2019/08/User-guide-PayPal-PrestaShop-module.pdf"
<a target="_blank" href="https://help.202-ecommerce.com/wp-content/uploads/2019/11/Braintree_Prestashop_Doc_updated1411191.pdf"
class="btn btn-default">
{l s='Access user documentation for module configuration.' mod='braintreeofficial'}
</a>
Expand Down
8 changes: 8 additions & 0 deletions views/templates/front/payment_bt.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
</div>
{/if}
</div>

<div data-form-cvv-field class="bt__hidden">
<div id="block-cvv-field" class="form-group col-md-6">
<label for="btCvvField" class="bt__form-label">{l s='CVV' mod='braintreeofficial'}</label>
<input type="number" name="btCvvField" id="btCvvField" class="form-control bt__form-control bt__number-field" placeholder="123">
</div>
<div data-bt-cvv-error-msg class="bt__text-danger bt__mt-1 col-lg-12"></div>
</div>
</form>
<div data-bt-card-error-msg class="alert alert-danger bt__hidden"></div>
{else}
Expand Down

0 comments on commit 806f12f

Please sign in to comment.