# How to Merge Supabase and Stripe into One Endpoint

> Instead of having your frontend make 2 separate requests over high-latency cellular networks, RealComposer fetches your Supabase user record and Stripe subscription details concurrently using Promise.all on Cloudflare Workers, returning a unified JSON payload in a single round-trip.

- Canonical page: https://realcomposer.com/recipes/merge-supabase-and-stripe-into-single-endpoint
- Client platform: React / Flutter / Mobile
- Upstream services: Supabase, Stripe
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/merge-supabase-and-stripe-into-single-endpoint.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=merge-supabase-and-stripe-into-single-endpoint&via=agent

## Problem: The Chatty Round-Trip Problem on Mobile Networks

Mobile apps that call Supabase for profile data, then wait for a response, then call Stripe for subscription status suffer from multi-second load screens and high battery drain.

- Multiple sequential network round-trips stalling UI render
- Exposed Stripe credentials on mobile devices
- Inconsistent state between auth and billing

## Solution steps

1. **Configure Step 1 (Supabase)**: Target Supabase PostgREST endpoint with apikey header.

2. **Configure Step 2 (Stripe)**: Target Stripe customer endpoint in parallel with Secret Vault auth.

3. **Map to Unified Schema**: Merge profile and billing fields into a single clean JSON object.

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Supabase + Stripe BFF",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "steps": [
    {
      "stepKey": "user",
      "upstreamUrlTemplate": "https://xyz.supabase.co/rest/v1/profiles?id=eq.{{query.userId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "apikey": "{{secrets.SUPABASE_ANON_KEY}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "billing",
      "upstreamUrlTemplate": "https://api.stripe.com/v1/customers/{{query.stripeId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "userId",
        "sourceStep": "user",
        "sourcePath": "0.id"
      },
      {
        "targetPath": "fullName",
        "sourceStep": "user",
        "sourcePath": "0.full_name"
      },
      {
        "targetPath": "email",
        "sourceStep": "user",
        "sourcePath": "0.email"
      },
      {
        "targetPath": "billing.customerId",
        "sourceStep": "billing",
        "sourcePath": "id"
      },
      {
        "targetPath": "billing.balance",
        "sourceStep": "billing",
        "sourcePath": "balance",
        "type": "number"
      },
      {
        "targetPath": "billing.delinquent",
        "sourceStep": "billing",
        "sourcePath": "delinquent",
        "type": "boolean"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/acme/user-dashboard?userId=u_1&stripeId=cus_99"
```

## Payload before and after

Raw upstream response:

```json
{
  "user": [
    {
      "id": "u_1",
      "full_name": "Jane Doe",
      "email": "jane@example.com"
    }
  ],
  "billing": {
    "id": "cus_99",
    "balance": 0,
    "delinquent": false
  }
}
```

Slimmed RealComposer response:

```json
{
  "userId": "u_1",
  "fullName": "Jane Doe",
  "email": "jane@example.com",
  "billing": {
    "customerId": "cus_99",
    "balance": 0,
    "delinquent": false
  }
}
```

## FAQ

### What happens if Stripe is down or slow?

RealComposer supports per-step timeouts and fallback JSON, so your app still receives user profile data without failing completely.
