2023-08-22 08:44:32 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* The Googlepay module services.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Googlepay
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Googlepay;
|
|
|
|
|
2023-08-25 16:25:20 +01:00
|
|
|
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodTypeInterface;
|
2023-08-24 17:30:29 +01:00
|
|
|
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
2023-08-25 16:25:20 +01:00
|
|
|
use WooCommerce\PayPalCommerce\Googlepay\Assets\BlocksPaymentMethod;
|
|
|
|
use WooCommerce\PayPalCommerce\Googlepay\Assets\Button;
|
2023-09-08 18:43:33 +01:00
|
|
|
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmApplies;
|
|
|
|
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
2023-08-22 08:44:32 +01:00
|
|
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|
|
|
|
|
|
|
return array(
|
2023-09-08 18:43:33 +01:00
|
|
|
|
|
|
|
// If GooglePay can be configured.
|
|
|
|
'googlepay.eligible' => static function ( ContainerInterface $container ): bool {
|
|
|
|
$apm_applies = $container->get( 'googlepay.helpers.apm-applies' );
|
|
|
|
assert( $apm_applies instanceof ApmApplies );
|
|
|
|
|
|
|
|
return $apm_applies->for_country_currency();
|
|
|
|
},
|
|
|
|
|
|
|
|
'googlepay.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
|
|
|
|
return new ApmApplies(
|
|
|
|
$container->get( 'googlepay.supported-country-currency-matrix' ),
|
|
|
|
$container->get( 'api.shop.currency' ),
|
|
|
|
$container->get( 'api.shop.country' )
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
// If GooglePay is configured.
|
|
|
|
'googlepay.available' => static function ( ContainerInterface $container ): bool {
|
2023-09-11 10:04:38 +01:00
|
|
|
if ( apply_filters( 'woocommerce_paypal_payments_googlepay_validate_product_status', false ) ) {
|
|
|
|
$status = $container->get( 'googlepay.helpers.apm-product-status' );
|
|
|
|
assert( $status instanceof ApmProductStatus );
|
|
|
|
/**
|
2023-09-11 10:25:01 +01:00
|
|
|
* If merchant isn't onboarded via /v1/customer/partner-referrals this returns false as the API call fails.
|
2023-09-11 10:04:38 +01:00
|
|
|
*/
|
|
|
|
return apply_filters( 'woocommerce_paypal_payments_googlepay_product_status', $status->is_active() );
|
|
|
|
}
|
|
|
|
return true;
|
2023-09-01 11:32:26 +01:00
|
|
|
},
|
2023-09-08 18:43:33 +01:00
|
|
|
|
|
|
|
'googlepay.helpers.apm-product-status' => static function( ContainerInterface $container ): ApmProductStatus {
|
|
|
|
return new ApmProductStatus(
|
|
|
|
$container->get( 'wcgateway.settings' ),
|
|
|
|
$container->get( 'api.endpoint.partners' ),
|
|
|
|
$container->get( 'onboarding.state' )
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The matrix which countries and currency combinations can be used for GooglePay.
|
|
|
|
*/
|
|
|
|
'googlepay.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
|
|
|
|
/**
|
|
|
|
* Returns which countries and currency combinations can be used for GooglePay.
|
|
|
|
*/
|
|
|
|
return apply_filters(
|
2023-09-11 10:04:38 +01:00
|
|
|
'woocommerce_paypal_payments_googlepay_supported_country_currency_matrix',
|
2023-09-08 18:43:33 +01:00
|
|
|
array(
|
2023-09-13 10:15:32 +01:00
|
|
|
'GB' => array(
|
|
|
|
'AUD',
|
|
|
|
'CAD',
|
|
|
|
'CHF',
|
|
|
|
'CZK',
|
|
|
|
'DKK',
|
|
|
|
'EUR',
|
|
|
|
'GBP',
|
|
|
|
'HKD',
|
|
|
|
'HUF',
|
|
|
|
'JPY',
|
|
|
|
'NOK',
|
|
|
|
'NZD',
|
|
|
|
'PLN',
|
|
|
|
'SEK',
|
|
|
|
'SGD',
|
|
|
|
'USD',
|
|
|
|
),
|
2023-09-08 18:43:33 +01:00
|
|
|
'US' => array(
|
|
|
|
'AUD',
|
|
|
|
'CAD',
|
|
|
|
'EUR',
|
|
|
|
'GBP',
|
|
|
|
'JPY',
|
|
|
|
'USD',
|
|
|
|
),
|
2023-09-13 10:15:32 +01:00
|
|
|
'CA' => array(
|
|
|
|
'AUD',
|
|
|
|
'CAD',
|
|
|
|
'CHF',
|
|
|
|
'CZK',
|
|
|
|
'DKK',
|
|
|
|
'EUR',
|
|
|
|
'GBP',
|
|
|
|
'HKD',
|
|
|
|
'HUF',
|
|
|
|
'JPY',
|
|
|
|
'NOK',
|
|
|
|
'NZD',
|
|
|
|
'PLN',
|
|
|
|
'SEK',
|
|
|
|
'SGD',
|
|
|
|
'USD',
|
|
|
|
),
|
2023-09-08 18:43:33 +01:00
|
|
|
)
|
|
|
|
);
|
2023-09-01 11:32:26 +01:00
|
|
|
},
|
2023-08-22 08:44:32 +01:00
|
|
|
|
2023-09-08 18:43:33 +01:00
|
|
|
'googlepay.button' => static function ( ContainerInterface $container ): ButtonInterface {
|
2023-08-25 16:25:20 +01:00
|
|
|
return new Button(
|
2023-08-22 08:44:32 +01:00
|
|
|
$container->get( 'googlepay.url' ),
|
2023-08-22 11:34:52 +01:00
|
|
|
$container->get( 'googlepay.sdk_url' ),
|
2023-08-22 08:44:32 +01:00
|
|
|
$container->get( 'ppcp.asset-version' ),
|
|
|
|
$container->get( 'session.handler' ),
|
|
|
|
$container->get( 'wcgateway.settings' ),
|
|
|
|
$container->get( 'onboarding.environment' ),
|
2023-08-24 17:30:29 +01:00
|
|
|
$container->get( 'wcgateway.settings.status' ),
|
2023-08-22 08:44:32 +01:00
|
|
|
$container->get( 'api.shop.currency' ),
|
|
|
|
$container->get( 'woocommerce.logger.woocommerce' )
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2023-09-08 18:43:33 +01:00
|
|
|
'googlepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface {
|
2023-08-25 16:25:20 +01:00
|
|
|
return new BlocksPaymentMethod(
|
|
|
|
'ppcp-googlepay',
|
|
|
|
$container->get( 'googlepay.url' ),
|
|
|
|
$container->get( 'ppcp.asset-version' ),
|
|
|
|
$container->get( 'googlepay.button' ),
|
|
|
|
$container->get( 'blocks.method' )
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2023-09-08 18:43:33 +01:00
|
|
|
'googlepay.url' => static function ( ContainerInterface $container ): string {
|
2023-08-22 08:44:32 +01:00
|
|
|
$path = realpath( __FILE__ );
|
|
|
|
if ( false === $path ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return plugins_url(
|
|
|
|
'/modules/ppcp-googlepay/',
|
|
|
|
dirname( $path, 3 ) . '/woocommerce-paypal-payments.php'
|
|
|
|
);
|
|
|
|
},
|
2023-08-22 11:34:52 +01:00
|
|
|
|
2023-09-08 18:43:33 +01:00
|
|
|
'googlepay.sdk_url' => static function ( ContainerInterface $container ): string {
|
2023-08-22 08:44:32 +01:00
|
|
|
return 'https://pay.google.com/gp/p/js/pay.js';
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|