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

POC - Centralized payment method definitions #10217

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
3849078
Sorry for the big commit - first pass at getting the php side working…
brettshumaker Jan 15, 2025
888fcc6
We need to access this method outside of the definition.
brettshumaker Jan 15, 2025
66ab9a1
Update afterpay class to use new definitions.
brettshumaker Jan 15, 2025
ab7c4fb
Fix dark icon file checking.
brettshumaker Jan 15, 2025
845ecd6
Push generated types to client mapping
brettshumaker Jan 15, 2025
ae13734
Fix tests.
brettshumaker Jan 16, 2025
9d0cc13
Fixing the tests revealed that the stripe_id here should just be the …
brettshumaker Jan 16, 2025
c3c093c
Add note to Afterpay
brettshumaker Jan 16, 2025
b0aece2
Make get_stripe_id a consistent trait for the definitions.
brettshumaker Jan 16, 2025
b0d8884
Use existing constant for definition ID.
brettshumaker Jan 16, 2025
70ec9bd
Address notes from Marcin
brettshumaker Feb 3, 2025
2baec4b
Revert "Address notes from Marcin"
brettshumaker Feb 11, 2025
87e8f88
Rename classes to psr-4 and update references
brettshumaker Feb 11, 2025
ffe2a5d
Remove BNPL trait and definition.
brettshumaker Feb 11, 2025
136a012
Remove Payment_Method_Icons trait and add direct icon URL methods to …
brettshumaker Feb 11, 2025
45bc090
Remove Base_Payment_Method trait and move some of its functionality t…
brettshumaker Feb 11, 2025
9ae210b
Moved to static methods and updated all references to reflect that.
brettshumaker Feb 12, 2025
df36af2
white space clean up and use the "correct" id for the Affirm payment …
brettshumaker Feb 13, 2025
5258803
Update to definition registry, the definition registration process, a…
brettshumaker Feb 13, 2025
8fd22ab
Make a new CLI Commands class for implementing our CLI command and an…
brettshumaker Feb 13, 2025
d436df5
Fix PSR-4 naming inconsistencies in includes/payment-methods/Configs
brettshumaker Feb 13, 2025
22e3e4f
init payment definitions at run time
brettshumaker Feb 13, 2025
58e1feb
Make PaymentMethodDefinitionRegistry consistently have instance methods
brettshumaker Feb 14, 2025
bf2c18c
Rearrange method order
brettshumaker Feb 14, 2025
db37a11
Make is_reusable/bnpl/accept_only_domestic_payment part of the defini…
brettshumaker Feb 14, 2025
be7c41f
Merge remote-tracking branch 'origin/develop' into poc/centralized-pa…
brettshumaker Feb 14, 2025
76a18d2
Remove unused `use` statements
brettshumaker Feb 14, 2025
f3d88c0
Rename payment method definition method
brettshumaker Feb 14, 2025
7795dff
Add support for manual capture to definition
brettshumaker Feb 14, 2025
ff219f6
Add manual capture to the definition interface - missed this in the l…
brettshumaker Feb 14, 2025
a035b82
Remove unneeded npm command and associated file.
brettshumaker Feb 14, 2025
521b941
Simplify mapping class
brettshumaker Feb 17, 2025
fad6bde
Auto-generate icon components when generating types for payment methods.
brettshumaker Feb 17, 2025
174689d
Fix psalm linting
brettshumaker Feb 18, 2025
b4e30c1
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 18, 2025
c7b9b8e
Convert Klarna to new payment method definition
brettshumaker Feb 18, 2025
81f31e0
Add utility method for checking if a given currency is "domestic" for…
brettshumaker Feb 18, 2025
ceb5657
Remove unused method in definition.
brettshumaker Feb 18, 2025
dccdc2d
Fix js tests
brettshumaker Feb 18, 2025
8af7634
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 18, 2025
3069f05
Fix Klarna tests
brettshumaker Feb 18, 2025
ad0bc2e
Create poc-centralized-payment-method-definitions
brettshumaker Feb 18, 2025
ee07ebc
Merge branch 'develop' into poc/centralized-payment-method-definitions
frosso Feb 19, 2025
5e06321
Revert "Fix js tests"
brettshumaker Feb 19, 2025
b3cd1dc
Actually fix js tests
brettshumaker Feb 19, 2025
a16c8f3
Resolve (compiling) circular dependency.
brettshumaker Feb 19, 2025
7be446b
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 19, 2025
a52710f
Pass payment method config to inline script instead of generating
brettshumaker Feb 25, 2025
7ecea8a
Remove all code related to generating JS types for payment method def…
brettshumaker Feb 25, 2025
7e9f5e8
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 25, 2025
3b39e27
Fix FalsableReturnStatement error
brettshumaker Feb 26, 2025
2a9d6d1
Properly handle wp_json_encode
brettshumaker Feb 26, 2025
693f5ae
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 26, 2025
b1795e2
Really fix the psalm error - wasn't failing with npm run psalm
brettshumaker Feb 26, 2025
8aa160b
Merge branch 'poc/centralized-payment-method-definitions' of https://…
brettshumaker Feb 26, 2025
b55bca5
Fix jest config error - missed this when removing the js type generat…
brettshumaker Feb 26, 2025
6bcc283
Remove payment method definitions - will be re-added in individual PR…
brettshumaker Feb 26, 2025
10006d3
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 26, 2025
2a8ca73
Remove a few straggling references to the definitions I deleted.
brettshumaker Feb 26, 2025
78d4aa9
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 26, 2025
71d9650
Create tests for PaymentMethodDefinitionRegistry
brettshumaker Feb 26, 2025
df2d1fa
Create tests for PaymentMethodUtils
brettshumaker Feb 26, 2025
c9c83d9
Whoops!
brettshumaker Feb 27, 2025
13fec88
Remove accidental double encoding of JSON data.
brettshumaker Feb 27, 2025
43161c0
Use window instead of const just in case this ever gets added to the …
brettshumaker Feb 28, 2025
7850669
Restore Klarna payment method in WC_Payment_Gateway_WCPay_Test
brettshumaker Feb 28, 2025
186a0ac
Merge branch 'poc/centralized-payment-method-definitions' of https://…
brettshumaker Feb 28, 2025
5b86484
Use type parameter instead of casting
brettshumaker Feb 28, 2025
4f65ac7
Merge branch 'develop' into poc/centralized-payment-method-definitions
brettshumaker Feb 28, 2025
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
4 changes: 4 additions & 0 deletions changelog/poc-centralized-payment-method-definitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Add centralized payment method definitions to streamline implementation and maintenance of payment methods.
5 changes: 5 additions & 0 deletions client/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ declare global {
timeFormat: string;
};

