From a6534519038b39ff8e22f416a13ee695d27658f1 Mon Sep 17 00:00:00 2001 From: EJ Mercado Date: Thu, 2 Jul 2020 14:24:04 +0800 Subject: [PATCH] feat: init create shipment --- src/sections/merchant-fulfillment/codec.ts | 47 ++++++++++++++++++- .../merchant-fulfillment.ts | 20 ++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/sections/merchant-fulfillment/codec.ts b/src/sections/merchant-fulfillment/codec.ts index d7913afc..881c0104 100644 --- a/src/sections/merchant-fulfillment/codec.ts +++ b/src/sections/merchant-fulfillment/codec.ts @@ -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' @@ -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, +}) diff --git a/src/sections/merchant-fulfillment/merchant-fulfillment.ts b/src/sections/merchant-fulfillment/merchant-fulfillment.ts index 7737e877..dcd998c0 100644 --- a/src/sections/merchant-fulfillment/merchant-fulfillment.ts +++ b/src/sections/merchant-fulfillment/merchant-fulfillment.ts @@ -2,6 +2,8 @@ import { ParsingError } from '../../error' import { HttpClient, RequestMeta, Resource } from '../../http' import { getServiceStatusByResource } from '../shared' import { + CreateShipment, + CreateShipmentResponse, GetAdditionalSellerInputs, GetAdditionalSellerInputsResponse, GetEligibleShippingServices, @@ -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]> {