mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add applepay module behind flag
Add apple to onboarding products, add setting to onboard with a new filter add settings to enable in product and cart add button markup where the js will hook enqueue scripts echo validation file sandbox/live init apple payment method for onboarding
This commit is contained in:
parent
e94a59e9ae
commit
917976bfb4
15 changed files with 3195 additions and 6 deletions
14
modules/ppcp-applepay/.babelrc
Normal file
14
modules/ppcp-applepay/.babelrc
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"useBuiltIns": "usage",
|
||||
"corejs": "3.25.0"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@babel/preset-react"
|
||||
]
|
||||
]
|
||||
}
|
3
modules/ppcp-applepay/.gitignore
vendored
Normal file
3
modules/ppcp-applepay/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
node_modules
|
||||
assets/js
|
||||
assets/css
|
17
modules/ppcp-applepay/composer.json
Normal file
17
modules/ppcp-applepay/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "woocommerce/ppcp-applepay",
|
||||
"type": "dhii-mod",
|
||||
"description": "Applepay module for PPCP",
|
||||
"license": "GPL-2.0",
|
||||
"require": {
|
||||
"php": "^7.2 | ^8.0",
|
||||
"dhii/module-interface": "^0.3.0-alpha1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WooCommerce\\PayPalCommerce\\Applepay\\": "src"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
156
modules/ppcp-applepay/composer.lock
generated
Normal file
156
modules/ppcp-applepay/composer.lock
generated
Normal file
|
@ -0,0 +1,156 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "30c5bd428bece98b555ddc0b2da044f3",
|
||||
"packages": [
|
||||
{
|
||||
"name": "container-interop/service-provider",
|
||||
"version": "v0.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/container-interop/service-provider.git",
|
||||
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/4969b9e49460690b7430b3f1a87cab07be61418a",
|
||||
"reference": "4969b9e49460690b7430b3f1a87cab07be61418a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"psr/container": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Interop\\Container\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "Promoting container interoperability through standard service providers",
|
||||
"homepage": "https://github.com/container-interop/service-provider",
|
||||
"support": {
|
||||
"issues": "https://github.com/container-interop/service-provider/issues",
|
||||
"source": "https://github.com/container-interop/service-provider/tree/master"
|
||||
},
|
||||
"time": "2017-09-20T14:13:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dhii/module-interface",
|
||||
"version": "v0.3.0-alpha2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Dhii/module-interface.git",
|
||||
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Dhii/module-interface/zipball/0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
|
||||
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"container-interop/service-provider": "^0.4",
|
||||
"php": "^7.1 | ^8.0",
|
||||
"psr/container": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
|
||||
"slevomat/coding-standard": "^6.0",
|
||||
"vimeo/psalm": "^3.11.7 | ^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-develop": "0.3.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dhii\\Modular\\Module\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Dhii Team",
|
||||
"email": "development@dhii.co"
|
||||
}
|
||||
],
|
||||
"description": "Interfaces for modules",
|
||||
"support": {
|
||||
"issues": "https://github.com/Dhii/module-interface/issues",
|
||||
"source": "https://github.com/Dhii/module-interface/tree/v0.3.0-alpha2"
|
||||
},
|
||||
"time": "2021-08-23T08:23:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/container.git",
|
||||
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf",
|
||||
"reference": "8622567409010282b7aeebe4bb841fe98b58dcaf",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Container\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common Container Interface (PHP FIG PSR-11)",
|
||||
"homepage": "https://github.com/php-fig/container",
|
||||
"keywords": [
|
||||
"PSR-11",
|
||||
"container",
|
||||
"container-interface",
|
||||
"container-interop",
|
||||
"psr"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/php-fig/container/issues",
|
||||
"source": "https://github.com/php-fig/container/tree/1.1.1"
|
||||
},
|
||||
"time": "2021-03-05T17:36:06+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": "^7.2 | ^8.0"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
39
modules/ppcp-applepay/extensions.php
Normal file
39
modules/ppcp-applepay/extensions.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module extensions.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
|
||||
return array(
|
||||
'wcgateway.settings.fields' => static function ( ContainerInterface $container, array $fields ): array {
|
||||
$fields['applepay_button_enabled_product'] = array(
|
||||
'title' => __( 'Apple Pay Button on Product Page', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable Apple Pay button on product page', 'woocommerce-paypal-payments' ),
|
||||
'default' => 'yes',
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'paypal',
|
||||
'requirements' => array(),
|
||||
);
|
||||
$fields['applepay_button_enabled_cart'] = array(
|
||||
'title' => __( 'Apple Pay Button on Cart Page', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable Apple Pay button on cart page', 'woocommerce-paypal-payments' ),
|
||||
'default' => 'yes',
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'paypal',
|
||||
'requirements' => array(),
|
||||
);
|
||||
|
||||
return $fields;
|
||||
},
|
||||
);
|
16
modules/ppcp-applepay/module.php
Normal file
16
modules/ppcp-applepay/module.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
|
||||
return static function (): ModuleInterface {
|
||||
return new ApplepayModule();
|
||||
};
|
33
modules/ppcp-applepay/package.json
Normal file
33
modules/ppcp-applepay/package.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "ppcp-applepay",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"browserslist": [
|
||||
"> 0.5%",
|
||||
"Safari >= 8",
|
||||
"Chrome >= 41",
|
||||
"Firefox >= 43",
|
||||
"Edge >= 14"
|
||||
],
|
||||
"dependencies": {
|
||||
"core-js": "^3.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.19",
|
||||
"@babel/preset-env": "^7.19",
|
||||
"@babel/preset-react": "^7.18.6",
|
||||
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0",
|
||||
"babel-loader": "^8.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"file-loader": "^6.2.0",
|
||||
"sass": "^1.42.1",
|
||||
"sass-loader": "^12.1.0",
|
||||
"webpack": "^5.76",
|
||||
"webpack-cli": "^4.10"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||
}
|
||||
}
|
91
modules/ppcp-applepay/services.php
Normal file
91
modules/ppcp-applepay/services.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module services.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
return array(
|
||||
'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
|
||||
return new AppleProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'api.endpoint.partners' ),
|
||||
$container->get( 'pui.status-cache' ),
|
||||
$container->get( 'onboarding.state' )
|
||||
);
|
||||
},
|
||||
'applepay.enabled' => static function ( ContainerInterface $container ): bool {
|
||||
$status = $container->get( 'applepay.apple-product-status' );
|
||||
return $status->apple_is_active();
|
||||
},
|
||||
'applepay.server_supported' => static function ( ContainerInterface $container ): bool {
|
||||
return ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off';
|
||||
},
|
||||
'applepay.merchant_validated' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
try {
|
||||
$settings->get( 'applepay_validated' );
|
||||
} catch ( \Exception $e ) {
|
||||
return false;
|
||||
}
|
||||
return $settings->get( 'applepay_validated' ) === 'yes';
|
||||
},
|
||||
'applepay.payment_method' => static function ( ContainerInterface $container ): ApplepayPaymentMethod {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
|
||||
return new ApplepayPaymentMethod( $settings );
|
||||
},
|
||||
'applepay.url' => static function ( ContainerInterface $container ): string {
|
||||
$path = realpath( __FILE__ );
|
||||
if ( false === $path ) {
|
||||
return '';
|
||||
}
|
||||
return plugins_url(
|
||||
'/modules/ppcp-applepay/',
|
||||
dirname( $path, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'applepay.sdk_script_url' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';
|
||||
},
|
||||
'applepay.paypal_sdk_url' => static function ( ContainerInterface $container ): string {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
if ( ! $settings->has( 'client_id' ) || ! $settings->has( 'merchant_id' ) ) {
|
||||
return 'https://www.paypal.com/sdk/js?components=applepay';
|
||||
}
|
||||
$client_id = $settings->get( 'client_id' );
|
||||
$shop_currency = get_woocommerce_currency();
|
||||
$merchant_id = $settings->get( 'merchant_id' );
|
||||
return 'https://www.paypal.com/sdk/js?client-id='
|
||||
. $client_id . '¤cy='
|
||||
. $shop_currency . '&merchant-id='
|
||||
. $merchant_id . '&components=applepay';
|
||||
},
|
||||
'applepay.script_url' => static function ( ContainerInterface $container ): string {
|
||||
return trailingslashit( $container->get( 'applepay.url' ) ) . '/assets/js/paypal-applepay-direct.js';
|
||||
},
|
||||
'applepay.setting_button_enabled_product' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof ContainerInterface );
|
||||
|
||||
return $settings->has( 'applepay_button_enabled_product' ) ?
|
||||
(bool) $settings->get( 'applepay_button_enabled_product' ) :
|
||||
false;
|
||||
},
|
||||
'applepay.setting_button_enabled_cart' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof ContainerInterface );
|
||||
|
||||
return $settings->has( 'applepay_button_enabled_cart' ) ?
|
||||
(bool) $settings->get( 'applepay_button_enabled_cart' ) :
|
||||
false;
|
||||
},
|
||||
);
|
208
modules/ppcp-applepay/src/ApplepayModule.php
Normal file
208
modules/ppcp-applepay/src/ApplepayModule.php
Normal file
|
@ -0,0 +1,208 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class ApplepayModule
|
||||
*/
|
||||
class ApplepayModule implements ModuleInterface {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface {
|
||||
return new ServiceProvider(
|
||||
require __DIR__ . '/../services.php',
|
||||
require __DIR__ . '/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function run( ContainerInterface $c ): void {
|
||||
$apple_payment_method = $c->get( 'applepay.payment_method' );
|
||||
// add onboarding and referrals hooks.
|
||||
$apple_payment_method->initialize();
|
||||
if ( ! $c->get( 'applepay.enabled' ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! $c->get( 'applepay.server_supported' ) ) {
|
||||
add_action(
|
||||
'admin_notices',
|
||||
static function () {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
__( 'Apple Pay is not supported on this server. Please contact your hosting provider to enable it.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
if ( ! $c->get( 'applepay.merchant_validated' ) ) {
|
||||
add_action(
|
||||
'admin_notices',
|
||||
static function () {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses_post(
|
||||
__( 'Apple Pay Validation Error. Please check the requirements.', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
);
|
||||
}
|
||||
$this->loadAssets( $c );
|
||||
$env = $c->get( 'onboarding.environment' );
|
||||
/**
|
||||
* The environment.
|
||||
*
|
||||
* @var Environment $env
|
||||
*/
|
||||
$is_sandobx = $env->current_environment_is( Environment::SANDBOX );
|
||||
$this->domain_association_file( $is_sandobx );
|
||||
$this->renderButtons( $c );
|
||||
|
||||
$apple_payment_method->bootstrapAjaxRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the module.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function getKey() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the assets.
|
||||
*
|
||||
* @param boolean $is_sandbox The environment for this merchant.
|
||||
*/
|
||||
protected function domain_association_file( $is_sandbox ): void {
|
||||
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
|
||||
return;
|
||||
}
|
||||
$request_uri = (string) filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
|
||||
if ( strpos( $request_uri, '.well-known/apple-developer-merchantid-domain-association' ) !== false ) {
|
||||
$validation_string = $is_sandbox ? 'apple-developer-merchantid-domain-association-sandbox' : 'apple-developer-merchantid-domain-association';
|
||||
$validation_file = file_get_contents( __DIR__ . '/../assets/validation_files/' . $validation_string );
|
||||
nocache_headers();
|
||||
header( 'Content-Type: text/plain', true, 200 );
|
||||
echo $validation_file;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers and enqueues the assets.
|
||||
*
|
||||
* @param ContainerInterface $c The container.
|
||||
* @return void
|
||||
*/
|
||||
public function loadAssets( ContainerInterface $c ): void {
|
||||
add_action(
|
||||
'init',
|
||||
function () use ( $c ) {
|
||||
wp_register_script(
|
||||
'wc-ppcp-applepay-sdk',
|
||||
$c->get( 'applepay.sdk_script_url' ),
|
||||
array(),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
wp_enqueue_script( 'wc-ppcp-applepay-sdk' );
|
||||
wp_register_script(
|
||||
'wc-ppcp-paypal-sdk',
|
||||
$c->get( 'applepay.paypal_sdk_url' ),
|
||||
array(),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
wp_enqueue_script( 'wc-ppcp-paypal-sdk' );
|
||||
wp_register_script(
|
||||
'wc-ppcp-applepay',
|
||||
$c->get( 'applepay.script_url' ),
|
||||
array( 'wc-ppcp-applepay-sdk', 'wc-ppcp-paypal-sdk' ),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
wp_enqueue_script( 'wc-ppcp-applepay' );
|
||||
wp_localize_script(
|
||||
'wc-ppcp-applepay',
|
||||
'wc_ppcp_applepay',
|
||||
array()
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ApplePay button markup
|
||||
*/
|
||||
protected function applePayDirectButton(): void {
|
||||
?>
|
||||
<div class="ppc-button-wrapper">
|
||||
<div id="woocommerce_paypal_payments_applepayDirect-button">
|
||||
<?php wp_nonce_field( 'woocommerce-process_checkout', 'woocommerce-process-checkout-nonce' ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Apple Pay buttons.
|
||||
*
|
||||
* @param ContainerInterface $c The container.
|
||||
* @return void
|
||||
*/
|
||||
public function renderButtons( ContainerInterface $c ): void {
|
||||
$button_enabled_product = $c->get( 'applepay.setting_button_enabled_product' );
|
||||
$button_enabled_cart = $c->get( 'applepay.setting_button_enabled_cart' );
|
||||
if ( $button_enabled_product ) {
|
||||
$render_placeholder = apply_filters( 'woocommerce_paypal_payments_applepay_render_hook_product', 'woocommerce_after_add_to_cart_form' );
|
||||
$render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : 'woocommerce_after_add_to_cart_form';
|
||||
add_action(
|
||||
$render_placeholder,
|
||||
function () {
|
||||
$this->applePayDirectButton();
|
||||
}
|
||||
);
|
||||
}
|
||||
if ( $button_enabled_cart ) {
|
||||
$render_placeholder = apply_filters( 'woocommerce_paypal_payments_applepay_render_hook_cart', 'woocommerce_cart_totals_after_order_total' );
|
||||
$render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : 'woocommerce_cart_totals_after_order_total';
|
||||
add_action(
|
||||
$render_placeholder,
|
||||
function () {
|
||||
$this->applePayDirectButton();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
197
modules/ppcp-applepay/src/ApplepayPaymentMethod.php
Normal file
197
modules/ppcp-applepay/src/ApplepayPaymentMethod.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
/**
|
||||
* Class PayPalPaymentMethod
|
||||
*/
|
||||
class ApplepayPaymentMethod {
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
private $plugin_settings;
|
||||
|
||||
/**
|
||||
* PayPalPaymentMethod constructor.
|
||||
*
|
||||
* @param Settings $plugin_settings The settings.
|
||||
*/
|
||||
public function __construct(
|
||||
Settings $plugin_settings
|
||||
) {
|
||||
$this->plugin_settings = $plugin_settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the class hooks.
|
||||
*/
|
||||
public function initialize(): void {
|
||||
add_filter( 'ppcp_onboarding_options', array( $this, 'add_apple_onboarding_option' ), 10, 1 );
|
||||
add_filter(
|
||||
'ppcp_partner_referrals_data',
|
||||
function ( array $data ): array {
|
||||
try {
|
||||
$onboard_with_apple = $this->plugin_settings->get( 'ppcp-onboarding-apple' );
|
||||
if ( $onboard_with_apple !== '1' ) {
|
||||
return $data;
|
||||
}
|
||||
} catch ( NotFoundException $exception ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
if ( in_array( 'PPCP', $data['products'], true ) ) {
|
||||
$data['products'][] = 'PAYMENT_METHODS';
|
||||
} elseif ( in_array( 'EXPRESS_CHECKOUT', $data['products'], true ) ) {
|
||||
$data['products'][0] = 'PAYMENT_METHODS';
|
||||
}
|
||||
$data['capabilities'][] = 'APPLE_PAY';
|
||||
|
||||
return $data;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the ApplePay onboarding option.
|
||||
*
|
||||
* @param string $options The options.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function add_apple_onboarding_option( $options ): string {
|
||||
$checked = '';
|
||||
try {
|
||||
$onboard_with_apple = $this->plugin_settings->get( 'ppcp-onboarding-apple' );
|
||||
if ( $onboard_with_apple === '1' ) {
|
||||
$checked = 'checked';
|
||||
}
|
||||
} catch ( NotFoundException $exception ) {
|
||||
$checked = '';
|
||||
}
|
||||
|
||||
return $options . '<li><label><input type="checkbox" id="ppcp-onboarding-apple" ' . $checked . '> ' .
|
||||
__( 'Onboard with ApplePay', 'woocommerce-paypal-payments' ) . '
|
||||
</label></li>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the Ajax actions to perform the whole workflow
|
||||
*/
|
||||
public function bootstrap_ajax_request(): void {
|
||||
add_action(
|
||||
'wp_ajax_' . PropertiesDictionary::VALIDATION,
|
||||
array( $this, 'validate_merchant' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_' . PropertiesDictionary::VALIDATION,
|
||||
array( $this, 'validate_merchant' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_' . PropertiesDictionary::CREATE_ORDER,
|
||||
array( $this, 'create_wc_order' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_' . PropertiesDictionary::CREATE_ORDER,
|
||||
array( $this, 'create_wc_order' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_' . PropertiesDictionary::CREATE_ORDER_CART,
|
||||
array( $this, 'create_wc_order_from_cart' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_' . PropertiesDictionary::CREATE_ORDER_CART,
|
||||
array( $this, 'create_wc_order_from_cart' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_' . PropertiesDictionary::UPDATE_SHIPPING_CONTACT,
|
||||
array( $this, 'update_shipping_contact' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_' . PropertiesDictionary::UPDATE_SHIPPING_CONTACT,
|
||||
array( $this, 'update_shipping_contact' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_' . PropertiesDictionary::UPDATE_SHIPPING_METHOD,
|
||||
array( $this, 'update_shipping_method' )
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_nopriv_' . PropertiesDictionary::UPDATE_SHIPPING_METHOD,
|
||||
array( $this, 'update_shipping_method' )
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Method to validate the merchant against Apple system
|
||||
* On fail triggers and option that shows an admin notice showing the error
|
||||
* On success returns the validation data to the script
|
||||
*/
|
||||
public function validate_merchant(): void {
|
||||
// TODO validate merchant.
|
||||
|
||||
// $this->plugin_settings->set('applepay_validated', 'yes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate and update the shipping contact of the user
|
||||
* It updates the amount paying information if needed
|
||||
* On error returns an array of errors to be handled by the script
|
||||
* On success returns the new contact data
|
||||
*/
|
||||
public function update_shipping_contact(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate and update the shipping method selected by the user
|
||||
* It updates the amount paying information if needed
|
||||
* On error returns an array of errors to be handled by the script
|
||||
* On success returns the new contact data
|
||||
*/
|
||||
public function update_shipping_method(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a WC order from the data received from the ApplePay JS
|
||||
* On error returns an array of errors to be handled by the script
|
||||
* On success returns the new order data
|
||||
*/
|
||||
public function create_wc_order(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a WC order from the data received from the ApplePay JS
|
||||
* On error returns an array of errors to be handled by the script
|
||||
* On success returns the new order data
|
||||
*/
|
||||
public function create_wc_order_from_cart(): void {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the nonce in the data object is valid
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
protected function is_nonce_valid(): bool {
|
||||
$nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS );
|
||||
if ( ! $nonce ) {
|
||||
return false;
|
||||
}
|
||||
return wp_verify_nonce(
|
||||
$nonce,
|
||||
'woocommerce-process_checkout'
|
||||
);
|
||||
}
|
||||
}
|
113
modules/ppcp-applepay/src/PropertiesDictionary.php
Normal file
113
modules/ppcp-applepay/src/PropertiesDictionary.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* The Applepay module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\Applepay
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Applepay;
|
||||
|
||||
/**
|
||||
* Class PropertiesDictionary
|
||||
*/
|
||||
class PropertiesDictionary {
|
||||
|
||||
|
||||
public const VALIDATION_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::VALIDATION_URL,
|
||||
);
|
||||
|
||||
public const BILLING_CONTACT_INVALID = 'billing Contact Invalid';
|
||||
|
||||
public const CREATE_ORDER_SINGLE_PROD_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::PRODUCT_ID,
|
||||
self::PRODUCT_QUANTITY,
|
||||
self::BILLING_CONTACT,
|
||||
self::SHIPPING_CONTACT,
|
||||
);
|
||||
|
||||
public const UPDATE_METHOD_CART_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::SHIPPING_METHOD,
|
||||
self::CALLER_PAGE,
|
||||
self::SIMPLIFIED_CONTACT,
|
||||
);
|
||||
|
||||
public const UPDATE_CONTACT_CART_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::CALLER_PAGE,
|
||||
self::SIMPLIFIED_CONTACT,
|
||||
self::NEED_SHIPPING,
|
||||
);
|
||||
|
||||
public const UPDATE_CONTACT_SINGLE_PROD_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::PRODUCT_ID,
|
||||
self::PRODUCT_QUANTITY,
|
||||
self::CALLER_PAGE,
|
||||
self::SIMPLIFIED_CONTACT,
|
||||
self::NEED_SHIPPING,
|
||||
);
|
||||
|
||||
public const VALIDATION_URL = 'validationUrl';
|
||||
|
||||
public const UPDATE_METHOD_SINGLE_PROD_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::PRODUCT_ID,
|
||||
self::PRODUCT_QUANTITY,
|
||||
self::SHIPPING_METHOD,
|
||||
self::CALLER_PAGE,
|
||||
self::SIMPLIFIED_CONTACT,
|
||||
);
|
||||
|
||||
public const PRODUCT_ID = 'productId';
|
||||
|
||||
public const SIMPLIFIED_CONTACT = 'simplifiedContact';
|
||||
|
||||
public const SHIPPING_METHOD = 'shippingMethod';
|
||||
|
||||
public const SHIPPING_CONTACT = 'shippingContact';
|
||||
|
||||
public const SHIPPING_CONTACT_INVALID = 'shipping Contact Invalid';
|
||||
|
||||
public const NONCE = 'nonce';
|
||||
|
||||
public const WCNONCE = 'woocommerce-process-checkout-nonce';
|
||||
|
||||
public const CREATE_ORDER_CART_REQUIRED_FIELDS =
|
||||
array(
|
||||
self::WCNONCE,
|
||||
self::BILLING_CONTACT,
|
||||
self::SHIPPING_CONTACT,
|
||||
);
|
||||
|
||||
public const PRODUCT_QUANTITY = 'productQuantity';
|
||||
|
||||
public const CALLER_PAGE = 'callerPage';
|
||||
|
||||
public const BILLING_CONTACT = 'billingContact';
|
||||
|
||||
public const NEED_SHIPPING = 'needShipping';
|
||||
|
||||
public const UPDATE_SHIPPING_CONTACT = 'woocommerce_paypal_payments_update_shipping_contact';
|
||||
|
||||
public const UPDATE_SHIPPING_METHOD = 'woocommerce_paypal_payments_update_shipping_method';
|
||||
|
||||
public const VALIDATION = 'woocommerce_paypal_payments_validation';
|
||||
|
||||
public const CREATE_ORDER = 'woocommerce_paypal_payments_create_order';
|
||||
|
||||
public const CREATE_ORDER_CART = 'woocommerce_paypal_payments_create_order_cart';
|
||||
|
||||
public const REDIRECT = 'woocommerce_paypal_payments_redirect';
|
||||
}
|
39
modules/ppcp-applepay/webpack.config.js
Normal file
39
modules/ppcp-applepay/webpack.config.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
const path = require('path');
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
||||
|
||||
module.exports = {
|
||||
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
target: 'web',
|
||||
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||
entry: {
|
||||
'applepayDirect': path.resolve('./resources/js/applepayDirect.js'),
|
||||
'applepayDirectCart': path.resolve('./resources/js/applepayDirectCart.js')
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'assets/'),
|
||||
filename: 'js/[name].js',
|
||||
},
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
name: 'css/[name].css',
|
||||
}
|
||||
},
|
||||
{loader:'sass-loader'}
|
||||
]
|
||||
}]
|
||||
}
|
||||
};
|
2257
modules/ppcp-applepay/yarn.lock
Normal file
2257
modules/ppcp-applepay/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue