Skip to content

Commit

Permalink
feat(core): Implement eligibility checking for PaymentMethods
Browse files Browse the repository at this point in the history
Relates to #469
  • Loading branch information
michaelbromley committed Jan 29, 2021
1 parent ee9ba23 commit 690514a
Show file tree
Hide file tree
Showing 29 changed files with 511 additions and 94 deletions.
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>;
paymentMethodEligibilityCheckers: Array<ConfigurableOperationDefinition>;
paymentMethodHandlers: Array<ConfigurableOperationDefinition>;
productOptionGroups: Array<ProductOptionGroup>;
productOptionGroup?: Maybe<ProductOptionGroup>;
Expand Down Expand Up @@ -1735,6 +1736,7 @@ export type CreatePaymentMethodInput = {
code: Scalars['String'];
description?: Maybe<Scalars['String']>;
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperationInput>;
handler: ConfigurableOperationInput;
};

Expand All @@ -1744,6 +1746,7 @@ export type UpdatePaymentMethodInput = {
code?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
enabled?: Maybe<Scalars['Boolean']>;
checker?: Maybe<ConfigurableOperationInput>;
handler?: Maybe<ConfigurableOperationInput>;
};

Expand All @@ -1755,6 +1758,7 @@ export type PaymentMethod = Node & {
code: Scalars['String'];
description: Scalars['String'];
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperation>;
handler: ConfigurableOperation;
};

Expand Down Expand Up @@ -2679,6 +2683,16 @@ export type Success = {
success: Scalars['Boolean'];
};

export type ShippingMethodQuote = {
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
/** Any optional metadata returned by the ShippingCalculator in the ShippingCalculationResult */
metadata?: Maybe<Scalars['JSON']>;
};

