# Integration Guide

## Development Tasks

### 🔗  Payment Button&#x20;

On the checkout page you create a payment button/link to:

`https://yodl.me/$handle?amount=..&currency=..&memo=..`

* `$handle` is your YODL.me link
* `amount` is the amount of the payment in the minor denomination of the currency
* `currency` to indicate the invoice currency
* `memo` is your order/customer/cart ID, whatever you need to reconcile the payment

  (on stripe API it's called \`client\_reference\_id\`)

```javascript
handle = "unicorn_socks" // your yodl.me handle
amountInMinor = 500;     // for 5.00
invoiceCurrency = "USD"; // invoice currency, defaults to "USD"
memo = order.orderID;

queryParameters = "amount=${amountInMinor}&currency=${invoiceCurrency}&memo=${memo}";

<a href="https://yodl.me/${handle}?${queryParameters}" target="_blank">
  YODL Pay
</a>
```

### ✅ Success Redirect Page

When the checkout is completed and the payment is confirmed, YODL.me redirects the user back to the success redirect page hosted on your webshop. This URL is configured in the YODL.me account admin.&#x20;

The SDK appends to the URL, as query parameters the `chainId` and `txHash`. So you can engage in post-processing of the payment (similar to the webhook). However as we cannot guarantee that the user really returns to your page, you should still implement webhooks for consistent processing.

### ⚙️ Webhook

The webhook is called by the YODL.me backend when the payment was confirmed on-chain and when the payment is *probabilistically final* and unlikely to be reverted. The payload is minimal and only contains:

* `chainId`
* `txHash`
* `state` of the blockchain transaction: `confirmed` or `probabilistic`

1. The Webhook needs to query `yodl.me/api/tx/:chainId/:txHash` to retrieve the payment details: `pmt`
2. With the retrieve `pmt.memo` lookup the order/cart/customer
3. Verify in your code that the payment was not tampered with.&#x20;

   Use [#lookup-and-verify-a-payment-against-given-parameters](https://docs.yodl.me/yodl-documentation/api/api-endpoints#lookup-and-verify-a-payment-against-given-parameters "mention")
4. Mark payment as complete and do your post processing

### 💾 Environment Variables

```
YODL_HANDLE=  # yodl.me/YOUR_HANDLE
YODL_API_KEY= # find in your yodl.me admin
```

## Flow and Sequence Diagram

<figure><img src="https://2278483089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFW9E5qvD8Ww1D50jiayN%2Fuploads%2FWAAriYJF3qSwPTPkSkmm%2FUntitled.svg?alt=media&#x26;token=8444668f-d955-45db-8597-66c30c8ceaf8" alt=""><figcaption></figcaption></figure>
