Skip to content

Commit

Permalink
Add ordercloud provider (vercel#500)
Browse files Browse the repository at this point in the history
* Add ordercloud provider

* Fix provider errors

* Make submit checkout optional

* Make submit checkout optional

* Remove nullables when creating endpoint type

* Update readme

* Log checkout error

* Log error

* Save token to cookie

* Update fetch rest

* Use token at checkout

Co-authored-by: Luis Alvarez <[email protected]>
  • Loading branch information
goncy and lfades authored Oct 5, 2021
1 parent f9644fe commit 3f0c384
Show file tree
Hide file tree
Showing 90 changed files with 2,560 additions and 76 deletions.
4 changes: 4 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ NEXT_PUBLIC_SALEOR_CHANNEL=

NEXT_PUBLIC_VENDURE_SHOP_API_URL=
NEXT_PUBLIC_VENDURE_LOCAL_URL=

ORDERCLOUD_CLIENT_ID=
ORDERCLOUD_CLIENT_SECRET=
STRIPE_SECRET=
4 changes: 2 additions & 2 deletions framework/commerce/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export type EndpointHandlers<
[H in keyof E['handlers']]: APIHandler<
C,
EndpointHandlers<C, E>,
E['handlers'][H]['data'],
E['handlers'][H]['body'],
NonNullable<E['handlers'][H]>['data'],
NonNullable<E['handlers'][H]>['body'],
E['options']
>
}
Expand Down
1 change: 1 addition & 0 deletions framework/commerce/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PROVIDERS = [
'shopify',
'swell',
'vendure',
'ordercloud',
]

function getProviderName() {
Expand Down
2 changes: 1 addition & 1 deletion framework/commerce/types/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type GetCheckoutHook<T extends CheckoutTypes = CheckoutTypes> = {
}

export type CheckoutHooks<T extends CheckoutTypes = CheckoutTypes> = {
submitCheckout: SubmitCheckoutHook<T>
submitCheckout?: SubmitCheckoutHook<T>
getCheckout: GetCheckoutHook<T>
}

Expand Down
98 changes: 58 additions & 40 deletions framework/commerce/types/customer/address.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,109 @@
export interface Address {
id: string;
mask: string;
id: string
mask: string
}

export interface AddressFields {
type: string;
firstName: string;
lastName: string;
company: string;
streetNumber: string;
apartments: string;
zipCode: string;
city: string;
country: string;
type: string
firstName: string
lastName: string
company: string
streetNumber: string
apartments: string
zipCode: string
city: string
country: string
}

export type CustomerAddressTypes = {
address?: Address;
fields: AddressFields;
address?: Address
fields: AddressFields
}

export type GetAddressesHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address'] | null
export type GetAddressesHook<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
data: T['address'][] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
}

export type AddItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
data: T['address']
input?: T['fields']
fetcherInput: T['fields']
body: { item: T['fields'] }
actionInput: T['fields']
}
export type AddItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> =
{
data: T['address']
input?: T['fields']
fetcherInput: T['fields']
body: { item: T['fields'] }
actionInput: T['fields']
}

export type UpdateItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
export type UpdateItemHook<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
data: T['address'] | null
input: { item?: T['fields']; wait?: number }
fetcherInput: { itemId: string; item: T['fields'] }
body: { itemId: string; item: T['fields'] }
actionInput: T['fields'] & { id: string }
}

export type RemoveItemHook<T extends CustomerAddressTypes = CustomerAddressTypes> = {
export type RemoveItemHook<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
data: T['address'] | null
input: { item?: T['fields'] }
input: { item?: T['address'] }
fetcherInput: { itemId: string }
body: { itemId: string }
actionInput: { id: string }
}

export type CustomerAddressHooks<T extends CustomerAddressTypes = CustomerAddressTypes> = {
export type CustomerAddressHooks<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
getAddresses: GetAddressesHook<T>
addItem: AddItemHook<T>
updateItem: UpdateItemHook<T>
removeItem: RemoveItemHook<T>
}

