Skip to content

Commit

Permalink
Merge branch task/PP-8963 into master
Browse files Browse the repository at this point in the history
task/PP-8963: Google Pay Readiness Check (Apple Pay Readiness Check (PP-8964))
  • Loading branch information
vekkon authored Apr 25, 2023
2 parents 01fc6c3 + 9c05e2d commit 1f923dd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
38 changes: 37 additions & 1 deletion payrexx/payrexx.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()
$this->name = 'payrexx';
$this->tab = 'payments_gateways';
$this->module_key = '0c4dbfccbd85dd948fd9a13d5a4add90';
$this->version = '1.4.4';
$this->version = '1.4.5';
$this->author = 'Payrexx';
$this->is_eu_compatible = 1;
$this->ps_versions_compliancy = ['min' => '1.7'];
Expand Down Expand Up @@ -279,6 +279,42 @@ public function hookActionFrontControllerSetMedia(array $params)
'payrexx-payment-method-icon',
'/modules/' . $this->name . '/views/css/custom.css'
);
$paymentMeans = array_column($this->getPaymentMethodsList(true), 'pm');
if (!in_array('apple-pay', $paymentMeans) && !in_array('google-pay', $paymentMeans)) {
return;
}

// Apple pay device check related js
if (in_array('apple-pay', $paymentMeans)) {
$this->context->controller->registerJavascript(
'payrexx-payment-method-apple-pay',
'/modules/' . $this->name . '/views/js/applepay.js',
[
'priority' => 996,
'position' => 'bottom',
]
);
}
// Google pay device check related js
if (in_array('google-pay', $paymentMeans)) {
$this->context->controller->registerJavascript(
'payrexx-payment-method-google-pay-lib',
'https://pay.google.com/gp/p/js/pay.js',
[
'priority' => 996,
'server' => 'remote',
'position' => 'bottom',
]
);
$this->context->controller->registerJavascript(
'payrexx-payment-method-google-pay',
'/modules/' . $this->name . '/views/js/googlepay.js',
[
'priority' => 997,
'position' => 'bottom',
]
);
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions payrexx/views/js/applepay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$(document).on('ready', function() {
if ((window.ApplePaySession && ApplePaySession.canMakePayments()) !== true) {
var $containerId = $('input[name=payrexxPaymentMethod][value=apple-pay]')
.parent('form')
.parent('.js-payment-option-form')
.attr('id').match(/\d+/);
if ($containerId > 0) {
jQuery('#payment-option-' + $containerId + '-container').remove();
}
console.warn("Payrexx Apple Pay is not supported on this device/browser");
}
});
43 changes: 43 additions & 0 deletions payrexx/views/js/googlepay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$(document).on('ready', function() {
try {
const baseRequest = {
apiVersion: 2,
apiVersionMinor: 0
};
const allowedCardNetworks = ['MASTERCARD', 'VISA'];
const allowedCardAuthMethods = ['CRYPTOGRAM_3DS'];
const baseCardPaymentMethod = {
type: 'CARD',
parameters: {
allowedAuthMethods: allowedCardAuthMethods,
allowedCardNetworks: allowedCardNetworks
}
};

const isReadyToPayRequest = Object.assign({}, baseRequest);
isReadyToPayRequest.allowedPaymentMethods = [
baseCardPaymentMethod
];
const paymentsClient = new google.payments.api.PaymentsClient(
{
environment: 'TEST'
}
);
paymentsClient.isReadyToPay(isReadyToPayRequest).then(function(response) {
if (!response.result) {
var $containerId = $('input[name=payrexxPaymentMethod][value=google-pay]')
.parent('form')
.parent('.js-payment-option-form')
.attr('id').match(/\d+/);
if ($containerId > 0) {
jQuery('#payment-option-' + $containerId + '-container').remove();
console.warn("Payrexx Google Pay is not supported on this device/browser");
}
}
}).catch(function(err) {
console.log(err);
});
} catch (err) {
console.log(err);
}
});
17 changes: 17 additions & 0 deletions payrexx/views/js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Payrexx Payment Gateway.
*
* @author Payrexx <[email protected]>
* @copyright 2023 Payrexx
* @license MIT License
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;

0 comments on commit 1f923dd

Please sign in to comment.