Initial commit.

This commit is contained in:
2025-11-24 21:33:55 +00:00
parent 14b7ade051
commit d6e9d316bc
8974 changed files with 1423277 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
/**
* Payment Method Capability Constants
*
* @package WCPay\PaymentMethods\Configs\Constants
*/
namespace WCPay\PaymentMethods\Configs\Constants;
/**
* Class defining payment method capability constants.
*/
class PaymentMethodCapability {
/**
* Payment method can be saved and reused
*
* @var string
*/
public const TOKENIZATION = 'tokenization';
/**
* Payment method supports refunds
*
* @var string
*/
public const REFUNDS = 'refunds';
/**
* Payment method supports capturing payment later
*
* @var string
*/
public const CAPTURE_LATER = 'capture_later';
/**
* Payment method supports multiple currencies
*
* @var string
*/
public const MULTI_CURRENCY = 'multi_currency';
/**
* Payment method is a Buy Now Pay Later method
*
* @var string
*/
public const BUY_NOW_PAY_LATER = 'buy_now_pay_later';
/**
* Payment method only accepts domestic transactions
*
* @var string
*/
public const DOMESTIC_TRANSACTIONS_ONLY = 'domestic_transactions_only';
}

View File

@@ -0,0 +1,322 @@
<?php
/**
* Alipay Payment Method Definition
*
* @package WCPay\PaymentMethods\Configs\Definitions
*/
namespace WCPay\PaymentMethods\Configs\Definitions;
use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
use WCPay\PaymentMethods\Configs\Utils\PaymentMethodUtils;
/**
* Class implementing the Alipay payment method definition.
*/
class AlipayDefinition implements PaymentMethodDefinitionInterface {
/**
* Get the internal ID for the payment method
*
* @return string
*/
public static function get_id(): string {
return 'alipay';
}
/**
* Get the keywords for the payment method. These are used by the duplicates detection service.
*
* @return string[]
*/
public static function get_keywords(): array {
return [ 'alipay' ];
}
/**
* Get the Stripe payment method ID
*
* @return string
*/
public static function get_stripe_id(): string {
return PaymentMethodUtils::get_stripe_id( self::get_id() );
}
/**
* Get the customer-facing title of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_title( ?string $account_country = null ): string {
return __( 'Alipay', 'woocommerce-payments' );
}
/**
* Get the title of the payment method for the settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_label( ?string $account_country = null ): string {
return self::get_title( $account_country );
}
/**
* Get the customer-facing description of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_description( ?string $account_country = null ): string {
return __( 'Alipay is a popular wallet in China, operated by Ant Financial Services Group, a financial services provider affiliated with Alibaba.', 'woocommerce-payments' );
}
/**
* Is the payment method a BNPL (Buy Now Pay Later) payment method?
*
* @return boolean
*/
public static function is_bnpl(): bool {
return PaymentMethodUtils::is_bnpl( self::get_capabilities() );
}
/**
* Is the payment method a reusable payment method?
*
* @return boolean
*/
public static function is_reusable(): bool {
return PaymentMethodUtils::is_reusable( self::get_capabilities() );
}
/**
* Does the payment method accept only domestic payments?
*
* @return boolean
*/
public static function accepts_only_domestic_payments(): bool {
return PaymentMethodUtils::accepts_only_domestic_payments( self::get_capabilities() );
}
/**
* Does the payment method allow manual capture?
*
* @return boolean
*/
public static function allows_manual_capture(): bool {
return PaymentMethodUtils::allows_manual_capture( self::get_capabilities() );
}
/**
* Get the list of supported currencies
*
* @return string[] Array of currency codes
*/
public static function get_supported_currencies(): array {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
if ( Country_Code::AUSTRALIA === $account_country ) {
return [ Currency_Code::AUSTRALIAN_DOLLAR ];
}
if ( Country_Code::CANADA === $account_country ) {
return [ Currency_Code::CANADIAN_DOLLAR ];
}
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return [ Currency_Code::POUND_STERLING ];
}
if ( Country_Code::HONG_KONG === $account_country ) {
return [ Currency_Code::HONG_KONG_DOLLAR ];
}
if ( Country_Code::JAPAN === $account_country ) {
return [ Currency_Code::JAPANESE_YEN ];
}
if ( Country_Code::NEW_ZEALAND === $account_country ) {
return [ Currency_Code::NEW_ZEALAND_DOLLAR ];
}
if ( Country_Code::SINGAPORE === $account_country ) {
return [ Currency_Code::SINGAPORE_DOLLAR ];
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return [ Currency_Code::UNITED_STATES_DOLLAR ];
}
if ( Country_Code::HUNGARY === $account_country ) {
return [ Currency_Code::HUNGARIAN_FORINT ];
}
if ( in_array(
$account_country,
[
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::BULGARIA,
Country_Code::CYPRUS,
Country_Code::CZECHIA,
Country_Code::DENMARK,
Country_Code::ESTONIA,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::GREECE,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LATVIA,
Country_Code::LITHUANIA,
Country_Code::LUXEMBOURG,
Country_Code::MALTA,
Country_Code::NETHERLANDS,
Country_Code::NORWAY,
Country_Code::PORTUGAL,
Country_Code::ROMANIA,
Country_Code::SLOVAKIA,
Country_Code::SLOVENIA,
Country_Code::SPAIN,
Country_Code::SWEDEN,
Country_Code::SWITZERLAND,
Country_Code::CROATIA,
],
true
) ) {
return [ Currency_Code::EURO ];
}
// fallback currency code, just in case.
return [ Currency_Code::CHINESE_YUAN ];
}
/**
* Get the list of supported countries
*
* @return string[] Array of country codes
*/
public static function get_supported_countries(): array {
return [];
}
/**
* Get the payment method capabilities
*
* @return string[]
*/
public static function get_capabilities(): array {
return [
PaymentMethodCapability::REFUNDS,
PaymentMethodCapability::MULTI_CURRENCY,
];
}
/**
* Get the URL for the payment method's icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/alipay-logo.svg', WCPAY_PLUGIN_FILE );
}
/**
* Get the URL for the payment method's dark mode icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string Returns regular icon URL if no dark mode icon exists
*/
public static function get_dark_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the URL for the payment method's settings icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the testing instructions for the payment method
*
* @param string $account_country The merchant's account country.
* @return string HTML string containing testing instructions
*/
public static function get_testing_instructions( string $account_country ): string {
return '';
}
/**
* Get the currency limits for the payment method
*
* @return array<string,array<string,array{min:int,max:int}>>
*/
public static function get_limits_per_currency(): array {
return [];
}
/**
* Whether this payment method is available for the given currency and country
*
* @param string $currency The currency code to check.
* @param string $account_country The merchant's account country.
*
* @return bool
*/
public static function is_available_for( string $currency, string $account_country ): bool {
if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ) ) {
return false;
}
return true;
}
/**
* Whether this payment method should be enabled by default
*
* @return bool
*/
public static function is_enabled_by_default(): bool {
return false;
}
/**
* Get the minimum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The minimum amount or null if no minimum.
*/
public static function get_minimum_amount( string $currency, string $country ): ?int {
return null;
}
/**
* Get the maximum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The maximum amount or null if no maximum.
*/
public static function get_maximum_amount( string $currency, string $country ): ?int {
return null;
}
}

