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

[PAYSHIP-2916] Apple Pay Domain Association #1256

Merged
merged 7 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
28 changes: 28 additions & 0 deletions .well-known/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
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;
43 changes: 36 additions & 7 deletions controllers/front/applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface;
use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController;
use PrestaShop\Module\PrestashopCheckout\PayPal\ApplePay\Query\GetApplePayPaymentRequestQuery;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration;

/**
* This controller receive ajax call on customer click on a payment button
Expand All @@ -45,22 +46,50 @@ class Ps_CheckoutApplepayModuleFrontController extends AbstractFrontController
public function postProcess()
{
try {
$bodyValues = [];
$action = '';
$bodyContent = file_get_contents('php://input');

if (!empty($bodyContent)) {
$bodyValues = json_decode($bodyContent, true);
$action = $bodyValues['action'];
}

$action = $bodyValues['action'];
if (empty($action)) {
$getParam = Tools::getValue('action');
if ($getParam === 'getDomainAssociation') {
$action = $getParam;
}
}

$this->commandBus = $this->module->getService('ps_checkout.bus.command');

if ($action === 'getPaymentRequest') {
$this->getPaymentRequest();
} else {
$exception = new Exception('Invalid request', 400);
$this->exitWithExceptionMessage($exception);
switch ($action) {
case 'getPaymentRequest':
$this->getPaymentRequest();
break;
case 'getDomainAssociation':
/**
* @var PayPalConfiguration $payPalConfiguration
*/
$payPalConfiguration = $this->module->getService(PayPalConfiguration::class);
$environment = $payPalConfiguration->getPaymentMode();
$associationFile = _PS_MODULE_DIR_ . "ps_checkout/.well-known/apple-$environment-merchantid-domain-association";
if (file_exists($associationFile)) {
if (!headers_sent()) {
ob_end_clean();
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('X-Robots-Tag: noindex, nofollow');
header_remove('Last-Modified');
header('Content-Type: text/plain', true, 200);
}
echo file_get_contents($associationFile);
L3RAZ marked this conversation as resolved.
Show resolved Hide resolved
exit;
} else {
$this->exitWithExceptionMessage(new Exception('File not found', 404));
}
break;
default:
$this->exitWithExceptionMessage(new Exception('Invalid request', 400));
}
} catch (Exception $exception) {
$this->exitWithExceptionMessage($exception);
Expand Down
30 changes: 30 additions & 0 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Ps_checkout extends PaymentModule
'actionObjectOrderPaymentUpdateAfter',
'displayPaymentReturn',
'displayOrderDetail',
'moduleRoutes'
];

/**
Expand Down Expand Up @@ -1789,4 +1790,33 @@ public function hookDisplayOrderDetail(array $params)

return $this->display(__FILE__, 'views/templates/hook/displayOrderDetail.tpl');
}

public function hookModuleRoutes()
{
/**
* @var \PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration $paypalConfiguration
*/
$payPalConfiguration = $this->getService(\PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration::class);
/**
* @var \PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceConfigurationRepository $fundingSourceRepository
*/
$fundingSourceRepository = $this->getService(\PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceConfigurationRepository::class);

$applePay = $fundingSourceRepository->get('apple_pay');

if ($payPalConfiguration->isApplePayEligible() && $applePay && $applePay['active']) {
return [
'ps_checkout_applepay' => [
'rule' => '.well-known/apple-developer-merchantid-domain-association',
'keywords' => [],
'controller' => 'applepay',
'params' => [
'fc' => 'module',
'module' => 'ps_checkout',
'action' => 'getDomainAssociation'
],
]
];
}
}
}