Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat: made createFulfillmentOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 17, 2020
1 parent c932b0c commit 49c0c02
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/sections/fulfillment-outbound-shipment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,15 @@ export const GetFulfillmentPreviewResponse = Codec.interface({
GetFulfillmentPreviewResult: GetFulfillmentPreview,
}),
})

export const CreateFulfillmentOrderResponse = Codec.interface({
CreateFulfillmentOrderResponse: Codec.interface({
/**
* This part of the response is usually ignored but, this response returns exactly nothing
* This is just here to make sure the response is parsed correctly
*/
ResponseMetadata: Codec.interface({
RequestId: string,
}),
}),
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { ParsingError } from '../../error'
import { HttpClient, RequestMeta, Resource } from '../../http'
import { getServiceStatusByResource } from '../shared'
import { GetFulfillmentPreview, GetFulfillmentPreviewResponse } from './codec'
import {
CreateFulfillmentOrderResponse,
GetFulfillmentPreview,
GetFulfillmentPreviewResponse,
} from './codec'
import {
canonicalizeCreateFulfillmentOrderParameters,
canonicalizeGetFulfillmentPreviewParameters,
CreateFulfillmentOrderParameters,
GetFulfillmentPreviewParameters,
} from './type'

Expand All @@ -12,6 +18,24 @@ const FOS_API_VERSION = '2010-10-01'
export class FulfillmentOutboundShipment {
constructor(private httpClient: HttpClient) {}

async createFulfillmentOrder(
parameters: CreateFulfillmentOrderParameters,
): Promise<['', RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.FulfillmentOutboundShipment,
version: FOS_API_VERSION,
action: 'CreateFulfillmentOrder',
parameters: canonicalizeCreateFulfillmentOrderParameters(parameters),
})

return CreateFulfillmentOrderResponse.decode(response).caseOf({
Right: () => ['', meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async getFulfillmentPreview(
parameters: GetFulfillmentPreviewParameters,
): Promise<[GetFulfillmentPreview, RequestMeta]> {
Expand Down
88 changes: 88 additions & 0 deletions src/sections/fulfillment-outbound-shipment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,91 @@ export enum FISFeeTypesEnum {
'FBATransportationFee',
'FBAFulfillmentCODFee',
}

enum FulfillmentActionEnum {
'Ship',
'Hold',
}

type FulfillmentAction = keyof typeof FulfillmentActionEnum

enum FulfillmentPolicyEnum {
'FillOrKill',
'FillAll',
'FillAllAvailable',
}

type FulfillmentPolicy = keyof typeof FulfillmentPolicyEnum

interface FISCurrency {
CurrencyCode: string
Value: string
[key: string]: string
}

interface CreateFulfillmentOrderItem {
SellerSKU: string
SellerFulfillmentOrderItemId: string
Quantity: number
GiftMessage?: string
DisplayableComment?: string
FulfillmentNetworkSKU?: string
PerUnitDeclaredValue?: FISCurrency
PerUnitPrice?: FISCurrency
PerUnitTax?: FISCurrency
}

interface CODSettings {
IsCODRequired?: boolean
CODCharge?: FISCurrency
CODChargeTax?: FISCurrency
ShippingCharge?: FISCurrency
ShippingChargeTax?: FISCurrency
[key: string]: boolean | undefined | FISCurrency
}

interface DeliveryWindow {
StartDateTime: Date
EndDateTime: Date
}

export interface CreateFulfillmentOrderParameters {
MarketplaceId?: string
SellerFulfillmentOrderId: string
FulfillmentAction?: FulfillmentAction
DisplayableOrderId: string
DisplayableOrderDateTime: Date
DisplayableOrderComment: string
ShippingSpeedCategory: ShippingSpeedCategory
DestinationAddress: FOSAddress
FulfillmentPolicy?: FulfillmentPolicy
NotificationEmailList?: string[]
CODSettings?: CODSettings
Items: CreateFulfillmentOrderItem[]
DeliveryWindow?: DeliveryWindow
}

export const canonicalizeCreateFulfillmentOrderParameters = (
parameters: CreateFulfillmentOrderParameters,
) => {
return {
MarketplaceId: parameters.MarketplaceId,
SellerFulfillmentOrderId: parameters.SellerFulfillmentOrderId,
FulfillmentAction: parameters.FulfillmentAction,
DisplayableOrderId: parameters.DisplayableOrderId,
DisplayableOrderDateTime: parameters.DisplayableOrderDateTime?.toISOString(),
DisplayableOrderComment: parameters.DisplayableOrderComment,
ShippingSpeedCategory: parameters.ShippingSpeedCategory,
DestinationAddress: parameters.DestinationAddress,
FulfillmentPolicy: parameters.FulfillmentPolicy,
'NotificationEmailList.member': parameters.NotificationEmailList,
CODSettings: parameters.CODSettings,
'Items.member': parameters.Items,
DeliveryWindow: parameters.DeliveryWindow
? {
StartDateTime: parameters.DeliveryWindow.StartDateTime?.toISOString(),
EndDateTime: parameters.DeliveryWindow.EndDateTime?.toISOString(),
}
: undefined,
}
}
13 changes: 13 additions & 0 deletions test/unit/__snapshots__/fulfillment-outbound-shipment.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fulfillmentOutboundShipment createFulfillmentOrder returns the standard response elements if succesful 1`] = `
Array [
"",
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`fulfillmentOutboundShipment getFulfillmentPreview returns a list of fulfillment previews if succesful 1`] = `
Array [
Object {
Expand Down
5 changes: 3 additions & 2 deletions test/unit/fulfillment-outbound-shipment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ParsingError } from '../../src'
import { CreateFulfillmentOrderParameters } from '../../src/sections/fulfillment-outbound-shipment/type'
import { createMockHttpClient, mockMwsFail, mockMwsServiceStatus, parsingError } from '../utils'

const mockAddress = {
Expand All @@ -22,8 +23,8 @@ const mockCreateFulfillmentOrderItem = {

describe('fulfillmentOutboundShipment', () => {
describe('createFulfillmentOrder', () => {
const parameters = {
SellerFulfillmentOrderItemId: '',
const parameters: CreateFulfillmentOrderParameters = {
SellerFulfillmentOrderId: '',
DisplayableOrderId: '',
DisplayableOrderDateTime: new Date(),
DisplayableOrderComment: '',
Expand Down

0 comments on commit 49c0c02

Please sign in to comment.