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

Commit

Permalink
feat: get my price for asin
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 1, 2020
1 parent 9fd72a5 commit 3aaf854
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/sections/products/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ export const GetMyPriceForSKUResponse = Codec.interface({
GetMyPriceForSKUResponse: GetMyPriceForSKUResult,
})

const GetMyPriceForASINResult = ensureArray('GetMyPriceForASINResult', SingleProductInterface)

export const GetMyPriceForASINResponse = Codec.interface({
GetMyPriceForASINResponse: GetMyPriceForASINResult,
})

/**
*
* Types derived from codecs
Expand All @@ -347,3 +353,4 @@ export type GetLowestOfferListingsForASINResult = GetInterface<
export type GetLowestPricedOffersForSKU = GetInterface<typeof GetLowestPricedOffersForSKU>
export type GetLowestPricedOffersForASIN = GetInterface<typeof GetLowestPricedOffersForASIN>
export type GetMyPriceForSKUResult = GetInterface<typeof GetMyPriceForSKUResult>
export type GetMyPriceForASINResult = GetInterface<typeof GetMyPriceForASINResult>
25 changes: 25 additions & 0 deletions src/sections/products/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
GetMatchingProductResult,
GetMyFeesEstimate,
GetMyFeesEstimateResponse,
GetMyPriceForASINResponse,
GetMyPriceForASINResult,
GetMyPriceForSKUResponse,
GetMyPriceForSKUResult,
ListMatchingProducts,
Expand All @@ -35,6 +37,7 @@ import {
GetMatchingProductForIdParameters,
GetMatchingProductParameters,
GetMyFeesEstimateParameters,
GetMyPriceForAsinParameters,
GetMyPriceForSkuParameters,
ListMatchingProductsRequestParameters,
} from './type'
Expand Down Expand Up @@ -273,4 +276,26 @@ export class Products {
},
})
}

async getMyPriceForAsin(
parameters: GetMyPriceForAsinParameters,
): Promise<[GetMyPriceForASINResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetLowestPricedOffersForASIN',
parameters: {
MarketplaceId: parameters.MarketplaceId,
'ASINList.ASIN': parameters.ASINList,
ItemCondition: parameters.ItemCondition,
},
})

return GetMyPriceForASINResponse.decode(response).caseOf({
Right: (x) => [x.GetMyPriceForASINResponse, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
6 changes: 6 additions & 0 deletions src/sections/products/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ export interface GetMyPriceForSkuParameters {
SellerSKUList: string[]
ItemCondition?: ItemCondition
}

export interface GetMyPriceForAsinParameters {
MarketplaceId: string
ASINList: string[]
ItemCondition?: ItemCondition
}
51 changes: 51 additions & 0 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,57 @@ Array [
]
`;

exports[`products getMyPriceForAsin returns price for prouct for asin when response is valid 1`] = `
Array [
Array [
Object {
"Product": Object {
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": 1933890517,
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"Offers": Object {
"Offer": Object {
"BuyingPrice": Object {
"LandedPrice": Object {
"Amount": 303.99,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 300,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 3.99,
"CurrencyCode": "USD",
},
},
"FulfillmentChannel": "MERCHANT",
"ItemCondition": "Used",
"ItemSubCondition": "Acceptable",
"RegularPrice": Object {
"Amount": 300,
"CurrencyCode": "USD",
},
"SellerId": "A1IMEXAMPLEWRC",
"SellerSKU": "SKU2468",
},
},
},
},
],
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getMyPriceForSku returns price for prouct for sku when response is valid 1`] = `
Array [
Array [
Expand Down

0 comments on commit 3aaf854

Please sign in to comment.