Skip to content

Commit

Permalink
Merge branch 'develop' into fix/deprecated-message-on-empty-pmme
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso authored Nov 8, 2024
2 parents 5340575 + 75a11d0 commit 83cc4f7
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 21 deletions.
4 changes: 4 additions & 0 deletions changelog/add-country-specific-test-cards
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add country-specific test card numbers for credit card testing
6 changes: 3 additions & 3 deletions includes/class-wc-payments-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function get_enabled_payment_method_config() {
$gateway_for_payment_method = $this->gateway->wc_payments_get_payment_gateway_by_id( $payment_method_id );
$settings[ $payment_method_id ]['testingInstructions'] = WC_Payments_Utils::esc_interpolated_html(
/* translators: link to Stripe testing page */
$payment_method->get_testing_instructions(),
$payment_method->get_testing_instructions( $account_country ),
[
'a' => '<a href="https://woocommerce.com/document/woopayments/testing-and-troubleshooting/testing/#test-cards" target="_blank">',
'strong' => '<strong>',
Expand Down Expand Up @@ -420,14 +420,14 @@ function () use ( $prepared_customer_data ) {
<?php
endif;

if ( WC_Payments::mode()->is_test() && false !== $this->gateway->get_payment_method()->get_testing_instructions() ) :
if ( WC_Payments::mode()->is_test() && false !== $this->gateway->get_payment_method()->get_testing_instructions( $this->account->get_account_country() ) ) :
?>
<p class="testmode-info">
<?php
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo WC_Payments_Utils::esc_interpolated_html(
/* translators: link to Stripe testing page */
$this->gateway->get_payment_method()->get_testing_instructions(),
$this->gateway->get_payment_method()->get_testing_instructions( $this->account->get_account_country() ),
[
'a' => '<a href="https://woocommerce.com/document/woopayments/testing-and-troubleshooting/testing/#test-cards" target="_blank">',
'strong' => '<strong>',
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public static function init() {
include_once __DIR__ . '/exceptions/class-invalid-address-exception.php';
include_once __DIR__ . '/constants/class-base-constant.php';
include_once __DIR__ . '/constants/class-country-code.php';
include_once __DIR__ . '/constants/class-country-test-cards.php';
include_once __DIR__ . '/constants/class-currency-code.php';
include_once __DIR__ . '/constants/class-fraud-meta-box-type.php';
include_once __DIR__ . '/constants/class-order-mode.php';
Expand Down
95 changes: 95 additions & 0 deletions includes/constants/class-country-test-cards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Class Country_Test_Cards
*
* @package WooCommerce\Payments
*/

namespace WCPay\Constants;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}


/**
* Class handling country-specific test card numbers for WooPayments
*/
class Country_Test_Cards extends Base_Constant {
/**
* Map of country codes to their test card numbers
* Source: https://docs.stripe.com/testing?testing-method=card-numbers#international-cards
*
* @var array
*/
private static $country_test_cards = [
Country_Code::UNITED_STATES => '4242 4242 4242 4242',
Country_Code::ARGENTINA => '4000 0003 2000 0021',
Country_Code::BRAZIL => '4000 0007 6000 0002',
Country_Code::CANADA => '4000 0012 4000 0000',
Country_Code::CHILE => '4000 0015 2000 0001',
Country_Code::COLOMBIA => '4000 0017 0000 0003',
Country_Code::COSTA_RICA => '4000 0018 8000 0005',
Country_Code::ECUADOR => '4000 0021 8000 0000',
Country_Code::MEXICO => '4000 0048 4000 8001',
Country_Code::PANAMA => '4000 0059 1000 0000',
Country_Code::PARAGUAY => '4000 0060 0000 0066',
Country_Code::PERU => '4000 0060 4000 0068',
Country_Code::URUGUAY => '4000 0085 8000 0003',
Country_Code::UNITED_ARAB_EMIRATES => '4000 0078 4000 0001',
Country_Code::AUSTRIA => '4000 0004 0000 0008',
Country_Code::BELGIUM => '4000 0005 6000 0004',
Country_Code::BULGARIA => '4000 0010 0000 0000',
Country_Code::BELARUS => '4000 0011 2000 0005',
Country_Code::CROATIA => '4000 0019 1000 0009',
Country_Code::CYPRUS => '4000 0019 6000 0008',
Country_Code::CZECHIA => '4000 0020 3000 0002',
Country_Code::DENMARK => '4000 0020 8000 0001',
Country_Code::ESTONIA => '4000 0023 3000 0009',
Country_Code::FINLAND => '4000 0024 6000 0001',
Country_Code::FRANCE => '4000 0025 0000 0003',
Country_Code::GERMANY => '4000 0027 6000 0016',
Country_Code::GIBRALTAR => '4000 0029 2000 0005',
Country_Code::GREECE => '4000 0030 0000 0030',
Country_Code::HUNGARY => '4000 0034 8000 0005',
Country_Code::IRELAND => '4000 0037 2000 0005',
Country_Code::ITALY => '4000 0038 0000 0008',
Country_Code::LATVIA => '4000 0042 8000 0005',
Country_Code::LIECHTENSTEIN => '4000 0043 8000 0004',
Country_Code::LITHUANIA => '4000 0044 0000 0000',
Country_Code::LUXEMBOURG => '4000 0044 2000 0006',
Country_Code::MALTA => '4000 0047 0000 0007',
Country_Code::NETHERLANDS => '4000 0052 8000 0002',
Country_Code::NORWAY => '4000 0057 8000 0007',
Country_Code::POLAND => '4000 0061 6000 0005',
Country_Code::PORTUGAL => '4000 0062 0000 0007',
Country_Code::ROMANIA => '4000 0064 2000 0001',
Country_Code::SAUDI_ARABIA => '4000 0068 2000 0007',
Country_Code::SLOVENIA => '4000 0070 5000 0006',
Country_Code::SLOVAKIA => '4000 0070 3000 0001',
Country_Code::SPAIN => '4000 0072 4000 0007',
Country_Code::SWEDEN => '4000 0075 2000 0008',
Country_Code::SWITZERLAND => '4000 0075 6000 0009',
Country_Code::UNITED_KINGDOM => '4000 0082 6000 0000',
Country_Code::AUSTRALIA => '4000 0003 6000 0006',
Country_Code::CHINA => '4000 0015 6000 0002',
Country_Code::HONG_KONG => '4000 0034 4000 0004',
Country_Code::INDIA => '4000 0035 6000 0008',
Country_Code::JAPAN => '4000 0039 2000 0003',
Country_Code::MALAYSIA => '4000 0045 8000 0002',
Country_Code::NEW_ZEALAND => '4000 0055 4000 0008',
Country_Code::SINGAPORE => '4000 0070 2000 0003',
Country_Code::TAIWAN => '4000 0015 8000 0008',
Country_Code::THAILAND => '4000 0076 4000 0003',
];

/**
* Get test card number for a specific country.
*
* @param string $country_code Two-letter country code.
* @return string Test card number
*/
public static function get_test_card_for_country( string $country_code ) {
return self::$country_test_cards[ $country_code ] ?? self::$country_test_cards[ Country_Code::UNITED_STATES ];
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-affirm-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-afterpay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public function get_icon( string $account_country = null ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-bancontact-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-becs-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
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' );
}
}
12 changes: 10 additions & 2 deletions includes/payment-methods/class-cc-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace WCPay\Payment_Methods;

use WC_Payments_Token_Service;
use WCPay\Constants\Country_Test_Cards;

/**
* Credit card Payment Method class extending UPE base class
Expand Down Expand Up @@ -67,9 +68,16 @@ public function get_title( string $account_country = null, $payment_details = fa
/**
* 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() {
return __( 'Use test card <number>4242 4242 4242 4242</number> or refer to our <a>testing guide</a>.', 'woocommerce-payments' );
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
);
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-eps-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-giropay-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-ideal-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-klarna-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public function 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-link-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-p24-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-sepa-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public function __construct( $token_service ) {
/**
* 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() {
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' );
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-sofort-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public function __construct( $token_service ) {
/**
* 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() {
public function get_testing_instructions( string $account_country ) {
return '';
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ public function get_payment_token_for_user( $user, $payment_method_id ) {
/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @param string $account_country The country of the account.
* @return string
*/
abstract public function get_testing_instructions();
abstract public function get_testing_instructions( string $account_country );

/**
* Returns the payment method icon URL or an empty string.
Expand Down
Loading

0 comments on commit 83cc4f7

Please sign in to comment.