Skip to content

Commit

Permalink
Merge branch 'develop' into fix/fatal-error-editing-shortcode-checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocurbelo authored Jan 24, 2025
2 parents 3fc9496 + 6b1fd26 commit e80b7c5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/payment-method-icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export default {
oxxo: OxxoIcon,
wechat_pay: WechatPayIcon,
cashapp: CashAppIcon,
bacs_debit: CreditCardIcon,
};
18 changes: 17 additions & 1 deletion client/payment-methods-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import icons from './payment-method-icons';
const accountCountry =
window.wc_stripe_settings_params?.account_country || 'US';

export default {
const paymentMethodsMap = {
card: {
id: 'card',
label: __( 'Credit card / debit card', 'woocommerce-gateway-stripe' ),
Expand Down Expand Up @@ -240,3 +240,19 @@ export default {
capability: 'cashapp_payments',
},
};

// Enable Bacs according to feature flag value
if ( window.wc_stripe_settings_params?.is_bacs_enabled ) {
paymentMethodsMap.bacs_debit = {
id: 'bacs_debit',
label: 'Bacs Direct Debit',
description: __(
'Bacs Direct Debit enables customers in the UK to pay by providing their bank account details.',
'woocommerce-gateway-stripe'
),
Icon: icons.card,
currencies: [ 'GBP' ],
};
}

export default paymentMethodsMap;
2 changes: 2 additions & 0 deletions client/stripe-utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const PAYMENT_METHOD_STRIPE_AFTERPAY_CLEARPAY =
'stripe_afterpay_clearpay';
export const PAYMENT_METHOD_STRIPE_WECHAT_PAY = 'stripe_wechat_pay';
export const PAYMENT_METHOD_STRIPE_CASHAPP = 'stripe_cashapp';
export const PAYMENT_METHOD_STRIPE_BACS = 'stripe_bacs_debit';

export function getPaymentMethodsConstants() {
return {
Expand All @@ -63,6 +64,7 @@ export function getPaymentMethodsConstants() {
afterpay_clearpay: PAYMENT_METHOD_STRIPE_AFTERPAY_CLEARPAY,
wechat_pay: PAYMENT_METHOD_STRIPE_WECHAT_PAY,
cashapp: PAYMENT_METHOD_STRIPE_CASHAPP,
bacs_debit: PAYMENT_METHOD_STRIPE_BACS,
};
}

Expand Down
11 changes: 9 additions & 2 deletions includes/class-wc-stripe-intent-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,15 @@ private function build_base_payment_intent_request_params( $payment_information
* @return bool True if a mandate must be shown and acknowledged by customer before deferred intent UPE payment can be processed, false otherwise.
*/
public function is_mandate_data_required( $selected_payment_type, $is_using_saved_payment_method = false ) {

if ( in_array( $selected_payment_type, [ WC_Stripe_Payment_Methods::SEPA_DEBIT, WC_Stripe_Payment_Methods::BANCONTACT, WC_Stripe_Payment_Methods::IDEAL, WC_Stripe_Payment_Methods::SOFORT, WC_Stripe_Payment_Methods::LINK ], true ) ) {
$payment_methods_with_mandates = [
WC_Stripe_Payment_Methods::BACS_DEBIT,
WC_Stripe_Payment_Methods::SEPA_DEBIT,
WC_Stripe_Payment_Methods::BANCONTACT,
WC_Stripe_Payment_Methods::IDEAL,
WC_Stripe_Payment_Methods::SOFORT,
WC_Stripe_Payment_Methods::LINK,
];
if ( in_array( $selected_payment_type, $payment_methods_with_mandates, true ) ) {
return true;
}

Expand Down
1 change: 1 addition & 0 deletions includes/constants/class-wc-stripe-payment-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WC_Stripe_Payment_Methods {
const SOFORT = 'sofort';
const WECHAT_PAY = 'wechat_pay';
const CARD_PRESENT = 'card_present';
const BACS_DEBIT = 'bacs_debit';

/**
* Payment methods that are considered as voucher payment methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public function __construct() {
$is_sofort_enabled = in_array( WC_Stripe_Payment_Methods::SOFORT, $enabled_payment_methods, true );

$this->payment_methods = [];

if ( WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
self::$UPE_AVAILABLE_METHODS[] = WC_Stripe_UPE_Payment_Method_Bacs::class;
}

foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) {

/** Show Sofort if it's already enabled. Hide from the new merchants and keep it for the old ones who are already using this gateway, until we remove it completely.
Expand Down Expand Up @@ -416,9 +422,6 @@ public function javascript_params() {
// ACH LPM Feature flag.
$stripe_params['is_ach_enabled'] = WC_Stripe_Feature_Flags::is_ach_lpm_enabled();

// Bacs LPM Feature flag.
$stripe_params['is_bacs_enabled'] = WC_Stripe_Feature_Flags::is_bacs_lpm_enabled();

$cart_total = ( WC()->cart ? WC()->cart->get_total( '' ) : 0 );
$currency = get_woocommerce_currency();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* The Bacs Direct Debit Payment Method class extending UPE base class.
*/
class WC_Stripe_UPE_Payment_Method_Bacs extends WC_Stripe_UPE_Payment_Method {
/**
* The Stripe ID for the payment method.
*/
const STRIPE_ID = WC_Stripe_Payment_Methods::BACS_DEBIT;

/**
* Constructor for Bacs Direct Debit payment method.
*/
public function __construct() {
parent::__construct();

$this->stripe_id = self::STRIPE_ID;
$this->title = __( 'Bacs Direct Debit', 'woocommerce-gateway-stripe' );
$this->is_reusable = true;
$this->supported_currencies = [ WC_Stripe_Currency_Code::POUND_STERLING ];
$this->supported_countries = [ 'GB' ];
$this->accept_only_domestic_payment = true;
$this->label = __( 'Bacs Direct Debit', 'woocommerce-gateway-stripe' );
$this->description = __( 'Bacs Direct Debit enables customers in the UK to pay by providing their bank account details.', 'woocommerce-gateway-stripe' );
}

/**
* Determines if the Stripe Account country supports Bacs Direct Debit.
*
* @return bool
*/
public function is_available_for_account_country() {
return in_array( WC_Stripe::get_instance()->account->get_account_country(), $this->supported_countries, true );
}

/**
* Returns true if Bacs Direct Debit is available for processing payments.
*
* @return bool
*/
public function is_enabled_at_checkout( $order_id = null, $account_domestic_currency = null ) {
if ( ! WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
return false;
}

return parent::is_enabled_at_checkout( $order_id, $account_domestic_currency );
}
}
1 change: 1 addition & 0 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public function init() {
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-alipay.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-bacs.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-giropay.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-ideal.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-method-klarna.php';
Expand Down

0 comments on commit e80b7c5

Please sign in to comment.