View File

@@ -0,0 +1,337 @@
<?php
/**
* WeChat Pay Payment Method Definition
*
* @package WCPay\PaymentMethods\Configs\Definitions
*/
namespace WCPay\PaymentMethods\Configs\Definitions;
use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
use WCPay\PaymentMethods\Configs\Utils\PaymentMethodUtils;
/**
* Class implementing the WeChat Pay payment method definition.
*/
class WechatPayDefinition implements PaymentMethodDefinitionInterface {
/**
* Get the internal ID for the payment method
*
* @return string
*/
public static function get_id(): string {
return 'wechat_pay';
}
/**
* Get the keywords for the payment method. These are used by the duplicates detection service.
*
* @return string[]
*/
public static function get_keywords(): array {
return [ 'wechat_pay', 'wechatpay' ];
}
/**
* Get the Stripe payment method ID
*
* @return string
*/
public static function get_stripe_id(): string {
return PaymentMethodUtils::get_stripe_id( self::get_id() );
}
/**
* Get the customer-facing title of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_title( ?string $account_country = null ): string {
return __( 'WeChat Pay', 'woocommerce-payments' );
}
/**
* Get the title of the payment method for the settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_label( ?string $account_country = null ): string {
return self::get_title( $account_country );
}
/**
* Get the customer-facing description of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_description( ?string $account_country = null ): string {
return __( 'A digital wallet popular with customers from China.', 'woocommerce-payments' );
}
/**
* Is the payment method a BNPL (Buy Now Pay Later) payment method?
*
* @return boolean
*/
public static function is_bnpl(): bool {
return PaymentMethodUtils::is_bnpl( self::get_capabilities() );
}
/**
* Is the payment method a reusable payment method?
*
* @return boolean
*/
public static function is_reusable(): bool {
return PaymentMethodUtils::is_reusable( self::get_capabilities() );
}
/**
* Does the payment method accept only domestic payments?
*
* @return boolean
*/
public static function accepts_only_domestic_payments(): bool {
return PaymentMethodUtils::accepts_only_domestic_payments( self::get_capabilities() );
}
/**
* Does the payment method allow manual capture?
*
* @return boolean
*/
public static function allows_manual_capture(): bool {
return PaymentMethodUtils::allows_manual_capture( self::get_capabilities() );
}
/**
* Get the list of supported currencies
*
* @return string[] Array of currency codes
*/
public static function get_supported_currencies(): array {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
// For all European countries in the supported list, return EUR.
if ( in_array(
$account_country,
[
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LUXEMBOURG,
Country_Code::NETHERLANDS,
Country_Code::PORTUGAL,
Country_Code::SPAIN,
],
true
) ) {
return [ Currency_Code::EURO ];
}
if ( Country_Code::AUSTRALIA === $account_country ) {
return [ Currency_Code::AUSTRALIAN_DOLLAR ];
}
if ( Country_Code::CANADA === $account_country ) {
return [ Currency_Code::CANADIAN_DOLLAR ];
}
if ( Country_Code::DENMARK === $account_country ) {
return [ Currency_Code::DANISH_KRONE ];
}
if ( Country_Code::HONG_KONG === $account_country ) {
return [ Currency_Code::HONG_KONG_DOLLAR ];
}
if ( Country_Code::JAPAN === $account_country ) {
return [ Currency_Code::JAPANESE_YEN ];
}
if ( Country_Code::NORWAY === $account_country ) {
return [ Currency_Code::NORWEGIAN_KRONE ];
}
if ( Country_Code::SINGAPORE === $account_country ) {
return [ Currency_Code::SINGAPORE_DOLLAR ];
}
if ( Country_Code::SWEDEN === $account_country ) {
return [ Currency_Code::SWEDISH_KRONA ];
}
if ( Country_Code::SWITZERLAND === $account_country ) {
return [ Currency_Code::SWISS_FRANC ];
}
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return [ Currency_Code::POUND_STERLING ];
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return [ Currency_Code::UNITED_STATES_DOLLAR ];
}
return [ 'NONE_SUPPORTED' ];
}
/**
* Get the list of supported countries
*
* @return string[] Array of country codes
*/
public static function get_supported_countries(): array {
return [
Country_Code::UNITED_STATES,
Country_Code::AUSTRALIA,
Country_Code::CANADA,
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::DENMARK,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LUXEMBOURG,
Country_Code::NETHERLANDS,
Country_Code::NORWAY,
Country_Code::PORTUGAL,
Country_Code::SPAIN,
Country_Code::SWEDEN,
Country_Code::SWITZERLAND,
Country_Code::UNITED_KINGDOM,
Country_Code::HONG_KONG,
Country_Code::JAPAN,
Country_Code::SINGAPORE,
];
}
/**
* Get the payment method capabilities
*
* @return string[]
*/
public static function get_capabilities(): array {
return [
PaymentMethodCapability::REFUNDS,
PaymentMethodCapability::MULTI_CURRENCY,
];
}
/**
* Get the URL for the payment method's icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/wechat-pay.svg', WCPAY_PLUGIN_FILE );
}
/**
* Get the URL for the payment method's dark mode icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string Returns regular icon URL if no dark mode icon exists
*/
public static function get_dark_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the URL for the payment method's settings icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the testing instructions for the payment method
*
* @param string $account_country The merchant's account country.
* @return string HTML string containing testing instructions
*/
public static function get_testing_instructions( string $account_country ): string {
return '';
}
/**
* Get the currency limits for the payment method
*
* @return array<string,array<string,array{min:int,max:int}>>
*/
public static function get_limits_per_currency(): array {
return [];
}
/**
* Whether this payment method is available for the given currency and country
*
* @param string $currency The currency code to check.
* @param string $account_country The merchant's account country.
*
* @return bool
*/
public static function is_available_for( string $currency, string $account_country ): bool {
if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ) ) {
return false;
}
return true;
}
/**
* Whether this payment method should be enabled by default
*
* @return bool
*/
public static function is_enabled_by_default(): bool {
return false;
}
/**
* Get the minimum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The minimum amount or null if no minimum.
*/
public static function get_minimum_amount( string $currency, string $country ): ?int {
return null;
}
/**
* Get the maximum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The maximum amount or null if no maximum.
*/
public static function get_maximum_amount( string $currency, string $country ): ?int {
return null;
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* Payment Method Definition Interface
*
* @package WCPay\PaymentMethods\Configs\Interfaces
*/
namespace WCPay\PaymentMethods\Configs\Interfaces;
/**
* Interface for defining payment method configurations.
* Provides a single source of truth for both backend and frontend payment method properties.
*/
interface PaymentMethodDefinitionInterface {
/**
* Get the internal ID for the payment method (e.g. 'card', 'klarna')
*
* @return string
*/
public static function get_id(): string;
/**
* Get the keywords for the payment method. These are used by the duplicates detection service.
*
* @return string[]
*/
public static function get_keywords(): array;
/**
* Get the Stripe payment method ID (e.g. 'card_payments', 'klarna_payments')
*
* @return string
*/
public static function get_stripe_id(): string;
/**
* Get the customer-facing title of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_title( ?string $account_country = null ): string;
/**
* Get the title of the payment method for the settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_settings_label( ?string $account_country = null ): string;
/**
* Get the customer-facing description of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_description( ?string $account_country = null ): string;
/**
* Is the payment method a BNPL (Buy Now Pay Later) payment method?
*
* @return boolean
*/
public static function is_bnpl(): bool;
/**
* Is the payment method a reusable payment method?
*
* @return boolean
*/
public static function is_reusable(): bool;
/**
* Does the payment method accept only domestic payments?
*
* @return boolean
*/
public static function accepts_only_domestic_payments(): bool;
/**
* Does the payment method allow manual capture?
*
* @return boolean
*/
public static function allows_manual_capture(): bool;
/**
* Get the list of supported currencies
* Empty array means all currencies are supported
*
* @return string[] Array of currency codes
*/
public static function get_supported_currencies(): array;
/**
* Get the list of supported countries
* Empty array means all countries are supported
*
* @return string[] Array of country codes
*/
public static function get_supported_countries(): array;
/**
* Get the payment method capabilities
* Examples: tokenization, refunds, capture_later
*
* @return string[]
*/
public static function get_capabilities(): array;
/**
* Get the URL for the payment method's icon
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_icon_url( ?string $account_country = null ): string;
/**
* Get the URL for the payment method's dark mode icon
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string Returns regular icon URL if no dark mode icon exists
*/
public static function get_dark_icon_url( ?string $account_country = null ): string;
/**
* Get the URL for the payment method's settings icon
* This icon is used in the payment method settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_settings_icon_url( ?string $account_country = null ): string;
/**
* Get the testing instructions for the payment method
*
* @param string $account_country The merchant's account country.
* @return string HTML string containing testing instructions
*/
public static function get_testing_instructions( string $account_country ): string;
/**
* Whether this payment method is available for the given currency and country
*
* @param string $currency The currency code to check.
* @param string $account_country The merchant's account country.
* @return bool
*/
public static function is_available_for( string $currency, string $account_country ): bool;
/**
* Whether this payment method is enabled by default
*
* @return bool
*/
public static function is_enabled_by_default(): bool;
/**
* Get the currency limits for the payment method
*
* @return array<string,array<string,array{min:int,max:int}>>
*/
public static function get_limits_per_currency(): array;
/**
* Get minimum amount for a currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
* @return int|null Returns null if no limit is set
*/
public static function get_minimum_amount( string $currency, string $country ): ?int;
/**
* Get maximum amount for a currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
* @return int|null Returns null if no limit is set
*/
public static function get_maximum_amount( string $currency, string $country ): ?int;
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* Payment method definition registry.
*
* @package WCPay\PaymentMethods\Configs\Registry
*/
namespace WCPay\PaymentMethods\Configs\Registry;
use WCPay\PaymentMethods\Configs\Definitions\AlipayDefinition;
use WCPay\PaymentMethods\Configs\Definitions\WechatPayDefinition;
use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
/**
* Registry for payment method definitions.
*/
class PaymentMethodDefinitionRegistry {
/**
* Singleton instance.
*
* @var PaymentMethodDefinitionRegistry|null
*/
private static $instance = null;
/**
* List of all available payment method definitions.
*
* @var array<class-string<PaymentMethodDefinitionInterface>>
*/
private $available_definitions = [
// Add new payment method definitions here.
AlipayDefinition::class,
WechatPayDefinition::class,
];
/**
* Payment method definitions that have been registered for use.
*
* @var array<string,class-string<PaymentMethodDefinitionInterface>>
*/
private $payment_methods = [];
/**
* Constructor is private to enforce singleton pattern.
*/
private function __construct() {}
/**
* Get the singleton instance.
*
* @return PaymentMethodDefinitionRegistry
*/
public static function instance(): self {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Initialize the registry by registering all available payment method definitions.
*
* @return void
*/
public function init(): void {
foreach ( $this->available_definitions as $definition ) {
$this->register_payment_method( $definition );
}
}
/**
* Get all available payment method definitions.
*
* @return array<class-string<PaymentMethodDefinitionInterface>> Array of payment method definition class names.
*/
public function get_available_definitions(): array {
return $this->available_definitions;
}
/**
* Register a payment method definition.
*
* @param string $definition_class The payment method definition class to register.
* @psalm-param class-string<PaymentMethodDefinitionInterface> $definition_class
* @throws \InvalidArgumentException If the class does not exist or does not implement PaymentMethodDefinitionInterface.
*/
public function register_payment_method( string $definition_class ): void {
if ( ! class_exists( $definition_class ) ) {
throw new \InvalidArgumentException(
sprintf(
'Payment method definition class "%s" does not exist.',
$definition_class
)
);
}
$interfaces = class_implements( $definition_class );
if ( ! isset( $interfaces[ PaymentMethodDefinitionInterface::class ] ) ) {
throw new \InvalidArgumentException(
sprintf(
'Payment method definition class "%s" must implement %s.',
$definition_class,
PaymentMethodDefinitionInterface::class
)
);
}
/**
* Ensure type safety for the payment method definition class.
*
* @var class-string<PaymentMethodDefinitionInterface> $definition_class
*/
$this->payment_methods[ $definition_class::get_id() ] = $definition_class;
}
/**
* Get all registered payment method definitions.
*
* @return class-string<PaymentMethodDefinitionInterface>[] All registered payment method definition classes.
*/
public function get_all_payment_method_definitions(): array {
return $this->payment_methods;
}
/**
* Get all available payment method definitions for a given account and currency.
*
* @param string $account_country The account country.
* @param string $currency The currency.
* @return string[] All available payment method definition classes.
*/
public function get_available_payment_method_definitions( string $account_country, string $currency ): array {
return array_filter(
$this->payment_methods,
function ( $definition_class ) use ( $account_country, $currency ) {
return $definition_class::is_available_for( $currency, $account_country );
}
);
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Payment Method Utilities
*
* @package WCPay\PaymentMethods\Configs\Utils
*/
namespace WCPay\PaymentMethods\Configs\Utils;
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
use WCPay\PaymentMethods\Configs\Registry\PaymentMethodDefinitionRegistry;
/**
* Utility class for payment method related functions.
*/
class PaymentMethodUtils {
/**
* Get the Stripe payment method ID.
* By default, this appends '_payments' to the payment method ID.
*
* @param string $payment_method_id The payment method ID.
* @return string
*/
public static function get_stripe_id( string $payment_method_id ): string {
return $payment_method_id . '_payments';
}
/**
* Whether a payment method is available for the given currency and country
*
* @param array<string> $supported_currencies The list of supported currencies.
* @param array<string> $supported_countries The list of supported countries.
* @param string $currency The currency code to check.
* @param string $account_country The merchant's account country.
* @return bool
*/
public static function is_available_for( array $supported_currencies, array $supported_countries, string $currency, string $account_country ): bool {
// Check if currency is supported.
if ( ! empty( $supported_currencies ) && ! in_array( $currency, $supported_currencies, true ) ) {
return false;
}
// Check if country is supported.
if ( ! empty( $supported_countries ) && ! in_array( $account_country, $supported_countries, true ) ) {
return false;
}
return true;
}
/**
* Is the payment method a BNPL (Buy Now Pay Later) payment method?
*
* @param array<string> $capabilities The payment method capabilities.
* @return boolean
*/
public static function is_bnpl( array $capabilities ): bool {
return in_array( PaymentMethodCapability::BUY_NOW_PAY_LATER, $capabilities, true );
}
/**
* Is the payment method a reusable payment method?
*
* @param array<string> $capabilities The payment method capabilities.
* @return boolean
*/
public static function is_reusable( array $capabilities ): bool {
return in_array( PaymentMethodCapability::TOKENIZATION, $capabilities, true );
}
/**
* Does the payment method accept only domestic payments?
*
* @param array<string> $capabilities The payment method capabilities.
* @return boolean
*/
public static function accepts_only_domestic_payments( array $capabilities ): bool {
return in_array( PaymentMethodCapability::DOMESTIC_TRANSACTIONS_ONLY, $capabilities, true );
}
/**
* Does the payment method allow manual capture?
*
* @param array<string> $capabilities The payment method capabilities.
* @return boolean
*/
public static function allows_manual_capture( array $capabilities ): bool {
return in_array( PaymentMethodCapability::CAPTURE_LATER, $capabilities, true );
}
/**
* Checks if a currency is domestic for a given country.
*
* @param string $currency The currency code to check.
* @param string $country The country code to check against.
* @return bool True if the currency is domestic for the country
*/
public static function is_domestic_currency_for_country( string $currency, string $country ): bool {
// Get the locale info which contains country->currency mapping.
$locale_info = include WC()->plugin_path() . '/i18n/locale-info.php';
// If country doesn't exist in our locale info, we can't validate.
if ( ! isset( $locale_info[ $country ] ) ) {
return false;
}
return $locale_info[ $country ]['currency_code'] === $currency;
}
/**
* Get the payment method definitions as a JSON string.
*
* @return string
*/
public static function get_payment_method_definitions_json() {
$registry = PaymentMethodDefinitionRegistry::instance();
$payment_method_definitions = [];
foreach ( $registry->get_available_definitions() as $payment_method_definition ) {
$payment_method_definitions[ $payment_method_definition::get_id() ] = [
'id' => $payment_method_definition::get_id(),
'stripe_key' => $payment_method_definition::get_stripe_id(),
'title' => $payment_method_definition::get_title(),
'description' => $payment_method_definition::get_description(),
'settings_icon_url' => $payment_method_definition::get_settings_icon_url(),
'currencies' => $payment_method_definition::get_supported_currencies(),
'allows_manual_capture' => $payment_method_definition::allows_manual_capture(),
'allows_pay_later' => $payment_method_definition::is_bnpl(),
'accepts_only_domestic_payment' => $payment_method_definition::accepts_only_domestic_payments(),
];
}
$encoded_response = wp_json_encode( $payment_method_definitions );
return false === $encoded_response ? '' : $encoded_response;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* Class Affirm_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Affirm Payment Method class extending UPE base class
*/
class Affirm_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'affirm';
/**
* Constructor for Affirm payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo.svg', WCPAY_PLUGIN_FILE );
$this->dark_icon_url = plugins_url( 'assets/images/payment-methods/affirm-logo-dark.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR ];
$this->accept_only_domestic_payment = true;
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA ];
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Affirm', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Allow customers to pay over time with Affirm.',
'woocommerce-payments'
);
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
return plugins_url( 'assets/images/payment-methods/affirm-badge.svg', WCPAY_PLUGIN_FILE );
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* Class Afterpay_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Afterpay Payment Method class extending UPE base class
*/
class Afterpay_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'afterpay_clearpay';
/**
* Constructor for Afterpay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/afterpay-logo.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::CANADIAN_DOLLAR, Currency_Code::AUSTRALIAN_DOLLAR, Currency_Code::NEW_ZEALAND_DOLLAR, Currency_Code::POUND_STERLING ];
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA, Country_Code::AUSTRALIA, Country_Code::NEW_ZEALAND, Country_Code::UNITED_KINGDOM ];
$this->accept_only_domestic_payment = true;
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
}
/**
* Returns payment method title.
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Payment details from charge object. Not used by this class.
* @return string|null
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return __( 'Clearpay', 'woocommerce-payments' );
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return __( 'Cash App Afterpay', 'woocommerce-payments' );
}
return __( 'Afterpay', 'woocommerce-payments' );
}
/**
* Returns payment method icon.
*
* @param string|null $account_country Country of merchants account.
* @return string|null
*/
public function get_icon( ?string $account_country = null ) {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-logo.svg', WCPAY_PLUGIN_FILE );
}
return plugins_url( 'assets/images/payment-methods/afterpay-badge.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns payment method dark icon.
*
* @param string|null $account_country Country of merchants account.
* @return string|null
*/
public function get_dark_icon( ?string $account_country = null ) {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay-dark.svg', WCPAY_PLUGIN_FILE );
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-logo-dark.svg', WCPAY_PLUGIN_FILE );
}
return plugins_url( 'assets/images/payment-methods/afterpay-badge-dark.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return __(
'Allow customers to pay over time with Clearpay.',
'woocommerce-payments'
);
}
return __(
'Allow customers to pay over time with Afterpay.',
'woocommerce-payments'
);
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return plugins_url( 'assets/images/payment-methods/clearpay.svg', WCPAY_PLUGIN_FILE );
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return plugins_url( 'assets/images/payment-methods/afterpay-cashapp-badge.svg', WCPAY_PLUGIN_FILE );
}
return plugins_url( 'assets/images/payment-methods/afterpay-logo.svg', WCPAY_PLUGIN_FILE );
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class Bancontact_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Bancontact Payment Method class extending UPE base class
*/
class Bancontact_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'bancontact';
/**
* Constructor for Bancontact payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Bancontact';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/bancontact.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::BELGIUM ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Bancontact is a bank redirect payment method offered by more than 80% of online businesses in Belgium.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class Becs_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Becs Payment Method class extending UPE base class
*/
class Becs_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'au_becs_debit';
/**
* Constructor for Becs payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'BECS Direct Debit';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::AUSTRALIAN_DOLLAR ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/bank-debit.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRALIA ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return __( '<strong>Test mode:</strong> use the test account number <number>000123456</number>. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a>here</a>.', 'woocommerce-payments' );
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Bulk Electronic Clearing System — Accept secure bank transfer from Australia.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* Class CC_Payment_Gateway
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payment_Gateway_WCPay;
use WC_Payments_Account;
use WC_Payments_Action_Scheduler_Service;
use WC_Payments_API_Client;
use WC_Payments_Customer_Service;
use WC_Payments_Token_Service;
use WC_Payments_Order_Service;
/**
* Credit card Payment method.
* Right now behaves exactly like WC_Payment_Gateway_WCPay for max compatibility.
*/
class CC_Payment_Gateway extends WC_Payment_Gateway_WCPay {
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* Class CC_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Test_Cards;
/**
* Credit card Payment Method class extending UPE base class
*/
class CC_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'card';
/**
* Constructor for card payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = true;
$this->currencies = [];// All currencies are supported.
$this->icon_url = plugins_url( 'assets/images/payment-methods/generic-card.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns payment method title
*
* @param string|null $account_country Account country.
* @param array|false $payment_details Payment details.
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( ! $payment_details ) {
return __( 'Card', 'woocommerce-payments' );
}
$details = $payment_details[ $this->stripe_id ];
$funding_types = [
'credit' => __( 'credit', 'woocommerce-payments' ),
'debit' => __( 'debit', 'woocommerce-payments' ),
'prepaid' => __( 'prepaid', 'woocommerce-payments' ),
'unknown' => __( 'unknown', 'woocommerce-payments' ),
];
$card_network = $details['display_brand'] ?? $details['network'] ?? $details['networks']['preferred'] ?? $details['networks']['available'][0];
// Networks like `cartes_bancaires` may use underscores, so we replace them with spaces.
$card_network = str_replace( '_', ' ', $card_network );
$payment_method_title = sprintf(
// Translators: %1$s card brand, %2$s card funding (prepaid, credit, etc.).
__( '%1$s %2$s card', 'woocommerce-payments' ),
ucwords( $card_network ),
$funding_types[ $details['funding'] ]
);
return $payment_method_title;
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
$test_card_number = Country_Test_Cards::get_test_card_for_country( $account_country );
return sprintf(
// Translators: %s is a test card number.
__( 'Use test card <number>%s</number> or refer to our <a>testing guide</a>.', 'woocommerce-payments' ),
$test_card_number
);
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Let your customers pay with major credit and debit cards without leaving your store.',
'woocommerce-payments'
);
}
/**
* Returns payment method settings label.
*
* @param string $account_country Country of merchants account.
* @return string
*/
public function get_settings_label( string $account_country ) {
return __( 'Credit / Debit Cards', 'woocommerce-payments' );
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
return plugins_url( 'assets/images/payment-methods/generic-card-black.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns boolean dependent on whether payment method allows manual capture.
*
* @return bool
*/
public function allows_manual_capture() {
return true;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class Eps_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* EPS Payment Method class extending UPE base class
*/
class Eps_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'eps';
/**
* Constructor for EPS payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'EPS';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/eps.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRIA ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Accept your payment with EPS — a common payment method in Austria.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class Giropay_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Giropay Payment Method class extending UPE base class
*/
class Giropay_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'giropay';
/**
* Constructor for Giropay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'giropay';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/giropay.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::GERMANY ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Expand your business with giropay — Germanys second most popular payment system.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Class Grabpay_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* GrabPay Payment Method class extending UPE base class
*/
class Grabpay_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'grabpay';
/**
* Constructor for GrabPay payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
// Note: If WooPayments becomes available to merchants from Malaysia in the future, we'll need to not only add MYR here, but also implement
// logic to limit the currency based on the Stripe account country, so SG accounts only accept SGD, and MY accounts only accept MYR.
$this->currencies = [ Currency_Code::SINGAPORE_DOLLAR ];
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = false;
$this->icon_url = plugins_url( 'assets/images/payment-methods/grabpay.svg', WCPAY_PLUGIN_FILE );
$this->accept_only_domestic_payment = true;
$this->countries = [ Country_Code::SINGAPORE ];
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'GrabPay', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'A popular digital wallet for cashless payments in Singapore.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class Ideal_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* IDEAL Payment Method class extending UPE base class
*/
class Ideal_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'ideal';
/**
* Constructor for iDEAL payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'iDEAL';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/ideal.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::NETHERLANDS ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Expand your business with iDEAL — Netherlandss most popular payment method.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Class Klarna_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Klarna Payment Method class extending UPE base class
*/
class Klarna_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'klarna';
/**
* Constructor for Klarna payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = false;
$this->is_bnpl = true;
$this->icon_url = plugins_url( 'assets/images/payment-methods/klarna-pill.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR, Currency_Code::POUND_STERLING, Currency_Code::EURO, Currency_Code::DANISH_KRONE, Currency_Code::NORWEGIAN_KRONE, Currency_Code::SWEDISH_KRONA ];
$this->accept_only_domestic_payment = true;
$this->countries = [ Country_Code::UNITED_STATES, Country_Code::UNITED_KINGDOM, Country_Code::AUSTRIA, Country_Code::GERMANY, Country_Code::NETHERLANDS, Country_Code::BELGIUM, Country_Code::SPAIN, Country_Code::ITALY, Country_Code::IRELAND, Country_Code::DENMARK, Country_Code::FINLAND, Country_Code::NORWAY, Country_Code::SWEDEN, Country_Code::FRANCE ];
$this->limits_per_currency = WC_Payments_Utils::get_bnpl_limits_per_currency( self::PAYMENT_METHOD_STRIPE_ID );
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Klarna', 'woocommerce-payments' );
}
/**
* Returns payment method supported countries.
*
* For Klarna we need to include additional logic to support transactions between countries in the EEA,
* UK, and Switzerland.
*
* @return array
*/
public function get_countries() {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
// Countries in the EEA can transact across all other EEA countries. This includes Switzerland and the UK who aren't strictly in the EU.
$eea_countries = array_merge(
WC_Payments_Utils::get_european_economic_area_countries(),
[ Country_Code::SWITZERLAND, Country_Code::UNITED_KINGDOM ]
);
// If the merchant is in the EEA, UK, or Switzerland, only the countries that have the same domestic currency as the store currency will be supported.
if ( in_array( $account_country, $eea_countries, true ) ) {
$store_currency = strtoupper( get_woocommerce_currency() );
// if the store is set to an EU country, but the currency used is not set as a valid EU currency, I guess Klarna shouldn't be eligible.
if ( ! isset( $this->limits_per_currency[ $store_currency ] ) ) {
return [ 'NONE_SUPPORTED' ];
}
$countries_that_support_store_currency = array_keys( $this->limits_per_currency[ $store_currency ] );
return array_values( array_intersect( $eea_countries, $countries_that_support_store_currency ) );
}
return parent::get_countries();
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Allow customers to pay over time or pay now with Klarna.',
'woocommerce-payments'
);
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
return plugins_url( 'assets/images/payment-methods/klarna.svg', WCPAY_PLUGIN_FILE );
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Class CC_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Currency_Code;
/**
* Link Payment Method class extending UPE base class
*/
class Link_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'link';
/**
* Constructor for link payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->is_reusable = true;
$this->currencies = [ Currency_Code::UNITED_STATES_DOLLAR ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/link.svg', WCPAY_PLUGIN_FILE );
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Link', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
// Description is hardcoded in the react component.
return '';
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Class Multibanco_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Multibanco Payment Method class extending UPE base class
*/
class Multibanco_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'multibanco';
/**
* Constructor for Multibanco payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Multibanco';
$this->is_reusable = false;
$this->icon_url = plugins_url( 'assets/images/payment-methods/multibanco-logo.svg', WCPAY_PLUGIN_FILE );
$this->dark_icon_url = plugins_url( 'assets/images/payment-methods/multibanco-logo-dark.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ Currency_Code::EURO ];
$this->countries = [ Country_Code::PORTUGAL ];
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
return __( 'Multibanco', 'woocommerce-payments' );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'A voucher based payment method for your customers in Portugal.',
'woocommerce-payments'
);
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
return plugins_url( 'assets/images/payment-methods/multibanco.svg', WCPAY_PLUGIN_FILE );
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class P24_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* P24 Payment Method class extending UPE base class
*/
class P24_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'p24';
/**
* Constructor for P24 payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Przelewy24 (P24)';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO, Currency_Code::POLISH_ZLOTY ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/p24.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::POLAND ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Accept payments with Przelewy24 (P24), the most popular payment method in Poland.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Class Sepa_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Token_Service;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
/**
* Sepa Payment Method class extending UPE base class
*/
class Sepa_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'sepa_debit';
/**
* Constructor for Sepa payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'SEPA Direct Debit';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/sepa-debit.svg', WCPAY_PLUGIN_FILE );
// https://stripe.com/en-br/resources/more/sepa-country-list#list-of-sepa-countries.
$eu_countries = [ Country_Code::AUSTRIA, Country_Code::BELGIUM, Country_Code::BULGARIA, Country_Code::CROATIA, Country_Code::CYPRUS, Country_Code::CZECHIA, Country_Code::DENMARK, Country_Code::ESTONIA, Country_Code::FINLAND, Country_Code::FRANCE, Country_Code::GERMANY, Country_Code::GREECE, Country_Code::HUNGARY, Country_Code::IRELAND, Country_Code::ITALY, Country_Code::LATVIA, Country_Code::LITHUANIA, Country_Code::LUXEMBOURG, Country_Code::MALTA, Country_Code::NETHERLANDS, Country_Code::POLAND, Country_Code::PORTUGAL, Country_Code::ROMANIA, Country_Code::SLOVAKIA, Country_Code::SLOVENIA, Country_Code::SPAIN, Country_Code::SWEDEN ];
$additional_sepa_countries = [ Country_Code::SWITZERLAND, Country_Code::UNITED_KINGDOM, Country_Code::SAN_MARINO, Country_Code::VATICAN_CITY, Country_Code::ANDORRA, Country_Code::MONACO, Country_Code::LIECHTENSTEIN, Country_Code::NORWAY, Country_Code::ICELAND ];
$this->countries = array_merge( $eu_countries, $additional_sepa_countries );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return __( '<strong>Test mode:</strong> use the test account number <number>AT611904300234573201</number>. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed <a>here</a>.', 'woocommerce-payments' );
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Reach 500 million customers and over 20 million businesses across the European Union.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Class Sofort_Payment_Method
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WCPay\Constants\Country_Code;
use WP_User;
use WC_Payments_Token_Service;
use WCPay\Constants\Currency_Code;
/**
* Sofort Payment Method class extending UPE base class
*/
class Sofort_Payment_Method extends UPE_Payment_Method {
const PAYMENT_METHOD_STRIPE_ID = 'sofort';
/**
* Constructor for Sofort payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = 'Sofort';
$this->is_reusable = false;
$this->currencies = [ Currency_Code::EURO ];
$this->icon_url = plugins_url( 'assets/images/payment-methods/sofort.svg', WCPAY_PLUGIN_FILE );
$this->countries = [ Country_Code::AUSTRIA, Country_Code::BELGIUM, Country_Code::GERMANY, Country_Code::NETHERLANDS, Country_Code::SPAIN ];
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
return '';
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
return __(
'Accept secure bank transfers from Austria, Belgium, Germany, Italy, Netherlands, and Spain.',
'woocommerce-payments'
);
}
}

View File

@@ -0,0 +1,479 @@
<?php
/**
* UPE Payment Method class
*
* Handles general functionality for UPE payment methods
*
* @package WCPay\Payment_Methods
*/
namespace WCPay\Payment_Methods;
use WC_Payments_Utils;
use WP_User;
use WC_Payments_Token_Service;
use WC_Payment_Token_CC;
use WC_Payment_Token_WCPay_SEPA;
use WC_Payments_Subscriptions_Utilities;
/**
* Extendable class for payment methods.
*
* @template T of \WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface
*/
class UPE_Payment_Method {
use WC_Payments_Subscriptions_Utilities;
/**
* Payment method definition.
*
* @var class-string<T>|null
*/
protected $definition;
/**
* Stripe key name
*
* @var string
*/
protected $stripe_id;
/**
* Display title
*
* @var string
*/
protected $title;
/**
* Can payment method be saved or reused?
*
* @var bool
*/
protected $is_reusable;
/**
* Instance of WC Payments Token Service to save payment method
*
* @var WC_Payments_Token_Service
*/
protected $token_service;
/**
* Supported presentment currencies for which charges for a payment method can be processed
* Empty if all currencies are supported
*
* @var string[]
*/
protected $currencies;
/**
* Should payment method be restricted to only domestic payments.
* E.g. only to Stripe's connected account currency.
*
* @var boolean
*/
protected $accept_only_domestic_payment = false;
/**
* Represent payment total limitations for the payment method (per-currency).
*
* @var array<string,array<string,array<string,int>>>
*/
protected $limits_per_currency = [];
/**
* Payment method icon URL
*
* @var string
*/
protected $icon_url;
/**
* Payment method icon URL for dark themes (optional)
*
* @var string
*/
protected $dark_icon_url;
/**
* Is the payment method a BNPL (Buy Now Pay Later) method?
*
* @var boolean
*/
protected $is_bnpl = false;
/**
* Supported customer locations for which charges for a payment method can be processed
* Empty if all customer locations are supported
*
* @var string[]
*/
protected $countries = [];
/**
* Create instance of payment method
*
* @param WC_Payments_Token_Service $token_service Instance of WC_Payments_Token_Service.
* @param class-string<T>|null $definition Optional payment method definition class name.
*/
public function __construct( $token_service, ?string $definition = null ) {
$this->token_service = $token_service;
$this->definition = $definition;
if ( null !== $this->definition ) {
// Cache values that don't require context.
$this->stripe_id = $this->definition::get_id();
$this->is_reusable = $this->definition::is_reusable();
$this->currencies = $this->definition::get_supported_currencies();
$this->accept_only_domestic_payment = $this->definition::accepts_only_domestic_payments();
$this->limits_per_currency = $this->definition::get_limits_per_currency();
$this->is_bnpl = $this->definition::is_bnpl();
$this->countries = $this->definition::get_supported_countries();
}
}
/**
* Returns payment method ID
*
* @return string
*/
public function get_id() {
if ( null !== $this->definition ) {
return $this->definition::get_id();
}
return $this->stripe_id;
}
/**
* Returns payment method title
*
* @param string|null $account_country Country of merchants account.
* @param array|false $payment_details Optional payment details from charge object.
*
* @return string
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_title( ?string $account_country = null, $payment_details = false ) {
if ( null !== $this->definition ) {
return $this->definition::get_title( $account_country );
}
return $this->title;
}
/**
* Returns payment method currencies
*
* @return array
*/
public function get_currencies() {
return $this->currencies;
}
/**
* Determines whether the payment method is restricted to the Stripe account's currency.
* E.g.: Afterpay/Clearpay and Affirm only supports domestic payments; Klarna also implements a simplified version of these market restrictions.
*
* @return bool
*/
public function has_domestic_transactions_restrictions() {
return $this->accept_only_domestic_payment;
}
/**
* Returns boolean dependent on whether payment method
* can be used at checkout
*
* @param string $account_country Country of merchants account.
* @param bool $skip_limits_per_currency_check Whether to skip limits per currency check.
*
* @return bool
*/
public function is_enabled_at_checkout( string $account_country, bool $skip_limits_per_currency_check = false ) {
if ( $this->is_subscription_item_in_cart() || $this->is_changing_payment_method_for_subscription() ) {
return $this->is_reusable();
}
// This part ensures that when payment limits for the currency declared, those will be respected (e.g. BNPLs).
if ( [] !== $this->limits_per_currency && ! $skip_limits_per_currency_check ) {
$order = null;
if ( is_wc_endpoint_url( 'order-pay' ) ) {
$order = wc_get_order( absint( get_query_var( 'order-pay' ) ) );
$order = is_a( $order, 'WC_Order' ) ? $order : null;
}
$currency = get_woocommerce_currency();
if ( $order ) {
$currency = $order->get_currency();
}
// If the currency limits are not defined, we allow the PM for now (gateway has similar validation for limits).
$total = null;
if ( $order ) {
$total = $order->get_total();
} elseif ( isset( WC()->cart ) ) {
$total = WC()->cart->get_total( '' );
}
if ( isset( $this->limits_per_currency[ $currency ], WC()->cart ) && ! empty( $total ) ) {
$amount = WC_Payments_Utils::prepare_amount( $total, $currency );
if ( $amount > 0 ) {
$range = null;
if ( isset( $this->limits_per_currency[ $currency ][ $account_country ] ) ) {
$range = $this->limits_per_currency[ $currency ][ $account_country ];
} elseif ( isset( $this->limits_per_currency[ $currency ]['default'] ) ) {
$range = $this->limits_per_currency[ $currency ]['default'];
}
// If there is no range specified for the currency-country pair we don't support it and return false.
if ( null === $range ) {
return false;
}
$is_valid_minimum = null === $range['min'] || $amount >= $range['min'];
$is_valid_maximum = null === $range['max'] || $amount <= $range['max'];
return $is_valid_minimum && $is_valid_maximum;
}
}
}
return true;
}
/**
* Returns boolean dependent on whether payment method
* will support saved payments/subscription payments
*
* @return bool
*/
public function is_reusable() {
return $this->is_reusable;
}
/**
* Returns boolean dependent on whether payment method
* will support BNPL (Buy Now Pay Later) payments
*
* @return bool
*/
public function is_bnpl() {
return $this->is_bnpl;
}
/**
* Returns boolean dependent on whether payment method will accept charges
* with chosen currency
*
* @param string $account_domestic_currency Domestic currency of the account.
* @param int|null $order_id Optional order ID, if order currency should take precedence.
*
* @return bool
*/
public function is_currency_valid( string $account_domestic_currency, $order_id = null ) {
$current_store_currency = $this->get_currency( $order_id );
if ( null === $current_store_currency ) {
return false;
}
if ( $this->has_domestic_transactions_restrictions() ) {
if ( strtolower( $current_store_currency ) !== strtolower( $account_domestic_currency ) ) {
return false;
}
}
$supported_currencies = $this->get_currencies();
return empty( $supported_currencies ) || in_array( $current_store_currency, $supported_currencies, true );
}
/**
* Add payment method to user and return WC payment token
*
* @param WP_User $user User to get payment token from.
* @param string $payment_method_id Stripe payment method ID string.
*
* @return WC_Payment_Token_CC|WC_Payment_Token_WCPay_SEPA WC object for payment token.
*/
public function get_payment_token_for_user( $user, $payment_method_id ) {
return $this->token_service->add_payment_method_to_user( $payment_method_id, $user );
}
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
public function get_testing_instructions( string $account_country ) {
if ( null !== $this->definition ) {
return $this->definition::get_testing_instructions( $account_country );
}
return '';
}
/**
* Returns the payment method icon URL or an empty string.
*
* @param string|null $account_country Optional account country.
* @return string
*
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
*/
public function get_icon( ?string $account_country = null ) {
if ( null !== $this->definition ) {
return $this->definition::get_icon_url( $account_country );
}
return isset( $this->icon_url ) ? $this->icon_url : '';
}
/**
* Returns icon to use on dark themes.
*
* @param string|null $account_country Optional account country.
* @return string
*/
public function get_dark_icon( ?string $account_country = null ) {
if ( null !== $this->definition ) {
return $this->definition::get_dark_icon_url( $account_country );
}
return isset( $this->dark_icon_url ) ? $this->dark_icon_url : $this->get_icon( $account_country );
}
/**
* Gets the theme appropriate icon for the payment method for a given location and context.
*
* @param string $location The location to get the icon for.
* @param boolean $is_blocks Whether the icon is for blocks.
* @param string $account_country Optional account country.
* @return string
*/
public function get_payment_method_icon_for_location( string $location = 'checkout', bool $is_blocks = true, ?string $account_country = null ) {
$appearance_theme = WC_Payments_Utils::get_active_upe_theme_transient_for_location( $location, $is_blocks ? 'blocks' : 'classic' );
if ( 'night' === $appearance_theme ) {
return $this->get_dark_icon( $account_country );
}
return $this->get_icon( $account_country );
}
/**
* Returns payment method supported countries
*
* @return array
*/
public function get_countries() {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
return $this->has_domestic_transactions_restrictions() ? [ $account_country ] : $this->countries;
}
/**
* Returns payment method description for the settings page.
*
* @param string|null $account_country Country of merchants account.
*
* @return string
*/
public function get_description( ?string $account_country = null ) {
if ( null !== $this->definition ) {
return $this->definition::get_description( $account_country );
}
return '';
}
/**
* Returns payment method settings label.
*
* @param string $account_country Country of merchants account.
* @return string
*/
public function get_settings_label( string $account_country ) {
if ( null !== $this->definition ) {
return $this->definition::get_settings_label( $account_country );
}
return $this->get_title( $account_country );
}
/**
* Returns payment method settings icon.
*
* @param string|null $account_country Country of merchants account.
* @return string
*/
public function get_settings_icon_url( ?string $account_country = null ) {
if ( null !== $this->definition ) {
return $this->definition::get_settings_icon_url( $account_country );
}
return $this->get_icon( $account_country );
}
/**
* Returns boolean dependent on whether payment method allows manual capture.
*
* @return bool
*/
public function allows_manual_capture() {
if ( null !== $this->definition ) {
return $this->definition::allows_manual_capture();
}
return false;
}
/**
* Returns the Stripe key for the payment method.
*
* @return string
*/
public function get_stripe_key() {
if ( null !== $this->definition ) {
return $this->definition::get_stripe_id();
}
return \WC_Payments::get_gateway()->get_payment_method_capability_key_map()[ $this->stripe_id ];
}
/**
* Returns payment method settings definition.
*
* @param string $account_country Country of merchants account.
* @return array
*/
public function get_payment_method_information_object( string $account_country ) {
return [
'id' => $this->get_id(),
'label' => $this->get_settings_label( $account_country ),
'description' => $this->get_description( $account_country ),
'settings_icon_url' => $this->get_settings_icon_url( $account_country ),
'currencies' => $this->get_currencies(),
'stripe_key' => $this->get_stripe_key(),
'allows_manual_capture' => $this->allows_manual_capture(),
'allows_pay_later' => $this->is_bnpl(),
'accepts_only_domestic_payment' => $this->has_domestic_transactions_restrictions(),
];
}
/**
* Returns valid currency to use to filter payment methods.
*
* @param int $order_id Optional order ID, if order currency should take precedence.
*
* @return string|null
*/
private function get_currency( $order_id = null ) {
if ( is_wc_endpoint_url( 'order-pay' ) || null !== $order_id ) {
global $wp;
if ( null === $order_id ) {
$order_id = absint( $wp->query_vars['order-pay'] );
}
$order = wc_get_order( $order_id );
if ( false === $order ) {
return null;
}
return $order->get_currency();
}
return get_woocommerce_currency();
}
}