Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bacs: Process Payment with Saved Bank Details #3775

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
WC_Stripe_UPE_Payment_Method_Link::class,
WC_Stripe_UPE_Payment_Method_Wechat_Pay::class,
WC_Stripe_UPE_Payment_Method_Cash_App_Pay::class,
WC_Stripe_UPE_Payment_Method_Bacs::class,
];

/**
Expand Down Expand Up @@ -148,11 +149,6 @@ public function __construct() {

$this->payment_methods = [];

if ( WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$this->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 All @@ -167,6 +163,10 @@ public function __construct() {
continue;
}

if ( WC_Stripe_UPE_Payment_Method_Bacs::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
continue;
}

$payment_method = new $payment_method_class();
$this->payment_methods[ $payment_method->get_id() ] = $payment_method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ public function is_enabled_at_checkout( $order_id = null, $account_domestic_curr

return parent::is_enabled_at_checkout( $order_id, $account_domestic_currency );
}

public function get_retrievable_type() {
return $this->get_id();
}

public function create_payment_token_for_user( $user_id, $payment_method ) {
$token = new WC_Payment_Token_Bacs();
$token->set_token( $payment_method->id );
$token->set_gateway_id( $this->id );
$token->set_last4( $payment_method->bacs_debit->last4 );
$token->set_fingerprint( $payment_method->bacs_debit->fingerprint );
$token->set_payment_method_type( $this->get_id() );
$token->set_user_id( $user_id );
$token->save();
return $token;
}
}
35 changes: 35 additions & 0 deletions includes/payment-tokens/class-wc-stripe-bacs-payment-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

// phpcs:disable WordPress.Files.FileName

class WC_Payment_Token_Bacs extends WC_Payment_Token implements WC_Stripe_Payment_Method_Comparison_Interface {
use WC_Stripe_Fingerprint_Trait;

protected $type = WC_Stripe_Payment_Methods::BACS_DEBIT;

protected $extra_data = [
'last4' => '',
'payment_method_type' => WC_Stripe_Payment_Methods::BACS_DEBIT,
'fingerprint' => '',
];

public function is_equal_payment_method( $payment_method ): bool {
if ( WC_Stripe_Payment_Methods::BACS_DEBIT === $payment_method->type
&& ( $payment_method->bacs_debit->fingerprint ?? null ) === $this->get_fingerprint() ) {
return true;
}

return false;
}

public function set_last4( $last4 ) {
$this->set_prop( 'last4', $last4 );
}

public function set_payment_method_type( $type ) {
$this->set_prop( 'payment_method_type', $type );
}
}
1 change: 1 addition & 0 deletions includes/payment-tokens/class-wc-stripe-payment-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WC_Stripe_Payment_Tokens {
WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID => WC_Stripe_UPE_Payment_Gateway::ID . '_' . WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID,
WC_Stripe_UPE_Payment_Method_Sofort::STRIPE_ID => WC_Stripe_UPE_Payment_Gateway::ID . '_' . WC_Stripe_UPE_Payment_Method_Sofort::STRIPE_ID,
WC_Stripe_UPE_Payment_Method_Cash_App_Pay::STRIPE_ID => WC_Stripe_UPE_Payment_Gateway::ID . '_' . WC_Stripe_UPE_Payment_Method_Cash_App_Pay::STRIPE_ID,
WC_Stripe_UPE_Payment_Method_Bacs::STRIPE_ID => WC_Stripe_UPE_Payment_Gateway::ID . '_' . WC_Stripe_UPE_Payment_Method_Bacs::STRIPE_ID,
];

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/test-class-wc-stripe-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ private function reset_payment_method_mocks( $exclude_methods = [] ) {
$this->mock_payment_methods = [];

foreach ( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS as $payment_method_class ) {
// Bacs is under flag, remove when is enabled by default.
if ( WC_Stripe_UPE_Payment_Method_Bacs::class === $payment_method_class ) {
continue;
}

$mocked_methods = [
'get_capabilities_response',
'get_woocommerce_currency',
Expand Down
1 change: 1 addition & 0 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function init() {
require_once __DIR__ . '/includes/payment-tokens/class-wc-stripe-sepa-payment-token.php';
require_once __DIR__ . '/includes/payment-tokens/class-wc-stripe-link-payment-token.php';
require_once __DIR__ . '/includes/payment-tokens/class-wc-stripe-cash-app-payment-token.php';
require_once __DIR__ . '/includes/payment-tokens/class-wc-stripe-bacs-payment-token.php';
require_once __DIR__ . '/includes/class-wc-stripe-apple-pay-registration.php';
require_once __DIR__ . '/includes/class-wc-gateway-stripe.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-currency-code.php';
Expand Down
Loading