loading
Note:
Buying is a PaymentRequest This service only queries. The purchase itself is a PaymentRequest with the store's payment method identifier (https://play.google.com/billing) and the item id in its Data; the purchase then shows up in ListPurchases.
Warning:
Installed apps only - and the server decidesgetDigitalGoodsService() only connects inside an app installed from the store it is asking, so Connect returns false in a browser tab. And every entitlement decision belongs on your server, verified against the store's API with a PurchaseToken: a client saying it paid is a claim, not a receipt.

Support and connection

IsSupported / Connect

IsSupported says the function exists; Connect says there is a store behind it. An uninstalled app has the first and not the second, which is why the store UI should be gated on Connect.

C#
@inject Bit.Butil.DigitalGoods digitalGoods

var supported = await digitalGoods.IsSupported();
var connected = await digitalGoods.Connect();   // defaults to Google Play billing
Live sample
Service provider
support and connection output
Results will appear here when you interact with the samples.

Item details

GetDetails

The store's own title, description and price for each item id, in the user's currency. Render these rather than a copy from your database - the price here is the number the user will actually be charged.

C#
var items = await digitalGoods.GetDetails(["coins_100", "pro_monthly"]);

foreach (var item in items)
{
    var price = $"{item.Price?.Value} {item.Price?.Currency}";
}
Live sample
Item ids (comma-separated)
item details output
Results will appear here when you interact with the samples.

Purchases and history

ListPurchases / ListPurchaseHistory

ListPurchases is what is active now - unconsumed one-offs and live subscriptions - and what a client restores entitlements from after a reinstall. ListPurchaseHistory is the most recent purchase per item, consumed and expired ones included.

C#
var active = await digitalGoods.ListPurchases();
var history = await digitalGoods.ListPurchaseHistory();

// Send purchase.PurchaseToken to the server; let the server ask the store.
Live sample
purchases output
Results will appear here when you interact with the samples.

Consume a purchase

Consume

Marks a purchase as used up so the item can be bought again - the coin pack the user spent. Consume only after your server has recorded what the purchase bought: consuming first and crediting second loses the purchase entirely if anything in between fails.

C#
var consumed = await digitalGoods.Consume(purchase.PurchaseToken);
Live sample
Purchase token
consume output
Results will appear here when you interact with the samples.

API reference

Member
Signature
Description
GooglePlayBilling
const string GooglePlayBilling = "https://play.google.com/billing"
The default service provider, and the payment method identifier a PaymentRequest buys through.
IsSupported
ValueTask<bool> IsSupported()
True when the runtime exposes window.getDigitalGoodsService. Returns default (false) during prerender/SSR instead of throwing.
Connect
ValueTask<bool> Connect(string serviceProvider = GooglePlayBilling)
Connects to a store's billing service. False in a browser tab, where there is no store. The connection is cached.
GetDetails
ValueTask<DigitalGoodsItem[]> GetDetails(string[] itemIds, string serviceProvider = GooglePlayBilling)
The store's title, description and price per item id. Ids the store does not know are skipped.
ListPurchases
ValueTask<DigitalGoodsPurchase[]> ListPurchases(string serviceProvider = GooglePlayBilling)
The purchases that are currently active - unconsumed one-offs and live subscriptions.
ListPurchaseHistory
ValueTask<DigitalGoodsPurchase[]> ListPurchaseHistory(string serviceProvider = GooglePlayBilling)
The most recent purchase per item, including consumed and expired ones.
Consume
ValueTask<bool> Consume(string purchaseToken, string serviceProvider = GooglePlayBilling)
Marks a purchase as used up so the item can be bought again.
DigitalGoodsItem
string ItemId, string Title, string? Description, PaymentCurrencyAmount? Price, string? Type, string[] IconUrls, string? SubscriptionPeriod, string? FreeTrialPeriod, PaymentCurrencyAmount? IntroductoryPrice, string? IntroductoryPricePeriod, int? IntroductoryPriceCycles
One item as the store describes it. Periods are ISO 8601 durations; Type is product or subscription.
DigitalGoodsPurchase
string ItemId, string PurchaseToken
A purchase on file. The token is what your server verifies with the store.
An unhandled error has occurred. Reload 🗙