Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle google play notification pubsub data? #207

Closed
liuzhen2008 opened this issue Aug 29, 2018 · 10 comments
Closed

How to handle google play notification pubsub data? #207

liuzhen2008 opened this issue Aug 29, 2018 · 10 comments

Comments

@liuzhen2008
Copy link

liuzhen2008 commented Aug 29, 2018

I am trying to setup google play pubsub notifications.

By running a subscriber on the server, whenever a user makes an auto renewal subscription, my server currently is able to receive a notification via pubsub.

The message object received looks something like this:

{ connectionId: '419b8ce1-bb35-41f5-94eb-b7e00dced8a0',
  ackId: 'fi0_RUFeQBJMJgpESVMrQwsqWBFOBCEhPjA-RVNEUAYWLF1GSFE3GQhoUQ5PXiM_NSAoRRUjKBwRY1ZedA1oXFx1BlcIEXEpMndrX0cLAk9TVm95JAxgVVt1DlEMH3R7YHNuWzuc0oyc7OBAZhw9WBJLLD4',
  id: '189709016661641',
  attributes: {},
  publishTime: Wed Aug 29 2018 04:06:06 GMT+0000 (UTC),
  received: 1535515567620,
  data: <Buffer 7b 22 76 65 72 73 69 6f 6e 22 3a 22 31 2e 30 22 2c 22 70 61 63 6b 61 67 65 4e 61 6d 65 22 3a 22 6c 6f 76 65 2e 74 68 65 63 6f 76 65 2e 61 70 70 22 2c ... >,
  length: [Getter],
  ack: [Function],
  nack: [Function] }

And after I call toString() of the buffer, the string looks like this:

{"version":"1.0","packageName":"<my-app-bundle-id>","eventTimeMillis":"1535516522925","subscriptionNotification":{"version":"1.0","notificationType":4,"purchaseToken":"hjlbomjlhaminbjangoemekb.AO-J1OwzsRLC3a6xEy8G_NcsEMjtmt8yrjw97hp4xfRbGz14OaWL339CwHpstJzHuYtNdRaAx21IFynF-KwPlwBn2rsNB62GlfTymM6DqEkTG_CyaHdOiYWByMhk11IpwDsxYyH5D4iyj7UkkDAgZmnK-wnlukXEcw","subscriptionId":"<product-purchased>"}}
My question is, what do I do with this purchaseToken? How do I obtain the signature and other data so I can pass it to iap library?

@voltrue2
Copy link
Owner

So the stringified JSON object that you have above must be given to the library's .validate() function along with a signature in an object.
The structure of the object is:

{
  data: <your purchased JSON data>,
  signature: 'purchased JSON data signature as a string'
}

@superandrew213
Copy link
Contributor

@liuzhen2008 you can see here, how I made it work. Essentially you are passing a placeholder for signature.

@liuzhen2008
Copy link
Author

@superandrew213 uh, where do I check? Did you have an example somewhere?

@liuzhen2008
Copy link
Author

liuzhen2008 commented Aug 29, 2018

@voltrue2 Thats the problem! There are no signatures coming from google pubsub!

@liuzhen2008
Copy link
Author

I ended up using a different library https://www.npmjs.com/package/iap for google pubsub notifications.

It would be helpful to know what I need to do so I only need to use 1 library.

@voltrue2
Copy link
Owner

voltrue2 commented Aug 30, 2018 via email

@superandrew213
Copy link
Contributor

superandrew213 commented Aug 30, 2018

@liuzhen2008 looks like I forgot the link. Here it is: #141

Replace only xxx with your values.

{
  data: {
    packageName: "xxx",
    productId: "xxx",
    purchaseToken: "xxx",
    autoRenewing: true,
  },
  signature: 'signature',
}

@voltrue2
Copy link
Owner

@liuzhen2008 @superandrew213

I finally got to work on this. Now you can validate your receipts using Google Service Account.
It means that you only need packageName, productId, and purchaseToken to perform the validation.
Here is the commit: 709ca12

@liuzhen2008
Copy link
Author

Awesome, i will test this out some time.
Thanks a lot

@voltrue2
Copy link
Owner

voltrue2 commented Oct 3, 2018

Great! Thank you for the support.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants