Skip to content

Commit

Permalink
Added support to Cartes Bancaires (#8568)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpressutto5 authored Apr 9, 2024
1 parent d8f2ce5 commit c757b69
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 7 deletions.
4 changes: 4 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
background-image: url( '../images/cards/visa.svg' );
}

.payment-method__brand--cartes_bancaires {
background-image: url( '../images/cards/cartes_bancaires.svg' );
}

.payment-method__brand--unknown {
background-image: url( '../images/cards/unknown.svg' );
}
Expand Down
4 changes: 4 additions & 0 deletions assets/css/admin.rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
background-image: url( '../images/cards/visa.svg' );
}

.payment-method__brand--cartes_bancaires {
background-image: url( '../images/cards/cartes_bancaires.svg' );
}

.payment-method__brand--unknown {
background-image: url( '../images/cards/unknown.svg' );
}
Expand Down
4 changes: 4 additions & 0 deletions assets/images/cards/cartes_bancaires.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions changelog/cobranded-cards
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Added support to Cartes Bancaires
12 changes: 8 additions & 4 deletions client/components/payment-method-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ const PaymentMethodDetails = ( props ) => {
return <span>&ndash;</span>;
}

const brand =
paymentMethod && paymentMethod.brand
? paymentMethod.brand
: payment.type;
let brand = payment.type;
if ( paymentMethod && paymentMethod.brand ) {
brand = paymentMethod.brand;
}
if ( paymentMethod && paymentMethod.network ) {
brand = paymentMethod.network;
}

