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

Commit

Permalink
feat: init create shipment
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 2, 2020
1 parent 709c9d7 commit a653451
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/sections/merchant-fulfillment/codec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { boolean, Codec, enumeration, GetInterface, number, optional, string } from 'purify-ts'
import {
boolean,
Codec,
enumeration,
GetInterface,
number,
optional,
string,
unknown,
} from 'purify-ts'

import { ensureArray, ensureString, mwsDate } from '../../parsing'
import { CurrencyAmount } from '../codec'
Expand Down Expand Up @@ -192,3 +201,39 @@ export const GetAdditionalSellerInputsResponse = Codec.interface({
GetAdditionalSellerInputsResult: GetAdditionalSellerInputs,
}),
})

enum StatusEnum {
Purchase = 'Purchased',
RefundPending = 'RefundPending',
RefundRejected = 'RefundRejected',
RefundApplied = 'RefundApplied ',
}

const Status = enumeration(StatusEnum)
const Item = unknown

export const Shipment = Codec.interface({
ShipmentId: string,
AmazonOrderId: string,
SellerOrderId: optional(string),
ItemList: ensureArray('Item', Item),
ShipFromAddress: Address,
ShipToAddress: Address,
PackageDimensions,
Weight,
Insurance: CurrencyAmount,
ShippingService,
Label: unknown,
Status,
TrackingId: optional(string),
CreatedDate: mwsDate,
LastUpdatedDate: optional(mwsDate),
})

export const CreateShipment = Codec.interface({
Shipment,
})

export const CreateShipmentResponse = Codec.interface({
CreateShipmentResult: CreateShipment,
})
20 changes: 20 additions & 0 deletions src/sections/merchant-fulfillment/merchant-fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ParsingError } from '../../error'
import { HttpClient, RequestMeta, Resource } from '../../http'
import { getServiceStatusByResource } from '../shared'
import {
CreateShipment,
CreateShipmentResponse,
GetAdditionalSellerInputs,
GetAdditionalSellerInputsResponse,
GetEligibleShippingServices,
Expand All @@ -18,6 +20,24 @@ const MERCHANT_FULFILLMENT_API_VERSION = '2015-06-01'
export class MerchantFulfillment {
constructor(private httpClient: HttpClient) {}

async createShipment(
parameters: CreateShipmentParameters,
): Promise<[CreateShipment, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.MerchantFulfillment,
version: MERCHANT_FULFILLMENT_API_VERSION,
action: 'CreateShipment',
parameters,
})

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

async getAddtionalSellerInputs(
parameters: GetAdditionalSellerInputsParameters,
): Promise<[GetAdditionalSellerInputs, RequestMeta]> {
Expand Down

0 comments on commit a653451

Please sign in to comment.