Skip to content

Commit 785d4fc

Browse files
Apply suggestions from code review
1 parent b2dcb13 commit 785d4fc

1 file changed

Lines changed: 29 additions & 20 deletions

File tree

microsoft-edge/progressive-web-apps-chromium/how-to/digital-goods-api.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If your Progressive Web App (PWA) is listed in the Microsoft Store, you can prov
1616
<!-- ====================================================================== -->
1717
## Digital Goods API
1818

19-
The Digital Goods API is an interface between your PWA app and Microsoft Store. The Digital Goods API supports:
19+
The Digital Goods API is an interface between your PWA app and the Microsoft Store. The Digital Goods API supports:
2020
* Querying the details of a digital item from the Microsoft Store backend, such as the item's name, description, and regional price.
2121
* Consuming or acknowledging purchases.
2222
* Checking the digital items that are currently owned by the user.
@@ -30,9 +30,9 @@ See:
3030
<!-- ====================================================================== -->
3131
## Payment Request API
3232

33-
The Payment Request API⁠⁠ handles the actual payment transaction when a purchase is made by user. The Payment Request API uses the item details that the Digital Goods API provides, to make the in-app purchase by using whichever billing payment method the user has set up at the Microsoft Store.
33+
The Payment Request API⁠⁠ handles the actual payment transaction when a purchase is made by a user. The Payment Request API uses the item details that the Digital Goods API provides, to make the in-app purchase by using whichever billing payment method the user has set up at the Microsoft Store.
3434

35-
See [Payment Request API](https://www.w3.org/TR/payment-request/) at W3C.
35+
See [Payment Request API](https://developer.mozilla.org/docs/Web/API/Payment_Request_API) at MDN.
3636

3737

3838
<!-- ====================================================================== -->
@@ -70,7 +70,7 @@ try {
7070
...
7171
} catch (error) {
7272
// Our preferred service provider is not available.
73-
// Use a normal web-based payment flow.
73+
// Use a web-based payment flow instead.
7474
return;
7575
}
7676
```
@@ -86,19 +86,22 @@ After connecting the Digital Goods service to Microsoft Store, you can use the A
8686
The `getDetails` method takes a list of item IDs, which correspond to the product IDs of the in-app products and subscriptions you created in the Partner Center.
8787

8888
```javascript
89-
details = await digitalGoodsService.getDetails(['shiny_sword', 'gem', 'monthly_subscription']);
90-
for (item of details) {
89+
const itemDetails = await digitalGoodsService.getDetails(['shiny_sword', 'gem', 'monthly_subscription']);
90+
91+
for (item of itemDetails) {
9192
const priceStr = new Intl.NumberFormat(
9293
locale,
9394
{style: 'currency', currency: item.price.currency}
9495
).format(item.price.value);
95-
AddShopMenuItem(item.itemId, item.title, priceStr, item.description);
96+
97+
// Do something with the item's data, such as displaying it in the PWA's UI.
98+
displayProductItem(item.itemId, item.title, priceStr, item.description);
9699
}
97100
```
98101

99102
The returned `itemDetails` sequence may be in any order, and might not include an item if the item doesn't exist on the server (that is, if there's not a 1:1 correspondence between the input list and output list).
100103

101-
The item ID is a string that represents the primary key of the items. As in Microsoft Store, the item ID is `InAppOfferToken`. There is no function to get a list of item IDs; item IDs should be hardcoded in the client code or fetched from your own server (the developer's server).
104+
The item ID is a string that represents the primary key of the items. In the Microsoft Store, the item ID is `InAppOfferToken`. There is no function to get a list of item IDs; item IDs should be hardcoded in the client code or fetched from your own server (the developer's server).
102105

103106
The item's `price` is a `PaymentCurrencyAmount` that contains the current price of the item in the user's current region and currency. The `price` is designed to be formatted for the user's current locale by using `Intl.NumberFormat`, as shown above.
104107

@@ -111,7 +114,7 @@ See also:
111114
<!-- ====================================================================== -->
112115
## Purchasing an item (`show` method)
113116

114-
Use the `show` method to purchase an item, after you construct a request that contains item details.
117+
Use the `show` method to purchase an item, after you construct a request that contains the item details.
115118

116119
Once your products and details are displayed to the user, you can implement the purchase flow by using the Payment Request API. When combined with the Digital Goods API, the only required input parameter is `methodData`.
117120

@@ -120,11 +123,13 @@ Use the `supportedMethods` member of the `methodData`⁠⁠ parameter in the `Pa
120123
```javascript
121124
const details = await digitalGoodsService.getDetails(['monthly_subscription']);
122125
const item = details[0];
123-
const request = new PaymentRequest(
124-
[{supportedMethods: 'https://store.microsoft.com/billing',
125-
data: {sku: item.itemId}}
126-
]
127-
);
126+
127+
const request = new PaymentRequest([
128+
{
129+
supportedMethods: 'https://store.microsoft.com/billing',
130+
data: { sku: item.itemId }
131+
}
132+
]);
128133
```
129134

130135
Then call the `show` method to start the payment flow:
@@ -176,9 +181,11 @@ Use the `listPurchases` method to check existing purchases. This method returns
176181
The `listPurchases` method returns item IDs and purchase tokens. Before you grant an entitlement, you should verify the returned item ID or the returned purchase token, by using a direct developer-to-provider API, as shown below:
177182

178183
```javascript
179-
purchases = await digitalGoodsService.listPurchases();
180-
for (p of purchases) {
181-
VerifyAndGrantEntitlement(p.itemId, p.purchaseToken);
184+
const purchaseList = await digitalGoodsService.listPurchases();
185+
186+
for (const purchase of purchaseList) {
187+
// Handle the purchase data in your PWA.
188+
verifyAndGrantEntitlement(purchase.itemId, purchase.purchaseToken);
182189
}
183190
```
184191

@@ -191,9 +198,11 @@ The `listPurchases` method doesn't return consumed products or expired subscript
191198
Use the `listPurchaseHistory` method to get the purchase history. This method returns a list that shows the most recent purchase made by the user for each item, regardless of whether the purchase is expired, canceled, or consumed. This method returns a list of `PurchaseDetails` containing the `itemId` and `purchaseToken` for each purchase.
192199

193200
```javascript
194-
purchases = await digitalGoodsService.listPurchaseHistory();
195-
for (p of purchases) {
196-
VerifyAndCheckExpiredEntitlement(p.itemId, p.purchaseToken);
201+
const purchaseList = await digitalGoodsService.listPurchaseHistory();
202+
203+
for (const purchase of purchaseList) {
204+
// Handle the expired purchase data in your PWA.
205+
verifyAndCheckExpiredEntitlement(purchase.itemId, purchase.purchaseToken);
197206
}
198207
```
199208

0 commit comments

Comments
 (0)