In addition to basic features like device management and site management, the Bluesky Communication Box system also adds user management. For this user management function, the system also pairs an app for payment. Today, we’ll explain how to choose Google Pay.

1. Introduction to Google Pay
To implement Google Pay, the app first integrates the Google Play Billing Library to complete the purchase process and obtain purchase tokens (purchaseToken) and order IDs (orderId). The backend provides an API interface to receive purchase credentials (i.e., purchaseToken and productId) sent by the frontend. It then verifies the validity of the purchase credentials with the Google API and handles business logic (such as product delivery and updating user permissions). This article will focus on the backend integration.
2. Process Overview
Verifying Purchase Receipts: After the app completes the purchase process, the backend system receives a payment order record. The system needs to verify the record token. This verification process follows Google OAuth 2.0, and the order validity is confirmed based on the response status. A portion of the code is shown below:

Handling Developer Notifications: After receiving the order status, the system needs to determine whether the order status is valid. If so, it also determines whether the items in the order have been consumed. If so, it indicates that the order has been processed; otherwise, it processes the order items. The system also obtains the current order amount based on the order item number for subsequent use. A portion of the code is shown below:

Managing Order Status: If all order conditions are met but the order has not been consumed, the system processes the order and ultimately marks the items as consumed.

The figure above shows the complete Google Pay integration process. Furthermore, users need to record each order during the processing process and perform repetitive processing to prevent the app from sending duplicate messages and causing duplicate purchases of order items.