Question

"The receipt is not valid" when customer.subscription.created

  • 27 June 2024
  • 3 replies
  • 46 views

Badge

Hello RevenueCat team and community!

I’m trying to integrate Stripe with RC and so far i’ve been following the steps of this documentation.

The documentation says “When using Stripe Checkout, you should listen to and send subscriptions to RevenueCat after both the customer.subscription.created and checkout.session.completed events.”

It works when event is checkout.session.completed but it doesn`t if event is customer.subscription.created.

This is script sample

        if (
            self.event_type == "customer.subscription.created"
            or self.event_type == "checkout.session.completed"
        ):
            url = "https://api.revenuecat.com/v1/receipts"
            headers = {
                "Accept": "application/json",
                "Content-Type": "application/json",
                "X-Platform": "stripe",
                "Authorization": "Bearer strp_XXXXXXXXXX",
            }

            data = {
                "app_user_id": self.event_object.get("customer"),
                "fetch_token": self.event_object.get("id"),
            }

            try:
                response = requests.post(url, json=data, headers=headers)
            except Exception as e:
                print(e)

            if response.status_code == 200:
                print("Subscription updated successfully")
            else:
                print(
                    f"Failed to update subscription: {response.status_code} - {response.json()}"
                )

 

Why it doesn`t work with customer.subscription.created and why we need to sent POST to revenuecat two times?


This post has been closed for comments

3 replies

Userlevel 5
Badge +9

Hi @serhii-pachkovskyi,

We have updated our documentation to be clearer, you only need to send the purchase to RevenueCat one time and you can listen to either event. The update is here: https://www.revenuecat.com/docs/web/stripe#5-send-stripe-tokens-to-revenuecat

Can you explain more about what is not working with customer.subscription.created? Do you get an error from RevenueCat? Can you share an example request that you made to RevenueCat for customer.subscription.created?

Badge

Hi @serhii-pachkovskyi,

We have updated our documentation to be clearer, you only need to send the purchase to RevenueCat one time and you can listen to either event. The update is here: https://www.revenuecat.com/docs/web/stripe#5-send-stripe-tokens-to-revenuecat

Can you explain more about what is not working with customer.subscription.created? Do you get an error from RevenueCat? Can you share an example request that you made to RevenueCat for customer.subscription.created?

Thanks for answer, @sharif.
Yes, documentation is more clear now. Good)
And Yes, I get the 400 error “The receipt is not valid”, when using this script when I receive customer.subscription.created event from Stripe.
            url = "https://api.revenuecat.com/v1/receipts"
            headers = {
                "Accept": "application/json",
                "Content-Type": "application/json",
                "X-Platform": "stripe",
                "Authorization": "Bearer strp_XXXXXXXXXX",
            }

            data = {
                "app_user_id": self.event_object.get("customer"), # cus_XXXXXXXXX
                "fetch_token": self.event_object.get("id"), # sub_XXXXXXXXX
            }

            response = requests.post(url, json=data, headers=headers)

What am I doing wrong?

Userlevel 5
Badge +9

Hey @serhii-pachkovskyi,

In that case can you open a support ticket with the customer ID and subscription token so I can take a look?