Table of Contents

Class PortalWebBillingProvider

Namespace
VpnHood.AppLib.Portal
Assembly
VpnHood.AppLib.Portal.dll

The web-distribution channel's billing provider: the portal IS the store. Plans and prices come from GET /billing/plans — the rows the checkout bills, priced in the portal's default currency, which each checkout URL names. Each plan carries its checkout page (CheckoutUrl), which the UI opens as it opens any link — on a TV, as a QR code for the phone — so nothing is bought in the app: delivery arrives through the signed-in account like every web purchase.

public class PortalWebBillingProvider : IBillingProvider, IDisposable
Inheritance
PortalWebBillingProvider
Implements
Inherited Members

Constructors

PortalWebBillingProvider(Uri, string, bool)

Initializes a new instance of the PortalWebBillingProvider class.

public PortalWebBillingProvider(Uri portalBaseUrl, string packageName, bool ignoreSslVerification = false)

Parameters

portalBaseUrl Uri

The portal the plans are listed from and the checkout opens on.

packageName string

The app the plans are listed for, as the portal names it.

ignoreSslVerification bool

Accepts any server certificate: a development portal's.

Properties

IsSubscriptionManagementSupported

Whether this device can show the store's own manage-subscriptions surface (cancel, change plan, payment method). A runtime question, not a constant: a TV carries a store that cannot show that screen, and answering false there is what lets the UI say "manage it where you bought it" instead of offering a control that does nothing.

public bool IsSubscriptionManagementSupported { get; }

Property Value

bool

Remarks

It is false: a web subscription is managed on the website's account page, which no store on the device shows.

ProviderId

Which store this is (see StoreIds), in the vocabulary the account backend speaks. Declared here because the provider is the one thing that cannot be wrong about it — so nothing that wires a store has to state it a second time and risk disagreeing.

public string ProviderId { get; }

Property Value

string

Remarks

It is Web.

PurchaseState

Gets where the store's payment flow stands.

public PurchaseState PurchaseState { get; }

Property Value

PurchaseState

Remarks

It is always None: nothing is bought in the app.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

FinishPurchase(PurchaseProof, CancellationToken)

Tells the store the purchase behind this proof is delivered: the account backend has redeemed it. Called only then, so a purchase whose redeeming failed stays open where the store keeps one open (StoreKit's unfinished transaction), and a later Restore presents it again. A store whose backend closes the purchase itself (Play's acknowledgement) has nothing to do here.

public Task FinishPurchase(PurchaseProof purchaseProof, CancellationToken cancellationToken)

Parameters

purchaseProof PurchaseProof

The proof the account backend has redeemed.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Remarks

It does nothing: this provider gives no proof to finish.

Exceptions

BillingException

The store failed; its Code says how.

ArgumentException

The proof is not one this provider answered, as the App Store's checks.

OperationCanceledException

cancellationToken was canceled.

GetSubscriptionPlans(IReadOnlyList<string>, CancellationToken)

Prices the given products. The store is not asked WHICH products exist — it cannot answer that (neither StoreKit nor Play Billing can list an app's own catalog) and it is not the authority on it either: the account backend decides what may be sold, this prices and localizes it.

public Task<IReadOnlyList<SubscriptionPlan>> GetSubscriptionPlans(IReadOnlyList<string> productIds, CancellationToken cancellationToken)

Parameters

productIds IReadOnlyList<string>

The product IDs the account backend gives (GetProductIds(CancellationToken)).

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IReadOnlyList<SubscriptionPlan>>

A task whose result is the plans the store prices for them.

Remarks

The portal lists the app's web plans for a request without a session, so in its default currency, and each plan's checkout page (CheckoutUrl) names that currency; only the given products are kept.

Exceptions

ApiException

For the web store, the account backend refused the request.

BillingException

The store failed; its Code says how.

OperationCanceledException

cancellationToken was canceled.

OpenSubscriptionManagement(IUiContext?, CancellationToken)

Shows that surface. The store does it its own way — an in-app sheet, its own app — so no URL crosses to the UI and no browser has to exist. Only ever called for a subscription THIS store billed, and only while IsSubscriptionManagementSupported: the app refuses the call otherwise, so an implementation need not re-check its own answer.

public Task OpenSubscriptionManagement(IUiContext? uiContext, CancellationToken cancellationToken)

Parameters

uiContext IUiContext

The window, or null where none is open.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that completes once the store's surface is shown.

Remarks

It always throws NotSupportedException.

Exceptions

NotSupportedException

The store has no such surface here, as the web store's.

UiContextNotAvailableException

uiContext is null, and the store needs a window.

OperationCanceledException

cancellationToken was canceled.

Purchase(IUiContext?, PurchaseParams, PurchaseAttribution, CancellationToken)

Runs the store's payment flow and answers its proof of purchase.

Two arguments because they have two owners: purchaseParams is the buyer's choice, attribution is the app's answer to whose account is paying.

public Task<PurchaseProof> Purchase(IUiContext? uiContext, PurchaseParams purchaseParams, PurchaseAttribution attribution, CancellationToken cancellationToken)

Parameters

uiContext IUiContext

The window, or null where none is open.

purchaseParams PurchaseParams

The plan the buyer chose.

attribution PurchaseAttribution

Whose account the purchase is for.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<PurchaseProof>

A task whose result is the store's proof of purchase.

Remarks

It always throws NotSupportedException: a web plan is bought on its checkout page, and the purchase reaches the account on the server once it is provisioned and the account is linked to the website's client, which a sign-in does; an account refresh then reads the account's code and subscription, as the portal ranks them. An account first signed in with an identity provider may need another sign-in for that link.

Exceptions

BillingException

The store failed, or the person closed its payment flow (Cancelled); its Code says how.

NotSupportedException

The store sells outside the app, as the web store, on its checkout page.

InvalidOperationException

A purchase is under way already, or the account's ID does not fit the store, as the App Store's, which takes a UUID.

ArgumentException

The plan names a product the store does not have.

UiContextNotAvailableException

uiContext is null, and the store needs a window.

OperationCanceledException

cancellationToken was canceled.

RestorePurchase(IUiContext?, CancellationToken)

The proof for a subscription this store account already owns, or null when it owns none. Silent: it reads what the device already knows and never prompts.

public Task<PurchaseProof?> RestorePurchase(IUiContext? uiContext, CancellationToken cancellationToken)

Parameters

uiContext IUiContext

The window, or null where none is open.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<PurchaseProof>

A task whose result is the proof, or null where the store account owns no subscription.

Remarks

It gives null: a web purchase lives in the account, and signing in restores it.

Exceptions

BillingException

The store failed; its Code says how.

OperationCanceledException

cancellationToken was canceled.