-
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 #51 from vuestorefront/feat-#49/shipping-billing
feat: #49/shipping billing
- Loading branch information
Showing
66 changed files
with
1,861 additions
and
130 deletions.
There are no files selected for viewing
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,74 @@ | ||
# `useBilling` | ||
|
||
## Features | ||
|
||
`useBilling` composable can be used for: | ||
|
||
* Loading billing address for the current cart. | ||
* Saving billing address for the current cart. | ||
|
||
## API | ||
|
||
* `load` - function for fetching billing address. When invoked, it requests data from the API and populates `billing` property. This method accepts a single optional `params` object. The `params` has the following option: | ||
|
||
* `customQuery?: CustomQuery` | ||
|
||
```ts | ||
type CustomQuery = { | ||
getBasicProfile: string | ||
} | ||
``` | ||
* `save` - function for saving billing address. This method accepts a single `saveParams` object. The `saveParams` has the following options: | ||
* `billingDetails: CreateAddressInput` | ||
<https://www.vendure.io/docs/graphql-api/admin/input-types/#createaddressinput> | ||
* `customQuery?: CustomQuery` | ||
```ts | ||
type CustomQuery = { | ||
updateCart: string | ||
} | ||
``` | ||
* `billing: OrderAddress` - a main data object that contains a billing address. | ||
<https://www.vendure.io/docs/graphql-api/admin/object-types/#orderaddress> | ||
* `loading: boolean` - a reactive object containing information about loading state of your `load` or `save` method. | ||
* `error: UseBillingErrors` - a reactive object containing the error message, if `load` or `save` failed for any reason. | ||
```ts | ||
interface UseBillingErrors { | ||
load?: Error; | ||
save?: Error; | ||
} | ||
``` | ||
|
||
## Getters | ||
|
||
We do not provide getters for checkout and its parts. | ||
|
||
## Example | ||
|
||
```js | ||
import { useBilling } from '@vue-storefront/vendure'; | ||
import { onSSR } from '@vue-storefront/core' | ||
|
||
export default { | ||
setup () { | ||
const { load, billing } = useBilling(); | ||
|
||
onSSR(async () => { | ||
await load(); | ||
}); | ||
|
||
return { | ||
billing | ||
}; | ||
} | ||
} | ||
``` |
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,81 @@ | ||
# `useShippingProvider` | ||
|
||
## Features | ||
|
||
`useShippingProvider` composable can be used for: | ||
|
||
* Loading shipping methods for the current cart. | ||
|
||
## API | ||
|
||
* `load` - function for fetching shipping method. When invoked, it requests data from the API and populates the `response` key inside the `state` property. This method accepts a single optional `params` object. The `params` has the following option: | ||
|
||
* `customQuery?: CustomQuery` | ||
|
||
```ts | ||
type CustomQuery = { | ||
getBasicProfile: string | ||
} | ||
``` | ||
* `save` - not used in this integration. | ||
::: warning | ||
This integration does not use the `save` method. Instead a direct call from the theme to the API Client is being made and the response is saved as a new Cart object to update prices, details, etc. It works as follows: | ||
```ts | ||
import { useCart, useShippingProvider } from '@vue-storefront/vendure'; | ||
|
||
export default { | ||
setup () { | ||
const { setCart } = useCart(); | ||
|
||
const setShippingMethod = (shippingMethod) => { | ||
const newOrder = await $vendure.api.setShippingMethod({ shippingMethodId: shippingMethod.id }) | ||
setCart(newOrder.data.setOrderShippingMethod); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
::: | ||
|
||
* `state: ShippingMethodQuote[]` - a main data object that contains shipping methods | ||
|
||
<https://www.vendure.io/docs/graphql-api/shop/object-types/#shippingmethodquote> | ||
|
||
* `loading: boolean` - a reactive object containing information about loading state of your `load` or `save` method. | ||
|
||
* `error: UseShippingProviderErrors` - a reactive object containing the error message, if `load` or `save` failed for any reason. | ||
|
||
```ts | ||
interface UseShippingProviderErrors { | ||
load?: Error; | ||
save?: Error; | ||
} | ||
``` | ||
|
||
## Getters | ||
|
||
We do not provide getters for checkout and its parts. | ||
|
||
## Example | ||
|
||
```js | ||
import { useShippingProvider } from '@vue-storefront/vendure'; | ||
import { onSSR } from '@vue-storefront/core'; | ||
|
||
export default { | ||
setup () { | ||
const { load, state } = useShippingProvider(); | ||
|
||
onSSR(async () => { | ||
await load(); | ||
}); | ||
|
||
return { | ||
state | ||
}; | ||
} | ||
} | ||
``` |
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,74 @@ | ||
# `useShipping` | ||
|
||
## Features | ||
|
||
`useShipping` composable can be used for: | ||
|
||
* Loading shipping address for the current cart. | ||
* Saving shipping address for the current cart. | ||
|
||
## API | ||
|
||
* `load` - function for fetching shipping address. When invoked, it requests data from the API and populates `shipping` property. This method accepts a single optional `params` object. The `params` has the following option: | ||
|
||
* `customQuery?: CustomQuery` | ||
|
||
```ts | ||
type CustomQuery = { | ||
getBasicProfile: string | ||
} | ||
``` | ||
* `save` - function for saving shipping address. This method accepts a single `saveParams` object. The `saveParams` has the following options: | ||
* `shippingDetails: CreateAddressInput` | ||
<https://www.vendure.io/docs/graphql-api/admin/input-types/#createaddressinput> | ||
* `customQuery?: CustomQuery` | ||
```ts | ||
type CustomQuery = { | ||
updateCart: string | ||
} | ||
``` | ||
* `shipping: OrderAddress` - a main data object that contains a shipping address. | ||
<https://www.vendure.io/docs/graphql-api/admin/object-types/#orderaddress> | ||
* `loading: boolean` - a reactive object containing information about loading state of your `load` or `save` method. | ||
* `error: UseShippingErrors` - a reactive object containing the error message, if `load` or `save` failed for any reason. | ||
```ts | ||
interface UseShippingErrors { | ||
load?: Error; | ||
save?: Error; | ||
} | ||
``` | ||
|
||
## Getters | ||
|
||
We do not provide getters for checkout and its parts. | ||
|
||
## Example | ||
|
||
```js | ||
import { useShipping } from '@vue-storefront/vendure'; | ||
import { onSSR } from '@vue-storefront/core'; | ||
|
||
export default { | ||
setup () { | ||
const { load, shipping } = useShipping(); | ||
|
||
onSSR(async () => { | ||
await load(); | ||
}); | ||
|
||
return { | ||
shipping | ||
}; | ||
} | ||
} | ||
``` |
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
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
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
28 changes: 28 additions & 0 deletions
28
packages/api-client/__tests__/api/getShippingMethods.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 getShippingMethods from '../../src/api/getShippingMethods'; | ||
import eligibleShippingMethodsQuery from '../../src/api/getShippingMethods/eligibleShippingMethodsQuery'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] getShippingMethods', () => { | ||
it('returns shipping methods', async () => { | ||
const givenVariables = {}; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
query: ({ variables, query }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(query).toEqual(eligibleShippingMethodsQuery); | ||
|
||
return { data: 'get shipping methods response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await getShippingMethods(context); | ||
|
||
const expectedGetShippingMethods = 'get shipping methods response'; | ||
|
||
expect(data).toBe(expectedGetShippingMethods); | ||
}); | ||
}); |
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
28 changes: 28 additions & 0 deletions
28
packages/api-client/__tests__/api/setShippingMethod.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 setShippingMethod from '../../src/api/setShippingMethod'; | ||
import setOrderShippingMethodMutation from '../../src/api/setShippingMethod/setOrderShippingMethodMutation'; | ||
import { Context } from '../../src/types'; | ||
|
||
describe('[vendure-api-client] setShippingMethod', () => { | ||
it('sets shipping method for certain order', async () => { | ||
const givenVariables = { shippingMethodId: '1'}; | ||
|
||
const context = { | ||
config: {}, | ||
client: { | ||
mutate: ({ variables, mutation }) => { | ||
expect(variables).toEqual(givenVariables); | ||
expect(mutation).toEqual(setOrderShippingMethodMutation); | ||
|
||
return { data: 'set shipping method response' }; | ||
} | ||
}, | ||
extendQuery: (customQuery, args) => args | ||
} as unknown as Context; | ||
|
||
const { data } = await setShippingMethod(context, { shippingMethodId: '1' }); | ||
|
||
const expectedShippingMethod = 'set shipping method response'; | ||
|
||
expect(data).toBe(expectedShippingMethod); | ||
}); | ||
}); |
Oops, something went wrong.