This guide provides step-by-step instructions to configure your Google Cloud Console project, enable the Gmail API, configure OAuth 2.0 credentials, and obtain a persistent Refresh Token to connect your Gmail account directly to the YouPI PG Merchant Admin panel.
YouPI PG introduces a 2-Level Verification Architecture:
- Level 1 Verification: First incoming credit match detected via Direct Gmail API or Android SMS Gateway in the 5-minute payment window. Starts a 5-second dual-verification grace window.
- Level 2 Verification: Dual confirmation (
DUAL_VERIFIED_L2) when both Gmail and SMS Gateway confirm the credit within 5 seconds. - Aggressive 1-Second Polling: Background poller checks both channels every 1 second without requiring an active browser tab or manual click.
To connect Gmail in the Merchant Admin panel (http://localhost:5000), you will need:
- Google OAuth Client ID: e.g.,
YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com - Google OAuth Client Secret: e.g.,
YOUR_GOOGLE_CLIENT_SECRET - Google Refresh Token: e.g.,
YOUR_GOOGLE_REFRESH_TOKEN
- Open Google Cloud Console.
- Log in with the Google Account that receives your bank credit notification emails (or your merchant admin account).
- At the top navigation bar, click the project selection dropdown and click "New Project".
- Set Project Name to:
YouPI-PG-Observer. - Leave Organization as No organization (or select your organization).
- Click Create and wait a few seconds for project provisioning.
- In the Google Cloud Console navigation menu (☰), go to APIs & Services > Library.
- In the search box, search for:
Gmail API. - Click on the Gmail API tile.
- Click the blue Enable button.
- In the sidebar, navigate to APIs & Services > OAuth consent screen.
- Under User Type, select External (or Internal if using Google Workspace).
- Click Create.
- Fill in the required application information:
- App name:
YouPI Payment Observer - User support email: Your Gmail address
- Developer contact information: Your email address
- App name:
- Click Save and Continue.
- On the Scopes page:
- Click Add or Remove Scopes.
- Search for
gmail.readonlyor check.../auth/gmail.readonly(Read all resources and their metadata). - Alternatively, you can use
https://mail.google.com/for full access if restricted scopes are accepted. - Click Update and then Save and Continue.
- On the Test Users page:
- Click + Add Users.
- Enter your bank-linked Gmail address (the email that receives transaction alerts).
- Click Add, then click Save and Continue.
- Review the summary and click Back to Dashboard.
- In the sidebar, navigate to APIs & Services > Credentials.
- Click + Create Credentials at the top and select OAuth client ID.
- Under Application type, select Web application.
- Under Name, enter:
YouPI PG Web Client. - Under Authorized JavaScript origins, add:
http://localhost:5000http://localhost:6100https://developers.google.com
- Under Authorized redirect URIs, add both of the following URIs:
https://developers.google.com/oauthplayground(Required for generating the initial Refresh Token)http://localhost:5000/oauth2callback
- Click Create.
- A modal will appear displaying:
- Your Client ID
- Your Client Secret
- Copy both values to a safe location.
Google OAuth access tokens expire after 1 hour, but a Refresh Token allows the YouPI PG server to automatically fetch fresh access tokens indefinitely in the background.
- Open Google OAuth 2.0 Playground.
- Click the Gear Icon (⚙️) in the top right corner to open configuration settings:
- Check the box: "Use your own OAuth credentials".
- In OAuth Client ID, paste your Client ID from Step 4.
- In OAuth Client secret, paste your Client Secret from Step 4.
- On the left pane under Step 1 Select & authorize APIs:
- Scroll down to Gmail API v1.
- Check
https://www.googleapis.com/auth/gmail.readonly(or in the text box below, typehttps://mail.google.com/). - Click the blue Authorize APIs button.
- Google will display a sign-in screen:
- Select your bank-linked Gmail account.
- If prompted with "Google hasn't verified this app", click Advanced > Go to YouPI Payment Observer (unsafe).
- Review the requested permission and click Continue.
- You will be redirected back to the OAuth Playground under Step 2 Exchange authorization code for tokens:
- The authorization code will be populated automatically.
- Click the blue button: "Exchange authorization code for tokens".
- The right panel will display the JSON response containing:
refresh_token: "<your_refresh_token_here>"
- Copy the Refresh Token string.
- Open the YouPI Merchant Admin dashboard at
http://localhost:5000. - Navigate to 📡 Payment Observers (SMS & Gmail) (Tab 3).
- In the 📧 Gmail Direct API card:
- Paste your Google OAuth Client ID.
- Paste your Google OAuth Client Secret.
- Paste your Google Refresh Token.
- Click 💾 Save Gmail Credentials.
- Click 🔑 Test Connection:
- YouPI PG will exchange the refresh token with Google's OAuth server and query
users.getProfile. - The badge will turn green:
CONFIGUREDwith confirmation:Connected! Authorized as yourname@gmail.com. Total messages: 1,420.
- YouPI PG will exchange the refresh token with Google's OAuth server and query
Once configured:
- When a customer initiates a UPI payment, the session enters the 5-minute payment window.
- YouPI PG launches aggressive 1-second background pollers across both the Android SMS Gateway and the Gmail Direct API.
- When your bank sends an email credit alert (e.g. from HDFC, SBI, ICICI, Axis, Paytm, or Kotak):
- The poller extracts the amount, payer VPA, and bank reference/UTR.
- The payment is attributed as Level 1 Verified.
- A 5-second grace window starts to inspect for the companion Android SMS.
- If Android SMS also confirms within 5s, upgraded to Level 2 Dual Verified (
DUAL_VERIFIED_L2). - Payment is finalized as
SUCCESSand customer checkout updates in real-time.