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

995 lines
37 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\Authentication\Bearer;
2024-08-06 09:25:28 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ClientCredentials;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
2024-04-12 12:19:36 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Authentication\SdkClientToken;
use WooCommerce\PayPalCommerce\ApiClient\Authentication\UserIdToken;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingPlans;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingSubscriptions;
2023-01-05 15:43:32 +01:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\CatalogProducts;
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\Orders;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentMethodTokensEndpoint;
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\PaymentTokensEndpoint;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AddressFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AmountFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\BillingCycleFactory;
2020-09-28 11:47:24 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CardAuthenticationResultFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ContactPreferenceFactory;
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\PaymentPreferencesFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentsFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenActionLinksFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PlanFactory;
2022-02-11 17:49:44 +02:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PlatformFeeFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ProductFactory;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\RefundFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\RefundPayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerPayableBreakdownFactory;
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\ShippingOptionFactory;
2025-07-02 17:33:32 -04:00
use WooCommerce\PayPalCommerce\ApiClient\Factory\ReturnUrlFactory;
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\ReferenceTransactionStatus;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
2020-09-11 14:11:10 +03:00
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PartnerAttribution;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PurchaseUnitSanitizer;
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\Common\Pattern\SingletonDecorator;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
2025-06-13 15:02:53 +02:00
use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel;
use WooCommerce\PayPalCommerce\Settings\Enum\InstallationPathEnum;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Helper\EnvironmentConfig;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return array(
2025-08-22 17:00:32 +02:00
'api.host' => static function ( ContainerInterface $container ): string {
2025-02-17 18:48:38 +01:00
$environment = $container->get( 'settings.environment' );
assert( $environment instanceof Environment );
if ( $environment->is_sandbox() ) {
return (string) $container->get( 'api.sandbox-host' );
}
return (string) $container->get( 'api.production-host' );
2020-09-01 09:00:45 +03:00
},
2025-08-22 17:00:32 +02: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
},
2023-11-24 16:18:15 +00:00
// It seems this 'api.paypal-website-url' key is always overridden in ppcp-onboarding/services.php.
2025-08-22 17:00:32 +02:00
'api.paypal-website-url' => function ( ContainerInterface $container ): string {
2023-11-14 10:50:56 +02:00
return PAYPAL_URL;
},
2025-08-22 17:00:32 +02:00
'api.factory.paypal-checkout-url' => function ( ContainerInterface $container ): callable {
2023-11-14 10:50:56 +02:00
return function ( string $id ) use ( $container ): string {
return $container->get( 'api.paypal-website-url' ) . '/checkoutnow?token=' . $id;
};
},
2025-08-22 17:00:32 +02:00
'api.partner_merchant_id' => static function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
2025-08-22 17:00:32 +02:00
'api.merchant_email' => function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
2025-08-22 17:00:32 +02:00
'api.merchant_id' => function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
2023-11-23 15:05:43 +01:00
'api.key' => static function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
2023-11-23 15:05:43 +01:00
'api.secret' => static function (): string {
2020-09-01 09:00:45 +03:00
return '';
},
2023-11-23 15:05:43 +01:00
'api.prefix' => static function (): string {
2020-09-01 09:00:45 +03:00
return 'WC-';
},
2023-11-23 15:05:43 +01:00
'api.bearer' => static function ( ContainerInterface $container ): Bearer {
$is_connected = $container->get( 'settings.flag.is-connected' );
if ( ! $is_connected ) {
return new ConnectBearer();
}
2020-09-01 09:00:45 +03:00
return new PayPalBearer(
$container->get( 'api.paypal-bearer-cache' ),
$container->get( 'api.host' ),
$container->get( 'api.key' ),
$container->get( 'api.secret' ),
$container->get( 'woocommerce.logger.woocommerce' ),
$container->get( 'wcgateway.settings' )
2020-09-01 09:00:45 +03:00
);
},
2025-08-22 17:00:32 +02: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' ),
$container->get( 'api.helper.failure-registry' )
);
},
2025-08-22 17:00:32 +02:00
'api.factory.sellerstatus' => static function ( ContainerInterface $container ): SellerStatusFactory {
return new SellerStatusFactory();
},
2025-08-22 17:00:32 +02:00
'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
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.payment-tokens' => static function ( ContainerInterface $container ): PaymentTokensEndpoint {
2023-11-02 10:54:08 +01:00
return new PaymentTokensEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02: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' )
);
},
2025-08-22 17:00:32 +02:00
'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' )
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.partner-referrals-sandbox' => static function ( ContainerInterface $container ): PartnerReferrals {
return new PartnerReferrals(
CONNECT_WOO_SANDBOX_URL,
new ConnectBearer(),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.partner-referrals-production' => static function ( ContainerInterface $container ): PartnerReferrals {
return new PartnerReferrals(
CONNECT_WOO_URL,
new ConnectBearer(),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02:00
'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
);
},
2023-11-23 15:05:43 +01: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
);
},
2025-08-22 17:00:32 +02:00
'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
);
},
2023-11-23 15:05:43 +01:00
'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';
$subscription_helper = $container->get( 'wc-subscriptions.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,
$subscription_helper,
$container->get( 'wcgateway.is-fraudnet-enabled' ),
$container->get( 'wcgateway.fraudnet' ),
$bn_code
2020-09-01 09:00:45 +03:00
);
},
'api.endpoint.orders' => static function ( ContainerInterface $container ): Orders {
2024-08-05 17:36:56 +02:00
return new Orders(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
2024-08-05 17:36:56 +02:00
);
},
2025-06-30 18:28:30 +04:00
'api.reference-transaction-status' => static fn ( ContainerInterface $container ): ReferenceTransactionStatus => new ReferenceTransactionStatus(
$container->get( 'api.endpoint.partners' ),
$container->get( 'api.reference-transaction-status-cache' )
),
2023-11-23 15:05:43 +01:00
'api.endpoint.catalog-products' => static function ( ContainerInterface $container ): CatalogProducts {
2023-01-05 15:43:32 +01:00
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' )
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.billing-plans' => static function ( ContainerInterface $container ): BillingPlans {
2023-03-01 16:12:26 +01:00
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' )
);
},
2025-08-22 17:00:32 +02:00
'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' )
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.payment-method-tokens' => static function ( ContainerInterface $container ): PaymentMethodTokensEndpoint {
return new PaymentMethodTokensEndpoint(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02:00
'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
},
2023-11-23 15:05:43 +01: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 );
},
2025-08-22 17:00:32 +02:00
'api.repository.customer' => static function ( ContainerInterface $container ): CustomerRepository {
2022-01-05 12:49:49 +01:00
$prefix = $container->get( 'api.prefix' );
return new CustomerRepository( $prefix );
},
2025-08-22 17:00:32 +02:00
'api.repository.order' => static function ( ContainerInterface $container ): OrderRepository {
return new OrderRepository(
$container->get( 'api.endpoint.order' )
);
},
2025-06-13 15:02:53 +02:00
'api.factory.contact-preference' => static function ( ContainerInterface $container ): ContactPreferenceFactory {
if ( $container->has( 'settings.data.settings' ) ) {
$settings = $container->get( 'settings.data.settings' );
assert( $settings instanceof SettingsModel );
$contact_module_active = $settings->get_enable_contact_module();
} else {
// #legacy-ui: Auto-enable the feature; can be disabled via eligibility hook.
$contact_module_active = true;
}
return new ContactPreferenceFactory(
$contact_module_active,
$container->get( 'settings.merchant-details' )
);
},
2025-08-22 17:00:32 +02:00
'api.factory.payment-token' => static function ( ContainerInterface $container ): PaymentTokenFactory {
2020-09-01 09:00:45 +03:00
return new PaymentTokenFactory();
},
2025-08-22 17:00:32 +02:00
'api.factory.payment-token-action-links' => static function ( ContainerInterface $container ): PaymentTokenActionLinksFactory {
return new PaymentTokenActionLinksFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.webhook' => static function ( ContainerInterface $container ): WebhookFactory {
2020-09-01 09:00:45 +03:00
return new WebhookFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.webhook-event' => static function ( ContainerInterface $container ): WebhookEventFactory {
2021-09-22 17:13:38 +03:00
return new WebhookEventFactory();
},
2023-11-23 15:05:43 +01:00
'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
},
2023-11-23 15:05:43 +01:00
'api.factory.refund' => static function ( ContainerInterface $container ): RefundFactory {
$amount_factory = $container->get( 'api.factory.amount' );
return new RefundFactory(
$amount_factory,
$container->get( 'api.factory.seller-payable-breakdown' ),
$container->get( 'api.factory.refund_payer' )
);
},
2023-11-23 15:05:43 +01: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' );
$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' );
$soft_descriptor = $container->get( 'wcgateway.soft-descriptor' );
$sanitizer = $container->get( 'api.helper.purchase-unit-sanitizer' );
2020-08-31 13:38:54 +03:00
2020-09-01 09:00:45 +03:00
return new PurchaseUnitFactory(
$amount_factory,
$item_factory,
$shipping_factory,
$payments_factory,
$prefix,
$soft_descriptor,
$sanitizer
2020-09-01 09:00:45 +03:00
);
},
2023-11-23 15:05:43 +01:00
'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory {
2020-09-01 09:00:45 +03:00
return new PatchCollectionFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.payee' => static function ( ContainerInterface $container ): PayeeFactory {
2020-09-01 09:00:45 +03:00
return new PayeeFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.item' => static function ( ContainerInterface $container ): ItemFactory {
return new ItemFactory(
$container->get( 'api.shop.currency.getter' )
);
2020-09-01 09:00:45 +03:00
},
2023-11-23 15:05:43 +01: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
},
2025-07-02 17:33:32 -04:00
'api.factory.return-url' => static function ( ContainerInterface $container ): ReturnUrlFactory {
return new ReturnUrlFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.shipping-preference' => static function ( ContainerInterface $container ): ShippingPreferenceFactory {
return new ShippingPreferenceFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.shipping-option' => static function ( ContainerInterface $container ): ShippingOptionFactory {
return new ShippingOptionFactory(
$container->get( 'api.factory.money' )
);
},
2023-11-23 15:05:43 +01:00
'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.getter' )
);
2020-09-01 09:00:45 +03:00
},
2023-11-23 15:05:43 +01:00
'api.factory.money' => static function ( ContainerInterface $container ): MoneyFactory {
2022-02-11 12:05:21 +02:00
return new MoneyFactory();
},
2023-11-23 15:05:43 +01:00
'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 );
},
2023-11-23 15:05:43 +01:00
'api.factory.refund_payer' => static function ( ContainerInterface $container ): RefundPayerFactory {
return new RefundPayerFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.address' => static function ( ContainerInterface $container ): AddressFactory {
2020-09-01 09:00:45 +03:00
return new AddressFactory();
},
2023-11-23 15:05:43 +01:00
'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' );
return new OrderFactory(
$purchase_unit_factory,
2025-05-29 19:49:43 +03:00
$payer_factory
2020-09-01 09:00:45 +03:00
);
},
2023-11-23 15:05:43 +01:00
'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' );
$refund_factory = $container->get( 'api.factory.refund' );
return new PaymentsFactory( $authorizations_factory, $capture_factory, $refund_factory );
2020-09-01 09:00:45 +03:00
},
2023-11-23 15:05:43 +01:00
'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory {
2024-01-30 17:39:21 +04:00
return new AuthorizationFactory( $container->get( 'api.factory.fraud-processor-response' ) );
2020-09-01 09:00:45 +03:00
},
2023-11-23 15:05:43 +01:00
'api.factory.exchange-rate' => static function ( ContainerInterface $container ): ExchangeRateFactory {
2022-02-11 17:49:44 +02:00
return new ExchangeRateFactory();
},
2023-11-23 15:05:43 +01:00
'api.factory.platform-fee' => static function ( ContainerInterface $container ): PlatformFeeFactory {
2022-02-11 17:49:44 +02:00
return new PlatformFeeFactory(
$container->get( 'api.factory.money' ),
$container->get( 'api.factory.payee' )
);
},
2023-11-23 15:05:43 +01:00
'api.factory.seller-receivable-breakdown' => static function ( ContainerInterface $container ): SellerReceivableBreakdownFactory {
2022-02-11 17:49:44 +02:00
return new SellerReceivableBreakdownFactory(
$container->get( 'api.factory.money' ),
$container->get( 'api.factory.exchange-rate' ),
$container->get( 'api.factory.platform-fee' )
);
},
2023-11-23 15:05:43 +01:00
'api.factory.seller-payable-breakdown' => static function ( ContainerInterface $container ): SellerPayableBreakdownFactory {
return new SellerPayableBreakdownFactory(
$container->get( 'api.factory.money' ),
$container->get( 'api.factory.platform-fee' )
2022-02-11 17:49:44 +02:00
);
},
2023-11-23 15:05:43 +01:00
'api.factory.fraud-processor-response' => static function ( ContainerInterface $container ): FraudProcessorResponseFactory {
return new FraudProcessorResponseFactory();
},
2025-08-22 17:00:32 +02:00
'api.factory.product' => static function ( ContainerInterface $container ): ProductFactory {
2023-03-17 16:06:26 +01:00
return new ProductFactory();
},
2025-08-22 17:00:32 +02:00
'api.factory.billing-cycle' => static function ( ContainerInterface $container ): BillingCycleFactory {
return new BillingCycleFactory( $container->get( 'api.shop.currency.getter' ) );
2023-03-17 16:06:26 +01:00
},
2025-08-22 17:00:32 +02:00
'api.factory.payment-preferences' => static function ( ContainerInterface $container ): PaymentPreferencesFactory {
return new PaymentPreferencesFactory( $container->get( 'api.shop.currency.getter' ) );
2023-03-17 16:06:26 +01:00
},
2025-08-22 17:00:32 +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
);
},
2025-08-22 17:00:32 +02:00
'api.factory.card-authentication-result-factory' => static function ( ContainerInterface $container ): CardAuthenticationResultFactory {
2023-11-23 14:58:11 +01:00
return new CardAuthenticationResultFactory();
2023-11-23 14:53:47 +01:00
},
2025-08-22 17:00:32 +02: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.getter' ),
$container->get( 'api.shop.country' )
);
2020-09-01 09:00:45 +03:00
},
2025-08-22 17:00:32 +02:00
'api.shop.currency.getter' => static function ( ContainerInterface $container ): CurrencyGetter {
return new CurrencyGetter();
},
2025-08-22 17:00:32 +02:00
'api.shop.country' => static function ( ContainerInterface $container ): string {
$location = wc_get_base_location();
return $location['country'];
},
2025-08-22 17:00:32 +02:00
'api.shop.is-psd2-country' => static function ( ContainerInterface $container ): bool {
return in_array(
$container->get( 'api.shop.country' ),
$container->get( 'api.psd2-countries' ),
true
);
},
2025-08-22 17:00:32 +02:00
'api.shop.is-currency-supported' => static function ( ContainerInterface $container ): bool {
return in_array(
$container->get( 'api.shop.currency.getter' )->get(),
$container->get( 'api.supported-currencies' ),
true
);
},
2023-11-23 15:05:43 +01:00
'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/
*/
2025-08-22 17:00:32 +02:00
'api.supported-currencies' => static function ( ContainerInterface $container ): array {
return array(
'AUD',
'BRL',
'CAD',
'CNY',
'CZK',
'DKK',
'EUR',
2024-11-25 16:18:21 +01:00
'HKD',
'HUF',
'ILS',
'JPY',
'MYR',
'MXN',
'TWD',
'NZD',
'NOK',
'PHP',
'PLN',
'GBP',
'RUB',
2024-11-25 16:18:21 +01:00
'SGD',
'SEK',
'CHF',
'THB',
'USD',
);
},
/**
* The matrix which countries and currency combinations can be used for DCC.
*/
2025-08-22 17:00:32 +02:00
'api.dcc-supported-country-currency-matrix' => static function ( ContainerInterface $container ): array {
2024-12-02 16:21:24 +01:00
$default_currencies = apply_filters(
2024-12-02 16:25:24 +01:00
'woocommerce_paypal_payments_supported_currencies',
2024-12-02 16:21:24 +01:00
array(
'AUD',
'BRL',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'HKD',
'GBP',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PHP',
'PLN',
'SGD',
'SEK',
'THB',
'TWD',
'USD',
)
);
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' => $default_currencies,
'AT' => $default_currencies,
'BE' => $default_currencies,
'BG' => $default_currencies,
'CA' => $default_currencies,
'CN' => $default_currencies,
'CY' => $default_currencies,
'CZ' => $default_currencies,
'DK' => $default_currencies,
'EE' => $default_currencies,
'FI' => $default_currencies,
'FR' => $default_currencies,
'DE' => $default_currencies,
'GR' => $default_currencies,
2025-02-13 09:54:21 +01:00
'HK' => $default_currencies,
'HU' => $default_currencies,
'IE' => $default_currencies,
'IT' => $default_currencies,
'JP' => $default_currencies,
'LV' => $default_currencies,
'LI' => $default_currencies,
'LT' => $default_currencies,
'LU' => $default_currencies,
'MT' => $default_currencies,
2023-06-02 12:56:55 +02:00
'MX' => array(
'MXN',
),
'NL' => $default_currencies,
'PL' => $default_currencies,
'PT' => $default_currencies,
'RO' => $default_currencies,
'SK' => $default_currencies,
2025-02-13 09:54:21 +01:00
'SG' => $default_currencies,
'SI' => $default_currencies,
'ES' => $default_currencies,
'SE' => $default_currencies,
'GB' => $default_currencies,
'US' => $default_currencies,
'NO' => $default_currencies,
'YT' => $default_currencies,
'RE' => $default_currencies,
'GP' => $default_currencies,
'GF' => $default_currencies,
'MQ' => $default_currencies,
)
);
},
/**
* Which countries support which credit cards. Empty credit card arrays mean no restriction on currency.
*/
2025-08-22 17:00:32 +02:00
'api.dcc-supported-country-card-matrix' => static function ( ContainerInterface $container ): array {
$mastercard_visa_amex = array(
'mastercard' => array(),
'visa' => array(),
'amex' => 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' ),
),
'AT' => $mastercard_visa_amex,
'BE' => $mastercard_visa_amex,
'BG' => $mastercard_visa_amex,
'CN' => array(
'mastercard' => array(),
'visa' => array(),
),
'CY' => $mastercard_visa_amex,
'CZ' => $mastercard_visa_amex,
'DE' => $mastercard_visa_amex,
'DK' => $mastercard_visa_amex,
'EE' => $mastercard_visa_amex,
'ES' => $mastercard_visa_amex,
'FI' => $mastercard_visa_amex,
'FR' => $mastercard_visa_amex,
'GB' => $mastercard_visa_amex,
'GR' => $mastercard_visa_amex,
2025-02-13 09:54:21 +01:00
'HK' => $mastercard_visa_amex,
'HU' => $mastercard_visa_amex,
'IE' => $mastercard_visa_amex,
'IT' => $mastercard_visa_amex,
'US' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'USD' ),
'discover' => array( 'USD' ),
),
'CA' => array(
'mastercard' => array(),
'visa' => array(),
2024-03-28 11:53:53 +01:00
'amex' => array( 'CAD', 'USD' ),
'jcb' => array( 'CAD' ),
),
'LI' => $mastercard_visa_amex,
'LT' => $mastercard_visa_amex,
'LU' => $mastercard_visa_amex,
'LV' => $mastercard_visa_amex,
'MT' => $mastercard_visa_amex,
'MX' => $mastercard_visa_amex,
'NL' => $mastercard_visa_amex,
'NO' => $mastercard_visa_amex,
'PL' => $mastercard_visa_amex,
'PT' => $mastercard_visa_amex,
'RO' => $mastercard_visa_amex,
'SE' => $mastercard_visa_amex,
'SI' => $mastercard_visa_amex,
'SK' => $mastercard_visa_amex,
2025-02-13 09:54:21 +01:00
'SG' => $mastercard_visa_amex,
2023-06-02 12:56:55 +02:00
'JP' => array(
'mastercard' => array(),
'visa' => array(),
'amex' => array( 'JPY' ),
'jcb' => array( 'JPY' ),
),
2025-06-26 10:01:33 +02:00
'YT' => $mastercard_visa_amex, // Mayotte.
'RE' => $mastercard_visa_amex, // Reunion.
'GP' => $mastercard_visa_amex, // Guadelope.
'GF' => $mastercard_visa_amex, // French Guiana.
'MQ' => $mastercard_visa_amex, // Martinique.
)
);
},
2025-08-22 17:00:32 +02:00
'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',
);
},
2025-08-22 17:00:32 +02:00
'api.paylater-countries' => static function ( ContainerInterface $container ): array {
return apply_filters(
'woocommerce_paypal_payments_supported_paylater_countries',
array(
'US',
'DE',
'GB',
'FR',
'AU',
'IT',
'ES',
)
);
},
2025-08-22 17:00:32 +02:00
'api.order-helper' => static function ( ContainerInterface $container ): OrderHelper {
return new OrderHelper();
},
2025-08-22 17:00:32 +02:00
'api.helper.order-transient' => static function ( ContainerInterface $container ): OrderTransient {
$cache = $container->get( 'api.paypal-bearer-cache' );
$purchase_unit_sanitizer = $container->get( 'api.helper.purchase-unit-sanitizer' );
return new OrderTransient( $cache, $purchase_unit_sanitizer );
},
2025-08-22 17:00:32 +02:00
'api.helper.failure-registry' => static function ( ContainerInterface $container ): FailureRegistry {
$cache = new Cache( 'ppcp-paypal-api-status-cache' );
return new FailureRegistry( $cache );
},
2023-11-23 15:05:43 +01:00
'api.helper.purchase-unit-sanitizer' => SingletonDecorator::make(
2025-08-22 17:00:32 +02:00
static function ( ContainerInterface $container ): PurchaseUnitSanitizer {
2023-08-10 10:01:28 +01:00
$settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
2023-08-10 10:01:28 +01:00
$behavior = $settings->has( 'subtotal_mismatch_behavior' ) ? $settings->get( 'subtotal_mismatch_behavior' ) : null;
$line_name = $settings->has( 'subtotal_mismatch_line_name' ) ? $settings->get( 'subtotal_mismatch_line_name' ) : null;
return new PurchaseUnitSanitizer( $behavior, $line_name );
}
),
2025-08-22 17:00:32 +02:00
'api.client-credentials' => static function ( ContainerInterface $container ): ClientCredentials {
2024-08-06 09:25:28 +02:00
return new ClientCredentials(
$container->get( 'wcgateway.settings' )
);
},
2025-08-22 17:00:32 +02:00
'api.paypal-bearer-cache' => static function ( ContainerInterface $container ): Cache {
return new Cache( 'ppcp-paypal-bearer' );
},
2025-08-22 17:00:32 +02:00
'api.client-credentials-cache' => static function ( ContainerInterface $container ): Cache {
return new Cache( 'ppcp-client-credentials-cache' );
},
2025-08-22 17:00:32 +02:00
'api.user-id-token-cache' => static function ( ContainerInterface $container ): Cache {
2024-10-04 12:58:16 +02:00
return new Cache( 'ppcp-id-token-cache' );
},
2025-08-22 17:00:32 +02:00
'api.reference-transaction-status-cache' => static function ( ContainerInterface $container ): Cache {
return new Cache( 'ppcp-reference-transaction-status-cache' );
},
2025-08-22 17:00:32 +02:00
'api.user-id-token' => static function ( ContainerInterface $container ): UserIdToken {
return new UserIdToken(
$container->get( 'api.host' ),
2024-08-06 09:25:28 +02:00
$container->get( 'woocommerce.logger.woocommerce' ),
2024-10-04 12:58:16 +02:00
$container->get( 'api.client-credentials' ),
$container->get( 'api.user-id-token-cache' )
);
},
2025-08-22 17:00:32 +02:00
'api.sdk-client-token' => static function ( ContainerInterface $container ): SdkClientToken {
2024-04-12 12:19:36 +01:00
return new SdkClientToken(
$container->get( 'api.host' ),
2024-08-06 09:25:28 +02:00
$container->get( 'woocommerce.logger.woocommerce' ),
2024-08-06 10:44:54 +02:00
$container->get( 'api.client-credentials' ),
$container->get( 'api.client-credentials-cache' )
2024-04-12 12:19:36 +01:00
);
},
2025-08-22 17:00:32 +02:00
'api.paypal-host-production' => static function ( ContainerInterface $container ): string {
return PAYPAL_API_URL;
},
2025-08-22 17:00:32 +02:00
'api.paypal-host-sandbox' => static function ( ContainerInterface $container ): string {
return PAYPAL_SANDBOX_API_URL;
},
2025-08-22 17:00:32 +02:00
'api.paypal-website-url-production' => static function ( ContainerInterface $container ): string {
return PAYPAL_URL;
},
2025-08-22 17:00:32 +02:00
'api.paypal-website-url-sandbox' => static function ( ContainerInterface $container ): string {
return PAYPAL_SANDBOX_URL;
},
2025-08-22 17:00:32 +02:00
'api.partner_merchant_id-production' => static function ( ContainerInterface $container ): string {
return CONNECT_WOO_MERCHANT_ID;
},
2025-08-22 17:00:32 +02:00
'api.partner_merchant_id-sandbox' => static function ( ContainerInterface $container ): string {
return CONNECT_WOO_SANDBOX_MERCHANT_ID;
},
2025-08-22 17:00:32 +02:00
'api.endpoint.login-seller-production' => static function ( ContainerInterface $container ): LoginSeller {
return new LoginSeller(
$container->get( 'api.paypal-host-production' ),
$container->get( 'api.partner_merchant_id-production' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02:00
'api.endpoint.login-seller-sandbox' => static function ( ContainerInterface $container ): LoginSeller {
return new LoginSeller(
$container->get( 'api.paypal-host-sandbox' ),
$container->get( 'api.partner_merchant_id-sandbox' ),
$container->get( 'woocommerce.logger.woocommerce' )
);
},
2025-08-22 17:00:32 +02:00
'api.env.paypal-host' => static function ( ContainerInterface $container ): EnvironmentConfig {
2025-01-09 12:34:22 +01:00
/**
* Environment specific API host names.
*
* @type EnvironmentConfig<string>
*/
return EnvironmentConfig::create(
'string',
$container->get( 'api.paypal-host-production' ),
$container->get( 'api.paypal-host-sandbox' )
);
},
2025-08-22 17:00:32 +02:00
'api.env.endpoint.login-seller' => static function ( ContainerInterface $container ): EnvironmentConfig {
2025-01-09 12:34:22 +01:00
/**
* Environment specific LoginSeller API instances.
*
* @type EnvironmentConfig<LoginSeller>
*/
return EnvironmentConfig::create(
LoginSeller::class,
$container->get( 'api.endpoint.login-seller-production' ),
$container->get( 'api.endpoint.login-seller-sandbox' )
);
},
2025-08-22 17:00:32 +02:00
'api.env.endpoint.partner-referrals' => static function ( ContainerInterface $container ): EnvironmentConfig {
2025-01-09 12:34:22 +01:00
/**
* Environment specific PartnerReferrals API instances.
*
* @type EnvironmentConfig<PartnerReferrals>
*/
return EnvironmentConfig::create(
PartnerReferrals::class,
$container->get( 'api.endpoint.partner-referrals-production' ),
$container->get( 'api.endpoint.partner-referrals-sandbox' )
);
},
'api.sandbox-host' => static function ( ContainerInterface $container ): string {
$is_connected = $container->get( 'settings.flag.is-connected' );
if ( $is_connected ) {
return PAYPAL_SANDBOX_API_URL;
}
return CONNECT_WOO_SANDBOX_URL;
},
'api.production-host' => static function ( ContainerInterface $container ): string {
$is_connected = $container->get( 'settings.flag.is-connected' );
if ( $is_connected ) {
return PAYPAL_API_URL;
}
return CONNECT_WOO_URL;
},
2025-08-22 17:00:32 +02:00
'api.helper.partner-attribution' => static function ( ContainerInterface $container ): PartnerAttribution {
2025-03-21 14:46:31 +04:00
return new PartnerAttribution(
'ppcp_bn_code',
array(
InstallationPathEnum::CORE_PROFILER => 'WooPPCP_Ecom_PS_CoreProfiler',
InstallationPathEnum::PAYMENT_SETTINGS => 'WooPPCP_Ecom_PS_CoreProfiler',
),
2025-03-21 14:46:31 +04:00
PPCP_PAYPAL_BN_CODE
);
2025-03-20 17:44:07 +04:00
},
2020-09-01 09:00:45 +03:00
);