const woopaymentsPaymentMethodDefinitions: Record<
string,
PaymentMethodDefinition
>;

const wc: {
wcSettings: typeof wcSettingsModule;
tracks: {
Expand Down
47 changes: 36 additions & 11 deletions client/payment-methods-map.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* External dependencies
*/
import React from 'react';
import { __ } from '@wordpress/i18n';
import classNames from 'classnames';

/**
* Internal dependencies
Expand Down Expand Up @@ -29,17 +31,39 @@ import {

const accountCountry = window.wcpaySettings?.accountStatus?.country || 'US';

export interface PaymentMethodMapEntry {
id: string;
label: string;
description: string;
icon: ReactImgFuncComponent;
currencies: string[];
stripe_key: string;
allows_manual_capture: boolean;
allows_pay_later: boolean;
accepts_only_domestic_payment: boolean;
}
import type { PaymentMethodMapEntry } from './types/payment-methods';

// Get any payment method definitions from the client.
const PaymentMethodDefinitions =
typeof woopaymentsPaymentMethodDefinitions !== 'undefined'
? woopaymentsPaymentMethodDefinitions
: {};

const convertedPaymentMethodDefinitions = Object.fromEntries(
Object.entries( PaymentMethodDefinitions ).map( ( [ key, value ] ) => [
key,
{
id: value.id,
label: value.title,
description: value.description,
icon: ( { className } ) => (
<img
src={ value.icon }
alt={ value.title }
className={ classNames(
'payment-method__icon',
className
) }
/>
),
currencies: value.currencies,
stripe_key: value.stripeId,
allows_manual_capture: value.allows_manual_capture,
allows_pay_later: value.allows_pay_later,
accepts_only_domestic_payment: value.accepts_only_domestic_payment,
} as PaymentMethodMapEntry,
] )
);

const PaymentMethodInformationObject: Record<
string,
Expand Down Expand Up @@ -292,6 +316,7 @@ const PaymentMethodInformationObject: Record<
allows_pay_later: false,
accepts_only_domestic_payment: false,
},
...convertedPaymentMethodDefinitions,
};

export default PaymentMethodInformationObject;
16 changes: 13 additions & 3 deletions client/types/payment-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export type PaymentMethod =
| 'ideal'
| 'p24'
| 'sepa_debit'
| 'sofort'
| 'affirm'
| 'afterpay_clearpay';
| 'sofort';

export interface PaymentMethodMapEntry {
id: string;
label: string;
description: string;
icon: ReactImgFuncComponent;
currencies: string[];
stripe_key: string;
allows_manual_capture: boolean;
allows_pay_later: boolean;
accepts_only_domestic_payment: boolean;
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"autoload": {
"psr-4": {
"WCPay\\MultiCurrency\\": "includes/multi-currency",
"WCPay\\PaymentMethods\\Configs\\": "includes/payment-methods/Configs",
"WCPay\\Vendor\\": "lib/packages",
"WCPay\\": "src"
},
Expand Down
Loading
Loading