Skip to content

Commit

Permalink
feat(core): De-couple PaymentMethod from PaymentMethodHandler
Browse files Browse the repository at this point in the history
Relates to #671

BREAKING CHANGE: The PaymentMethod entity and type has changed. Previously, a PaymentMethod was
coupled to the configured PaymentMethodHandlers 1-to-1. Now the PaymentMethodHandler is just
a configurable _property_ of the PaymentMethod, much in the same way that a ShippingCalculator
relates to a ShippingMethod. Any existing PaymentMethod entities will need to be migrated to the
new structure.
  • Loading branch information
michaelbromley committed Jan 29, 2021
1 parent 0a1fadd commit ee9ba23
Show file tree
Hide file tree
Showing 35 changed files with 551 additions and 158 deletions.
6 changes: 5 additions & 1 deletion e2e-common/e2e-initial-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export const initialData: InitialData = {
{ name: 'Reduced Tax', percentage: 10 },
{ name: 'Zero Tax', percentage: 0 },
],
shippingMethods: [{ name: 'Standard Shipping', price: 500 }, { name: 'Express Shipping', price: 1000 }],
shippingMethods: [
{ name: 'Standard Shipping', price: 500 },
{ name: 'Express Shipping', price: 1000 },
],
paymentMethods: [],
countries: [
{ name: 'Australia', code: 'AU', zone: 'Oceania' },
{ name: 'Austria', code: 'AT', zone: 'Europe' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type Query = {
orders: OrderList;
paymentMethods: PaymentMethodList;
paymentMethod?: Maybe<PaymentMethod>;
paymentMethodHandlers: Array<ConfigurableOperationDefinition>;
productOptionGroups: Array<ProductOptionGroup>;
productOptionGroup?: Maybe<ProductOptionGroup>;
search: SearchResponse;
Expand Down Expand Up @@ -366,6 +367,8 @@ export type Mutation = {
* Payment.
*/
addManualPaymentToOrder: AddManualPaymentToOrderResult;
/** Create existing PaymentMethod */
createPaymentMethod: PaymentMethod;
/** Update an existing PaymentMethod */
updatePaymentMethod: PaymentMethod;
/** Create a new ProductOptionGroup */
Expand Down Expand Up @@ -693,6 +696,10 @@ export type MutationAddManualPaymentToOrderArgs = {
input: ManualPaymentInput;
};

export type MutationCreatePaymentMethodArgs = {
input: CreatePaymentMethodInput;
};

export type MutationUpdatePaymentMethodArgs = {
input: UpdatePaymentMethodInput;
};
Expand Down Expand Up @@ -959,6 +966,7 @@ export type CreateChannelInput = {
currencyCode: CurrencyCode;
defaultTaxZoneId: Scalars['ID'];
defaultShippingZoneId: Scalars['ID'];
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateChannelInput = {
Expand All @@ -970,6 +978,7 @@ export type UpdateChannelInput = {
currencyCode?: Maybe<CurrencyCode>;
defaultTaxZoneId?: Maybe<Scalars['ID']>;
defaultShippingZoneId?: Maybe<Scalars['ID']>;
customFields?: Maybe<Scalars['JSON']>;
};

/** Returned if attempting to set a Channel's defaultLanguageCode to a language which is not enabled in GlobalSettings */
Expand Down Expand Up @@ -1721,21 +1730,32 @@ export type PaymentMethodList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type CreatePaymentMethodInput = {
name: Scalars['String'];
code: Scalars['String'];
description?: Maybe<Scalars['String']>;
enabled: Scalars['Boolean'];
handler: ConfigurableOperationInput;
};

export type UpdatePaymentMethodInput = {
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
code?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
enabled?: Maybe<Scalars['Boolean']>;
configArgs?: Maybe<Array<ConfigArgInput>>;
handler?: Maybe<ConfigurableOperationInput>;
};

export type PaymentMethod = Node & {
id: Scalars['ID'];
createdAt: Scalars['DateTime'];
updatedAt: Scalars['DateTime'];
name: Scalars['String'];
code: Scalars['String'];
description: Scalars['String'];
enabled: Scalars['Boolean'];
configArgs: Array<ConfigArg>;
definition: ConfigurableOperationDefinition;
handler: ConfigurableOperation;
};

export type Product = Node & {
Expand Down Expand Up @@ -2279,6 +2299,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type CollectionBreadcrumb = {
Expand Down Expand Up @@ -4260,15 +4281,19 @@ export type OrderSortParameter = {
export type PaymentMethodFilterParameter = {
createdAt?: Maybe<DateOperators>;
updatedAt?: Maybe<DateOperators>;
name?: Maybe<StringOperators>;
code?: Maybe<StringOperators>;
description?: Maybe<StringOperators>;
enabled?: Maybe<BooleanOperators>;
};

export type PaymentMethodSortParameter = {
id?: Maybe<SortOrder>;
createdAt?: Maybe<SortOrder>;
updatedAt?: Maybe<SortOrder>;
name?: Maybe<SortOrder>;
code?: Maybe<SortOrder>;
description?: Maybe<SortOrder>;
};

export type ProductFilterParameter = {
Expand Down Expand Up @@ -4431,6 +4456,7 @@ export type NativeAuthInput = {

export type CustomFields = {
Address: Array<CustomFieldConfig>;
Channel: Array<CustomFieldConfig>;
Collection: Array<CustomFieldConfig>;
Customer: Array<CustomFieldConfig>;
Facet: Array<CustomFieldConfig>;
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type Collection = Node & {
Expand Down
45 changes: 36 additions & 9 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type Query = {
orders: OrderList;
paymentMethods: PaymentMethodList;
paymentMethod?: Maybe<PaymentMethod>;
paymentMethodHandlers: Array<ConfigurableOperationDefinition>;
productOptionGroups: Array<ProductOptionGroup>;
productOptionGroup?: Maybe<ProductOptionGroup>;
search: SearchResponse;
Expand Down Expand Up @@ -411,6 +412,8 @@ export type Mutation = {
* Payment.
*/
addManualPaymentToOrder: AddManualPaymentToOrderResult;
/** Create existing PaymentMethod */
createPaymentMethod: PaymentMethod;
/** Update an existing PaymentMethod */
updatePaymentMethod: PaymentMethod;
/** Create a new ProductOptionGroup */
Expand Down Expand Up @@ -797,6 +800,11 @@ export type MutationAddManualPaymentToOrderArgs = {
};


export type MutationCreatePaymentMethodArgs = {
input: CreatePaymentMethodInput;
};


export type MutationUpdatePaymentMethodArgs = {
input: UpdatePaymentMethodInput;
};
Expand Down Expand Up @@ -1106,6 +1114,7 @@ export type CreateChannelInput = {
currencyCode: CurrencyCode;
defaultTaxZoneId: Scalars['ID'];
defaultShippingZoneId: Scalars['ID'];
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateChannelInput = {
Expand All @@ -1117,6 +1126,7 @@ export type UpdateChannelInput = {
currencyCode?: Maybe<CurrencyCode>;
defaultTaxZoneId?: Maybe<Scalars['ID']>;
defaultShippingZoneId?: Maybe<Scalars['ID']>;
customFields?: Maybe<Scalars['JSON']>;
};

/** Returned if attempting to set a Channel's defaultLanguageCode to a language which is not enabled in GlobalSettings */
Expand Down Expand Up @@ -1428,7 +1438,7 @@ export type ImportInfo = {
/**
* @description
* The state of a Job in the JobQueue
*
*
* @docsCategory common
*/
export enum JobState {
Expand Down Expand Up @@ -1878,22 +1888,33 @@ export type PaymentMethodList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type CreatePaymentMethodInput = {
name: Scalars['String'];
code: Scalars['String'];
description?: Maybe<Scalars['String']>;
enabled: Scalars['Boolean'];
handler: ConfigurableOperationInput;
};

export type UpdatePaymentMethodInput = {
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
code?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
enabled?: Maybe<Scalars['Boolean']>;
configArgs?: Maybe<Array<ConfigArgInput>>;
handler?: Maybe<ConfigurableOperationInput>;
};

export type PaymentMethod = Node & {
__typename?: 'PaymentMethod';
id: Scalars['ID'];
createdAt: Scalars['DateTime'];
updatedAt: Scalars['DateTime'];
name: Scalars['String'];
code: Scalars['String'];
description: Scalars['String'];
enabled: Scalars['Boolean'];
configArgs: Array<ConfigArg>;
definition: ConfigurableOperationDefinition;
handler: ConfigurableOperation;
};

export type Product = Node & {
Expand Down Expand Up @@ -2452,6 +2473,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type CollectionBreadcrumb = {
Expand Down Expand Up @@ -2506,7 +2528,7 @@ export enum DeletionResult {
* @description
* Permissions for administrators and customers. Used to control access to
* GraphQL resolvers via the {@link Allow} decorator.
*
*
* @docsCategory common
*/
export enum Permission {
Expand Down Expand Up @@ -2883,7 +2905,7 @@ export type CountryList = PaginatedList & {
/**
* @description
* ISO 4217 currency code
*
*
* @docsCategory common
*/
export enum CurrencyCode {
Expand Down Expand Up @@ -3420,7 +3442,7 @@ export type HistoryEntryList = PaginatedList & {
* region or script modifier (e.g. de_AT). The selection available is based
* on the [Unicode CLDR summary list](https://unicode-org.github.io/cldr-staging/charts/37/summary/root.html)
* and includes the major spoken languages of the world and any widely-used variants.
*
*
* @docsCategory common
*/
export enum LanguageCode {
Expand Down Expand Up @@ -3809,7 +3831,7 @@ export type OrderItem = Node & {
unitPriceWithTax: Scalars['Int'];
/**
* The price of a single unit including discounts, excluding tax.
*
*
* If Order-level discounts have been applied, this will not be the
* actual taxable unit price (see `proratedUnitPrice`), but is generally the
* correct price to display to customers to avoid confusion
Expand Down Expand Up @@ -3849,7 +3871,7 @@ export type OrderLine = Node & {
unitPriceWithTax: Scalars['Int'];
/**
* The price of a single unit including discounts, excluding tax.
*
*
* If Order-level discounts have been applied, this will not be the
* actual taxable unit price (see `proratedUnitPrice`), but is generally the
* correct price to display to customers to avoid confusion
Expand Down Expand Up @@ -4506,15 +4528,19 @@ export type OrderSortParameter = {
export type PaymentMethodFilterParameter = {
createdAt?: Maybe<DateOperators>;
updatedAt?: Maybe<DateOperators>;
name?: Maybe<StringOperators>;
code?: Maybe<StringOperators>;
description?: Maybe<StringOperators>;
enabled?: Maybe<BooleanOperators>;
};

export type PaymentMethodSortParameter = {
id?: Maybe<SortOrder>;
createdAt?: Maybe<SortOrder>;
updatedAt?: Maybe<SortOrder>;
name?: Maybe<SortOrder>;
code?: Maybe<SortOrder>;
description?: Maybe<SortOrder>;
};

export type ProductFilterParameter = {
Expand Down Expand Up @@ -4678,6 +4704,7 @@ export type NativeAuthInput = {
export type CustomFields = {
__typename?: 'CustomFields';
Address: Array<CustomFieldConfig>;
Channel: Array<CustomFieldConfig>;
Collection: Array<CustomFieldConfig>;
Customer: Array<CustomFieldConfig>;
Facet: Array<CustomFieldConfig>;
Expand Down
10 changes: 9 additions & 1 deletion packages/core/e2e/fulfillment-process.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ describe('Fulfillment process', () => {

beforeAll(async () => {
await server.init({
initialData,
initialData: {
...initialData,
paymentMethods: [
{
name: testSuccessfulPaymentMethod.code,
handler: { code: testSuccessfulPaymentMethod.code, arguments: [] },
},
],
},
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
customerCount: 1,
});
Expand Down
Loading

0 comments on commit ee9ba23

Please sign in to comment.