2023-07-17 14:17:50 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The Applepay module services.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Applepay
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Applepay;
|
|
|
|
|
2023-08-17 09:42:45 +02:00
|
|
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
2023-07-17 14:17:50 +02:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|
|
|
|
|
|
|
return array(
|
2023-08-17 09:42:45 +02:00
|
|
|
'apple.status-cache' => static function( ContainerInterface $container ): Cache {
|
|
|
|
return new Cache( 'ppcp-paypal-apple-status-cache' );
|
|
|
|
},
|
2023-07-17 14:17:50 +02:00
|
|
|
'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
|
|
|
|
return new AppleProductStatus(
|
|
|
|
$container->get( 'wcgateway.settings' ),
|
|
|
|
$container->get( 'api.endpoint.partners' ),
|
2023-08-17 09:42:45 +02:00
|
|
|
$container->get( 'apple.status-cache' ),
|
2023-07-17 14:17:50 +02:00
|
|
|
$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' );
|
2023-07-31 17:08:42 +02:00
|
|
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
2023-08-17 09:42:45 +02:00
|
|
|
$order_processor = $container->get( 'wcgateway.order-processor' );
|
2023-07-17 14:17:50 +02:00
|
|
|
|
2023-08-17 09:42:45 +02:00
|
|
|
return new ApplepayPaymentMethod( $settings, $logger, $order_processor );
|
2023-07-17 14:17:50 +02:00
|
|
|
},
|
|
|
|
'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.script_url' => static function ( ContainerInterface $container ): string {
|
2023-07-31 17:08:42 +02:00
|
|
|
return trailingslashit( $container->get( 'applepay.url' ) ) . '/assets/js/applePayDirect.js';
|
|
|
|
},
|
2023-08-17 09:42:45 +02:00
|
|
|
'applepay.style_url' => static function ( ContainerInterface $container ): string {
|
2023-07-31 17:08:42 +02:00
|
|
|
return trailingslashit( $container->get( 'applepay.url' ) ) . '/assets/css/applepaydirect.css';
|
2023-07-17 14:17:50 +02:00
|
|
|
},
|
|
|
|
'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;
|
|
|
|
},
|
2023-08-17 09:42:45 +02:00
|
|
|
'applepay.data_to_scripts' => static function ( ContainerInterface $container ): DataToAppleButtonScripts {
|
2023-07-31 17:08:42 +02:00
|
|
|
return new DataToAppleButtonScripts();
|
|
|
|
},
|
2023-07-17 14:17:50 +02:00
|
|
|
);
|