# igive.money Connect, version 1

Connect lets a charity platform send a donor, right after a completed donation, to igive.money to make a gift card in someone's name. The card shows "confirmed donation" because the platform signed the return link.

The donation, the payment and the donor's data stay with the platform. igive.money never receives an amount, card details, a name, a phone number or an email address. It receives only an opaque reference that says "a donation with this reference completed on this platform".

## 1. What you get from us

When you join, igive.money gives you:

| Item | Example | Notes |
|---|---|---|
| Partner ID | `ehsan` | Lowercase letters, digits and hyphens, 2 to 32 characters. |
| Secret key | 64 hex characters | Keep it on your server only. Never put it in a web page, an app or a URL. |
| Directory entry | `ehsan` | The organization the card names, from `https://igive.money/data/causes.json`. |

You can ask for a test key first; it behaves the same as a live one.

## 2. The return link

After a donation completes, show the donor a button (suggested text: "أهدِ هذا التبرع ببطاقة" / "Gift this donation as a card") that opens:

```
https://igive.money/connect?p={partner}&ref={reference}&ts={timestamp}&sig={signature}
```

For an English page, use `https://igive.money/en/connect?...`.

| Parameter | Rule |
|---|---|
| `p` | Your partner ID. |
| `ref` | Your reference for this donation: 1 to 128 characters from `A-Z a-z 0-9 . _ : -`. Use an opaque ID such as a transaction ID. Never a phone number, an email or a national ID. |
| `ts` | The current Unix time in seconds, when the link is made. |
| `sig` | `hex(HMAC-SHA256(secret, "v1|" + p + "|" + ref + "|" + ts))`, 64 lowercase hex characters. |

Build the link on your server, at the moment the thank-you page is shown.

## 3. Rules igive.money enforces

1. The signature must match. A wrong or tampered link is refused.
2. A link is accepted for 30 minutes after `ts` (and up to 2 minutes early, for clock drift).
3. Each `(p, ref)` gives exactly one card. A second use of the same reference is refused, even with a fresh signature.
4. The reference is stored only as a SHA-256 hash.
5. The partner can be switched off at any time, which stops new cards immediately. Existing cards stay valid.

## 4. What the donor sees

1. igive.money checks the link (one second or less) and opens the card designer.
2. The donor writes the recipient's name, picks the occasion, the artwork and the lettering, and adds a message.
3. The donor presses "Create the card" and gets a link like `https://igive.money/نورة#...` to share.
4. The card names your organization and carries the "confirmed donation" mark. Its "give one back" button leads the recipient to igive.money, where your organization is listed.

No amount is ever shown.

## 5. Code samples

All three produce the same signature for the same input.

**Node.js**

```js
import { createHmac } from 'node:crypto';

function igiveLink(partner, secret, ref) {
  const ts = Math.floor(Date.now() / 1000);
  const sig = createHmac('sha256', secret).update(`v1|${partner}|${ref}|${ts}`).digest('hex');
  return `https://igive.money/connect?${new URLSearchParams({ p: partner, ref, ts: String(ts), sig })}`;
}
```

**PHP**

```php
function igive_link(string $partner, string $secret, string $ref): string {
  $ts = time();
  $sig = hash_hmac('sha256', "v1|$partner|$ref|$ts", $secret);
  return 'https://igive.money/connect?' . http_build_query(['p' => $partner, 'ref' => $ref, 'ts' => $ts, 'sig' => $sig]);
}
```

**Python**

```python
import hmac, hashlib, time, urllib.parse

def igive_link(partner: str, secret: str, ref: str) -> str:
    ts = str(int(time.time()))
    sig = hmac.new(secret.encode(), f"v1|{partner}|{ref}|{ts}".encode(), hashlib.sha256).hexdigest()
    return "https://igive.money/connect?" + urllib.parse.urlencode({"p": partner, "ref": ref, "ts": ts, "sig": sig})
```

**Test vector.** With partner `demo`, secret `test-secret`, ref `ORDER-1` and ts `1800000000`, the message is `v1|demo|ORDER-1|1800000000` and the signature must be `b13c33c52beef76141e6fe9c11051f44a37635c332bbb6d4e953b77c1307fdc6`.

## 6. Security notes

- The secret never leaves your server. If it leaks, tell us and we issue a new one at once.
- The link itself carries no personal data. It reaches igive.money's logs like any URL, which is why `ref` must be opaque.
- Only show the button after the payment is confirmed, not when it is merely started.
- igive.money cannot see or change anything on your platform. Connect is one-way: you send a signed reference, and nothing is sent back to you.

## 7. Versioning

The message starts with `v1`. A future version will use a new prefix, and `v1` links will keep working.

## 8. Contact

To join or to get a test key, use the contact on https://igive.money/partners.
