Skip to content

Commit

Permalink
feat: add google RTDN
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Jun 30, 2022
1 parent 8565ff8 commit 34b1c04
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 122 deletions.
124 changes: 6 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* Interfaces extracted from the Apple documentation
* @link https://developer.apple.com/documentation/appstorereceipts
*/

Expand Down
1 change: 0 additions & 1 deletion packages/apple-api-types/src/app-store-server.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* Interfaces extracted from the Apple documentation
* @link https://developer.apple.com/documentation/appstoreserverapi
*/

Expand Down
1 change: 1 addition & 0 deletions packages/google-api-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions packages/google-api-types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './src/android-publisher.interface';
export * from './src/rtdn.interface';
2 changes: 0 additions & 2 deletions packages/google-api-types/src/android-publisher.interface.ts
Original file line number Diff line number Diff line change
@@ -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
*/

Expand Down
112 changes: 112 additions & 0 deletions packages/google-api-types/src/rtdn.interface.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
data: string;
messageId: string;
}

export interface BodyPayload {
message: Message;
subscription: string;
}

0 comments on commit 34b1c04

Please sign in to comment.