Google IAP In App Purchase auto-renewing subscriptions Webhook for Subscription update / cancellation in NodeJS - node.js

Is there any way to implement a Webhook for automatic update of subscriptions on server side, in nodejs for example, for situations such as: the user renewed or canceled his subscription?
Currently I save the subscription data in my Database after purchase and use the Google Developers API to verify that it has been renewed or canceled when necessary.
However, for some Administrator routines I need to check all subscriptions at once and this includes calling the Google API for each one. This process is slow and can take a long time.
I could create a method that checks and updates all subscriptions according to the Google API response, and leave this process running through a Cronjob every day at night. I believe it will work, but a server-side Webhook would be the ideal solution.
Something which automatically notifies my server as soon as there is a change to a subscription so that I can update it in my DB immediately.

Found the answer. We can use Google Cloud Platform (GCP) to subscribe to topics and receive real-time notifications when a subscription change.
All steps are described in detail in their documentation: https://developer.android.com/google/play/billing/getting-ready#configure-rtdn

Related

Stripe Webhooks: check if object changed

I am integrating Stripe webhooks in a webapp to implement subscriptions using Stripe Billing. The webapp has a frontend and backend.
When a subscription is started or canceled the frontend directly communicates with the backend and everything happens by synchronously calling the Stripe API.
For example, to cancel a subscription, this is the flow:
the user taps on a button in the frontend
frontend calls my app backend to cancel the sub
backend calls the stripe api to actually cancel the sub
backend updates the saved subscription object in its own db
Here comes the "problem": after some seconds a customer.subscription.deleted webhook calls comes at my backend telling me to update the subscription I just saved. I want to avoid the double-save for performance reasons and was wondering if these stripe objects have some kind of signature or update count to check if they have changed with respect to the previous version.
I think it's quite common to use webhooks only for out-of-band updates, so this use case should be supported.
There is not an "update" count or signature for each state of a Subscription. One alternative might be to skip updating your Subscription object in the database directly when processing the request from your own front end to your backend. Instead you could depend primarily on the event notification from Stripe to update your database. This way, you're only updating the database once and if you need to make changes directly from the Stripe dashboard for some reason, those will still propagate to your backend.
I also wanted to note that you should build your webhook event handler to be idempotent by checking the ID of the event before processing as occasionally Stripe will send the same event more than once even if acknowledged successfully.
https://stripe.com/docs/webhooks/best-practices#event-handling

Authorize.Net Recurring Billing Events

I have successfully deployed Authorize.net API(currently sandbox mode) for subscription purposes. I have also configured its webhooks that are also working. But I have a confusion that still exists even after a week on working with the said API.
The question is, when a subscription starts in case of recurring billing(in my scenario subscription is monthly) the event that is called is
net.authorize.customer.subscription.created
When a month passes on a subscription and next bill payment is made by the API, what event will get called? How can I capture Or to what event should I be listening to? . Is it going to be
net.authorize.customer.subscription.updated
Currently I have clicked yes on all the all the events that are there for the webhooks
The event will be a payment related event, not a subscription related event. Subscription related events only happen when you do something to a subscription (i.e. create, modify, or delete) not with it (make payment).
So you would look out for any of the following:
net.authorize.payment.capture.created
net.authorize.payment.fraud.approved
net.authorize.payment.fraud.declined
net.authorize.payment.fraud.held

If I cancel user's subscription manually in Stripe dashboard, should a webhook endpoint I set up on my web server be notified of that?

I am currently in test mode with Stripe.
I cancelled a users subscription is Stripe dashboard, but the webhook I set up on my site's web server (which uses Laravel Cashier) does not fire i.e. the subscription data is unaffected on my site's web server.
I thought this should happen. The webhook is otherwise tested and working.
Whenever a subscription is canceled, the event customer.subscription.deleted will be generated on your account and sent to your webhook endpoint (assuming it listens for it). This is true whether the subscription is canceled automatically after too many failures, via the API or manually in the dashboard.
You can easily confirm this in the dashboard by looking at the Events section for your customer and see this event.
It's likely an issue in the configuration for your webhook or the code server-side with Cashier.
For testing: also make sure, that you set "cancel subscription immediately" instead of at the end of the billing period otherwise it won't fire instantly.
You could also test it with a test clock properly :)

Google Calendar live sync with node js app

I want to sync google calendar with my app.
When user add some event in the Google calendar at that time, I want these new event in my node server response
Means live sync with google calendar.
I want something like listener that listen new event.
With Google Calendar API you can watch for changes to Events or CalendarList resources, see this and this. Basically you will need to create an endpoint on your server which will receive events/calendars update notifications. When notification arrives, request a calendars/events synchronization. To make the synchronization efficient, use incremental sync. Check this question also to see the algorithm.
You may check this Quickstart tutorial and node-google-calendar.
You need to create a service account if you don't have one. A public/private key pair is generated for the service account, which is created from the Google API console. Take note of the service account's email address and store the service account's json or P12 private key file in a location accessible to your application. Your application needs them to make authorized API calls. If a user wants to give access to his Google Calendar to your application, he must give specific permission for each of the calendars to the created Service Account using the supplied email address under the Google Calendar settings.

Should I use Azure Service (such as Scheduler) for sending rest messages to my bot, or use a separate thread for notifications?

I am creating a bot using Microsoft Bot Framework (BotBuilder) and want it to message the user when an appointment is about to begin.
I currently use Microsoft Graph api to access the user's Office 365 calendar and store the appointments. A background thread then keeps track of time and then messages the user when an appointment is about to start.
The current idea is to use Graph webhooks to notify my bot about new appointments.
My question is, would it be smarter to use an Azure service (such as Scheduler) to keep track of the appointments, and send rest messages to my bot, which will then send a message to the user?
My worry is, that as the amount of users rise, the amount of appointments and time checks will become too large, and that maybe Azure services would be able to handle it better.
This is a perfect fit for Azure Functions with a HTTP Trigger.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook
This article explains how to configure and work with HTTP triggers and bindings in Azure Functions. With these, you can use Azure Functions to build serverless APIs and respond to webhooks.
Azure Functions provides the following bindings:
An HTTP trigger lets you invoke a function with an HTTP request. This can be customized to respond to webhooks.
An HTTP output binding allows you to respond to the request.

Resources