Skip to main content

So I am able to use RC to complete purchases of a product.

Here’s what happens once a user has purchased a product.

 

→ I grab their Revenue Cat ID, and extract their latest transactionIdentifier

→ An API request is made with this info to our backend server to process their order.

 

Here is a code snippet of how I am using the React-Native SDK to get their transaction Id.

 

On the backend I want to verify their Revenue Cat ID has indeed made the purchase based on the provided transactionIdentifier.

 

What’s the best way to do this?

Can anyone help me with this?


Hey @Uchenna Okafor ,

 

A solution that I could think of for this would be to call allPurchasedIdentifiers which can be found in CustomerInfo which returns an array of strings which that is filled with all purchased skus, active and inactive from this customer. I would compare the transaction ID that you are returning above,  with that array and see if the ID shows in the array. if that ID shows in the array, it would be verified that the purchase was made. 

 

I hope this helps! 


Hey @Michael Fogel 

While the approach you've mentioned could work in certain scenarios, it's important to note that it's not a foolproof solution to verify transactions.

Calling the allPurchasedIdentifiers method from the RevenueCat CustomerInfo API would give you a list of all the SKUs that the customer has purchased in the past. However, this method does not provide transaction-specific details such as purchase dates, cancellation dates, and renewal dates, which are essential for verifying the current status of a subscription.

Moreover, relying solely on comparing the transaction ID with the purchased SKUs may not be accurate in all cases. For instance, a user may have multiple subscriptions or may have upgraded/downgraded their subscription plan since the transaction was made. In such cases, the transaction ID may not match the current active subscription, even though the user has made the purchase.

Therefore, while the approach you've suggested may work in certain scenarios, it's not a comprehensive solution for verifying transactions. It's still important to use web hooks and/or the Verify Receipt API to obtain real-time transaction details and keep your records up to date.


How can I use the Verify Receipt API?

Otherwise, is there a way to extract the transaction receipt and signature to send them to my backend for validation?


Hey @Michael Fogel 

While the approach you've mentioned could work in certain scenarios, it's important to note that it's not a foolproof solution to verify transactions.

Calling the allPurchasedIdentifiers method from the RevenueCat CustomerInfo API would give you a list of all the SKUs that the customer has purchased in the past. However, this method does not provide transaction-specific details such as purchase dates, cancellation dates, and renewal dates, which are essential for verifying the current status of a subscription.

Moreover, relying solely on comparing the transaction ID with the purchased SKUs may not be accurate in all cases. For instance, a user may have multiple subscriptions or may have upgraded/downgraded their subscription plan since the transaction was made. In such cases, the transaction ID may not match the current active subscription, even though the user has made the purchase.

Therefore, while the approach you've suggested may work in certain scenarios, it's not a comprehensive solution for verifying transactions. It's still important to use web hooks and/or the Verify Receipt API to obtain real-time transaction details and keep your records up to date.

 

hi, is there a guide on this? what is the “Verify Receipt API”? Is this a Revenuecat feature, or is this something in the app store APIs directly?


Hi @DoughBoy,

The validation itself is what RevenueCat provides out of the box - what would be your use case?

With the new RevenueCat v2 API you have these 2 endpoints that can be useful to achieve the initial scenario:

  • You can get all purchases done by a customer.
  • You can get the store_purchase_identifier for a purchase with this endpoint 

Let me know if this helps!


Hi @DoughBoy,

The validation itself is what RevenueCat provides out of the box - what would be your use case?

With the new RevenueCat v2 API you have these 2 endpoints that can be useful to achieve the initial scenario:

  • You can get all purchases done by a customer.
  • You can get the store_purchase_identifier for a purchase with this endpoint 

Let me know if this helps!

Hey Joan, thanks for sharing these endpoints.

My use case is I have a mobile game which has a backend that does a lot of game logic.

I don't want malicious users with a cracked version of the game to be able to play still, which someone could easily create by spoofing and faking the RevenueCat receipt validation logic on device.

 

So in my backend, I want to also validate the subscription and confirm they are a paying customer each time they log in, to prevent this abuse.

 

Is the API call you shared real time? I'll be able to call it on my backend immediately after they subscribe? 

Thanks!


Here’s how I got it working

After a purchase is complete, send `transaction.transactionIdentifier`, `productIdentifier` and `appUserId` to your backend.

In the backend, using the productIdentifier figure out if it’s a “purchase” or a “subscription” (I use a descriptive product identifier - iap_ or subscription_ to figure this out).

Call the respective revenuecat endpoints for either customer purchases or customer subscriptions and find the item with store_purchase_identifier matching the transactionIdentifier supplied from the app.

That should be enough.

 


For those wondering, here's how I did it. It's not really efficient; I wish there were better query parameters that can filter by transaction ID or even allow sorting/order by descending/ascending

```
$transactionId = 'xxx';

    $revenuecatService = app(\App\Contracts\RevenueCatContract::class);
    $found = false;
    $lastId = null;
    $counter = 0;

    while (!$found) {
        $params = 'limit' => 20];
        if ($lastId) {
            $params'starting_after'] = $lastId;
        }
        $counter++;
        $results = $revenuecatService->listCustomerPurchases('$RCAnonymousID:0f374bee3f124ec0991c3bda3f0c0f99', $params);

        if (empty($resultss'items'])) {
            break;
        }

        foreach ($resultsb'items'] as $item) {
            if (isset($item['store_purchase_identifier']) && $item 'store_purchase_identifier'] === $transactionId) {
                $found = true;
                $results = $item;
                break;
            }
        }

        if (!$found) {
            $lastId = end($results'items'])/'id'];
        }
    }
```


Reply