export type Country = Node & {
id: Scalars['ID'];
createdAt: Scalars['DateTime'];
Expand Down Expand Up @@ -3587,15 +3601,6 @@ export type OrderList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type ShippingMethodQuote = {
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
metadata?: Maybe<Scalars['JSON']>;
};

export type ShippingLine = {
shippingMethod: ShippingMethod;
price: Scalars['Int'];
Expand Down
33 changes: 22 additions & 11 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ export enum ErrorCode {
ORDER_MODIFICATION_ERROR = 'ORDER_MODIFICATION_ERROR',
INELIGIBLE_SHIPPING_METHOD_ERROR = 'INELIGIBLE_SHIPPING_METHOD_ERROR',
ORDER_PAYMENT_STATE_ERROR = 'ORDER_PAYMENT_STATE_ERROR',
INELIGIBLE_PAYMENT_METHOD_ERROR = 'INELIGIBLE_PAYMENT_METHOD_ERROR',
PAYMENT_FAILED_ERROR = 'PAYMENT_FAILED_ERROR',
PAYMENT_DECLINED_ERROR = 'PAYMENT_DECLINED_ERROR',
COUPON_CODE_INVALID_ERROR = 'COUPON_CODE_INVALID_ERROR',
Expand Down Expand Up @@ -788,6 +789,17 @@ export type Success = {
success: Scalars['Boolean'];
};

export type ShippingMethodQuote = {
__typename?: 'ShippingMethodQuote';
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
/** Any optional metadata returned by the ShippingCalculator in the ShippingCalculationResult */
metadata?: Maybe<Scalars['JSON']>;
};

export type Country = Node & {
__typename?: 'Country';
id: Scalars['ID'];
Expand Down Expand Up @@ -1826,16 +1838,6 @@ export type OrderList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type ShippingMethodQuote = {
__typename?: 'ShippingMethodQuote';
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
metadata?: Maybe<Scalars['JSON']>;
};

export type ShippingLine = {
__typename?: 'ShippingLine';
shippingMethod: ShippingMethod;
Expand Down Expand Up @@ -2336,7 +2338,7 @@ export type OrderModificationError = ErrorResult & {
message: Scalars['String'];
};

/** Returned when attempting to set a ShippingMethod for which the order is not eligible */
/** Returned when attempting to set a ShippingMethod for which the Order is not eligible */
export type IneligibleShippingMethodError = ErrorResult & {
__typename?: 'IneligibleShippingMethodError';
errorCode: ErrorCode;
Expand All @@ -2350,6 +2352,14 @@ export type OrderPaymentStateError = ErrorResult & {
message: Scalars['String'];
};

/** Returned when attempting to add a Payment using a PaymentMethod for which the Order is not eligible. */
export type IneligiblePaymentMethodError = ErrorResult & {
__typename?: 'IneligiblePaymentMethodError';
errorCode: ErrorCode;
message: Scalars['String'];
eligibilityCheckerMessage?: Maybe<Scalars['String']>;
};

/** Returned when a Payment fails due to an error. */
export type PaymentFailedError = ErrorResult & {
__typename?: 'PaymentFailedError';
Expand Down Expand Up @@ -2545,6 +2555,7 @@ export type ApplyCouponCodeResult =
export type AddPaymentToOrderResult =
| Order
| OrderPaymentStateError
| IneligiblePaymentMethodError
| PaymentFailedError
| PaymentDeclinedError
| OrderStateTransitionError
Expand Down
25 changes: 15 additions & 10 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>;
paymentMethodEligibilityCheckers: Array<ConfigurableOperationDefinition>;
paymentMethodHandlers: Array<ConfigurableOperationDefinition>;
productOptionGroups: Array<ProductOptionGroup>;
productOptionGroup?: Maybe<ProductOptionGroup>;
Expand Down Expand Up @@ -1893,6 +1894,7 @@ export type CreatePaymentMethodInput = {
code: Scalars['String'];
description?: Maybe<Scalars['String']>;
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperationInput>;
handler: ConfigurableOperationInput;
};

Expand All @@ -1902,6 +1904,7 @@ export type UpdatePaymentMethodInput = {
code?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
enabled?: Maybe<Scalars['Boolean']>;
checker?: Maybe<ConfigurableOperationInput>;
handler?: Maybe<ConfigurableOperationInput>;
};

Expand All @@ -1914,6 +1917,7 @@ export type PaymentMethod = Node & {
code: Scalars['String'];
description: Scalars['String'];
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperation>;
handler: ConfigurableOperation;
};

Expand Down Expand Up @@ -2875,6 +2879,17 @@ export type Success = {
success: Scalars['Boolean'];
};

export type ShippingMethodQuote = {
__typename?: 'ShippingMethodQuote';
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
/** Any optional metadata returned by the ShippingCalculator in the ShippingCalculationResult */
metadata?: Maybe<Scalars['JSON']>;
};

export type Country = Node & {
__typename?: 'Country';
id: Scalars['ID'];
Expand Down Expand Up @@ -3799,16 +3814,6 @@ export type OrderList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type ShippingMethodQuote = {
__typename?: 'ShippingMethodQuote';
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
metadata?: Maybe<Scalars['JSON']>;
};

export type ShippingLine = {
__typename?: 'ShippingLine';
shippingMethod: ShippingMethod;
Expand Down
71 changes: 62 additions & 9 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
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>;
paymentMethodEligibilityCheckers: Array<ConfigurableOperationDefinition>;
paymentMethodHandlers: Array<ConfigurableOperationDefinition>;
productOptionGroups: Array<ProductOptionGroup>;
productOptionGroup?: Maybe<ProductOptionGroup>;
Expand Down Expand Up @@ -1735,6 +1736,7 @@ export type CreatePaymentMethodInput = {
code: Scalars['String'];
description?: Maybe<Scalars['String']>;
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperationInput>;
handler: ConfigurableOperationInput;
};

Expand All @@ -1744,6 +1746,7 @@ export type UpdatePaymentMethodInput = {
code?: Maybe<Scalars['String']>;
description?: Maybe<Scalars['String']>;
enabled?: Maybe<Scalars['Boolean']>;
checker?: Maybe<ConfigurableOperationInput>;
handler?: Maybe<ConfigurableOperationInput>;
};

Expand All @@ -1755,6 +1758,7 @@ export type PaymentMethod = Node & {
code: Scalars['String'];
description: Scalars['String'];
enabled: Scalars['Boolean'];
checker?: Maybe<ConfigurableOperation>;
handler: ConfigurableOperation;
};

Expand Down Expand Up @@ -2679,6 +2683,16 @@ export type Success = {
success: Scalars['Boolean'];
};

export type ShippingMethodQuote = {
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
/** Any optional metadata returned by the ShippingCalculator in the ShippingCalculationResult */
metadata?: Maybe<Scalars['JSON']>;
};

export type Country = Node & {
id: Scalars['ID'];
createdAt: Scalars['DateTime'];
Expand Down Expand Up @@ -3587,15 +3601,6 @@ export type OrderList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type ShippingMethodQuote = {
id: Scalars['ID'];
price: Scalars['Int'];
priceWithTax: Scalars['Int'];
name: Scalars['String'];
description: Scalars['String'];
metadata?: Maybe<Scalars['JSON']>;
};

export type ShippingLine = {
shippingMethod: ShippingMethod;
price: Scalars['Int'];
Expand Down Expand Up @@ -6039,6 +6044,26 @@ export type UpdatePaymentMethodMutationVariables = Exact<{

export type UpdatePaymentMethodMutation = { updatePaymentMethod: PaymentMethodFragment };

export type GetPaymentMethodHandlersQueryVariables = Exact<{ [key: string]: never }>;

export type GetPaymentMethodHandlersQuery = {
paymentMethodHandlers: Array<
Pick<ConfigurableOperationDefinition, 'code'> & {
args: Array<Pick<ConfigArgDefinition, 'name' | 'type'>>;
}
>;
};

export type GetPaymentMethodCheckersQueryVariables = Exact<{ [key: string]: never }>;

export type GetPaymentMethodCheckersQuery = {
paymentMethodEligibilityCheckers: Array<
Pick<ConfigurableOperationDefinition, 'code'> & {
args: Array<Pick<ConfigArgDefinition, 'name' | 'type'>>;
}
>;
};

export type UpdateProductOptionGroupMutationVariables = Exact<{
input: UpdateProductOptionGroupInput;
}>;
Expand Down Expand Up @@ -8142,6 +8167,34 @@ export namespace UpdatePaymentMethod {
export type UpdatePaymentMethod = NonNullable<UpdatePaymentMethodMutation['updatePaymentMethod']>;
}

export namespace GetPaymentMethodHandlers {
export type Variables = GetPaymentMethodHandlersQueryVariables;
export type Query = GetPaymentMethodHandlersQuery;
export type PaymentMethodHandlers = NonNullable<
NonNullable<GetPaymentMethodHandlersQuery['paymentMethodHandlers']>[number]
>;
export type Args = NonNullable<
NonNullable<
NonNullable<NonNullable<GetPaymentMethodHandlersQuery['paymentMethodHandlers']>[number]>['args']
>[number]
>;
}

export namespace GetPaymentMethodCheckers {
export type Variables = GetPaymentMethodCheckersQueryVariables;
export type Query = GetPaymentMethodCheckersQuery;
export type PaymentMethodEligibilityCheckers = NonNullable<
NonNullable<GetPaymentMethodCheckersQuery['paymentMethodEligibilityCheckers']>[number]
>;
export type Args = NonNullable<
NonNullable<
NonNullable<
NonNullable<GetPaymentMethodCheckersQuery['paymentMethodEligibilityCheckers']>[number]
>['args']
>[number]
>;
}

export namespace UpdateProductOptionGroup {
export type Variables = UpdateProductOptionGroupMutationVariables;
export type Mutation = UpdateProductOptionGroupMutation;
Expand Down
Loading

0 comments on commit 690514a

Please sign in to comment.