# Stripe payment received notifications on your phone

> Get a push notification with the amount and customer email every time a Stripe payment succeeds, with a button to open it in the Dashboard.

- Company: Stripe (https://www.justpush.io/recipes/stripe)
- Event: `payment_intent.succeeded` (payment_intent.succeeded)
- Tags: Finance, Payments
- Install: https://studio.justpush.io/recipes/stripe/payment-succeeded
- Web page: https://www.justpush.io/recipes/stripe/payment-succeeded

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. In the Stripe Dashboard, open Workbench > Webhooks and click Add destination.
3. Select the payment_intent.succeeded event and choose Webhook endpoint.
4. Paste your webhook URL (shown in Studio after install) as the endpoint URL and save.
5. Reveal the signing secret (whsec_…) and copy it into JustPush.

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Stripe → payment_intent.succeeded
// Fires when a payment succeeds.
// Docs: https://docs.stripe.com/api/events/types
//
// Paste this into a JustPush Studio integration and add a Stripe webhook destination
// for the "payment_intent.succeeded" event pointing at the integration's endpoint URL.

// Stripe amounts are in the currency's smallest unit (cents), except for
// zero-decimal currencies such as JPY, where 500 means ¥500.
const ZERO_DECIMAL = new Set([
    "bif", "clp", "djf", "gnf", "jpy", "kmf", "krw", "mga",
    "pyg", "rwf", "ugx", "vnd", "vuv", "xaf", "xof", "xpf",
])

function money(amount, currency) {
    // Don't invent a figure when the event doesn't carry one.
    if (typeof amount !== "number" || !Number.isFinite(amount) || !currency) return null

    const code = String(currency).toLowerCase()
    const value = ZERO_DECIMAL.has(code) ? amount : amount / 100

    try {
        return new Intl.NumberFormat("en-GB", { style: "currency", currency: code }).format(value)
    } catch {
        return `${value} ${code.toUpperCase()}`
    }
}

// Test-mode objects live under /test in the Dashboard.
function dashboardUrl(event, path) {
    return `https://dashboard.stripe.com/${event.livemode ? "" : "test/"}${path}`
}

function handleRequest(request) {
    const event = request.body

    // Guard: only handle this event type, so other Stripe events on this integration stay quiet.
    if (event?.object !== "event" || event.type !== "payment_intent.succeeded" || !event.data?.object) {
        console.log(`Ignoring Stripe event "${event?.type ?? "unknown"}"`)
        return null
    }

    const payment = event.data.object
    const amount = money(payment.amount_received ?? payment.amount, payment.currency) ?? "A payment"
    const who = payment.receipt_email ? ` from ${payment.receipt_email}` : ""
    const about = payment.description ? ` — ${payment.description}` : ""

    return {
        title: "💰 Payment received",
        message: `${amount}${who}${about}`,
        topic: "Stripe",
        priority: 0, // Normal — money in is good news, not an emergency
        sound: "cashregister",
        buttons: [{ cta: "View payment", url: dashboardUrl(event, `payments/${payment.id}`) }],
    }
}
```

## Stripe payment_intent.succeeded webhook payload (sample)

```json
{
  "id": "evt_test_payment_succeeded",
  "data": {
    "object": {
      "id": "pi_test_3Qx1Y2",
      "amount": 4900,
      "object": "payment_intent",
      "status": "succeeded",
      "currency": "eur",
      "customer": "cus_test_R2d2",
      "description": "Pro plan — annual upgrade",
      "receipt_email": "jane@example.com",
      "amount_received": 4900
    }
  },
  "type": "payment_intent.succeeded",
  "object": "event",
  "created": 1790584200,
  "livemode": false,
  "api_version": "2025-09-30.clover"
}
```

## Signature check

Stripe signs every webhook with a timestamped HMAC-SHA256 signature in the Stripe-Signature header, made with your endpoint's signing secret. JustPush checks it before the code runs.

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Stripe and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
