Google pub/sub subscription data doesn’t match with the app

I’m trying to listen for subscription changes (new and existing) of my Google Play app on the server. Here’s the code I’m using. This uses the google/cloud-pubsub composer package:

$projectId = 'app-name';
$keyFile = file_get_contents(storage_path('app/app-name.json'));
$pubsub = new PubSubClient([
    'projectId' => $projectId,
    'keyFile' => json_decode($keyFile, true)

$httpPostRequestBody = file_get_contents('php://input');
$requestData = json_decode($httpPostRequestBody, true);


$message = $pubsub->consume($requestData);

The code above works but the problem is that the data I get doesn’t match the one I’m getting in the app side. This is a sample data:


If you base64_decode() the data, you’ll get something like this:

version: "1.0",
packageName: "",
eventTimeMillis: "1607997631636",
subscriptionNotification: {
    version: "1.0",
    notificationType: 4,
    purchaseToken: "kmloa....",
    subscriptionId: "app_subs1"

This is where I’m expecting the purchaseToken to be the same as the one I’m getting from the client side.

Here’s the code in the client-side. I’m using Expo in-app purchases to implement subscriptions:

setPurchaseListener(async ({ responseCode, results, errorCode }) => {
if (responseCode === IAPResponseCode.OK) {
    const { orderId, purchaseToken, acknowledged } = results[0];
    if (!acknowledged) {
        await"/subscribe", {
            order_id: orderId,
            order_token: purchaseToken,
            data: JSON.stringify(results[0]),

        finishTransactionAsync(results[0], true);
            "You're now subscribed! You can now use the full functionality of the app."

I’m expecting the purchaseToken I’m extracting from results[0] to be the same as the one the Google server is returning when it pushes the notification to the endpoint. But it doesn’t.

Source: Laravel

Leave a Reply