update pricing UPAPI properties

This commit is contained in:
Tara Zou 2024-05-10 15:09:12 -04:00
parent 5de6c46a93
commit 586ae376a3
3 changed files with 15 additions and 15 deletions

View File

@ -195,7 +195,7 @@ export const getPriceMapAndCurrencyCode = async (map: OfferingIdMap): Promise<Pr
try { try {
const priceMap = new Map<string, Map<string, number>>(); const priceMap = new Map<string, Map<string, number>>();
let pricingCurrency; let billingCurrency;
for (const region of map.keys()) { for (const region of map.keys()) {
const regionPriceMap = new Map<string, number>(); const regionPriceMap = new Map<string, number>();
const regionShortName = await getRegionShortName(region); const regionShortName = await getRegionShortName(region);
@ -213,30 +213,30 @@ export const getPriceMapAndCurrencyCode = async (map: OfferingIdMap): Promise<Pr
}); });
for (const item of response.result) { for (const item of response.result) {
if (pricingCurrency === undefined) { if (item.error) {
pricingCurrency = item.pricingCurrency; continue;
} else if (item.pricingCurrency !== pricingCurrency) {
throw Error("Currency Code Mismatch: Currency code not same for all regions / skus.");
} }
if (item.error) { if (billingCurrency === undefined) {
throw Error(`Get price error ${item.error.type} for ${item.id}: ${item.error.description}`); billingCurrency = item.billingCurrency;
} else if (item.billingCurrency !== billingCurrency) {
throw Error("Currency Code Mismatch: Currency code not same for all regions / skus.");
} }
const offeringId = item.id; const offeringId = item.id;
const skuName = map.get(region).get(offeringId); const skuName = map.get(region).get(offeringId);
const unitPrice = item.prices.find((x) => x.type === "Consumption")?.unitPrice; const unitEffectivePriceInBillingCurrency = item.prices.find((x) => x.type === "Consumption")?.unitEffectivePriceInBillingCurrency;
regionPriceMap.set(skuName, unitPrice); regionPriceMap.set(skuName, unitEffectivePriceInBillingCurrency);
} }
priceMap.set(region, regionPriceMap); priceMap.set(region, regionPriceMap);
} }
selfServeTraceSuccess(telemetryData, getPriceMapAndCurrencyCodeTimestamp); selfServeTraceSuccess(telemetryData, getPriceMapAndCurrencyCodeTimestamp);
return { priceMap: priceMap, pricingCurrency: pricingCurrency }; return { priceMap: priceMap, billingCurrency: billingCurrency };
} catch (err) { } catch (err) {
const failureTelemetry = { err, selfServeClassName: SqlX.name }; const failureTelemetry = { err, selfServeClassName: SqlX.name };
selfServeTraceFailure(failureTelemetry, getPriceMapAndCurrencyCodeTimestamp); selfServeTraceFailure(failureTelemetry, getPriceMapAndCurrencyCodeTimestamp);
return { priceMap: undefined, pricingCurrency: undefined }; return { priceMap: undefined, billingCurrency: undefined };
} }
}; };

View File

@ -374,7 +374,7 @@ export default class SqlX extends SelfServeBaseClass {
const offeringIdMap = await getOfferingIds(regions); const offeringIdMap = await getOfferingIds(regions);
const priceMapAndCurrencyCode = await getPriceMapAndCurrencyCode(offeringIdMap); const priceMapAndCurrencyCode = await getPriceMapAndCurrencyCode(offeringIdMap);
priceMap = priceMapAndCurrencyCode.priceMap; priceMap = priceMapAndCurrencyCode.priceMap;
currencyCode = priceMapAndCurrencyCode.pricingCurrency; currencyCode = priceMapAndCurrencyCode.billingCurrency;
const response = await getCurrentProvisioningState(); const response = await getCurrentProvisioningState();
if (response.status && response.status !== "Deleting") { if (response.status && response.status !== "Deleting") {

View File

@ -35,13 +35,13 @@ export type FetchPricesResponse = Array<PriceItem>;
export type PriceItem = { export type PriceItem = {
prices: Array<PriceType>; prices: Array<PriceType>;
id: string; id: string;
pricingCurrency: string; billingCurrency: string;
error: PriceError; error: PriceError;
}; };
export type PriceType = { export type PriceType = {
type: string; type: string;
unitPrice: number; unitEffectivePriceInBillingCurrency: number;
}; };
export type PriceError = { export type PriceError = {
@ -51,7 +51,7 @@ export type PriceError = {
export type PriceMapAndCurrencyCode = { export type PriceMapAndCurrencyCode = {
priceMap: Map<string, Map<string, number>>; priceMap: Map<string, Map<string, number>>;
pricingCurrency: string; billingCurrency: string;
}; };
export type GetOfferingIdsResponse = { export type GetOfferingIdsResponse = {