Skip to content

Commit 325a46d

Browse files
authored
feat: add Amazon Pay gateway class (#11219)
1 parent ffc4549 commit 325a46d

File tree

9 files changed

+246
-30
lines changed

9 files changed

+246
-30
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: add
3+
4+
feat: add Amazon Pay payment gateway class

client/payment-methods-icons.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ const iconComponent = (
3939
/>
4040
);
4141

42-
export const AmazonPayIcon = iconComponent(
43-
AmazonPayAsset,
44-
__( 'Amazon Pay', 'woocommerce-payments' )
45-
);
4642
export const AmericanExpressIcon = iconComponent(
4743
AmexAsset,
4844
__( 'American Express', 'woocommerce-payments' )

client/settings/express-checkout-settings/amazon-pay-settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const AmazonPaySettings = ( { section } ) => {
104104
'woocommerce-payments'
105105
) }
106106
help={ __(
107-
'Show Amazon Pay button on store pages for faster purchases. ' +
107+
'Show Amazon Pay buttons on store pages for faster purchases. ' +
108108
'Customers with Amazon accounts can use their stored payment information.',
109109
'woocommerce-payments'
110110
) }

client/settings/express-checkout-settings/index.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SettingsLayout from '../settings-layout';
1717
import LoadableSettingsSection from '../loadable-settings-section';
1818
import SaveSettingsSection from '../save-settings-section';
1919
import ErrorBoundary from '../../components/error-boundary';
20-
import { AmazonPayIcon, WooIcon } from 'wcpay/payment-methods-icons';
20+
import { WooIcon } from 'wcpay/payment-methods-icons';
2121
import methodsConfiguration from 'wcpay/payment-methods-map';
2222

2323
const methods = {
@@ -122,19 +122,25 @@ const methods = {
122122
sections: [
123123
{
124124
section: 'enable',
125-
description: () => (
126-
<>
127-
<div className="express-checkout-settings__icon">
128-
<AmazonPayIcon />
129-
</div>
130-
<p>
131-
{ __(
132-
'Allow your customers to collect payments via Amazon Pay.',
133-
'woocommerce-payments'
134-
) }
135-
</p>
136-
</>
137-
),
125+
description: () => {
126+
const {
127+
icon: AmazonPayIcon,
128+
} = methodsConfiguration.amazon_pay;
129+
130+
return (
131+
<>
132+
<div className="express-checkout-settings__icon">
133+
<AmazonPayIcon />
134+
</div>
135+
<p>
136+
{ __(
137+
'Allow your customers to collect payments via Amazon Pay.',
138+
'woocommerce-payments'
139+
) }
140+
</p>
141+
</>
142+
);
143+
},
138144
},
139145
{
140146
section: 'general',

client/settings/express-checkout/amazon-pay-item.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ import { getPaymentMethodSettingsUrl } from '../../utils';
99
* Internal dependencies
1010
*/
1111
import { Button, CheckboxControl } from '@wordpress/components';
12-
import { AmazonPayIcon } from 'wcpay/payment-methods-icons';
1312
import interpolateComponents from '@automattic/interpolate-components';
13+
import methodsConfiguration from '../../payment-methods-map';
1414

1515
const AmazonPayExpressCheckoutItem = (): React.ReactElement => {
1616
const [ isAmazonPayEnabled, setIsAmazonPayEnabled ] = useState( false );
1717

18+
const {
19+
icon: AmazonPayIcon,
20+
label,
21+
description,
22+
} = methodsConfiguration.amazon_pay;
23+
1824
return (
1925
<li className="express-checkout" id="express-checkouts-amazon-pay">
2026
<div className="express-checkout__row">
2127
<div className="express-checkout__checkbox">
2228
<CheckboxControl
23-
label={ __( 'Amazon Pay', 'woocommerce-payments' ) }
29+
label={ label }
2430
checked={ isAmazonPayEnabled }
2531
onChange={ setIsAmazonPayEnabled }
2632
data-testid="amazon-pay-toggle"
@@ -34,23 +40,20 @@ const AmazonPayExpressCheckoutItem = (): React.ReactElement => {
3440
<AmazonPayIcon />
3541
</div>
3642
<div className="express-checkout__label express-checkout__label-mobile">
37-
{ __( 'Amazon Pay', 'woocommerce-payments' ) }
43+
{ label }
3844
</div>
3945
<div className="express-checkout__label-container">
4046
<div className="express-checkout__label express-checkout__label-desktop">
41-
{ __(
42-
'Amazon Pay',
43-
'woocommerce-payments'
44-
) }
47+
{ label }
4548
</div>
4649
<div className="express-checkout__description">
50+
{ description + ' ' }
4751
{ interpolateComponents( {
4852
mixedString: __(
4953
/* eslint-disable-next-line max-len */
50-
'Enhance sales by providing a quick, straightforward, and secure checkout experience. ' +
51-
'By activating this feature, you accept ' +
54+
'By activating this feature, you accept ' +
5255
'{{stripeLink}}Stripe{{/stripeLink}} and ' +
53-
"{{amazonLink}}Amazon{{/amazonLink}}'s terms of use. ",
56+
"{{amazonLink}}Amazon{{/amazonLink}}'s terms of use.",
5457
'woocommerce-payments'
5558
),
5659
/* eslint-disable jsx-a11y/anchor-has-content */

client/settings/express-checkout/style.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
.express-checkout {
88
margin: 0;
99
padding: 24px;
10-
background: #fff;
1110

1211
.loadable-checkbox__icon .gridicons-notice-outline {
1312
fill: #f0b849;
@@ -34,6 +33,7 @@
3433
justify-content: flex-start;
3534
align-items: center;
3635
flex-wrap: nowrap;
36+
background: #fff;
3737
}
3838

3939
&__notice {
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<?php
2+
/**
3+
* Amazon Pay Payment Method Definition
4+
*
5+
* @package WCPay\PaymentMethods\Configs\Definitions
6+
*/
7+
8+
namespace WCPay\PaymentMethods\Configs\Definitions;
9+
10+
use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
11+
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
12+
use WCPay\PaymentMethods\Configs\Utils\PaymentMethodUtils;
13+
14+
/**
15+
* Class implementing the Amazon Pay payment method definition.
16+
*/
17+
class AmazonPayDefinition implements PaymentMethodDefinitionInterface {
18+
19+
/**
20+
* Get the internal ID for the payment method
21+
*
22+
* @return string
23+
*/
24+
public static function get_id(): string {
25+
return 'amazon_pay';
26+
}
27+
28+
/**
29+
* Get the keywords for the payment method. These are used by the duplicates detection service.
30+
*
31+
* @return string[]
32+
*/
33+
public static function get_keywords(): array {
34+
return [ 'amazon_pay', 'amazonpay', 'amazon' ];
35+
}
36+
37+
/**
38+
* Get the Stripe payment method ID
39+
*
40+
* @return string
41+
*/
42+
public static function get_stripe_id(): string {
43+
return PaymentMethodUtils::get_stripe_id( self::get_id() );
44+
}
45+
46+
/**
47+
* Get the customer-facing title of the payment method
48+
*
49+
* @param string|null $account_country Optional. The merchant's account country.
50+
*
51+
* @return string
52+
*/
53+
public static function get_title( ?string $account_country = null ): string {
54+
return __( 'Amazon Pay', 'woocommerce-payments' );
55+
}
56+
57+
/**
58+
* Get the title of the payment method for the settings page.
59+
*
60+
* @param string|null $account_country Optional. The merchant's account country.
61+
*
62+
* @return string
63+
*/
64+
public static function get_settings_label( ?string $account_country = null ): string {
65+
return self::get_title( $account_country );
66+
}
67+
68+
/**
69+
* Get the customer-facing description of the payment method
70+
*
71+
* @param string|null $account_country Optional. The merchant's account country.
72+
* @return string
73+
*/
74+
public static function get_description( ?string $account_country = null ): string {
75+
return __( 'Offer customers a fast, secure checkout experience with Amazon Pay.', 'woocommerce-payments' );
76+
}
77+
78+
/**
79+
* Get the list of supported currencies
80+
*
81+
* @return string[] Array of currency codes
82+
*/
83+
public static function get_supported_currencies(): array {
84+
// Amazon Pay supports the same currencies as card payments.
85+
// Return all available currencies.
86+
return [];
87+
}
88+
89+
/**
90+
* Get the list of supported countries
91+
*
92+
* @param string|null $account_country Optional. The merchant's account country.
93+
* @return string[] Array of country codes
94+
*/
95+
public static function get_supported_countries( ?string $account_country = null ): array {
96+
return [];
97+
}
98+
99+
/**
100+
* Get the payment method capabilities
101+
*
102+
* @return string[]
103+
*/
104+
public static function get_capabilities(): array {
105+
return [
106+
PaymentMethodCapability::REFUNDS,
107+
PaymentMethodCapability::MULTI_CURRENCY,
108+
PaymentMethodCapability::TOKENIZATION,
109+
PaymentMethodCapability::CAPTURE_LATER,
110+
];
111+
}
112+
113+
/**
114+
* Get the URL for the payment method's icon
115+
*
116+
* @param string|null $account_country Optional. The merchant's account country.
117+
*
118+
* @return string
119+
*/
120+
public static function get_icon_url( ?string $account_country = null ): string {
121+
return plugins_url( 'assets/images/payment-methods/amazon-pay.svg', WCPAY_PLUGIN_FILE );
122+
}
123+
124+
/**
125+
* Get the URL for the payment method's dark mode icon
126+
*
127+
* @param string|null $account_country Optional. The merchant's account country.
128+
*
129+
* @return string Returns regular icon URL if no dark mode icon exists
130+
*/
131+
public static function get_dark_icon_url( ?string $account_country = null ): string {
132+
return self::get_icon_url( $account_country );
133+
}
134+
135+
/**
136+
* Get the URL for the payment method's settings icon
137+
*
138+
* @param string|null $account_country Optional. The merchant's account country.
139+
*
140+
* @return string
141+
*/
142+
public static function get_settings_icon_url( ?string $account_country = null ): string {
143+
return self::get_icon_url( $account_country );
144+
}
145+
146+
/**
147+
* Get the testing instructions for the payment method
148+
*
149+
* @param string $account_country The merchant's account country.
150+
* @return string HTML string containing testing instructions
151+
*/
152+
public static function get_testing_instructions( string $account_country ): string {
153+
return '';
154+
}
155+
156+
/**
157+
* Get the currency limits for the payment method
158+
*
159+
* @return array<string,array<string,array{min:int,max:int}>>
160+
*/
161+
public static function get_limits_per_currency(): array {
162+
return [];
163+
}
164+
165+
/**
166+
* Whether this payment method is available for the given currency and country
167+
*
168+
* @param string $currency The currency code to check.
169+
* @param string $account_country The merchant's account country.
170+
*
171+
* @return bool
172+
*/
173+
public static function is_available_for( string $currency, string $account_country ): bool {
174+
return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country );
175+
}
176+
177+
/**
178+
* Get the minimum amount for this payment method for a given currency and country
179+
*
180+
* @param string $currency The currency code.
181+
* @param string $country The country code.
182+
*
183+
* @return int|null The minimum amount or null if no minimum.
184+
*/
185+
public static function get_minimum_amount( string $currency, string $country ): ?int {
186+
return null;
187+
}
188+
189+
/**
190+
* Get the maximum amount for this payment method for a given currency and country
191+
*
192+
* @param string $currency The currency code.
193+
* @param string $country The country code.
194+
*
195+
* @return int|null The maximum amount or null if no maximum.
196+
*/
197+
public static function get_maximum_amount( string $currency, string $country ): ?int {
198+
return null;
199+
}
200+
}

includes/payment-methods/Configs/Registry/PaymentMethodDefinitionRegistry.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use WCPay\PaymentMethods\Configs\Definitions\AffirmDefinition;
1111
use WCPay\PaymentMethods\Configs\Definitions\AfterpayDefinition;
1212
use WCPay\PaymentMethods\Configs\Definitions\AlipayDefinition;
13+
use WCPay\PaymentMethods\Configs\Definitions\AmazonPayDefinition;
1314
use WCPay\PaymentMethods\Configs\Definitions\ApplePayDefinition;
1415
use WCPay\PaymentMethods\Configs\Definitions\BancontactDefinition;
1516
use WCPay\PaymentMethods\Configs\Definitions\BecsDefinition;
@@ -99,6 +100,11 @@ public function init(): void {
99100
foreach ( $this->available_definitions as $definition ) {
100101
$this->register_payment_method( $definition );
101102
}
103+
104+
// When Amazon Pay is promoted from feature flag, we can register it directly in the `available_definitions` array.
105+
if ( \WC_Payments_Features::is_amazon_pay_enabled() ) {
106+
$this->register_payment_method( AmazonPayDefinition::class );
107+
}
102108
}
103109

104110
/**

tests/js/jest-test-file-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,5 @@ global.wooPaymentsPaymentMethodDefinitions = {
188188
alipay: buildMockDefinition( 'alipay', 'Alipay', [ 'USD' ] ),
189189
google_pay: buildMockDefinition( 'google_pay', 'Google Pay' ),
190190
apple_pay: buildMockDefinition( 'apple_pay', 'Apple Pay' ),
191+
amazon_pay: buildMockDefinition( 'amazon_pay', 'Amazon Pay' ),
191192
};

0 commit comments

Comments
 (0)