in-app-purchase
in-app-purchase copied to clipboard
Provide type definitions
I miss typing when using this library with TypeScript. There's this typing definition package, but I don't know whether it is official or not, and it is way outdated.
Yeah, that package is not reliable anymore
I'm trying to update the types. Think it's good if the type definitions are just added to this project, as it's easier to keep it in sync with the code.
I've just started this fork: https://github.com/jvandenaardweg/in-app-purchase/blob/develop/index.d.ts
Feel free to help. Types are not finished yet.
Only using the Android and Apple subscriptions part in my app. So have not looked at Windows or Amazon, or non-subscription purchases.
I'm also splitting the types correctly using their own interface per service. As this makes more sense than adding all the types to PurchasedItem
. So you can just type check the thing you expect, like:
const purchaseData: inAppPurchase.GoogleSubscriptionPurchase[] | null = await inAppPurchase.getPurchaseData(validationResponse, getPurchaseDataOptions);
Preview:
export function getPurchaseData(purchaseData?: ValidationResponse, options?: {
ignoreCanceled: boolean;
ignoreExpired: boolean;
}): GoogleSubscriptionPurchase[] | AppleSubscriptionPurchase[] | null;
export interface PurchasedItem {
transactionId: string;
productId: string;
purchaseDate: number | string;
expirationDate?: number;
quantity?: number;
}
export interface WindowsSubscriptionPurchase extends PurchasedItem {
}
export interface AmazonSubscriptionPurchase extends PurchasedItem {
}
export interface AppleSubscriptionPurchase extends PurchasedItem {
bundleId?: string;
originalPurchaseDateMs?: number | string; // TODO: check if number OR string
originalPurchaseDate?: number | string; // TODO: check if number OR string
originalTransactionId?: string;
purchaseDateMs?: number | string; // TODO: check if number OR string
cancellationDateMs?: number | string; // TODO: check if number OR string
isTrial?: boolean;
cancellationDate?: number;
}
export interface GoogleSubscriptionPurchase extends PurchasedItem {
cancellationDate?: number;
purchaseToken?: string;
/**
* The type of purchase of the subscription.
* This field is only set if this purchase was not made using the standard in-app billing flow. Possible values are:
* Test (i.e. purchased from a license testing account)
* */
purchaseType?: number;
/** Whether the subscription will automatically be renewed when it reaches its current expiry time. */
autoRenewing?: boolean;
/**
* The reason why a subscription was cancelled or is not auto-renewing. Possible values are:
* - User cancelled the subscription
* - Subscription was cancelled by the system, for example because of a billing problem
* - Subscription was replaced with a new subscription
*/
cancelReason?: number;
/** ISO 3166-1 alpha-2 billing country/region code of the user at the time the subscription was granted. */
countryCode?: string;
/** A developer-specified string that contains supplemental information about an order. */
developerPayload?: string;
/** Time at which the subscription will expire, in milliseconds since the Epoch. */
expiryTimeMillis?: string;
/** This kind represents a subscriptionPurchase object in the androidpublisher service. */
kind?: string;
/** The order id of the latest recurring order associated with the purchase of the subscription. */
orderId?: string;
/**
* The payment state of the subscription. Possible values are:
* - Payment pending
* - Payment received
* - Free trial
*/
paymentState?: number;
/**
* Price of the subscription, not including tax. Price is expressed in micro-units, where 1,000,000 micro-units represents one unit of the currency. For
* example, if the subscription price is €1.99, price_amount_micros is 1990000.
*/
priceAmountMicros?: string;
/** ISO 4217 currency code for the subscription price. For example, if the price is specified in British pounds sterling, price_currency_code is "GBP". */
priceCurrencyCode?: string;
/** Time at which the subscription was granted, in milliseconds since the Epoch. */
startTimeMillis?: string;
/** The time at which the subscription was canceled by the user, in milliseconds since the epoch. Only present if cancelReason is 0. */
userCancellationTimeMillis?: string;
}
Resources used for now: Android: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/gapi.client.androidpublisher/index.d.ts#L396 https://developers.google.com/android-publisher/api-ref/purchases/subscriptions
@jvandenaardweg did you update the @types/in-app-purchases ? looks like it has been updated not so long ago