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

Commit

Permalink
feat: create getShipment
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 6, 2020
1 parent 7af1ed5 commit 5902f39
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/sections/merchant-fulfillment/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ enum DeliveryExperienceEnum {
DeliveryConfirmationWithSignature = 'DeliveryConfirmationWithSignature',
DeliveryConfirmationWithoutSignature = 'DeliveryConfirmationWithoutSignature',
NoTracking = 'NoTracking',
// Adding this in because it has been in two mock requests from Amazon, but is not in the docs
DELIVERY_CONFIRMATION = 'DELIVERY_CONFIRMATION',
}

export const DeliveryExperience = enumeration(DeliveryExperienceEnum)
Expand Down Expand Up @@ -275,3 +277,15 @@ export const CreateShipmentResponse = Codec.interface({
CreateShipmentResult: CreateShipment,
}),
})

const GetShipment = Codec.interface({
Shipment,
})

export type GetShipment = GetInterface<typeof GetShipment>

export const GetShipmentResponse = Codec.interface({
GetShipmentResponse: Codec.interface({
GetShipmentResult: GetShipment,
}),
})
21 changes: 21 additions & 0 deletions src/sections/merchant-fulfillment/merchant-fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,41 @@ import {
GetAdditionalSellerInputsResponse,
GetEligibleShippingServices,
GetEligibleShippingServicesResponse,
GetShipment,
GetShipmentResponse,
} from './codec'
import {
canonicalizeCreateShipmentParameters,
canonicalizeParametersGetEligibleShippingServiceParameters,
CreateShipmentParameters,
GetAdditionalSellerInputsParameters,
GetEligibleShippingServicesParameters,
GetShipmentParameters,
} from './type'

const MERCHANT_FULFILLMENT_API_VERSION = '2015-06-01'

export class MerchantFulfillment {
constructor(private httpClient: HttpClient) {}

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

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

async createShipment(
parameters: CreateShipmentParameters,
): Promise<[CreateShipment, RequestMeta]> {
Expand Down
7 changes: 7 additions & 0 deletions src/sections/merchant-fulfillment/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,10 @@ export const canonicalizeCreateShipmentParameters = (
/**
* END CreateShipmentParameters
*/

/**
* START GetShipmentParameters
*/
export interface GetShipmentParameters {
ShipmentId: string
}
5 changes: 3 additions & 2 deletions test/unit/__fixtures__/merchant_fulfillment_get_shipment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<CurrencyCode>USD</CurrencyCode>
<Amount>10.00</Amount>
</DeclaredValue>
<DeliveryExperience>DELIVERY_CONFIRMATION </DeliveryExperience>
<DeliveryExperience>DELIVERY_CONFIRMATION</DeliveryExperience>
</ShippingServiceOptions>
<ShippingServiceId>FEDEX_PTP_PRIORITY_OVERNIGHT </ShippingServiceId>
<ShippingServiceId>FEDEX_PTP_PRIORITY_OVERNIGHT</ShippingServiceId>
<Rate>
<CurrencyCode>USD</CurrencyCode>
<Amount>27.81</Amount>
Expand All @@ -66,6 +66,7 @@
</PackageDimensions>
<CreatedDate>2015-09-23T20:11:12.908Z</CreatedDate>
<ShipFromAddress>
<Email/>
<City>Seattle</City>
<Phone>2061234567</Phone>
<CountryCode>US</CountryCode>
Expand Down
99 changes: 99 additions & 0 deletions test/unit/__snapshots__/merchant-fulfillment.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,102 @@ Array [
},
]
`;

exports[`merchant-fulfillment getShipment should properly return shipment if succesful 1`] = `
Array [
Object {
"Shipment": Object {
"AmazonOrderId": "903-1713775-3598252",
"CreatedDate": 2015-09-23T20:11:12.908Z,
"Insurance": Object {
"Amount": 10,
"CurrencyCode": "USD",
},
"ItemList": Array [
Object {
"OrderItemId": "40525960574974",
"Quantity": 1,
},
],
"Label": Object {
"CustomTextForLabel": "ABC123",
"Dimensions": Object {
"Length": 11,
"Unit": "inches",
"Width": 8.5,
},
"FileContents": Object {
"Checksum": "DmsWbJpdMPALN3jV4wHOrg==",
"Contents": "H4sIAAAAAAAAAK16WbeqyrLmO2Pc/zBVRLG...
...kI0Ycv76w378UfL6O6ev7UsAwmkWBfL6nycD/Bd+Zx3S8LwAA",
"FileType": "application/zpl",
},
"LabelFormat": "ZPL203",
"StandardIdForLabel": "AmazonOrderId",
},
"PackageDimensions": Object {
"Height": 5,
"Length": 5,
"Unit": "inches",
"Width": 5,
},
"ShipFromAddress": Object {
"AddressLine1": "1234 Westlake Ave",
"City": "Seattle",
"CountryCode": "US",
"Email": "",
"Name": "John Doe",
"Phone": "2061234567",
"PostalCode": "98121",
"StateOrProvinceCode": "WA",
},
"ShipToAddress": Object {
"AddressLine1": "321 Main St",
"City": "Seattle",
"CountryCode": "US",
"Email": "",
"Name": "Jane Smith",
"Phone": "",
"PostalCode": "98121-2778",
"StateOrProvinceCode": "WA",
},
"ShipmentId": "6f77095e-9f75-47eb-aaab-a42d5428fa1a",
"ShippingService": Object {
"CarrierName": "FEDEX",
"EarliestEstimatedDeliveryDate": 2015-09-24T10:30:00.000Z,
"LatestEstimatedDeliveryDate": 2015-09-24T10:30:00.000Z,
"Rate": Object {
"Amount": 27.81,
"CurrencyCode": "USD",
},
"ShipDate": 2015-09-23T20:10:56.829Z,
"ShippingServiceId": "FEDEX_PTP_PRIORITY_OVERNIGHT",
"ShippingServiceName": "FedEx Priority Overnight®",
"ShippingServiceOfferId": "HDDUKqtQVFetpBZAqx5c1yaCZ9vuFfND0kudyw3lLWCa
3mN2+zUOsRCAZS2oYt0ey6fXKdOAucmYVXR9LAkU9O9eys9V3FJCgvQ+vAqm4bSAzHVH04vD8oLy oUPKqxa8Otbek97Z85LFUSsfcUf8frNRMEfNLP8t5RyLXa4ZOjc=",
"ShippingServiceOptions": Object {
"CarrierWillPickUp": false,
"DeclaredValue": Object {
"Amount": 10,
"CurrencyCode": "USD",
},
"DeliveryExperience": "DELIVERY_CONFIRMATION",
},
},
"Status": "Purchased",
"TrackingId": "794657111237",
"Weight": Object {
"Unit": "oz",
"Value": 10,
},
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

0 comments on commit 5902f39

Please sign in to comment.