Skip to content

Commit 3769e49

Browse files
dpaun1985Dan Paun
andauthored
StripeLink: Add payment method option in admin (#2370)
Co-authored-by: Dan Paun <[email protected]>
1 parent a73bdfb commit 3769e49

12 files changed

+114
-32
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
= 6.5.0 - 2022-xx-xx =
44
* Add - Stripe Link: Add beta headers for Stripe server requests
5+
* Add - Stripe Link payment method option in admin
56

67
= 6.4.3 - 2022-06-30 =
78
* Fix - Replace unnecessary throws with empty string when keys are invalid.
Lines changed: 28 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import BaseIcon from '../styles/base-icon';
3+
import icon from './icon.svg';
4+
5+
const LinkIcon = ( props ) => <BaseIcon { ...props } src={ icon } />;
6+
7+
export default LinkIcon;

client/payment-methods-map.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import IdealIcon from './payment-method-icons/ideal';
99
import P24Icon from './payment-method-icons/p24';
1010
import BoletoIcon from './payment-method-icons/boleto';
1111
import OxxoIcon from './payment-method-icons/oxxo';
12+
import LinkIcon from './payment-method-icons/link';
1213

1314
export default {
1415
card: {
@@ -23,6 +24,19 @@ export default {
2324
capability: 'card_payments',
2425
allows_manual_capture: true,
2526
},
27+
link: {
28+
id: 'link',
29+
label: __( 'Stripe Link', 'woocommerce-gateway-stripe' ),
30+
description: __(
31+
'Link is a payment method that allows customers to save payment information ' +
32+
'and use the payment details for further payments.',
33+
'woocommerce-gateway-stripe'
34+
),
35+
Icon: LinkIcon,
36+
currencies: [ 'USD' ],
37+
capability: 'link_payments',
38+
allows_manual_capture: true,
39+
},
2640
giropay: {
2741
id: 'giropay',
2842
label: __( 'giropay', 'woocommerce-gateway-stripe' ),

client/settings/general-settings-section/__tests__/general-settings-section.test.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,17 @@ describe( 'GeneralSettingsSection', () => {
3838
useGetCapabilities.mockReturnValue( {
3939
card_payments: 'active',
4040
giropay_payments: 'active',
41+
link_payments: 'active',
4142
} );
4243
useManualCapture.mockReturnValue( [ false ] );
43-
useGetAvailablePaymentMethodIds.mockReturnValue( [ 'card' ] );
44-
useEnabledPaymentMethodIds.mockReturnValue( [ [ 'card' ], jest.fn() ] );
44+
useGetAvailablePaymentMethodIds.mockReturnValue( [ 'card', 'link' ] );
45+
useEnabledPaymentMethodIds.mockReturnValue( [
46+
[ 'card', 'link' ],
47+
jest.fn(),
48+
] );
4549
useAccount.mockReturnValue( { isRefreshing: false } );
4650
} );
4751

48-
it( 'should render the card information with action elements if UPE is disabled', () => {
49-
render(
50-
<UpeToggleContext.Provider value={ { isUpeEnabled: false } }>
51-
<GeneralSettingsSection />
52-
</UpeToggleContext.Provider>
53-
);
54-
55-
expect(
56-
screen.queryByText( 'Credit card / debit card' )
57-
).toBeInTheDocument();
58-
expect(
59-
screen.queryByText(
60-
'Let your customers pay with major credit and debit cards without leaving your store.'
61-
)
62-
).toBeInTheDocument();
63-
expect(
64-
screen.queryByText( 'Get more payment methods' )
65-
).not.toBeInTheDocument();
66-
expect(
67-
screen.queryByRole( 'button', {
68-
name: 'Payment methods menu',
69-
} )
70-
).not.toBeInTheDocument();
71-
} );
72-
7352
it( 'should show information to screen readers about the payment methods being updated', () => {
7453
const refreshAccountMock = jest.fn();
7554
useAccount.mockReturnValue( {
@@ -132,6 +111,7 @@ describe( 'GeneralSettingsSection', () => {
132111
'giropay',
133112
'sofort',
134113
'sepa_debit',
114+
'link',
135115
] );
136116
const updateEnabledMethodsMock = jest.fn();
137117
useEnabledPaymentMethodIds.mockReturnValue( [

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
2626
WC_Stripe_UPE_Payment_Method_Sepa::class,
2727
WC_Stripe_UPE_Payment_Method_P24::class,
2828
WC_Stripe_UPE_Payment_Method_Sofort::class,
29+
WC_Stripe_UPE_Payment_Method_Link::class,
2930
];
3031

3132
const UPE_APPEARANCE_TRANSIENT = 'wc_stripe_upe_appearance';
@@ -412,9 +413,16 @@ public function get_upe_available_payment_methods() {
412413
$available_payment_methods = [];
413414

414415
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) {
416+
//@TODO remove this when Stripe Link is fully implemented
417+
if (
418+
WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID === $payment_method_class::STRIPE_ID &&
419+
! get_option( '_wc_stripe_feature_link' )
420+
) {
421+
continue;
422+
}
423+
415424
$available_payment_methods[] = $payment_method_class::STRIPE_ID;
416425
}
417-
418426
return $available_payment_methods;
419427
}
420428

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) {
3+
exit;
4+
}
5+
6+
/**
7+
* Link Payment Method class extending UPE base class
8+
*/
9+
class WC_Stripe_UPE_Payment_Method_Link extends WC_Stripe_UPE_Payment_Method {
10+
11+
const STRIPE_ID = 'link';
12+
13+
/**
14+
* Constructor for Link payment method
15+
*/
16+
public function __construct() {
17+
parent::__construct();
18+
$this->stripe_id = self::STRIPE_ID;
19+
$this->title = __( 'Pay with Link', 'woocommerce-gateway-stripe' );
20+
$this->is_reusable = false;
21+
$this->supported_currencies = [ 'USD' ];
22+
$this->label = __( 'Stripe Link', 'woocommerce-gateway-stripe' );
23+
$this->description = __(
24+
'Link is a payment method that allows customers to save payment information and use the payment details
25+
for further payments.',
26+
'woocommerce-gateway-stripe'
27+
);
28+
}
29+
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
129129
== Changelog ==
130130

131131
= 6.5.0 - 2022-xx-xx =
132+
* Add - Stripe Link payment method option in admin
132133
* Add - Stripe Link: Add beta headers for Stripe server requests
133134

134135
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public function test_short_statement_descriptor_is_not_updated() {
228228
}
229229

230230
public function test_get_settings_returns_available_payment_method_ids() {
231+
update_option( '_wc_stripe_feature_link', 1 );
231232
$response = $this->rest_get_settings();
232233

233234
$expected_method_ids = WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS;

tests/phpunit/test-class-wc-stripe-upe-payment-method.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class WC_Stripe_UPE_Payment_Method_Test extends WP_UnitTestCase {
6060
'transfers' => 'inactive',
6161
'boleto_payments' => 'inactive',
6262
'oxxo_payments' => 'inactive',
63+
'link_payments' => 'inactive',
6364
];
6465

6566
/**
@@ -77,6 +78,7 @@ class WC_Stripe_UPE_Payment_Method_Test extends WP_UnitTestCase {
7778
'transfers' => 'active',
7879
'boleto_payments' => 'active',
7980
'oxxo_payments' => 'active',
81+
'link_payments' => 'active',
8082
];
8183

8284
/**
@@ -329,9 +331,10 @@ public function test_payment_methods_are_only_enabled_when_capability_is_active(
329331
}
330332

331333
$mock_capabilities_response = self::MOCK_INACTIVE_CAPABILITIES_RESPONSE;
334+
$currency = 'link' === $id ? 'USD' : 'EUR';
332335

333336
$this->set_mock_payment_method_return_value( 'get_capabilities_response', $mock_capabilities_response, true );
334-
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', 'EUR' );
337+
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', $currency );
335338
$this->set_mock_payment_method_return_value( 'is_subscription_item_in_cart', false );
336339

337340
$payment_method = $this->mock_payment_methods[ $id ];
@@ -341,7 +344,7 @@ public function test_payment_methods_are_only_enabled_when_capability_is_active(
341344
$mock_capabilities_response[ $capability_key ] = 'active';
342345

343346
$this->set_mock_payment_method_return_value( 'get_capabilities_response', $mock_capabilities_response, true );
344-
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', 'EUR' );
347+
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', $currency );
345348
$this->set_mock_payment_method_return_value( 'is_subscription_item_in_cart', false );
346349

347350
$payment_method = $this->mock_payment_methods[ $id ];
@@ -382,9 +385,11 @@ public function test_payment_methods_are_only_enabled_when_currency_is_supported
382385
public function test_payment_methods_are_reusable_if_cart_contains_subscription() {
383386
$this->set_mock_payment_method_return_value( 'is_subscription_item_in_cart', true );
384387
$this->set_mock_payment_method_return_value( 'get_capabilities_response', self::MOCK_ACTIVE_CAPABILITIES_RESPONSE );
385-
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', 'EUR' );
386388

387-
foreach ( $this->mock_payment_methods as $payment_method ) {
389+
foreach ( $this->mock_payment_methods as $payment_method_id => $payment_method ) {
390+
$currency = 'link' === $payment_method_id ? 'USD' : 'EUR';
391+
$this->set_mock_payment_method_return_value( 'get_woocommerce_currency', $currency );
392+
388393
if ( $payment_method->is_reusable() ) {
389394
$this->assertTrue( $payment_method->is_enabled_at_checkout() );
390395
} else {

0 commit comments

Comments
 (0)