diff --git a/README.md b/README.md index 148e077..26eb840 100644 --- a/README.md +++ b/README.md @@ -7,127 +7,15 @@ Libraries to server-side verify in-app purchases for iOS and Android. Additional - πŸ’Έ Verify in-app purchases for iOS and Android receipts in Node.js - πŸ”Œ [NestJS](https://nestjs.com) wrapper to easily integrates the library in your project. - Uses [axios](https://github.com/axios/axios) under the hood for the requests. -- Typescript definition for App Store Receipts, App Store Server API and Google Play Developer API. +- Typescript definition for App Store Receipts, App Store Server API, Google Play Developer API and Google Play Real-time developer notifications. - All types come with their descriptions extracted from the Apple and Google documentations. -## Node.js IAP library +## Installation and usage -This is the core library wrapping the Apple and Google IAP APIs to get and verify in-app purchases. - -β†’ [README.md](./packages/node-iap/README.md) for more information. - -### Installation - -```bash -yarn add @jeremybarbet/node-iap -``` - -### Usage - -```ts -import { verifyAppleReceipt, verifyGoogleReceipt } from '@jeremybarbet/node-iap'; - -const { data } = verifyAppleReceipt( - { - transactionReceipt: 'BASE_64_RECEIPT', - }, - { - password: 'APPLE_PASSWORD', - }, -); - -const { data } = verifyGoogleReceipt( - { - packageName: 'PACKAGE_NAME', - token: 'TOKEN', - productId: 'PRODUCT_ID', - }, - { - clientEmail: 'GOOGLE_CLIENT_EMAIL', - privateKey: 'GOOGLE_PRIVATE_KEY', - }, -); -``` - -## NestJS IAP wrapper - -This is a NestJS wrapper for the Node.js library. - -β†’ [README.md](./packages/nest-iap/README.md) for more information. - -### Installation - -```bash -yarn add @jeremybarbet/nest-iap -``` - -### Usage - -```ts -import { IAPModule } from '@jeremybarbet/nest-iap'; - -@Module({ - controllers: [...], - providers: [...], - imports: [ - IAPModule.forRoot({ - apple: { - password: '', - }, - google: { - clientEmail: '', - privateKey: '', - }, - }), - ], -}) -``` - -```ts -import { IAPService } from '@jeremybarbet/nest-iap'; - -class MyService { - constructor(private readonly iapService: IAPService) {} - - async someMethod() { - const { response } = await this.iapService.verifyAppleReceipt({ - transactionReceipt: 'BASE_64_RECEIPT', - }); - } - - async someOtherMethod() { - const { response } = await this.iapService.verifyGoogleReceipt({ - packageName: 'PACKAGE_NAME', - token: 'TOKEN', - productId: 'PRODUCT_ID', - }); - } -} -``` - -## Apple API types - -Typescript definitions for Apple API services. - -β†’ [README.md](./packages/apple-api-types/README.md) for more information. - -### Installation - -```bash -yarn add @jeremybarbet/apple-api-types -``` - -## Google API types - -Typescript definitions for Google API services. - -β†’ [README.md](./packages/google-api-types/README.md) for more information. - -### Installation - -```bash -yarn add @jeremybarbet/google-api-types -``` +- [Node.js IAP](./packages/node-iap/README.md) - Core library wrapping the Apple and Google IAP APIs to get and verify in-app purchases +- [NestJS IAP](./packages/nest-iap/README.md) - NestJS wrapper for the Node.js library. +- [Apple API types](./packages/apple-api-types/README.md) - Typescript definitions for Apple API services. +- [Google API types](./packages/google-api-types/README.md) - Typescript definitions for Google API services. ## Acknowledgments diff --git a/packages/apple-api-types/src/app-store-receipts.interface.ts b/packages/apple-api-types/src/app-store-receipts.interface.ts index f4a261d..7fb9624 100644 --- a/packages/apple-api-types/src/app-store-receipts.interface.ts +++ b/packages/apple-api-types/src/app-store-receipts.interface.ts @@ -1,5 +1,4 @@ /** - * Interfaces extracted from the Apple documentation * @link https://developer.apple.com/documentation/appstorereceipts */ diff --git a/packages/apple-api-types/src/app-store-server.interface.ts b/packages/apple-api-types/src/app-store-server.interface.ts index cd120a5..54b6748 100644 --- a/packages/apple-api-types/src/app-store-server.interface.ts +++ b/packages/apple-api-types/src/app-store-server.interface.ts @@ -1,5 +1,4 @@ /** - * Interfaces extracted from the Apple documentation * @link https://developer.apple.com/documentation/appstoreserverapi */ diff --git a/packages/google-api-types/README.md b/packages/google-api-types/README.md index b144757..5f7a050 100644 --- a/packages/google-api-types/README.md +++ b/packages/google-api-types/README.md @@ -5,6 +5,7 @@ Typescript definitions for Google API services. ## Includes - [Google Play Developer API](https://developers.google.com/android-publisher) +- [Real-time developer notifications](https://developer.android.com/google/play/billing/rtdn-reference) ## Installation diff --git a/packages/google-api-types/index.ts b/packages/google-api-types/index.ts index 762a68b..4ebaccf 100644 --- a/packages/google-api-types/index.ts +++ b/packages/google-api-types/index.ts @@ -1 +1,2 @@ export * from './src/android-publisher.interface'; +export * from './src/rtdn.interface'; diff --git a/packages/google-api-types/src/android-publisher.interface.ts b/packages/google-api-types/src/android-publisher.interface.ts index 1a0e582..fd3fe94 100644 --- a/packages/google-api-types/src/android-publisher.interface.ts +++ b/packages/google-api-types/src/android-publisher.interface.ts @@ -1,6 +1,4 @@ /** - * Interfaces extracted from the Google API - * Would be nice to create a script to pull the data from a google endpoint and automatically update types and descriptions. * @link https://developers.google.com/android-publisher */ diff --git a/packages/google-api-types/src/rtdn.interface.ts b/packages/google-api-types/src/rtdn.interface.ts new file mode 100644 index 0000000..7082659 --- /dev/null +++ b/packages/google-api-types/src/rtdn.interface.ts @@ -0,0 +1,112 @@ +/** + * @link https://developer.android.com/google/play/billing/rtdn-reference + */ + +interface OneTimeProductNotification { + /** + * The version of this notification. Initially, this will be "1.0". This version is distinct from other version fields. + */ + version: string; + + /** + * The type of notification. It can have the following values: + * (1) ONE_TIME_PRODUCT_PURCHASED - A one-time product was successfully purchased by a user. + * (2) ONE_TIME_PRODUCT_CANCELED - A pending one-time product purchase has been canceled by the user. + */ + notificationType: number; + + /** + * The token provided to the user’s device when purchase was made. + */ + purchaseToken: string; + + /** + * The purchased one-time product ID (for example, "sword_001") + */ + sku: string; +} + +interface SubscriptionNotification { + /** + * The version of this notification. Initially, this is "1.0". This version is distinct from other version fields. + */ + version: string; + + /** + * The notificationType for a subscription can have the following values: + * (1) SUBSCRIPTION_RECOVERED - A subscription was recovered from account hold. + * (2) SUBSCRIPTION_RENEWED - An active subscription was renewed. + * (3) SUBSCRIPTION_CANCELED - A subscription was either voluntarily or involuntarily cancelled. For voluntary cancellation, sent when the user cancels. + * (4) SUBSCRIPTION_PURCHASED - A new subscription was purchased. + * (5) SUBSCRIPTION_ON_HOLD - A subscription has entered account hold (if enabled). + * (6) SUBSCRIPTION_IN_GRACE_PERIOD - A subscription has entered grace period (if enabled). + * (7) SUBSCRIPTION_RESTARTED - User has restored their subscription from Play > Account > Subscriptions. The subscription was canceled but had not expired yet when the user restores. For more information, see [Restorations](/google/play/billing/subscriptions#restore). + * (8) SUBSCRIPTION_PRICE_CHANGE_CONFIRMED - A subscription price change has successfully been confirmed by the user. + * (9) SUBSCRIPTION_DEFERRED - A subscription's recurrence time has been extended. + * (10) SUBSCRIPTION_PAUSED - A subscription has been paused. + * (11) SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED - A subscription pause schedule has been changed. + * (12) SUBSCRIPTION_REVOKED - A subscription has been revoked from the user before the expiration time. + * (13) SUBSCRIPTION_EXPIRED - A subscription has expired. + */ + notificationType: number; + + /** + * The token provided to the user's device when the subscription was purchased. + */ + purchaseToken: string; + + /** + * The purchased subscription's product ID (for example, "monthly001"). + */ + subscriptionId: string; +} + +interface TestNotification { + /** + * The version of this notification. Initially, this is "1.0". This version is distinct from other version fields. + */ + version: string; +} + +export interface DecodedData { + /** + * The version of this notification. Initially, this is "1.0". This version is distinct from other version fields. + */ + version: string; + + /** + * The package name of the application that this notification relates to (for example, `com.some.thing`). + */ + packageName: string; + + /** + * The timestamp when the event occurred, in milliseconds since the Epoch. + */ + eventTimeMillis: number; + + /** + * If this field is present, then this notification is related to a one-time purchase, and this field contains additional information related to the purchase. Note that this field is mutually exclusive with testNotification and subscriptionProductNotification. + */ + oneTimeProductNotification?: OneTimeProductNotification; + + /** + * If this field is present, then this notification is related to a subscription, and this field contains additional information related to the subscription. Note that this field is mutually exclusive with testNotification and oneTimeProductNotification. + */ + subscriptionNotification?: SubscriptionNotification; + + /** + * If this field is present, then this notification is related to a test publish. These are sent only through the Google Play Developer Console. Note that this field is mutually exclusive with subscriptionNotification and oneTimeProductNotification. + */ + testNotification?: TestNotification; +} + +interface Message { + attributes: Record; + data: string; + messageId: string; +} + +export interface BodyPayload { + message: Message; + subscription: string; +}