const details = formatDetails( payment );
return (
<span className="payment-method-details">
Expand Down
1 change: 1 addition & 0 deletions client/payment-methods/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const PAYMENT_METHOD_TITLES = {
bancontact: __( 'Bancontact', 'woocommerce-payments' ),
card: __( 'Card Payment', 'woocommerce-payments' ),
card_present: __( 'In-Person Card Payment', 'woocommerce-payments' ),
cartes_bancaires: __( 'Cartes Bancaires', 'woocommerce-payments' ),
diners: __( 'Diners Club', 'woocommerce-payments' ),
discover: __( 'Discover', 'woocommerce-payments' ),
eps: __( 'EPS', 'woocommerce-payments' ),
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-payments-token-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function add_token_to_user( $payment_method, $user ) {
$token->set_gateway_id( CC_Payment_Gateway::GATEWAY_ID );
$token->set_expiry_month( $payment_method[ Payment_Method::CARD ]['exp_month'] );
$token->set_expiry_year( $payment_method[ Payment_Method::CARD ]['exp_year'] );
$token->set_card_type( strtolower( $payment_method[ Payment_Method::CARD ]['brand'] ) );
$token->set_card_type( strtolower( $payment_method[ Payment_Method::CARD ]['display_brand'] ?? $payment_method[ Payment_Method::CARD ]['networks']['preferred'] ?? $payment_method[ Payment_Method::CARD ]['brand'] ) );
$token->set_last4( $payment_method[ Payment_Method::CARD ]['last4'] );

}
Expand Down
6 changes: 4 additions & 2 deletions includes/payment-methods/class-cc-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public function get_title( string $account_country = null, $payment_details = fa
'unknown' => __( 'unknown', 'woocommerce-payments' ),
];

$card_network = $details['network'] ?? $details['networks']['available'][0];
$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' ),
ucfirst( $card_network ),
ucwords( $card_network ),
$funding_types[ $details['funding'] ]
);

Expand Down
112 changes: 112 additions & 0 deletions tests/unit/test-class-wc-payments-token-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,56 @@ public function test_add_token_to_user() {
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

public function test_add_cobranded_token_to_user_with_preferred_network() {
$expiry_year = intval( gmdate( 'Y' ) ) + 1;
$mock_payment_method = [
'id' => 'pm_mock',
'card' => [
'brand' => 'visa',
'networks' => [ 'preferred' => 'cartes_bancaires' ],
'last4' => '4242',
'exp_month' => 6,
'exp_year' => $expiry_year,
],
'type' => Payment_Method::CARD,
];

$token = $this->token_service->add_token_to_user( $mock_payment_method, wp_get_current_user() );

$this->assertEquals( 'woocommerce_payments', $token->get_gateway_id() );
$this->assertEquals( 1, $token->get_user_id() );
$this->assertEquals( 'pm_mock', $token->get_token() );
$this->assertEquals( 'cartes_bancaires', $token->get_card_type() );
$this->assertEquals( '4242', $token->get_last4() );
$this->assertEquals( '06', $token->get_expiry_month() );
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

public function test_add_cobranded_token_to_user_with_display_brand() {
$expiry_year = intval( gmdate( 'Y' ) ) + 1;
$mock_payment_method = [
'id' => 'pm_mock',
'card' => [
'brand' => 'visa',
'display_brand' => 'cartes_bancaires',
'last4' => '4242',
'exp_month' => 6,
'exp_year' => $expiry_year,
],
'type' => Payment_Method::CARD,
];

$token = $this->token_service->add_token_to_user( $mock_payment_method, wp_get_current_user() );

$this->assertEquals( 'woocommerce_payments', $token->get_gateway_id() );
$this->assertEquals( 1, $token->get_user_id() );
$this->assertEquals( 'pm_mock', $token->get_token() );
$this->assertEquals( 'cartes_bancaires', $token->get_card_type() );
$this->assertEquals( '4242', $token->get_last4() );
$this->assertEquals( '06', $token->get_expiry_month() );
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

/**
* Test add SEPA token to user.
*/
Expand Down Expand Up @@ -261,6 +311,68 @@ public function test_add_payment_method_to_user() {
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

public function test_add_cobranded_payment_method_to_user_with_preferred_network() {
$expiry_year = intval( gmdate( 'Y' ) ) + 1;
$mock_payment_method = [
'id' => 'pm_mock',
'card' => [
'brand' => 'visa',
'networks' => [ 'preferred' => 'cartes_bancaires' ],
'last4' => '4242',
'exp_month' => 6,
'exp_year' => $expiry_year,
],
'type' => Payment_Method::CARD,
];

$this->mock_api_client
->expects( $this->once() )
->method( 'get_payment_method' )
->with( 'pm_mock' )
->willReturn( $mock_payment_method );

$token = $this->token_service->add_payment_method_to_user( $mock_payment_method['id'], wp_get_current_user() );

$this->assertEquals( 'woocommerce_payments', $token->get_gateway_id() );
$this->assertEquals( 1, $token->get_user_id() );
$this->assertEquals( 'pm_mock', $token->get_token() );
$this->assertEquals( 'cartes_bancaires', $token->get_card_type() );
$this->assertEquals( '4242', $token->get_last4() );
$this->assertEquals( '06', $token->get_expiry_month() );
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

public function test_add_cobranded_payment_method_to_user_with_display_brand() {
$expiry_year = intval( gmdate( 'Y' ) ) + 1;
$mock_payment_method = [
'id' => 'pm_mock',
'card' => [
'brand' => 'visa',
'display_brand' => 'cartes_bancaires',
'last4' => '4242',
'exp_month' => 6,
'exp_year' => $expiry_year,
],
'type' => Payment_Method::CARD,
];

$this->mock_api_client
->expects( $this->once() )
->method( 'get_payment_method' )
->with( 'pm_mock' )
->willReturn( $mock_payment_method );

$token = $this->token_service->add_payment_method_to_user( $mock_payment_method['id'], wp_get_current_user() );

$this->assertEquals( 'woocommerce_payments', $token->get_gateway_id() );
$this->assertEquals( 1, $token->get_user_id() );
$this->assertEquals( 'pm_mock', $token->get_token() );
$this->assertEquals( 'cartes_bancaires', $token->get_card_type() );
$this->assertEquals( '4242', $token->get_last4() );
$this->assertEquals( '06', $token->get_expiry_month() );
$this->assertEquals( $expiry_year, $token->get_expiry_year() );
}

public function test_woocommerce_payment_token_deleted() {
$this->mock_api_client
->expects( $this->once() )
Expand Down

0 comments on commit c757b69

Please sign in to comment.