woocommerce-paypal-payments/modules/ppcp-api-client/services.php

784 lines
25 KiB
PHP
Raw Normal View History

2020-08-31 13:38:54 +03:00
<?php
2020-09-01 09:00:45 +03:00
/**
* The services of the API client.
*
2020-09-11 14:11:10 +03:00
* @package WooCommerce\PayPalCommerce\ApiClient
2020-09-01 09:00:45 +03:00
*/
2020-08-31 13:38:54 +03:00
declare(strict_types=1);
2020-09-11 14:11:10 +03:00
namespace WooCommerce\PayPalCommerce\ApiClient;
2020-08-31 13:38:54 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingSubscriptions;
2023-01-05 15:43:32 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\CatalogProducts;
2023-03-01 16:12:26 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingPlans;
2023-03-17 16:06:26 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\BillingCycleFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentPreferencesFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PlanFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ProductFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingOptionFactory;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\IdentityToken;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AddressFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AmountFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ApplicationContextFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
2020-09-28 11:47:24 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
2022-02-11 17:49:44 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\ExchangeRateFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\FraudProcessorResponseFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\ItemFactory;
2022-02-11 12:05:21 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\MoneyFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayeeFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentsFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentSourceFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenActionLinksFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
2022-02-11 17:49:44 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PlatformFeeFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
2022-02-11 17:49:44 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerReceivableBreakdownFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
2021-09-22 17:13:38 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
2022-01-05 12:49:49 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Repository\CustomerRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\OrderRepository;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return array(
'api.host' => function( ContainerInterface $container ) : string {
2020-10-01 08:53:44 +03:00
return PAYPAL_API_URL;
2020-09-01 09:00:45 +03:00
},
'api.paypal-host' => function( ContainerInterface $container ) : string {
2020-10-01 08:53:44 +03:00
return PAYPAL_API_URL;
2020-09-01 09:00:45 +03:00
},
'api.partner_merchant_id' => static function () : string {
2020-09-01 09:00:45 +03:00
return '';
},
'api.merchant_email' => function () : string {
2020-09-01 09:00:45 +03:00
return '';
},
'api.merchant_id' => function () : string {
2020-09-01 09:00:45 +03:00
return '';
},
'api.key' => static function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
'api.secret' => static function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
'api.prefix' => static function (): string {
2020-09-01 09:00:45 +03:00
return 'WC-';
},
'api.bearer' => static function ( ContainerInterface $container ): Bearer {
2020-09-11 14:24:08 +03:00
$cache = new Cache( 'ppcp-paypal-bearer' );
2020-09-01 09:00:45 +03:00
$key = $container->get( 'api.key' );
$secret = $container->get( 'api.secret' );
$host = $container->get( 'api.host' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
2021-09-24 10:33:21 +02:00
$settings = $container->get( 'wcgateway.settings' );
2020-09-01 09:00:45 +03:00
return new PayPalBearer(
2020-09-11 13:38:02 +03:00
$cache,
2020-09-01 09:00:45 +03:00
$host,
$key,
$secret,
2021-09-24 10:33:21 +02:00
$logger,
$settings
2020-09-01 09:00:45 +03:00
);
},
'api.endpoint.partners' => static function ( ContainerInterface $container ) : PartnersEndpoint {
return new PartnersEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'api.factory.sellerstatus' ),
$container->get( 'api.partner_merchant_id' ),
$container->get( 'api.merchant_id' )
);
},
'api.factory.sellerstatus' => static function ( ContainerInterface $container ) : SellerStatusFactory {
return new SellerStatusFactory();
},
'api.endpoint.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenEndpoint {
2020-09-01 09:00:45 +03:00
return new PaymentTokenEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.factory.payment-token' ),
$container->get( 'api.factory.payment-token-action-links' ),
2020-09-01 09:00:45 +03:00
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'api.repository.customer' )
2020-09-01 09:00:45 +03:00
);
},
'api.endpoint.webhook' => static function ( ContainerInterface $container ) : WebhookEndpoint {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return new WebhookEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'api.factory.webhook' ),
2021-09-22 17:13:38 +03:00
$container->get( 'api.factory.webhook-event' ),
2020-09-01 09:00:45 +03:00
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.partner-referrals' => static function ( ContainerInterface $container ) : PartnerReferrals {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return new PartnerReferrals(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
2020-09-01 09:00:45 +03:00
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$settings = $container->get( 'wcgateway.settings' );
2022-01-05 12:49:49 +01:00
$customer_repository = $container->get( 'api.repository.customer' );
2020-09-01 09:00:45 +03:00
return new IdentityToken(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$logger,
2022-01-05 12:49:49 +01:00
$settings,
$customer_repository
2020-09-01 09:00:45 +03:00
);
},
'api.endpoint.payments' => static function ( ContainerInterface $container ): PaymentsEndpoint {
2020-09-01 09:00:45 +03:00
$authorizations_factory = $container->get( 'api.factory.authorization' );
2021-10-07 10:15:29 +03:00
$capture_factory = $container->get( 'api.factory.capture' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return new PaymentsEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$authorizations_factory,
2021-10-07 10:15:29 +03:00
$capture_factory,
2020-09-01 09:00:45 +03:00
$logger
);
},
'api.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSeller {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
$logger = $container->get( 'woocommerce.logger.woocommerce' );
return new LoginSeller(
$container->get( 'api.paypal-host' ),
$container->get( 'api.partner_merchant_id' ),
$logger
);
},
'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
2020-09-01 09:00:45 +03:00
$order_factory = $container->get( 'api.factory.order' );
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
2020-08-31 13:38:54 +03:00
$session_handler = $container->get( 'session.handler' );
assert( $session_handler instanceof SessionHandler );
$bn_code = $session_handler->bn_code();
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
2020-09-01 09:00:45 +03:00
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
$application_context_repository = $container->get( 'api.repository.application-context' );
$subscription_helper = $container->get( 'subscription.helper' );
2020-09-01 09:00:45 +03:00
return new OrderEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$order_factory,
$patch_collection_factory,
$intent,
$logger,
$application_context_repository,
$subscription_helper,
$container->get( 'wcgateway.is-fraudnet-enabled' ),
$container->get( 'wcgateway.fraudnet' ),
$bn_code
2020-09-01 09:00:45 +03:00
);
},
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {
return new BillingAgreementsEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2023-01-05 15:43:32 +01:00
'api.endpoint.catalog-products' => static function ( ContainerInterface $container ): CatalogProducts {
return new CatalogProducts(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
2023-04-11 11:58:11 +02:00
$container->get( 'api.factory.product' ),
2023-01-05 15:43:32 +01:00
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2023-03-01 16:12:26 +01:00
'api.endpoint.billing-plans' => static function( ContainerInterface $container ): BillingPlans {
return new BillingPlans(
2023-01-05 15:43:32 +01:00
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
2023-04-11 11:58:11 +02:00
$container->get( 'api.factory.billing-cycle' ),
$container->get( 'api.factory.plan' ),
2023-01-05 15:43:32 +01:00
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.endpoint.billing-subscriptions' => static function( ContainerInterface $container ): BillingSubscriptions {
return new BillingSubscriptions(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
$settings = $container->get( 'wcgateway.settings' );
return new ApplicationContextRepository( $settings );
},
'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
return new PartnerReferralsData( $dcc_applies );
2020-09-01 09:00:45 +03:00
},
'api.repository.payee' => static function ( ContainerInterface $container ): PayeeRepository {
2020-09-01 09:00:45 +03:00
$merchant_email = $container->get( 'api.merchant_email' );
$merchant_id = $container->get( 'api.merchant_id' );
return new PayeeRepository( $merchant_email, $merchant_id );
},
2022-01-05 12:49:49 +01:00
'api.repository.customer' => static function( ContainerInterface $container ): CustomerRepository {
$prefix = $container->get( 'api.prefix' );
return new CustomerRepository( $prefix );
},
'api.repository.order' => static function( ContainerInterface $container ): OrderRepository {
return new OrderRepository(
$container->get( 'api.endpoint.order' )
);
},
'api.factory.application-context' => static function ( ContainerInterface $container ) : ApplicationContextFactory {
2020-09-01 09:00:45 +03:00
return new ApplicationContextFactory();
},
'api.factory.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenFactory {
2020-09-01 09:00:45 +03:00
return new PaymentTokenFactory();
},
'api.factory.payment-token-action-links' => static function ( ContainerInterface $container ) : PaymentTokenActionLinksFactory {
return new PaymentTokenActionLinksFactory();
},
'api.factory.webhook' => static function ( ContainerInterface $container ): WebhookFactory {
2020-09-01 09:00:45 +03:00
return new WebhookFactory();
},
'api.factory.webhook-event' => static function ( ContainerInterface $container ): WebhookEventFactory {
2021-09-22 17:13:38 +03:00
return new WebhookEventFactory();
},
'api.factory.capture' => static function ( ContainerInterface $container ): CaptureFactory {
2020-09-28 11:47:24 +03:00
$amount_factory = $container->get( 'api.factory.amount' );
2022-02-14 10:46:33 +02:00
return new CaptureFactory(
$amount_factory,
$container->get( 'api.factory.seller-receivable-breakdown' ),
$container->get( 'api.factory.fraud-processor-response' )
2022-02-14 10:46:33 +02:00
);
2020-09-28 11:47:24 +03:00
},
'api.factory.purchase-unit' => static function ( ContainerInterface $container ): PurchaseUnitFactory {
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
$amount_factory = $container->get( 'api.factory.amount' );
$payee_repository = $container->get( 'api.repository.payee' );
$payee_factory = $container->get( 'api.factory.payee' );
$item_factory = $container->get( 'api.factory.item' );
$shipping_factory = $container->get( 'api.factory.shipping' );
$payments_factory = $container->get( 'api.factory.payments' );
$prefix = $container->get( 'api.prefix' );
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return new PurchaseUnitFactory(
$amount_factory,
$payee_repository,
$payee_factory,
$item_factory,
$shipping_factory,
$payments_factory,
$prefix
);
},
'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory {
2020-09-01 09:00:45 +03:00
return new PatchCollectionFactory();
},
'api.factory.payee' => static function ( ContainerInterface $container ): PayeeFactory {
2020-09-01 09:00:45 +03:00
return new PayeeFactory();
},
'api.factory.item' => static function ( ContainerInterface $container ): ItemFactory {
return new ItemFactory(
$container->get( 'api.shop.currency' )
);
2020-09-01 09:00:45 +03:00
},
'api.factory.shipping' => static function ( ContainerInterface $container ): ShippingFactory {
return new ShippingFactory(
$container->get( 'api.factory.address' ),
$container->get( 'api.factory.shipping-option' )
);
2020-09-01 09:00:45 +03:00
},
'api.factory.shipping-preference' => static function ( ContainerInterface $container ): ShippingPreferenceFactory {
return new ShippingPreferenceFactory();
},
'api.factory.shipping-option' => static function ( ContainerInterface $container ): ShippingOptionFactory {
return new ShippingOptionFactory(
$container->get( 'api.factory.money' )
);
},
'api.factory.amount' => static function ( ContainerInterface $container ): AmountFactory {
2020-09-01 09:00:45 +03:00
$item_factory = $container->get( 'api.factory.item' );
return new AmountFactory(
$item_factory,
2022-02-11 12:05:21 +02:00
$container->get( 'api.factory.money' ),
$container->get( 'api.shop.currency' )
);
2020-09-01 09:00:45 +03:00
},
2022-02-11 12:05:21 +02:00
'api.factory.money' => static function ( ContainerInterface $container ): MoneyFactory {
return new MoneyFactory();
},
'api.factory.payer' => static function ( ContainerInterface $container ): PayerFactory {
2020-09-01 09:00:45 +03:00
$address_factory = $container->get( 'api.factory.address' );
return new PayerFactory( $address_factory );
},
'api.factory.address' => static function ( ContainerInterface $container ): AddressFactory {
2020-09-01 09:00:45 +03:00
return new AddressFactory();
},
'api.factory.payment-source' => static function ( ContainerInterface $container ): PaymentSourceFactory {
2020-09-01 09:00:45 +03:00
return new PaymentSourceFactory();
},
'api.factory.order' => static function ( ContainerInterface $container ): OrderFactory {
2020-09-01 09:00:45 +03:00
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
$payer_factory = $container->get( 'api.factory.payer' );
$application_context_repository = $container->get( 'api.repository.application-context' );
$application_context_factory = $container->get( 'api.factory.application-context' );
$payment_source_factory = $container->get( 'api.factory.payment-source' );
return new OrderFactory(
$purchase_unit_factory,
$payer_factory,
$application_context_repository,
$application_context_factory,
$payment_source_factory
);
},
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
2020-09-01 09:00:45 +03:00
$authorizations_factory = $container->get( 'api.factory.authorization' );
2020-09-28 11:47:24 +03:00
$capture_factory = $container->get( 'api.factory.capture' );
return new PaymentsFactory( $authorizations_factory, $capture_factory );
2020-09-01 09:00:45 +03:00
},
'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory {
2020-09-01 09:00:45 +03:00
return new AuthorizationFactory();
},
2022-02-11 17:49:44 +02:00
'api.factory.exchange-rate' => static function ( ContainerInterface $container ): ExchangeRateFactory {
return new ExchangeRateFactory();
},
'api.factory.platform-fee' => static function ( ContainerInterface $container ): PlatformFeeFactory {
return new PlatformFeeFactory(
$container->get( 'api.factory.money' ),
$container->get( 'api.factory.payee' )
);
},
'api.factory.seller-receivable-breakdown' => static function ( ContainerInterface $container ): SellerReceivableBreakdownFactory {
return new SellerReceivableBreakdownFactory(
$container->get( 'api.factory.money' ),
$container->get( 'api.factory.exchange-rate' ),
$container->get( 'api.factory.platform-fee' )
);
},
'api.factory.fraud-processor-response' => static function ( ContainerInterface $container ): FraudProcessorResponseFactory {
return new FraudProcessorResponseFactory();
},
2023-04-11 11:58:11 +02:00
'api.factory.product' => static function( ContainerInterface $container ): ProductFactory {
2023-03-17 16:06:26 +01:00
return new ProductFactory();
},
2023-04-11 11:58:11 +02:00
'api.factory.billing-cycle' => static function( ContainerInterface $container ): BillingCycleFactory {
return new BillingCycleFactory( $container->get( 'api.shop.currency' ) );
2023-03-17 16:06:26 +01:00
},
2023-04-11 11:58:11 +02:00
'api.factory.payment-preferences' => static function( ContainerInterface $container ):PaymentPreferencesFactory {
return new PaymentPreferencesFactory( $container->get( 'api.shop.currency' ) );
2023-03-17 16:06:26 +01:00
},
2023-04-11 11:58:11 +02:00
'api.factory.plan' => static function( ContainerInterface $container ): PlanFactory {
2023-03-17 16:06:26 +01:00
return new PlanFactory(
2023-04-11 11:58:11 +02:00
$container->get( 'api.factory.billing-cycle' ),
$container->get( 'api.factory.payment-preferences' )
2023-03-17 16:06:26 +01:00
);
},
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
return new DccApplies(
$container->get( 'api.dcc-supported-country-currency-matrix' ),
$container->get( 'api.dcc-supported-country-card-matrix' ),
$container->get( 'api.shop.currency' ),
$container->get( 'api.shop.country' )
);
2020-09-01 09:00:45 +03:00
},
'api.shop.currency' => static function ( ContainerInterface $container ) : string {
$currency = get_woocommerce_currency();
2022-02-11 12:00:30 +01:00
if ( $currency ) {
return $currency;
}
2022-02-11 12:00:30 +01:00
$currency = get_option( 'woocommerce_currency' );
2022-01-06 13:41:12 +02:00
if ( ! $currency ) {
return 'NO_CURRENCY'; // Unlikely to happen.
}
2022-01-06 13:41:12 +02:00
return $currency;
},
'api.shop.country' => static function ( ContainerInterface $container ) : string {
$location = wc_get_base_location();
return $location['country'];
},
'api.shop.is-psd2-country' => static function ( ContainerInterface $container ) : bool {
return in_array(
$container->get( 'api.shop.country' ),
$container->get( 'api.psd2-countries' ),
true
);
},
'api.shop.is-currency-supported' => static function ( ContainerInterface $container ) : bool {
return in_array(
$container->get( 'api.shop.currency' ),
$container->get( 'api.supported-currencies' ),
true
);
},
'api.shop.is-latin-america' => static function ( ContainerInterface $container ): bool {
return in_array(
$container->get( 'api.shop.country' ),
array(
'AI',
'AG',
'AR',
'AW',
'BS',
'BB',
'BZ',
'BM',
'BO',
'BR',
'VG',
'KY',
'CL',
'CO',
'CR',
'DM',
'DO',
'EC',
'SV',
'FK',
'GF',
'GD',
'GP',
'GT',
'GY',
'HN',
'JM',
'MQ',
'MX',
'MS',
'AN',
'NI',
'PA',
'PY',
'PE',
'KN',
'LC',
'PM',
'VC',
'SR',
'TT',
'TC',
'UY',
'VE',
),
true
);
},
/**
* Currencies supported by PayPal.
*
* From https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
*/
'api.supported-currencies' => static function ( ContainerInterface $container ) : array {
return array(
'AUD',
'BRL',
'CAD',
'CNY',
'CZK',
'DKK',
'EUR',
'HKD',
'HUF',
'ILS',
'JPY',
'MYR',
'MXN',
'TWD',
'NZD',
'NOK',
'PHP',
'PLN',
'GBP',
'RUB',
'SGD',
'SEK',
'CHF',
'THB',
'USD',
);
},
/**
* The matrix which countries and currency combinations can be used for DCC.
*/
'api.dcc-supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
2022-02-17 18:19:55 +02:00
/**
* Returns which countries and currency combinations can be used for DCC.
*/
return apply_filters(
'woocommerce_paypal_payments_supported_country_currency_matrix',
array(
'AU' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'DE' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'ES' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'FR' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'GB' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'IT' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
'US' => array(
'AUD',
'CAD',
'EUR',
'GBP',
'JPY',
'USD',
),
'CA' => array(
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HKD',
'HUF',
'JPY',
'NOK',
'NZD',
'PLN',
'SEK',
'SGD',
'USD',
),
)
);
},
/**
* Which countries support which credit cards. Empty credit card arrays mean no restriction on currency.
*/
'api.dcc-supported-country-card-matrix' => static function ( ContainerInterface $container ) : array {
2022-02-17 18:19:55 +02:00
/**
* Returns which countries support which credit cards. Empty credit card arrays mean no restriction on currency.
*/
return apply_filters(
'woocommerce_paypal_payments_supported_country_card_matrix',
array(
'AU' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'AUD' ),
),
'DE' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'EUR' ),
),
'ES' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'EUR' ),
),
'FR' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'EUR' ),
),
'GB' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'GBP', 'USD' ),
),
'IT' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'EUR' ),
),
'US' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'USD' ),
'discover' => array( 'USD' ),
),
'CA' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'CAD' ),
'jcb' => array( 'CAD' ),
),
)
);
},
'api.psd2-countries' => static function ( ContainerInterface $container ) : array {
return array(
'AT',
'BE',
'BG',
'CY',
'CZ',
'DK',
'EE',
'FI',
'FR',
'DE',
'GB',
'GR',
'HU',
'IE',
'IT',
'LV',
'LT',
'LU',
'MT',
'NL',
'NO',
'PL',
'PT',
'RO',
'SK',
'SI',
'ES',
'SE',
);
},
'api.order-helper' => static function( ContainerInterface $container ): OrderHelper {
return new OrderHelper();
},
2020-09-01 09:00:45 +03:00
);