Skip to content
Aller au contenu
Charitips

Use cases · Commerce

A donation with every order

Above a basket amount, you give and your customer chooses the charity.

  • Who paysYour company
  • Starts withA purchase
  • Tax receiptIn your company's name

Needs API access on a validated account. Plans

Device
Charities shown as
Outline widget
Donation rule
your-store.example/checkout

your-store.example/checkout

Step by step

Click through the site. Each step shows what your customer does, what your server sends and what Charitips answers.

  1. 1Order paid

    To come

    Your customer does…

    Clicks “Pay 76,00 €”.

    Your server sends…

    Creates a 2 € donation for order #1042 on the campaign “Checkout donations”.

    POSTcreate-donation

    Charitips answers…

    Charitips records the donation and returns its id: it waits for your customer to pick a charity.

    Charitips will then tell your server the donation was created.

  2. 2Charity chosen

    To come

    Your customer does…

    Clicks “Give 2 € to the charity”.

    Your server sends…

    Assigns that donation to the charity your customer picks.

    POSTclaim-donation

    Charitips answers…

    The donation now goes to the charity your customer picks.

    Charitips will then tell your server the donation was updated.

  3. 3Order history

    To come

    Your customer does…

    Sees “Your orders”.

    Your server sends…

    Your server reads the donation_update webhook and keeps the charity on the order. An order still waiting for a choice offers it again.

    Charitips answers…

    Nothing: Charitips is not called at this step.

How to read this demo: the site shows what your customer does, and the panel what your server sends and what Charitips answers, step by step.

Build spec

The site is made up and nothing is sent. The endpoints, fields and webhook events are the real ones, and so are the charities.

This demo is one example. 2 € for every order over 50 €: that is the case the demo plays. The same flow also covers:

One flow, 3 variants

Each card is this flow in another sector or use case. Pick one: the demo above plays it, with its site, its amounts and its charities. The API calls stay the same.

RetailOnline storeAn online store adds 2 € to every order over 50 €, paid by the store. The customer picks the charity on the confirmation page; if they skip it, the donation still goes to one.2 € for every order over 50 €, or 1 % of each orderOpen its page
Culture and eventsMuseum shopA museum shop gives 2 € on every order over 50 € of prints or books. The shop pays; the visitor picks the charity on the confirmation page or later, from their order history.2 € for every order over 50 €, or 1 % of each orderOpen its page
Health and sportGym accessories shopA gym's accessories shop gives 2 € on each order over 50 €, or 1 % of the order. The gym pays, and the member picks the charity once the order is confirmed.2 € for every order over 50 €, or 1 % of each orderOpen its page

Build it

The calls behind the demo, in order. Each step shows the request your server sends.

  1. Create the campaign

    Once, create a charities selection with the charities you want to offer, create the campaign with its charitiesSelectionId, then activate it, as in steps 3 to 5 of Your first donation. It works as a charity cashback for an online store: the customer picks the charity after paying, so your checkout stays as it is.

    POST /v1/campaigns
    curl -X POST https://api.sandbox.charitips.com/v1/campaigns \  -H "Authorization: Bearer $CHARITIPS_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "name": "Order donations",    "charitiesSelectionId": "<charitiesSelectionId>"  }'
    Built from the spec and the API code

    Request bodies are written for this docs and checked against the API's validation; ids in angle brackets are placeholders. Response values are placeholders built from the schema.

  2. Give on each paid order

    When an order is paid, create a donation with the order id as uniqueExternalId. amount is in cents. Create it from your payment webhook, not from the browser: if the customer closes the tab, the donation still exists.

    POST /v1/donations
    curl -X POST https://api.sandbox.charitips.com/v1/donations \  -H "Authorization: Bearer $CHARITIPS_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "campaignId": "<campaignId>",    "amount": 200,    "uniqueExternalId": "<orderId>"  }'
    Built from the spec and the API code

    Request bodies are written for this docs and checked against the API's validation; ids in angle brackets are placeholders. Response values are placeholders built from the schema.

  3. Show the charities

    Read the selection with its charities from your server and render them on the confirmation page. Each charity comes with its charityId, name and logoUrl. The list changes only when you edit the selection: cache it rather than reading it for every order.

    Shell
    curl "https://api.sandbox.charitips.com/v1/charities-selections/<charitiesSelectionId>?includeCharities=true" \  -H "Authorization: Bearer $CHARITIPS_TOKEN"
  4. Claim it for the customer's charity

    Claim the donation for the charity the customer picks. If the customer never chooses, the donation is assigned automatically when it expires or when the campaign closes. No donation is lost.

    POST /v1/donations/<donationId>/claim
    curl -X POST https://api.sandbox.charitips.com/v1/donations/<donationId>/claim \  -H "Authorization: Bearer $CHARITIPS_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "charityId": "<charityId>"  }'
    Built from the spec and the API code

    Request bodies are written for this docs and checked against the API's validation; ids in angle brackets are placeholders. Response values are placeholders built from the schema.

  5. Listen for the claim

    Create a webhook for donation_update once, with Create a webhook. Each delivery, shortened here, holds event, payload, the donation as it is now, and diff, the fields that changed. When diff holds a charityId, the donation is claimed, by the customer or automatically: find the order with payload.uniqueExternalId. Verify the signature first, as shown in Webhooks configuration, and key your handler on donationId and status, since a delivery can arrive more than once.

    JSON
    {  "event": "donation_update",  "payload": { "donationId": "<donationId>", "status": "DONE", "charityId": "<charityId>", "uniqueExternalId": "<orderId>" },  "diff": { "status": "DONE", "charityId": "<charityId>" }}

Edge cases

  • Your payment webhook fires twice. The second create returns 409 Unique constraint failed on uniqueExternalId. Treat it as success.
  • The order is refunded. Delete the donation before it is billed or paid out; after that the API answers 403 (Donation already invoiced, Donation already paid or Donation already processed). Once claimed, its amount is fixed.
  • You want the choice by email instead. Use a time-limited campaign with sendingMode set to EMAIL and pass the customer in donor with the day to send it in sendingDate: Charitips sends the email.

The memo

Send the memo to your team

Already written for this flow

  • What it does and who pays, in a few sentences
  • What you need: plan, API calls and webhooks
  • What you can report: donations, charities, impact and receipts

To paste in an email, a document or a note.

Email it