# Demo: A donation for every referral

> A product gives 10 € when a referred friend signs up. The referrer picks the charity upfront, so every invite names it; the friend's own welcome gift waits for their choice.

One variant of **A donation for an achievement**, in Software and apps: 10 € when the friend signs up.

A made-up site, your-app.example/referrals, walked through screen by screen with the Charitips API calls the product makes at each step. Rebuild it in your own project to start from a working flow.

The charity choice in this demo is the Charitips [charity selection widget](https://www.charitips.com/docs/widgets/charity_selection.md), a ready-made proposal. Use it whole, use parts of it, or build your own experience from scratch with the API: [List charities](https://www.charitips.com/docs/api-reference/list-charities.md) gives the charities to show, and the calls below carry the chosen `charityId`.

Charitips widget: the charity cards, their profiles and the friend's thank-you card. Your own UI, built with the API: the referral link and invites, the button that saves the cause, and the cards that confirm each gift.

The full guide, with edge cases: https://www.charitips.com/docs/use-cases/referral.md.

The full guide, with edge cases: https://www.charitips.com/docs/use-cases/referral.md.

**Once, before the first customer:**

- [`POST /v1/charities-selections`](https://www.charitips.com/docs/api-reference/create-charities-selection.md) Create a charities selection: once: the charities you offer, from the catalog

  ```json
  {
    "name": "Referral charities",
    "charityIds": [
      "<charityId>"
    ]
  }
  ```
- [`POST /v1/campaigns`](https://www.charitips.com/docs/api-reference/create-campaign.md) Create a campaign: once: the campaign the donations go to

  ```json
  {
    "name": "Referral rewards",
    "charitiesSelectionId": "<charitiesSelectionId>"
  }
  ```
- [`POST /v1/campaigns/{campaignId}/activate`](https://www.charitips.com/docs/api-reference/activate-campaign.md) Activate a campaign: once: the campaign starts taking donations

## Screens and calls

### 1. Choose the charity your invites support

The referrer picks the charity upfront, so every invite can name it. Your app saves it on its side.

- The customer picks a charity from your selection.
- Button: Save

No call: this screen only shows the result.

### 2. Sam joined with your link

When the friend's account is confirmed, your server makes both donations: the referrer's, assigned at once to their charity, and the friend's, waiting for their own choice. You pay both, and the fiscal receipt goes to your company.

- Button: Simulate Sam's sign-up

**Your server calls:**

- [`POST /v1/donations`](https://www.charitips.com/docs/api-reference/create-donation.md) Create a donation: the referrer's reward, with the charity they chose; amount in cents

  ```json
  {
    "campaignId": "<campaignId>",
    "amount": 1000,
    "charityId": "<charityId>",
    "uniqueExternalId": "referral_871",
    "externalId": "customer_204"
  }
  ```
- [`POST /v1/donations`](https://www.charitips.com/docs/api-reference/create-donation.md) Create a donation: the friend's welcome gift, without charityId: it waits for their choice

  ```json
  {
    "campaignId": "<campaignId>",
    "amount": 1000,
    "uniqueExternalId": "referral_871_friend",
    "externalId": "customer_205"
  }
  ```

Charitips then sends the `donation_create` webhook to your endpoint.

### 3. Sam chooses a charity

The friend's first screen offers their own gift. Without a choice it still goes to one of the charities: none is lost.

- The customer picks a charity from your selection.
- Button: Give 10 €

**Your server calls:**

- [`POST /v1/donations/{donationId}/claim`](https://www.charitips.com/docs/api-reference/claim-donation.md) Claim a donation: donationId of the friend's donation

  ```json
  {
    "charityId": "<friendCharityId>"
  }
  ```

Charitips then sends the `donation_update` webhook to your endpoint.

## Clone it with a coding agent

```prompt
Clone the Charitips demo "A donation for every referral" into this project. Read https://www.charitips.com/docs/demos/referral.md: it lists each screen and the Charitips API calls behind it. Build the same flow in this codebase, on the sandbox (https://api.sandbox.charitips.com), with my client id and secret read from environment variables, and follow the rules of https://www.charitips.com/docs/skill.md. Make every API call from the server, never from the browser. When it works, show me each call and its response.
```