export type AddresssHandler<T extends CustomerAddressTypes = CustomerAddressTypes> = GetAddressesHook<T> & {
export type AddressHandler<
T extends CustomerAddressTypes = CustomerAddressTypes
> = GetAddressesHook<T> & {
body: { cartId?: string }
}

export type AddItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> = AddItemHook<T> & {
export type AddItemHandler<
T extends CustomerAddressTypes = CustomerAddressTypes
> = AddItemHook<T> & {
body: { cartId: string }
}

export type UpdateItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> =
UpdateItemHook<T> & {
data: T['address']
body: { cartId: string }
}

export type RemoveItemHandler<T extends CustomerAddressTypes = CustomerAddressTypes> =
RemoveItemHook<T> & {
body: { cartId: string }
}
export type UpdateItemHandler<
T extends CustomerAddressTypes = CustomerAddressTypes
> = UpdateItemHook<T> & {
data: T['address']
body: { cartId: string }
}

export type RemoveItemHandler<
T extends CustomerAddressTypes = CustomerAddressTypes
> = RemoveItemHook<T> & {
body: { cartId: string }
}

export type CustomerAddressHandlers<T extends CustomerAddressTypes = CustomerAddressTypes> = {
export type CustomerAddressHandlers<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
getAddresses: GetAddressesHook<T>
addItem: AddItemHandler<T>
updateItem: UpdateItemHandler<T>
removeItem: RemoveItemHandler<T>
}

export type CustomerAddressSchema<T extends CustomerAddressTypes = CustomerAddressTypes> = {
export type CustomerAddressSchema<
T extends CustomerAddressTypes = CustomerAddressTypes
> = {
endpoint: {
options: {}
handlers: CustomerAddressHandlers<T>
Expand Down
72 changes: 39 additions & 33 deletions framework/commerce/types/customer/card.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export interface Card {
id: string;
mask: string;
provider: string;
id: string
mask: string
provider: string
}

export interface CardFields {
cardHolder: string;
cardNumber: string;
cardExpireDate: string;
cardCvc: string;
firstName: string;
lastName: string;
company: string;
streetNumber: string;
zipCode: string;
city: string;
country: string;
cardHolder: string
cardNumber: string
cardExpireDate: string
cardCvc: string
firstName: string
lastName: string
company: string
streetNumber: string
zipCode: string
city: string
country: string
}

export type CustomerCardTypes = {
card?: Card;
fields: CardFields;
card?: Card
fields: CardFields
}

export type GetCardsHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card'] | null
data: T['card'][] | null
input: {}
fetcherInput: { cartId?: string }
swrState: { isEmpty: boolean }
Expand All @@ -48,26 +48,29 @@ export type UpdateItemHook<T extends CustomerCardTypes = CustomerCardTypes> = {

export type RemoveItemHook<T extends CustomerCardTypes = CustomerCardTypes> = {
data: T['card'] | null
input: { item?: T['fields'] }
input: { item?: T['card'] }
fetcherInput: { itemId: string }
body: { itemId: string }
actionInput: { id: string }
}

export type CustomerCardHooks<T extends CustomerCardTypes = CustomerCardTypes> = {
getCards: GetCardsHook<T>
addItem: AddItemHook<T>
updateItem: UpdateItemHook<T>
removeItem: RemoveItemHook<T>
}
export type CustomerCardHooks<T extends CustomerCardTypes = CustomerCardTypes> =
{
getCards: GetCardsHook<T>
addItem: AddItemHook<T>
updateItem: UpdateItemHook<T>
removeItem: RemoveItemHook<T>
}

export type CardsHandler<T extends CustomerCardTypes = CustomerCardTypes> = GetCardsHook<T> & {
body: { cartId?: string }
}
export type CardsHandler<T extends CustomerCardTypes = CustomerCardTypes> =
GetCardsHook<T> & {
body: { cartId?: string }
}

export type AddItemHandler<T extends CustomerCardTypes = CustomerCardTypes> = AddItemHook<T> & {
body: { cartId: string }
}
export type AddItemHandler<T extends CustomerCardTypes = CustomerCardTypes> =
AddItemHook<T> & {
body: { cartId: string }
}

export type UpdateItemHandler<T extends CustomerCardTypes = CustomerCardTypes> =
UpdateItemHook<T> & {
Expand All @@ -80,15 +83,18 @@ export type RemoveItemHandler<T extends CustomerCardTypes = CustomerCardTypes> =
body: { cartId: string }
}


export type CustomerCardHandlers<T extends CustomerCardTypes = CustomerCardTypes> = {
export type CustomerCardHandlers<
T extends CustomerCardTypes = CustomerCardTypes
> = {
getCards: GetCardsHook<T>
addItem: AddItemHandler<T>
updateItem: UpdateItemHandler<T>
removeItem: RemoveItemHandler<T>
}

export type CustomerCardSchema<T extends CustomerCardTypes = CustomerCardTypes> = {
export type CustomerCardSchema<
T extends CustomerCardTypes = CustomerCardTypes
> = {
endpoint: {
options: {}
handlers: CustomerCardHandlers<T>
Expand Down
5 changes: 5 additions & 0 deletions framework/ordercloud/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
COMMERCE_PROVIDER=ordercloud

ORDERCLOUD_CLIENT_ID=
ORDERCLOUD_CLIENT_SECRET=
STRIPE_SECRET=
3 changes: 3 additions & 0 deletions framework/ordercloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Next.js Ordercloud Provider

Create your own store from [here](https://nextjs.org/commerce)
Loading

0 comments on commit 3f0c384

Please sign in to comment.