Table of Contents

Interface IBillingApi

Namespace
VpnHood.AppLib.Api
Assembly
VpnHood.AppLib.Api.dll

Represents the app's API for the in-app purchase: the plans, the purchase and its restore.

public interface IBillingApi

Remarks

Where the app has no account backend, every call fails. A failure comes as IAppApi describes, in process and over HTTP.

Methods

GetSubscriptionPlans(CancellationToken)

Gets the plans the app may sell, as the store prices them.

Task<IReadOnlyList<SubscriptionPlan>> GetSubscriptionPlans(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IReadOnlyList<SubscriptionPlan>>

A task whose result is the plans.

Remarks

A store that fails comes as the app's BillingException.

Exceptions

InvalidOperationException

The account backend names no store for the app.

ApiException

The account backend refused the request; or, over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

OperationCanceledException

cancellationToken was canceled: over HTTP always, in process where the call honours it.

OpenSubscriptionManagement(CancellationToken)

Opens the store's screen for managing the subscription.

Task OpenSubscriptionManagement(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that represents the asynchronous operation.

Remarks

The UI offers it only where the subscription's Management is Available. It needs the app's window where the store shows one, and fails without it, as the app's UiContextNotAvailableException.

Exceptions

NotSupportedException

The device cannot show the store's subscription management.

ApiException

Over HTTP, the app failed with an exception of a type the transport does not rebuild, which ExceptionTypeName names, or answered with an error it does not name.

OperationCanceledException

cancellationToken was canceled: over HTTP always, in process where the call honours it.

Purchase(PurchaseParams, CancellationToken)

Runs the store's payment flow, and turns the purchase into access.

Task Purchase(PurchaseParams purchaseParams, CancellationToken cancellationToken)

Parameters

purchaseParams PurchaseParams

The plan the person chose.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that completes once the purchase is turned into access.

Remarks

The store's proof of the purchase stays with the app. A store that fails comes as the app's BillingException, whose code is Cancelled where the person closed the payment flow; a store that shows a window needs the app's, and fails without it, as the app's UiContextNotAvailableException.

Exceptions

InvalidDataException

For Google Play, the plan's token decodes to JSON null.

JsonException

For Google Play, the plan's token is not valid.

InvalidOperationException

The store cannot sell now, the signed-in account changed meanwhile, or the order was not settled.

ArgumentException

The store does not know the plan.

NotSupportedException

The store does not take the purchase.

AuthenticationException

Nobody is signed in.

AlreadyExistsException

The account is premium already.

ApiException

The account backend refused the request; or, over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

OperationCanceledException

cancellationToken was canceled: over HTTP always, in process where the call honours it.

RestorePurchase(CancellationToken)

Restores a subscription the store account owns, without a prompt.

Task<bool> RestorePurchase(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<bool>

A task whose result is true where a purchase was restored, or false where none was; a subscription bought on the web comes back through the account instead.

Remarks

A store that fails comes as the app's BillingException.

Exceptions

InvalidOperationException

The signed-in account changed meanwhile, or the order was not settled.

AuthenticationException

Nobody is signed in.

ApiException

The account backend refused the request; or, over HTTP, the app failed with an exception of a type the transport does not rebuild, or answered with an error it does not name.

OperationCanceledException

cancellationToken was canceled: over HTTP always, in process where the call honours it.