-
Notifications
You must be signed in to change notification settings - Fork 22
Preserve the base price when publishing #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alexandre Zollinger Chohfi (azchohfi)
wants to merge
11
commits into
main
Choose a base branch
from
azchohfi-preserve-pricing-on-publish
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
65b48f1
Preserve the base price when publishing (#112)
azchohfi b72ce89
Record that omitting PriceId also resets the price
azchohfi 51576d4
Stop publishing when the submission carries no pricing
azchohfi 5eea4a5
Word the submission update rejection as payload validation
azchohfi 0511a85
Drop a redundant fetch and describe the pricing failures accurately
azchohfi 5a782be
Reject an update payload that carries no pricing at all
azchohfi c92d60f
Log the actual pricing failure rather than a blanket PriceId message
azchohfi 8ca87ec
Do not let whitespace smuggle the Base sentinel past the guard
azchohfi f776cf8
Stop asserting on console text that Spectre may wrap
azchohfi 93f8429
Strip ANSI styling before asserting on console output
azchohfi 2bd7e92
Warn that --priceId sets one base price for the whole product
azchohfi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Globalization; | ||
|
|
||
| namespace MSStore.API.Packaged.Models | ||
| { | ||
| /// <summary> | ||
| /// Well-known values for <see cref="Pricing.PriceId"/>, and the rules for which | ||
| /// of them may be sent back to the Store submission API on an update. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// These live outside <see cref="Pricing"/> on purpose. That type is serialized with | ||
| /// <see cref="System.Text.Json.Serialization.JsonIgnoreCondition.Never"/>, so any member | ||
| /// added to it would show up in the request body. | ||
| /// </remarks> | ||
| public static class PriceIds | ||
| { | ||
| /// <summary> | ||
| /// Sentinel meaning "the price tier is not set; use the base price for the app". | ||
| /// It is a legal value inside <see cref="Pricing.MarketSpecificPricings"/>, but the | ||
| /// API also returns it as the <em>base</em> price of products managed by the newer | ||
| /// per-market pricing model - where it cannot be sent back. Updating a submission | ||
| /// with it fails with <c>'Base' is not a valid PriceId for base price.</c> | ||
| /// </summary> | ||
| public const string Base = "Base"; | ||
|
|
||
| /// <summary>The app is free.</summary> | ||
| public const string Free = "Free"; | ||
|
|
||
| /// <summary>The app is not available in the given market.</summary> | ||
| public const string NotAvailable = "NotAvailable"; | ||
|
|
||
| private const string TierPrefix = "Tier"; | ||
|
|
||
| /// <summary> | ||
| /// Whether a price id read from a submission can be sent back unchanged on update. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Everything except <see cref="Base"/> (and a missing value) round-trips. | ||
| /// <para> | ||
| /// An empty price id must never be sent. Update is a full replace with no patch | ||
| /// semantics, so anything the request does not state explicitly is reset to its default, | ||
| /// and the default is free. Verified against the API: a <c>null</c> price id, a pricing | ||
| /// object with the property removed, and an empty pricing object all answer | ||
| /// <c>200 OK</c> and silently turn the product free. Omitting the property is therefore | ||
| /// not a way to leave the price untouched - there is no such way. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <param name="priceId">The price id to check.</param> | ||
| /// <returns><c>true</c> when <paramref name="priceId"/> is safe to send back.</returns> | ||
| public static bool IsRoundTrippable(string? priceId) => | ||
| !string.IsNullOrWhiteSpace(priceId) && | ||
| !string.Equals(priceId.Trim(), Base, StringComparison.OrdinalIgnoreCase); | ||
|
|
||
| /// <summary> | ||
| /// Validates a user supplied price id and converts it to the casing the API expects. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Tier numbers are deliberately not range checked. The documented ranges | ||
| /// (<c>Tier2</c>-<c>Tier96</c> and <c>Tier1012</c>-<c>Tier1424</c>) describe what a | ||
| /// dashboard offers, not what the API accepts, and <c>isAdvancedPricingModel</c> is | ||
| /// not a reliable way to tell the two apart - the API reports it inconsistently for | ||
| /// the same product. Let the service reject an out of range tier. | ||
| /// </remarks> | ||
| /// <param name="priceId">The price id to normalize.</param> | ||
| /// <param name="normalized">The normalized price id, when valid.</param> | ||
| /// <returns><c>true</c> when <paramref name="priceId"/> is a value the API accepts.</returns> | ||
| public static bool TryNormalize(string? priceId, out string? normalized) | ||
| { | ||
| normalized = null; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(priceId)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var trimmed = priceId.Trim(); | ||
|
|
||
| if (string.Equals(trimmed, Free, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| normalized = Free; | ||
| return true; | ||
| } | ||
|
|
||
| if (string.Equals(trimmed, NotAvailable, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| normalized = NotAvailable; | ||
| return true; | ||
| } | ||
|
|
||
| if (!trimmed.StartsWith(TierPrefix, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var tier = trimmed[TierPrefix.Length..]; | ||
|
|
||
| if (tier.Length == 0 || !int.TryParse(tier, NumberStyles.None, CultureInfo.InvariantCulture, out var tierNumber)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| normalized = string.Concat(TierPrefix, tierNumber.ToString(CultureInfo.InvariantCulture)); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.