mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge pull request #386 from woocommerce/pcp-367-default-3ds-contingency
Change default 3ds contingency
This commit is contained in:
commit
b65200645a
13 changed files with 487 additions and 378 deletions
|
@ -40,7 +40,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
|
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
||||||
|
@ -50,31 +49,31 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'api.host' => function( ContainerInterface $container ) : string {
|
'api.host' => function( ContainerInterface $container ) : string {
|
||||||
return PAYPAL_API_URL;
|
return PAYPAL_API_URL;
|
||||||
},
|
},
|
||||||
'api.paypal-host' => function( ContainerInterface $container ) : string {
|
'api.paypal-host' => function( ContainerInterface $container ) : string {
|
||||||
return PAYPAL_API_URL;
|
return PAYPAL_API_URL;
|
||||||
},
|
},
|
||||||
'api.partner_merchant_id' => static function () : string {
|
'api.partner_merchant_id' => static function () : string {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'api.merchant_email' => function () : string {
|
'api.merchant_email' => function () : string {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'api.merchant_id' => function () : string {
|
'api.merchant_id' => function () : string {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'api.key' => static function (): string {
|
'api.key' => static function (): string {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'api.secret' => static function (): string {
|
'api.secret' => static function (): string {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
'api.prefix' => static function (): string {
|
'api.prefix' => static function (): string {
|
||||||
return 'WC-';
|
return 'WC-';
|
||||||
},
|
},
|
||||||
'api.bearer' => static function ( ContainerInterface $container ): Bearer {
|
'api.bearer' => static function ( ContainerInterface $container ): Bearer {
|
||||||
$cache = new Cache( 'ppcp-paypal-bearer' );
|
$cache = new Cache( 'ppcp-paypal-bearer' );
|
||||||
$key = $container->get( 'api.key' );
|
$key = $container->get( 'api.key' );
|
||||||
$secret = $container->get( 'api.secret' );
|
$secret = $container->get( 'api.secret' );
|
||||||
|
@ -90,7 +89,7 @@ return array(
|
||||||
$settings
|
$settings
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.partners' => static function ( ContainerInterface $container ) : PartnersEndpoint {
|
'api.endpoint.partners' => static function ( ContainerInterface $container ) : PartnersEndpoint {
|
||||||
return new PartnersEndpoint(
|
return new PartnersEndpoint(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
$container->get( 'api.bearer' ),
|
$container->get( 'api.bearer' ),
|
||||||
|
@ -100,10 +99,10 @@ return array(
|
||||||
$container->get( 'api.merchant_id' )
|
$container->get( 'api.merchant_id' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.factory.sellerstatus' => static function ( ContainerInterface $container ) : SellerStatusFactory {
|
'api.factory.sellerstatus' => static function ( ContainerInterface $container ) : SellerStatusFactory {
|
||||||
return new SellerStatusFactory();
|
return new SellerStatusFactory();
|
||||||
},
|
},
|
||||||
'api.endpoint.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenEndpoint {
|
'api.endpoint.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenEndpoint {
|
||||||
return new PaymentTokenEndpoint(
|
return new PaymentTokenEndpoint(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
$container->get( 'api.bearer' ),
|
$container->get( 'api.bearer' ),
|
||||||
|
@ -112,7 +111,7 @@ return array(
|
||||||
$container->get( 'api.prefix' )
|
$container->get( 'api.prefix' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.webhook' => static function ( ContainerInterface $container ) : WebhookEndpoint {
|
'api.endpoint.webhook' => static function ( ContainerInterface $container ) : WebhookEndpoint {
|
||||||
|
|
||||||
return new WebhookEndpoint(
|
return new WebhookEndpoint(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
|
@ -122,7 +121,7 @@ return array(
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.partner-referrals' => static function ( ContainerInterface $container ) : PartnerReferrals {
|
'api.endpoint.partner-referrals' => static function ( ContainerInterface $container ) : PartnerReferrals {
|
||||||
|
|
||||||
return new PartnerReferrals(
|
return new PartnerReferrals(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
|
@ -131,7 +130,7 @@ return array(
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
|
'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
$prefix = $container->get( 'api.prefix' );
|
$prefix = $container->get( 'api.prefix' );
|
||||||
$settings = $container->get( 'wcgateway.settings' );
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
|
@ -143,7 +142,7 @@ return array(
|
||||||
$settings
|
$settings
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.payments' => static function ( ContainerInterface $container ): PaymentsEndpoint {
|
'api.endpoint.payments' => static function ( ContainerInterface $container ): PaymentsEndpoint {
|
||||||
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
||||||
$capture_factory = $container->get( 'api.factory.capture' );
|
$capture_factory = $container->get( 'api.factory.capture' );
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
|
@ -156,7 +155,7 @@ return array(
|
||||||
$logger
|
$logger
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSeller {
|
'api.endpoint.login-seller' => static function ( ContainerInterface $container ) : LoginSeller {
|
||||||
|
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
return new LoginSeller(
|
return new LoginSeller(
|
||||||
|
@ -165,7 +164,7 @@ return array(
|
||||||
$logger
|
$logger
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
|
'api.endpoint.order' => static function ( ContainerInterface $container ): OrderEndpoint {
|
||||||
$order_factory = $container->get( 'api.factory.order' );
|
$order_factory = $container->get( 'api.factory.order' );
|
||||||
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
|
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
|
@ -192,54 +191,54 @@ return array(
|
||||||
$subscription_helper
|
$subscription_helper
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {
|
'api.endpoint.billing-agreements' => static function ( ContainerInterface $container ): BillingAgreementsEndpoint {
|
||||||
return new BillingAgreementsEndpoint(
|
return new BillingAgreementsEndpoint(
|
||||||
$container->get( 'api.host' ),
|
$container->get( 'api.host' ),
|
||||||
$container->get( 'api.bearer' ),
|
$container->get( 'api.bearer' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' )
|
$container->get( 'woocommerce.logger.woocommerce' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.repository.paypal-request-id' => static function( ContainerInterface $container ) : PayPalRequestIdRepository {
|
'api.repository.paypal-request-id' => static function( ContainerInterface $container ) : PayPalRequestIdRepository {
|
||||||
return new PayPalRequestIdRepository();
|
return new PayPalRequestIdRepository();
|
||||||
},
|
},
|
||||||
'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository {
|
'api.repository.application-context' => static function( ContainerInterface $container ) : ApplicationContextRepository {
|
||||||
|
|
||||||
$settings = $container->get( 'wcgateway.settings' );
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
return new ApplicationContextRepository( $settings );
|
return new ApplicationContextRepository( $settings );
|
||||||
},
|
},
|
||||||
'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
|
'api.repository.partner-referrals-data' => static function ( ContainerInterface $container ) : PartnerReferralsData {
|
||||||
|
|
||||||
$merchant_email = $container->get( 'api.merchant_email' );
|
$merchant_email = $container->get( 'api.merchant_email' );
|
||||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||||
return new PartnerReferralsData( $merchant_email, $dcc_applies );
|
return new PartnerReferralsData( $merchant_email, $dcc_applies );
|
||||||
},
|
},
|
||||||
'api.repository.cart' => static function ( ContainerInterface $container ): CartRepository {
|
'api.repository.cart' => static function ( ContainerInterface $container ): CartRepository {
|
||||||
$factory = $container->get( 'api.factory.purchase-unit' );
|
$factory = $container->get( 'api.factory.purchase-unit' );
|
||||||
return new CartRepository( $factory );
|
return new CartRepository( $factory );
|
||||||
},
|
},
|
||||||
'api.repository.payee' => static function ( ContainerInterface $container ): PayeeRepository {
|
'api.repository.payee' => static function ( ContainerInterface $container ): PayeeRepository {
|
||||||
$merchant_email = $container->get( 'api.merchant_email' );
|
$merchant_email = $container->get( 'api.merchant_email' );
|
||||||
$merchant_id = $container->get( 'api.merchant_id' );
|
$merchant_id = $container->get( 'api.merchant_id' );
|
||||||
return new PayeeRepository( $merchant_email, $merchant_id );
|
return new PayeeRepository( $merchant_email, $merchant_id );
|
||||||
},
|
},
|
||||||
'api.factory.application-context' => static function ( ContainerInterface $container ) : ApplicationContextFactory {
|
'api.factory.application-context' => static function ( ContainerInterface $container ) : ApplicationContextFactory {
|
||||||
return new ApplicationContextFactory();
|
return new ApplicationContextFactory();
|
||||||
},
|
},
|
||||||
'api.factory.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenFactory {
|
'api.factory.payment-token' => static function ( ContainerInterface $container ) : PaymentTokenFactory {
|
||||||
return new PaymentTokenFactory();
|
return new PaymentTokenFactory();
|
||||||
},
|
},
|
||||||
'api.factory.webhook' => static function ( ContainerInterface $container ): WebhookFactory {
|
'api.factory.webhook' => static function ( ContainerInterface $container ): WebhookFactory {
|
||||||
return new WebhookFactory();
|
return new WebhookFactory();
|
||||||
},
|
},
|
||||||
'api.factory.webhook-event' => static function ( ContainerInterface $container ): WebhookEventFactory {
|
'api.factory.webhook-event' => static function ( ContainerInterface $container ): WebhookEventFactory {
|
||||||
return new WebhookEventFactory();
|
return new WebhookEventFactory();
|
||||||
},
|
},
|
||||||
'api.factory.capture' => static function ( ContainerInterface $container ): CaptureFactory {
|
'api.factory.capture' => static function ( ContainerInterface $container ): CaptureFactory {
|
||||||
|
|
||||||
$amount_factory = $container->get( 'api.factory.amount' );
|
$amount_factory = $container->get( 'api.factory.amount' );
|
||||||
return new CaptureFactory( $amount_factory );
|
return new CaptureFactory( $amount_factory );
|
||||||
},
|
},
|
||||||
'api.factory.purchase-unit' => static function ( ContainerInterface $container ): PurchaseUnitFactory {
|
'api.factory.purchase-unit' => static function ( ContainerInterface $container ): PurchaseUnitFactory {
|
||||||
|
|
||||||
$amount_factory = $container->get( 'api.factory.amount' );
|
$amount_factory = $container->get( 'api.factory.amount' );
|
||||||
$payee_repository = $container->get( 'api.repository.payee' );
|
$payee_repository = $container->get( 'api.repository.payee' );
|
||||||
|
@ -259,34 +258,39 @@ return array(
|
||||||
$prefix
|
$prefix
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory {
|
'api.factory.patch-collection-factory' => static function ( ContainerInterface $container ): PatchCollectionFactory {
|
||||||
return new PatchCollectionFactory();
|
return new PatchCollectionFactory();
|
||||||
},
|
},
|
||||||
'api.factory.payee' => static function ( ContainerInterface $container ): PayeeFactory {
|
'api.factory.payee' => static function ( ContainerInterface $container ): PayeeFactory {
|
||||||
return new PayeeFactory();
|
return new PayeeFactory();
|
||||||
},
|
},
|
||||||
'api.factory.item' => static function ( ContainerInterface $container ): ItemFactory {
|
'api.factory.item' => static function ( ContainerInterface $container ): ItemFactory {
|
||||||
return new ItemFactory();
|
return new ItemFactory(
|
||||||
|
$container->get( 'api.shop.currency' )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'api.factory.shipping' => static function ( ContainerInterface $container ): ShippingFactory {
|
'api.factory.shipping' => static function ( ContainerInterface $container ): ShippingFactory {
|
||||||
$address_factory = $container->get( 'api.factory.address' );
|
$address_factory = $container->get( 'api.factory.address' );
|
||||||
return new ShippingFactory( $address_factory );
|
return new ShippingFactory( $address_factory );
|
||||||
},
|
},
|
||||||
'api.factory.amount' => static function ( ContainerInterface $container ): AmountFactory {
|
'api.factory.amount' => static function ( ContainerInterface $container ): AmountFactory {
|
||||||
$item_factory = $container->get( 'api.factory.item' );
|
$item_factory = $container->get( 'api.factory.item' );
|
||||||
return new AmountFactory( $item_factory );
|
return new AmountFactory(
|
||||||
|
$item_factory,
|
||||||
|
$container->get( 'api.shop.currency' )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'api.factory.payer' => static function ( ContainerInterface $container ): PayerFactory {
|
'api.factory.payer' => static function ( ContainerInterface $container ): PayerFactory {
|
||||||
$address_factory = $container->get( 'api.factory.address' );
|
$address_factory = $container->get( 'api.factory.address' );
|
||||||
return new PayerFactory( $address_factory );
|
return new PayerFactory( $address_factory );
|
||||||
},
|
},
|
||||||
'api.factory.address' => static function ( ContainerInterface $container ): AddressFactory {
|
'api.factory.address' => static function ( ContainerInterface $container ): AddressFactory {
|
||||||
return new AddressFactory();
|
return new AddressFactory();
|
||||||
},
|
},
|
||||||
'api.factory.payment-source' => static function ( ContainerInterface $container ): PaymentSourceFactory {
|
'api.factory.payment-source' => static function ( ContainerInterface $container ): PaymentSourceFactory {
|
||||||
return new PaymentSourceFactory();
|
return new PaymentSourceFactory();
|
||||||
},
|
},
|
||||||
'api.factory.order' => static function ( ContainerInterface $container ): OrderFactory {
|
'api.factory.order' => static function ( ContainerInterface $container ): OrderFactory {
|
||||||
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
||||||
$payer_factory = $container->get( 'api.factory.payer' );
|
$payer_factory = $container->get( 'api.factory.payer' );
|
||||||
$application_context_repository = $container->get( 'api.repository.application-context' );
|
$application_context_repository = $container->get( 'api.repository.application-context' );
|
||||||
|
@ -300,18 +304,278 @@ return array(
|
||||||
$payment_source_factory
|
$payment_source_factory
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
|
'api.factory.payments' => static function ( ContainerInterface $container ): PaymentsFactory {
|
||||||
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
||||||
$capture_factory = $container->get( 'api.factory.capture' );
|
$capture_factory = $container->get( 'api.factory.capture' );
|
||||||
return new PaymentsFactory( $authorizations_factory, $capture_factory );
|
return new PaymentsFactory( $authorizations_factory, $capture_factory );
|
||||||
},
|
},
|
||||||
'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory {
|
'api.factory.authorization' => static function ( ContainerInterface $container ): AuthorizationFactory {
|
||||||
return new AuthorizationFactory();
|
return new AuthorizationFactory();
|
||||||
},
|
},
|
||||||
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
|
'api.helpers.dccapplies' => static function ( ContainerInterface $container ) : DccApplies {
|
||||||
return new 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' )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'api.helpers.currency-support' => static function ( ContainerInterface $container ) : CurrencySupport {
|
|
||||||
return new CurrencySupport();
|
'api.shop.currency' => static function ( ContainerInterface $container ) : string {
|
||||||
|
return get_woocommerce_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
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
return array(
|
||||||
|
'AU' => 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 {
|
||||||
|
return array(
|
||||||
|
'AU' => array(
|
||||||
|
'mastercard' => array(),
|
||||||
|
'visa' => array(),
|
||||||
|
),
|
||||||
|
'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',
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,13 +28,22 @@ class AmountFactory {
|
||||||
*/
|
*/
|
||||||
private $item_factory;
|
private $item_factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3-letter currency code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AmountFactory constructor.
|
* AmountFactory constructor.
|
||||||
*
|
*
|
||||||
* @param ItemFactory $item_factory The Item factory.
|
* @param ItemFactory $item_factory The Item factory.
|
||||||
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
*/
|
*/
|
||||||
public function __construct( ItemFactory $item_factory ) {
|
public function __construct( ItemFactory $item_factory, string $currency ) {
|
||||||
$this->item_factory = $item_factory;
|
$this->item_factory = $item_factory;
|
||||||
|
$this->currency = $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,8 +54,7 @@ class AmountFactory {
|
||||||
* @return Amount
|
* @return Amount
|
||||||
*/
|
*/
|
||||||
public function from_wc_cart( \WC_Cart $cart ): Amount {
|
public function from_wc_cart( \WC_Cart $cart ): Amount {
|
||||||
$currency = get_woocommerce_currency();
|
$total = new Money( (float) $cart->get_total( 'numeric' ), $this->currency );
|
||||||
$total = new Money( (float) $cart->get_total( 'numeric' ), $currency );
|
|
||||||
|
|
||||||
$total_fees_amount = 0;
|
$total_fees_amount = 0;
|
||||||
$fees = WC()->session->get( 'ppcp_fees' );
|
$fees = WC()->session->get( 'ppcp_fees' );
|
||||||
|
@ -57,22 +65,22 @@ class AmountFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
$item_total = $cart->get_cart_contents_total() + $cart->get_discount_total() + $total_fees_amount;
|
$item_total = $cart->get_cart_contents_total() + $cart->get_discount_total() + $total_fees_amount;
|
||||||
$item_total = new Money( (float) $item_total, $currency );
|
$item_total = new Money( (float) $item_total, $this->currency );
|
||||||
$shipping = new Money(
|
$shipping = new Money(
|
||||||
(float) $cart->get_shipping_total() + $cart->get_shipping_tax(),
|
(float) $cart->get_shipping_total() + $cart->get_shipping_tax(),
|
||||||
$currency
|
$this->currency
|
||||||
);
|
);
|
||||||
|
|
||||||
$taxes = new Money(
|
$taxes = new Money(
|
||||||
$cart->get_subtotal_tax(),
|
$cart->get_subtotal_tax(),
|
||||||
$currency
|
$this->currency
|
||||||
);
|
);
|
||||||
|
|
||||||
$discount = null;
|
$discount = null;
|
||||||
if ( $cart->get_discount_total() ) {
|
if ( $cart->get_discount_total() ) {
|
||||||
$discount = new Money(
|
$discount = new Money(
|
||||||
(float) $cart->get_discount_total() + $cart->get_discount_tax(),
|
(float) $cart->get_discount_total() + $cart->get_discount_tax(),
|
||||||
$currency
|
$this->currency
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,21 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
* Class ItemFactory
|
* Class ItemFactory
|
||||||
*/
|
*/
|
||||||
class ItemFactory {
|
class ItemFactory {
|
||||||
|
/**
|
||||||
|
* 3-letter currency code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ItemFactory constructor.
|
||||||
|
*
|
||||||
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
|
*/
|
||||||
|
public function __construct( string $currency ) {
|
||||||
|
$this->currency = $currency;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates items based off a WooCommerce cart.
|
* Creates items based off a WooCommerce cart.
|
||||||
|
@ -27,9 +41,8 @@ class ItemFactory {
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
*/
|
*/
|
||||||
public function from_wc_cart( \WC_Cart $cart ): array {
|
public function from_wc_cart( \WC_Cart $cart ): array {
|
||||||
$currency = get_woocommerce_currency();
|
$items = array_map(
|
||||||
$items = array_map(
|
function ( array $item ): Item {
|
||||||
static function ( array $item ) use ( $currency ): Item {
|
|
||||||
$product = $item['data'];
|
$product = $item['data'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,10 +56,10 @@ class ItemFactory {
|
||||||
$price_without_tax = (float) wc_get_price_excluding_tax( $product );
|
$price_without_tax = (float) wc_get_price_excluding_tax( $product );
|
||||||
$price_without_tax_rounded = round( $price_without_tax, 2 );
|
$price_without_tax_rounded = round( $price_without_tax, 2 );
|
||||||
$tax = round( $price - $price_without_tax_rounded, 2 );
|
$tax = round( $price - $price_without_tax_rounded, 2 );
|
||||||
$tax = new Money( $tax, $currency );
|
$tax = new Money( $tax, $this->currency );
|
||||||
return new Item(
|
return new Item(
|
||||||
mb_substr( $product->get_name(), 0, 127 ),
|
mb_substr( $product->get_name(), 0, 127 ),
|
||||||
new Money( $price_without_tax_rounded, $currency ),
|
new Money( $price_without_tax_rounded, $this->currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
mb_substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ),
|
mb_substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ),
|
||||||
$tax,
|
$tax,
|
||||||
|
@ -61,13 +74,13 @@ class ItemFactory {
|
||||||
$fees_from_session = WC()->session->get( 'ppcp_fees' );
|
$fees_from_session = WC()->session->get( 'ppcp_fees' );
|
||||||
if ( $fees_from_session ) {
|
if ( $fees_from_session ) {
|
||||||
$fees = array_map(
|
$fees = array_map(
|
||||||
static function ( \stdClass $fee ) use ( $currency ): Item {
|
function ( \stdClass $fee ): Item {
|
||||||
return new Item(
|
return new Item(
|
||||||
$fee->name,
|
$fee->name,
|
||||||
new Money( (float) $fee->amount, $currency ),
|
new Money( (float) $fee->amount, $this->currency ),
|
||||||
1,
|
1,
|
||||||
'',
|
'',
|
||||||
new Money( (float) $fee->tax, $currency )
|
new Money( (float) $fee->tax, $this->currency )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
$fees_from_session
|
$fees_from_session
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Checks if the current installation uses supported currency.
|
|
||||||
*
|
|
||||||
* @package WooCommerce\PayPalCommerce\ApiClient\Helper
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Helper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class CurrencySupport
|
|
||||||
*/
|
|
||||||
class CurrencySupport {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Currencies supported by PayPal.
|
|
||||||
*
|
|
||||||
* From https://developer.paypal.com/docs/reports/reference/paypal-supported-currencies/
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private $supported_currencies = 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',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the given currency is supported.
|
|
||||||
*
|
|
||||||
* @param string $currency 3-letter currency code.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function supports_currency( string $currency ): bool {
|
|
||||||
return in_array( $currency, $this->supported_currencies, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the current WC currency is supported.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function supports_wc_currency(): bool {
|
|
||||||
return $this->supports_currency( get_woocommerce_currency() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,169 +19,50 @@ class DccApplies {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $allowed_country_currency_matrix = array(
|
private $allowed_country_currency_matrix;
|
||||||
'AU' => 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
|
* Which countries support which credit cards. Empty credit card arrays mean no restriction on
|
||||||
* currency. Otherwise only the currencies in the array are supported.
|
* currency.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $country_card_matrix = array(
|
private $country_card_matrix;
|
||||||
'AU' => array(
|
|
||||||
'mastercard' => array(),
|
/**
|
||||||
'visa' => array(),
|
* 3-letter currency code of the shop.
|
||||||
),
|
*
|
||||||
'ES' => array(
|
* @var string
|
||||||
'mastercard' => array(),
|
*/
|
||||||
'visa' => array(),
|
private $currency;
|
||||||
'amex' => array( 'EUR' ),
|
|
||||||
),
|
/**
|
||||||
'FR' => array(
|
* 2-letter country code of the shop.
|
||||||
'mastercard' => array(),
|
*
|
||||||
'visa' => array(),
|
* @var string
|
||||||
'amex' => array( 'EUR' ),
|
*/
|
||||||
),
|
private $country;
|
||||||
'GB' => array(
|
|
||||||
'mastercard' => array(),
|
/**
|
||||||
'visa' => array(),
|
* DccApplies constructor.
|
||||||
'amex' => array( 'GBP', 'USD' ),
|
*
|
||||||
),
|
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for DCC.
|
||||||
'IT' => array(
|
* @param array $country_card_matrix Which countries support which credit cards. Empty credit card arrays mean no restriction on
|
||||||
'mastercard' => array(),
|
* currency.
|
||||||
'visa' => array(),
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
'amex' => array( 'EUR' ),
|
* @param string $country 2-letter country code of the shop.
|
||||||
),
|
*/
|
||||||
'US' => array(
|
public function __construct(
|
||||||
'mastercard' => array(),
|
array $allowed_country_currency_matrix,
|
||||||
'visa' => array(),
|
array $country_card_matrix,
|
||||||
'amex' => array( 'USD' ),
|
string $currency,
|
||||||
'discover' => array( 'USD' ),
|
string $country
|
||||||
),
|
) {
|
||||||
'CA' => array(
|
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
|
||||||
'mastercard' => array(),
|
$this->country_card_matrix = $country_card_matrix;
|
||||||
'visa' => array(),
|
$this->currency = $currency;
|
||||||
'amex' => array( 'CAD' ),
|
$this->country = $country;
|
||||||
'jcb' => array( 'CAD' ),
|
}
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether DCC can be used in the current country and the current currency used.
|
* Returns whether DCC can be used in the current country and the current currency used.
|
||||||
|
@ -189,12 +70,10 @@ class DccApplies {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function for_country_currency(): bool {
|
public function for_country_currency(): bool {
|
||||||
$country = $this->country();
|
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
||||||
$currency = get_woocommerce_currency();
|
|
||||||
if ( ! in_array( $country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$applies = in_array( $currency, $this->allowed_country_currency_matrix[ $country ], true );
|
$applies = in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
|
||||||
return $applies;
|
return $applies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,13 +83,12 @@ class DccApplies {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function valid_cards() : array {
|
public function valid_cards() : array {
|
||||||
$country = $this->country();
|
$cards = array();
|
||||||
$cards = array();
|
if ( ! isset( $this->country_card_matrix[ $this->country ] ) ) {
|
||||||
if ( ! isset( $this->country_card_matrix[ $country ] ) ) {
|
|
||||||
return $cards;
|
return $cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
$supported_currencies = $this->country_card_matrix[ $country ];
|
$supported_currencies = $this->country_card_matrix[ $this->country ];
|
||||||
foreach ( $supported_currencies as $card => $currencies ) {
|
foreach ( $supported_currencies as $card => $currencies ) {
|
||||||
if ( $this->can_process_card( $card ) ) {
|
if ( $this->can_process_card( $card ) ) {
|
||||||
$cards[] = $card;
|
$cards[] = $card;
|
||||||
|
@ -233,11 +111,10 @@ class DccApplies {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function can_process_card( string $card ) : bool {
|
public function can_process_card( string $card ) : bool {
|
||||||
$country = $this->country();
|
if ( ! isset( $this->country_card_matrix[ $this->country ] ) ) {
|
||||||
if ( ! isset( $this->country_card_matrix[ $country ] ) ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( ! isset( $this->country_card_matrix[ $country ][ $card ] ) ) {
|
if ( ! isset( $this->country_card_matrix[ $this->country ][ $card ] ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,19 +122,7 @@ class DccApplies {
|
||||||
* If the supported currencies array is empty, there are no
|
* If the supported currencies array is empty, there are no
|
||||||
* restrictions, which currencies are supported by a card.
|
* restrictions, which currencies are supported by a card.
|
||||||
*/
|
*/
|
||||||
$supported_currencies = $this->country_card_matrix[ $country ][ $card ];
|
$supported_currencies = $this->country_card_matrix[ $this->country ][ $card ];
|
||||||
$currency = get_woocommerce_currency();
|
return empty( $supported_currencies ) || in_array( $this->currency, $supported_currencies, true );
|
||||||
return empty( $supported_currencies ) || in_array( $currency, $supported_currencies, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the country code of the shop.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function country() : string {
|
|
||||||
$region = wc_get_base_location();
|
|
||||||
$country = $region['country'];
|
|
||||||
return $country;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ return array(
|
||||||
$environment = $container->get( 'onboarding.environment' );
|
$environment = $container->get( 'onboarding.environment' );
|
||||||
$payment_token_repository = $container->get( 'vaulting.repository.payment-token' );
|
$payment_token_repository = $container->get( 'vaulting.repository.payment-token' );
|
||||||
$settings_status = $container->get( 'wcgateway.settings.status' );
|
$settings_status = $container->get( 'wcgateway.settings.status' );
|
||||||
|
$currency = $container->get( 'api.shop.currency' );
|
||||||
return new SmartButton(
|
return new SmartButton(
|
||||||
$container->get( 'button.url' ),
|
$container->get( 'button.url' ),
|
||||||
$container->get( 'session.handler' ),
|
$container->get( 'session.handler' ),
|
||||||
|
@ -82,7 +83,8 @@ return array(
|
||||||
$messages_apply,
|
$messages_apply,
|
||||||
$environment,
|
$environment,
|
||||||
$payment_token_repository,
|
$payment_token_repository,
|
||||||
$settings_status
|
$settings_status,
|
||||||
|
$currency
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'button.url' => static function ( ContainerInterface $container ): string {
|
'button.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
@ -171,7 +173,9 @@ return array(
|
||||||
return new ThreeDSecure( $logger );
|
return new ThreeDSecure( $logger );
|
||||||
},
|
},
|
||||||
'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
|
'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
|
||||||
return new MessagesApply();
|
return new MessagesApply(
|
||||||
|
$container->get( 'api.shop.country' )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
||||||
|
|
|
@ -114,6 +114,13 @@ class SmartButton implements SmartButtonInterface {
|
||||||
*/
|
*/
|
||||||
private $payment_token_repository;
|
private $payment_token_repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3-letter currency code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $currency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartButton constructor.
|
* SmartButton constructor.
|
||||||
*
|
*
|
||||||
|
@ -129,6 +136,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
* @param Environment $environment The environment object.
|
* @param Environment $environment The environment object.
|
||||||
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
||||||
* @param SettingsStatus $settings_status The Settings status helper.
|
* @param SettingsStatus $settings_status The Settings status helper.
|
||||||
|
* @param string $currency 3-letter currency code of the shop.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $module_url,
|
string $module_url,
|
||||||
|
@ -142,7 +150,8 @@ class SmartButton implements SmartButtonInterface {
|
||||||
MessagesApply $messages_apply,
|
MessagesApply $messages_apply,
|
||||||
Environment $environment,
|
Environment $environment,
|
||||||
PaymentTokenRepository $payment_token_repository,
|
PaymentTokenRepository $payment_token_repository,
|
||||||
SettingsStatus $settings_status
|
SettingsStatus $settings_status,
|
||||||
|
string $currency
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$this->module_url = $module_url;
|
$this->module_url = $module_url;
|
||||||
|
@ -157,6 +166,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
$this->payment_token_repository = $payment_token_repository;
|
$this->payment_token_repository = $payment_token_repository;
|
||||||
$this->settings_status = $settings_status;
|
$this->settings_status = $settings_status;
|
||||||
|
$this->currency = $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -750,7 +760,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'client-id' => $this->client_id,
|
'client-id' => $this->client_id,
|
||||||
'currency' => get_woocommerce_currency(),
|
'currency' => $this->currency,
|
||||||
'integration-date' => PAYPAL_INTEGRATION_DATE,
|
'integration-date' => PAYPAL_INTEGRATION_DATE,
|
||||||
'components' => implode( ',', $this->components() ),
|
'components' => implode( ',', $this->components() ),
|
||||||
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
|
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
|
||||||
|
|
|
@ -28,14 +28,28 @@ class MessagesApply {
|
||||||
'AU',
|
'AU',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2-letter country code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $country;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessagesApply constructor.
|
||||||
|
*
|
||||||
|
* @param string $country 2-letter country code of the shop.
|
||||||
|
*/
|
||||||
|
public function __construct( string $country ) {
|
||||||
|
$this->country = $country;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a credit messaging is enabled for the shops location country.
|
* Determines whether a credit messaging is enabled for the shops location country.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function for_country(): bool {
|
public function for_country(): bool {
|
||||||
$region = wc_get_base_location();
|
return in_array( $this->country, $this->countries, true );
|
||||||
$country = $region['country'];
|
|
||||||
return in_array( $country, $this->countries, true );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,28 @@ class MessagesDisclaimers {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2-letter country code of the shop.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $country;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessagesDisclaimers constructor.
|
||||||
|
*
|
||||||
|
* @param string $country 2-letter country code of the shop.
|
||||||
|
*/
|
||||||
|
public function __construct( string $country ) {
|
||||||
|
$this->country = $country;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a disclaimer link based on country.
|
* Returns a disclaimer link based on country.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function link_for_country(): string {
|
public function link_for_country(): string {
|
||||||
$region = wc_get_base_location();
|
return $this->disclaimers[ $this->country ]['link'] ?? '';
|
||||||
$country = $region['country'];
|
|
||||||
|
|
||||||
return $this->disclaimers[ $country ]['link'] ?? '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,8 @@ use Dhii\Modular\Module\ModuleInterface;
|
||||||
use Interop\Container\ServiceProviderInterface;
|
use Interop\Container\ServiceProviderInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencySupport;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||||
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
|
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
|
||||||
|
@ -57,9 +55,6 @@ class StatusReportModule implements ModuleInterface {
|
||||||
/* @var Bearer $bearer The bearer. */
|
/* @var Bearer $bearer The bearer. */
|
||||||
$bearer = $c->get( 'api.bearer' );
|
$bearer = $c->get( 'api.bearer' );
|
||||||
|
|
||||||
$currency_support = $c->get( 'api.helpers.currency-support' );
|
|
||||||
assert( $currency_support instanceof CurrencySupport );
|
|
||||||
|
|
||||||
/* @var DccApplies $dcc_applies The ddc applies. */
|
/* @var DccApplies $dcc_applies The ddc applies. */
|
||||||
$dcc_applies = $c->get( 'api.helpers.dccapplies' );
|
$dcc_applies = $c->get( 'api.helpers.dccapplies' );
|
||||||
|
|
||||||
|
@ -90,14 +85,14 @@ class StatusReportModule implements ModuleInterface {
|
||||||
'label' => esc_html__( 'Shop country code', 'woocommerce-paypal-payments' ),
|
'label' => esc_html__( 'Shop country code', 'woocommerce-paypal-payments' ),
|
||||||
'exported_label' => 'Shop country code',
|
'exported_label' => 'Shop country code',
|
||||||
'description' => esc_html__( 'Country / State value on Settings / General / Store Address.', 'woocommerce-paypal-payments' ),
|
'description' => esc_html__( 'Country / State value on Settings / General / Store Address.', 'woocommerce-paypal-payments' ),
|
||||||
'value' => wc_get_base_location()['country'],
|
'value' => $c->get( 'api.shop.country' ),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'label' => esc_html__( 'WooCommerce currency supported', 'woocommerce-paypal-payments' ),
|
'label' => esc_html__( 'WooCommerce currency supported', 'woocommerce-paypal-payments' ),
|
||||||
'exported_label' => 'WooCommerce currency supported',
|
'exported_label' => 'WooCommerce currency supported',
|
||||||
'description' => esc_html__( 'Whether PayPal supports the default store currency or not.', 'woocommerce-paypal-payments' ),
|
'description' => esc_html__( 'Whether PayPal supports the default store currency or not.', 'woocommerce-paypal-payments' ),
|
||||||
'value' => $this->bool_to_html(
|
'value' => $this->bool_to_html(
|
||||||
$currency_support->supports_wc_currency()
|
$c->get( 'api.shop.is-currency-supported' )
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -1907,7 +1907,7 @@ return array(
|
||||||
),
|
),
|
||||||
'class' => array(),
|
'class' => array(),
|
||||||
'input_class' => array( 'wc-enhanced-select' ),
|
'input_class' => array( 'wc-enhanced-select' ),
|
||||||
'default' => 'SCA_WHEN_REQUIRED',
|
'default' => $container->get( 'api.shop.is-psd2-country' ) ? '3D_SECURE' : 'NO_3D_SECURE',
|
||||||
'desc_tip' => true,
|
'desc_tip' => true,
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ),
|
'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ),
|
||||||
|
@ -2026,6 +2026,8 @@ return array(
|
||||||
},
|
},
|
||||||
|
|
||||||
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
|
'button.helper.messages-disclaimers' => static function ( ContainerInterface $container ): MessagesDisclaimers {
|
||||||
return new MessagesDisclaimers();
|
return new MessagesDisclaimers(
|
||||||
|
$container->get( 'api.shop.country' )
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,13 +13,13 @@ use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
class AmountFactoryTest extends TestCase
|
class AmountFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private $currency = 'EUR';
|
||||||
|
|
||||||
public function testFromWcCartDefault()
|
public function testFromWcCartDefault()
|
||||||
{
|
{
|
||||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||||
$testee = new AmountFactory($itemFactory);
|
$testee = new AmountFactory($itemFactory, $this->currency);
|
||||||
|
|
||||||
$expectedCurrency = 'EUR';
|
|
||||||
$cart = Mockery::mock(\WC_Cart::class);
|
$cart = Mockery::mock(\WC_Cart::class);
|
||||||
$cart
|
$cart
|
||||||
->shouldReceive('get_total')
|
->shouldReceive('get_total')
|
||||||
|
@ -47,8 +47,6 @@ class AmountFactoryTest extends TestCase
|
||||||
->shouldReceive('get_subtotal_tax')
|
->shouldReceive('get_subtotal_tax')
|
||||||
->andReturn(8);
|
->andReturn(8);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
|
||||||
|
|
||||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
$session = Mockery::mock(\WC_Session::class);
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
when('WC')->justReturn($woocommerce);
|
when('WC')->justReturn($woocommerce);
|
||||||
|
@ -56,22 +54,22 @@ class AmountFactoryTest extends TestCase
|
||||||
$session->shouldReceive('get')->andReturn([]);
|
$session->shouldReceive('get')->andReturn([]);
|
||||||
|
|
||||||
$result = $testee->from_wc_cart($cart);
|
$result = $testee->from_wc_cart($cart);
|
||||||
$this->assertEquals($expectedCurrency, $result->currency_code());
|
$this->assertEquals($this->currency, $result->currency_code());
|
||||||
$this->assertEquals((float) 1, $result->value());
|
$this->assertEquals((float) 1, $result->value());
|
||||||
$this->assertEquals((float) 10, $result->breakdown()->discount()->value());
|
$this->assertEquals((float) 10, $result->breakdown()->discount()->value());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->discount()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->discount()->currency_code());
|
||||||
$this->assertEquals((float) 9, $result->breakdown()->shipping()->value());
|
$this->assertEquals((float) 9, $result->breakdown()->shipping()->value());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->shipping()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->shipping()->currency_code());
|
||||||
$this->assertEquals((float) 5, $result->breakdown()->item_total()->value());
|
$this->assertEquals((float) 5, $result->breakdown()->item_total()->value());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->item_total()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->item_total()->currency_code());
|
||||||
$this->assertEquals((float) 8, $result->breakdown()->tax_total()->value());
|
$this->assertEquals((float) 8, $result->breakdown()->tax_total()->value());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->tax_total()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->tax_total()->currency_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFromWcCartNoDiscount()
|
public function testFromWcCartNoDiscount()
|
||||||
{
|
{
|
||||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||||
$testee = new AmountFactory($itemFactory);
|
$testee = new AmountFactory($itemFactory, $this->currency);
|
||||||
|
|
||||||
$expectedCurrency = 'EUR';
|
$expectedCurrency = 'EUR';
|
||||||
$expectedTotal = 1;
|
$expectedTotal = 1;
|
||||||
|
@ -102,8 +100,6 @@ class AmountFactoryTest extends TestCase
|
||||||
->shouldReceive('get_subtotal_tax')
|
->shouldReceive('get_subtotal_tax')
|
||||||
->andReturn(11);
|
->andReturn(11);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')->andReturn($expectedCurrency);
|
|
||||||
|
|
||||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
$session = Mockery::mock(\WC_Session::class);
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
when('WC')->justReturn($woocommerce);
|
when('WC')->justReturn($woocommerce);
|
||||||
|
@ -139,15 +135,14 @@ class AmountFactoryTest extends TestCase
|
||||||
->expects('from_wc_order')
|
->expects('from_wc_order')
|
||||||
->with($order)
|
->with($order)
|
||||||
->andReturn([$item]);
|
->andReturn([$item]);
|
||||||
$testee = new AmountFactory($itemFactory);
|
$testee = new AmountFactory($itemFactory, $this->currency);
|
||||||
|
|
||||||
$expectedCurrency = 'EUR';
|
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_total')
|
->shouldReceive('get_total')
|
||||||
->andReturn(100);
|
->andReturn(100);
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_currency')
|
->shouldReceive('get_currency')
|
||||||
->andReturn($expectedCurrency);
|
->andReturn($this->currency);
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_shipping_total')
|
->shouldReceive('get_shipping_total')
|
||||||
->andReturn(1);
|
->andReturn(1);
|
||||||
|
@ -165,11 +160,11 @@ class AmountFactoryTest extends TestCase
|
||||||
$this->assertEquals((float) 1.5, $result->breakdown()->shipping()->value());
|
$this->assertEquals((float) 1.5, $result->breakdown()->shipping()->value());
|
||||||
$this->assertEquals((float) 100, $result->value());
|
$this->assertEquals((float) 100, $result->value());
|
||||||
$this->assertEquals((float) 2, $result->breakdown()->tax_total()->value());
|
$this->assertEquals((float) 2, $result->breakdown()->tax_total()->value());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->discount()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->discount()->currency_code());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->item_total()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->item_total()->currency_code());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->shipping()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->shipping()->currency_code());
|
||||||
$this->assertEquals($expectedCurrency, $result->breakdown()->tax_total()->currency_code());
|
$this->assertEquals($this->currency, $result->breakdown()->tax_total()->currency_code());
|
||||||
$this->assertEquals($expectedCurrency, $result->currency_code());
|
$this->assertEquals($this->currency, $result->currency_code());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFromWcOrderDiscountIsNull()
|
public function testFromWcOrderDiscountIsNull()
|
||||||
|
@ -198,15 +193,14 @@ class AmountFactoryTest extends TestCase
|
||||||
->expects('from_wc_order')
|
->expects('from_wc_order')
|
||||||
->with($order)
|
->with($order)
|
||||||
->andReturn([$item]);
|
->andReturn([$item]);
|
||||||
$testee = new AmountFactory($itemFactory);
|
$testee = new AmountFactory($itemFactory, $this->currency);
|
||||||
|
|
||||||
$expectedCurrency = 'EUR';
|
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_total')
|
->shouldReceive('get_total')
|
||||||
->andReturn(100);
|
->andReturn(100);
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_currency')
|
->shouldReceive('get_currency')
|
||||||
->andReturn($expectedCurrency);
|
->andReturn($this->currency);
|
||||||
$order
|
$order
|
||||||
->shouldReceive('get_shipping_total')
|
->shouldReceive('get_shipping_total')
|
||||||
->andReturn(1);
|
->andReturn(1);
|
||||||
|
@ -229,7 +223,7 @@ class AmountFactoryTest extends TestCase
|
||||||
public function testFromPayPalResponse($response, $expectsException)
|
public function testFromPayPalResponse($response, $expectsException)
|
||||||
{
|
{
|
||||||
$itemFactory = Mockery::mock(ItemFactory::class);
|
$itemFactory = Mockery::mock(ItemFactory::class);
|
||||||
$testee = new AmountFactory($itemFactory);
|
$testee = new AmountFactory($itemFactory, $this->currency);
|
||||||
if ($expectsException) {
|
if ($expectsException) {
|
||||||
$this->expectException(RuntimeException::class);
|
$this->expectException(RuntimeException::class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,11 @@ use Mockery;
|
||||||
|
|
||||||
class ItemFactoryTest extends TestCase
|
class ItemFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private $currency = 'EUR';
|
||||||
|
|
||||||
public function testFromCartDefault()
|
public function testFromCartDefault()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$product = Mockery::mock(\WC_Product_Simple::class);
|
$product = Mockery::mock(\WC_Product_Simple::class);
|
||||||
$product
|
$product
|
||||||
|
@ -41,8 +42,6 @@ class ItemFactoryTest extends TestCase
|
||||||
->expects('get_cart_contents')
|
->expects('get_cart_contents')
|
||||||
->andReturn($items);
|
->andReturn($items);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')
|
|
||||||
->andReturn('EUR');
|
|
||||||
expect('wc_get_price_including_tax')
|
expect('wc_get_price_including_tax')
|
||||||
->with($product)
|
->with($product)
|
||||||
->andReturn(2.995);
|
->andReturn(2.995);
|
||||||
|
@ -78,7 +77,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromCartDigitalGood()
|
public function testFromCartDigitalGood()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$product = Mockery::mock(\WC_Product_Simple::class);
|
$product = Mockery::mock(\WC_Product_Simple::class);
|
||||||
$product
|
$product
|
||||||
|
@ -104,8 +103,6 @@ class ItemFactoryTest extends TestCase
|
||||||
->expects('get_cart_contents')
|
->expects('get_cart_contents')
|
||||||
->andReturn($items);
|
->andReturn($items);
|
||||||
|
|
||||||
expect('get_woocommerce_currency')
|
|
||||||
->andReturn('EUR');
|
|
||||||
expect('wc_get_price_including_tax')
|
expect('wc_get_price_including_tax')
|
||||||
->with($product)
|
->with($product)
|
||||||
->andReturn(2.995);
|
->andReturn(2.995);
|
||||||
|
@ -130,7 +127,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromWcOrderDefault()
|
public function testFromWcOrderDefault()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$product = Mockery::mock(\WC_Product::class);
|
$product = Mockery::mock(\WC_Product::class);
|
||||||
$product
|
$product
|
||||||
|
@ -160,7 +157,7 @@ class ItemFactoryTest extends TestCase
|
||||||
$order = Mockery::mock(\WC_Order::class);
|
$order = Mockery::mock(\WC_Order::class);
|
||||||
$order
|
$order
|
||||||
->expects('get_currency')
|
->expects('get_currency')
|
||||||
->andReturn('EUR');
|
->andReturn($this->currency);
|
||||||
$order
|
$order
|
||||||
->expects('get_items')
|
->expects('get_items')
|
||||||
->andReturn([$item]);
|
->andReturn([$item]);
|
||||||
|
@ -193,7 +190,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromWcOrderDigitalGood()
|
public function testFromWcOrderDigitalGood()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$product = Mockery::mock(\WC_Product::class);
|
$product = Mockery::mock(\WC_Product::class);
|
||||||
$product
|
$product
|
||||||
|
@ -223,7 +220,7 @@ class ItemFactoryTest extends TestCase
|
||||||
$order = Mockery::mock(\WC_Order::class);
|
$order = Mockery::mock(\WC_Order::class);
|
||||||
$order
|
$order
|
||||||
->expects('get_currency')
|
->expects('get_currency')
|
||||||
->andReturn('EUR');
|
->andReturn($this->currency);
|
||||||
$order
|
$order
|
||||||
->expects('get_items')
|
->expects('get_items')
|
||||||
->andReturn([$item]);
|
->andReturn([$item]);
|
||||||
|
@ -251,7 +248,7 @@ class ItemFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
$name = 'öawjetöagrjjaglörjötairgjaflkögjöalfdgjöalfdjblköajtlkfjdbljslkgjfklösdgjalkerjtlrajglkfdajblköajflköbjsdgjadfgjaöfgjaölkgjkladjgfköajgjaflgöjafdlgjafdögjdsflkgjö4jwegjfsdbvxj öskögjtaeröjtrgt';
|
$name = 'öawjetöagrjjaglörjötairgjaflkögjöalfdgjöalfdjblköajtlkfjdbljslkgjfklösdgjalkerjtlrajglkfdajblköajflköbjsdgjadfgjaöfgjaölkgjkladjgfköajgjaflgöjafdlgjafdögjdsflkgjö4jwegjfsdbvxj öskögjtaeröjtrgt';
|
||||||
$description = 'öawjetöagrjjaglörjötairgjaflkögjöalfdgjöalfdjblköajtlkfjdbljslkgjfklösdgjalkerjtlrajglkfdajblköajflköbjsdgjadfgjaöfgjaölkgjkladjgfköajgjaflgöjafdlgjafdögjdsflkgjö4jwegjfsdbvxj öskögjtaeröjtrgt';
|
$description = 'öawjetöagrjjaglörjötairgjaflkögjöalfdgjöalfdjblköajtlkfjdbljslkgjfklösdgjalkerjtlrajglkfdajblköajflköbjsdgjadfgjaöfgjaölkgjkladjgfköajgjaflgöjafdlgjafdögjdsflkgjö4jwegjfsdbvxj öskögjtaeröjtrgt';
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$product = Mockery::mock(\WC_Product::class);
|
$product = Mockery::mock(\WC_Product::class);
|
||||||
$product
|
$product
|
||||||
|
@ -308,7 +305,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponse()
|
public function testFromPayPalResponse()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
@ -335,7 +332,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseDigitalGood()
|
public function testFromPayPalResponseDigitalGood()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
@ -343,7 +340,7 @@ class ItemFactoryTest extends TestCase
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
'unit_amount' => (object) [
|
'unit_amount' => (object) [
|
||||||
'value' => 1,
|
'value' => 1,
|
||||||
'currency_code' => 'EUR',
|
'currency_code' => $this->currency,
|
||||||
],
|
],
|
||||||
'category' => Item::DIGITAL_GOODS,
|
'category' => Item::DIGITAL_GOODS,
|
||||||
];
|
];
|
||||||
|
@ -356,7 +353,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseHasTax()
|
public function testFromPayPalResponseHasTax()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
@ -377,7 +374,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseThrowsWithoutName()
|
public function testFromPayPalResponseThrowsWithoutName()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'description' => 'description',
|
'description' => 'description',
|
||||||
|
@ -397,7 +394,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseThrowsWithoutQuantity()
|
public function testFromPayPalResponseThrowsWithoutQuantity()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
@ -417,7 +414,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseThrowsWithStringInQuantity()
|
public function testFromPayPalResponseThrowsWithStringInQuantity()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
@ -438,7 +435,7 @@ class ItemFactoryTest extends TestCase
|
||||||
|
|
||||||
public function testFromPayPalResponseThrowsWithWrongUnitAmount()
|
public function testFromPayPalResponseThrowsWithWrongUnitAmount()
|
||||||
{
|
{
|
||||||
$testee = new ItemFactory();
|
$testee = new ItemFactory($this->currency);
|
||||||
|
|
||||||
$response = (object) [
|
$response = (object) [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue