-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from vuestorefront/feat-#56/payment-provider
feat: #56/payment provider
- Loading branch information
Showing
32 changed files
with
910 additions
and
32 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/getPaymentMethods.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import getPaymentMethods from '../../src/api/getPaymentMethods'; | ||
import eligiblePaymentMethodsQuery from '../../src/api/getPaymentMethods/eligiblePaymentMethodsQuery'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] getPaymentMethods', () => { | ||
it('returns shipping methods', async () => { | ||
const givenVariables = {}; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
query: ({ variables, query }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(query).toEqual(eligiblePaymentMethodsQuery); | ||
|
||
return { data: 'get payment methods response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await getPaymentMethods(context); | ||
|
||
expect(data).toBe('get payment methods response'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/setCustomerForOrder.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import setCustomerForOrder from '../../src/api/setCustomerForOrder'; | ||
import setCustomerForOrderMutation from '../../src/api/setCustomerForOrder/setCustomerForOrderMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setCustomerForOrder', () => { | ||
it('sets customer for certain order', async () => { | ||
const givenVariables = { firstName: 'test', lastName: 'test', emailAddress: 'test@test.com' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual({ input: givenVariables }); | ||
expect(mutation).toEqual(setCustomerForOrderMutation); | ||
|
||
return { data: 'set customer for order response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setCustomerForOrder(context, givenVariables); | ||
|
||
expect(data).toBe('set customer for order response'); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/api-client/__tests__/api/setPaymentMethod.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import setPaymentMethod from '../../src/api/setPaymentMethod'; | ||
import addPaymentToOrderMutation from '../../src/api/setPaymentMethod/addPaymentToOrderMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setPaymentMethod', () => { | ||
it('sets payment method for certain order', async () => { | ||
const givenVariables = { metadata: {}, method: 'test' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual({ input: givenVariables }); | ||
expect(mutation).toEqual(addPaymentToOrderMutation); | ||
|
||
return { data: 'set payment method response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setPaymentMethod(context, { method: 'test' }); | ||
|
||
const expectedSetPaymentResponse = 'set payment method response'; | ||
|
||
expect(data).toBe(expectedSetPaymentResponse); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/api-client/__tests__/api/transitionOrderToState.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import transitionOrderToState from '../../src/api/transitionOrderToState'; | ||
import transitionOrderToStateMutation from '../../src/api/transitionOrderToState/transitionOrderToStateMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] transitionOrderToState', () => { | ||
it('sets payment method for certain order', async () => { | ||
const givenVariables = { state: 'test' }; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(mutation).toEqual(transitionOrderToStateMutation); | ||
|
||
return { data: 'transition order to state response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await transitionOrderToState(context, { state: 'test' }); | ||
|
||
expect(data).toBe('transition order to state response'); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/getPaymentMethods/eligiblePaymentMethodsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
export default gql` | ||
query eligiblePaymentMethods { | ||
eligiblePaymentMethods { | ||
id | ||
code | ||
name | ||
description | ||
isEligible | ||
eligibilityMessage | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gql from 'graphql-tag'; | ||
import eligiblePaymentMethodsQuery from './eligiblePaymentMethodsQuery'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import { Context, RequestDataStructure, PaymentMethodQuote, GetPaymentMethodsResponse } from '../../types'; | ||
import { NO_CACHE_FETCH_POLICY } from '../../helpers'; | ||
|
||
const getPaymentMethods = async (context: Context, customQuery?: CustomQuery): Promise<GetPaymentMethodsResponse> => { | ||
const getPaymentMethodsVariables = {}; | ||
|
||
const { eligiblePaymentMethods } = context.extendQuery( | ||
customQuery, { eligiblePaymentMethods: { query: eligiblePaymentMethodsQuery, variables: getPaymentMethodsVariables } } | ||
); | ||
|
||
const request = await context.client.query<RequestDataStructure<'eligiblePaymentMethods', PaymentMethodQuote[]>>({ | ||
query: gql`${eligiblePaymentMethods.query}`, | ||
variables: eligiblePaymentMethods.variables, | ||
fetchPolicy: NO_CACHE_FETCH_POLICY | ||
}); | ||
return request; | ||
|
||
}; | ||
|
||
export default getPaymentMethods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import setCustomerForOrderMutation from './setCustomerForOrderMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, CreateCustomerInput, SetCustomerForOrderResponse } from '../../types'; | ||
import { NO_CACHE_FETCH_POLICY } from '../../helpers'; | ||
|
||
const setCustomerForOrder = async (context: Context, params: CreateCustomerInput, customQuery?: CustomQuery): Promise<SetCustomerForOrderResponse> => { | ||
const setCustomerForOrderVariables = { | ||
input: params | ||
}; | ||
|
||
const { setCustomerForOrder } = context.extendQuery( | ||
customQuery, { setCustomerForOrder: { query: setCustomerForOrderMutation, variables: setCustomerForOrderVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${setCustomerForOrder.query}`, | ||
variables: setCustomerForOrder.variables, | ||
fetchPolicy: NO_CACHE_FETCH_POLICY | ||
}) as SetCustomerForOrderResponse; | ||
|
||
return request; | ||
}; | ||
|
||
export default setCustomerForOrder; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/setCustomerForOrder/setCustomerForOrderMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import gql from 'graphql-tag'; | ||
import { CartFragment, ErrorResultFragment } from '../../fragments'; | ||
|
||
export default gql` | ||
${CartFragment} | ||
${ErrorResultFragment} | ||
mutation setCustomerForOrder($input: CreateCustomerInput!) { | ||
setCustomerForOrder(input: $input) { | ||
...Cart | ||
...ErrorResult | ||
} | ||
} | ||
`; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/setPaymentMethod/addPaymentToOrderMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import gql from 'graphql-tag'; | ||
import { CartFragment, ErrorResultFragment } from '../../fragments'; | ||
|
||
export default gql` | ||
${CartFragment} | ||
${ErrorResultFragment} | ||
mutation addPaymentToOrder($input: PaymentInput!) { | ||
addPaymentToOrder(input: $input) { | ||
...Cart | ||
...ErrorResult | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import addPaymentToOrderMutation from './addPaymentToOrderMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { AddPaymentToOrderParams, Context, PaymentInput, SetShippingMethodResponse } from '../../types'; | ||
import { NO_CACHE_FETCH_POLICY } from '../../helpers'; | ||
|
||
const setPaymentMethod = async (context: Context, params: AddPaymentToOrderParams, customQuery?: CustomQuery): Promise<SetShippingMethodResponse> => { | ||
const setPaymentMethodVariables = { | ||
input: { | ||
method: params.method, | ||
metadata: { | ||
// Here you would pass data from an external Payment Provided after successful payment process like payment id. | ||
} | ||
} as PaymentInput | ||
}; | ||
|
||
const { addPaymentToOrder } = context.extendQuery( | ||
customQuery, { addPaymentToOrder: { query: addPaymentToOrderMutation, variables: setPaymentMethodVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${addPaymentToOrder.query}`, | ||
variables: addPaymentToOrder.variables, | ||
fetchPolicy: NO_CACHE_FETCH_POLICY | ||
}) as SetShippingMethodResponse; | ||
|
||
return request; | ||
}; | ||
|
||
export default setPaymentMethod; |
25 changes: 25 additions & 0 deletions
25
packages/api-client/src/api/transitionOrderToState/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import transitionOrderToStateMutation from './transitionOrderToStateMutation'; | ||
import { CustomQuery } from '@vue-storefront/core'; | ||
import gql from 'graphql-tag'; | ||
import { Context, TransitionOrderToState, TransitionOrderToStateParams } from '../../types'; | ||
import { NO_CACHE_FETCH_POLICY } from '../../helpers'; | ||
|
||
const transitionOrderToState = async (context: Context, params: TransitionOrderToStateParams, customQuery?: CustomQuery): Promise<TransitionOrderToState> => { | ||
const transitionOrderToStateVariables = { | ||
...params | ||
}; | ||
|
||
const { transitionOrderToState } = context.extendQuery( | ||
customQuery, { transitionOrderToState: { query: transitionOrderToStateMutation, variables: transitionOrderToStateVariables } } | ||
); | ||
|
||
const request = await context.client.mutate({ | ||
mutation: gql`${transitionOrderToState.query}`, | ||
variables: transitionOrderToState.variables, | ||
fetchPolicy: NO_CACHE_FETCH_POLICY | ||
}) as TransitionOrderToState; | ||
|
||
return request; | ||
}; | ||
|
||
export default transitionOrderToState; |
14 changes: 14 additions & 0 deletions
14
packages/api-client/src/api/transitionOrderToState/transitionOrderToStateMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import gql from 'graphql-tag'; | ||
import { CartFragment, ErrorResultFragment } from '../../fragments'; | ||
|
||
export default gql` | ||
${CartFragment} | ||
${ErrorResultFragment} | ||
mutation transitionOrderToState($state: String!) { | ||
transitionOrderToState(state: $state) { | ||
...Cart | ||
...ErrorResult | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Order } from '../types'; | ||
|
||
export const isCustomerDataFilled = (order: Order): boolean => { | ||
if (!order) return; | ||
return Boolean(order?.customer?.emailAddress && order?.billingAddress?.streetLine1 && order?.shippingAddress?.streetLine1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const VENDURE_AUTH_TOKEN_NAME = 'vendure-auth-token'; | ||
export const BILLING_TYPE = 'billing'; | ||
export const ARRANGING_PAYMENT_STATE = 'ArrangingPayment'; | ||
export const NO_CACHE_FETCH_POLICY = 'no-cache'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants'; | ||
export * from './checkout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.