---
agentTools:
  siteIndex: https://docs.affirm.com/llms.txt
  projectIndex: https://docs.affirm.com/developers/llms.txt
---

# How To Use Webhooks With Affirm

Become a pro at creating webhooks by reading our step-by-step guide and learn how tools such as JSFiddle and Pipedream can help your skills reach the next level.

> 🚧 Merchant Eligibility
>
> Webhooks and Data Sharing Agreements (DSAs) are only available to Key and Enterprise merchants at this time. All available data and metrics can be accessed directly in the Merchant Dashboard.

## **A Webhook’s Purpose**

By now, you have heard at least one person mention the term “webhook.” Perhaps you are familiar with them, perhaps not. To provide a brief explanation, webhooks are HTTP requests that are triggered by specific events. Here is a “real-life” example:

Let’s say you would like to order a pizza 🍕online. You place the order and wait for the items to be made. Once the items in your order are ready, a text is sent to let you know they are on their way!

In this example, a webhook is used to send a text once the order is ready. Since we do not know exactly when the order will be ready, we use a webhook to **(1)** record when it is ready and **(2)** send a text to inform you of the order’s status. Beyond this example, using webhooks to send automated notifications has become common practice and is an efficient way to provide information to the masses.

At Affirm, webhooks can be used to send you notifications about **(1)** when a customer uses the Affirm payment method and **(2)** if they were successful in completing the entire Affirm checkout process.

### **Practice Makes Perfect (or something like that)**

There are a number of tools you can use to receive webhooks, but we suggest using a site like [Pipedream](https://pipedream.com/) (it is completely free by the way) that allows you to easily create servers and simulate an Affirm data capture. However, before we get too far ahead of ourselves, we recommend reaching out to <merchanthelp@affim.com> or your technical account manager to review your existing data-sharing agreement or to sign-up for one.

**Using Pipedream**

Luckily, [Pipedream](https://pipedream.com/) is easy to use and free to sign-up for, if you do not already have an account. In addition to Pipedream, we also recommend using a code playground or “sandbox” such as [JSFiddle](https://jsfiddle.net/) (also a free service) to test your code as needed.

Follow along below for a demonstration on how to receive a webhook event using Pipedream👇

1. Sign-in or sign-up for [Pipedream](https://pipedream.com/).
2. Once you have gained access to your account, you will notice a navigation bar on the left-side of your screen. Select the **“Sources” link**, followed by clicking the blue **“New +” button** located in the top-right corner to create a new **“Source.”**

<Image align="center" width="600px" src="https://files.readme.io/2abed66-small-screencapture-pipedream-sources-2023-05-15-09_12_21-edit.png" />

3. Next, you will choose a **“Source”** and for this example, we are selecting **“HTTP/Webhook.”**

<Image align="center" width="450px" src="https://files.readme.io/5f63c14-small-screencapture-pipedream-sources-new-2023-05-15-09_17_01-edit.png" />

4. The following screen will prompt you to choose from three options: **“New Requests,” “New Requests (Payload Only),"** or **“New event when the content of the URL changes”**. You will select the **“New Requests”** option.

<Image align="center" width="600px" src="https://files.readme.io/f779931-small-screencapture-pipedream-sources-new-2023-05-15-09_19_51-edit_1.png" />

5. After selecting **“New Requests,”** the next step is to specify the details of your request. This page contains 5 different fields, to which we will *only* make changes to **“Response Content-Type”** (response content-type is where you specify the “content type” you would like returned to the user, which generally defaults to text/HTML) and type **“application/x-www-form-urlencoded”** in that specified field. Once you have provided the necessary information, click on the blue **“Create Source” button**.

(*Optional*: Feel free to utilize the **“Name”** field and customize your webhook.)

<Image align="center" width="600px" src="https://files.readme.io/e754003-small-screencapture-pipedream-sources-new-2023-05-15-09_43_37-edit.png" />

(Hooray🎉You’ve now created a **“Source”** in Pipedream.)

6. Now that a **“Source”** has been created, a new **“Endpoint”** has been generated as well. So, you will **copy the “Endpoint”** provided for your new **“Source”** and **share it with<merchanthelp@affim.com> or your technical account manager to set it up for your sandbox account.**

<Image align="center" width="600px" src="https://files.readme.io/ac2f563-small-screencapture-pipedream-sources-dc-zquDxp3-2023-05-15-10_07_59-edit.png" />

7. Once set up on our end, you will retrieve your **Public API Key**[here](https://www.affirm.com/dashboard). The next steps can be completed in your development site, [JSFiddle](https://jsfiddle.net/), or a similar tool of your choosing by using the following **AffirmJS** and **HTML/CSS** code snippets:

<Recipe slug="embed-affirmjs" title="Embed Affirm.js" />

* [Embed Affirm.js](\[https://docs.affirm.com/developers/recipes/embed-affirmjs) enter your **Public API Key** in the **“public\_api\_key”** line.)

<Image align="center" width="600px" src="https://files.readme.io/dcbeb7a-small-screencapture-jsfiddle-net-hbdarwc6-2023-05-15-10_32_36-edit.png" />

* Configure the [Checkout Object](https://docs.affirm.com/developers/recipes/configure-the-checkout-object)

Here is an example of what a **Checkout function** *could* look like:

```javascript
affirm.checkout({

  "merchant": {
    
    "user_cancel_url"              : "https://examplemerchant.com/checkout/payment",
    
		//Put your confirmation URL here:    
    "user_confirmation_url": "https://examplemerchant.com/confirm_affirm_charge",
    
    "user_confirmation_url_action" : "POST"
  },

  //shipping contact
  "shipping": {
    "name": {
      "first" : "Joe",
      "last" : "Doe"
      // "full" : "Joe Doe"
    },
    "address": {
      "line1"  : "633 Folsom St",
      "line2"  : "Floor 7",
      "city"   : "San Francisco",
      "state"  : "CA",
      "zipcode": "94107"
    },
    "email"          : "joe.doe@email.com",
    "phone_number"   : "4155555555"
  },

  // cart 
  "items": [{
    "display_name"   : "Acme SLR-NG",
    "sku"            : "ACME-SLR-NG-01",
    "unit_price"     : 1500,
    "qty"            : 1,
    "item_image_url" : "https://examplemerchant.com/static/item.png",
    "item_url"       : "https://examplemerchant.com/acme-slr-ng-01.htm",
  }],

  // pricing / charge amount
  "currency"        : "USD",
  "discounts": {
    "savemoney123": {
      "discount_amount" : 500
    }
  },
  "tax_amount"      : 199,
  "shipping_amount" : 399,
  "total"           : 27500
});
```

* **Create a Form Submission Handler** for the **Checkout Function**:

  ```javascript
  $("#submit-form").click(function(){  
    affirm.checkout.post();  
  });
  ```
* **HTML Snippet**:

```html
<div class="container">
              <h3>Checkout Page - Select Payment Method</h3>
              <p class="affirm-as-low-as" data-amount="300000"></p>
              <form>
              <input type="radio" value="Affirm" checked="checked"> <img id="payment_method-affirm" src="https://cdn-assets.affirm.com/images/black_logo-white_bg.svg" height="24px">
              <h5>How does Affirm work?</h5>
              <span>
              Just enter your basic information and get a real-time credit decision. You will complete your payment on the Affirm website. If you're approved and confirm your loan, your purchase will be on its way as soon as it's ready.
              </span>
              </form>
              <input class="btn btn-primary" type="button" value="Affirm Checkout" id="submit-form" />
      </div>
```

* **CSS Snippet:**

  ```css
  .container{ padding-top:30px; }
  form {margin:20px 0;}
  #payment_method-affirm{ margin:0 0 10px 10px;}
  ```

8. At the completion of Step 7, your JSFiddle screen should resemble the following:

<Image align="center" width="600px" src="https://files.readme.io/e58bf98-screencapture-jsfiddle-net-hbdarwc6-2023-05-15-10_42_11-edit.png" />

Upon completing the configuration, navigate to the **Checkout Page window** in the bottom right corner and click the **“Affirm Checkout” button**.

<Image align="center" width="600px" src="https://files.readme.io/caff5d3-screencapture-jsfiddle-net-hbdarwc6-2023-05-15-10_45_47-edit.png" />

The next screen will prompt you to enter your **mobile number**, then select the **“Continue” button**.

<Image align="center" width="450px" src="https://files.readme.io/c37eb6e-Screen_Shot_2023-05-23_at_9.03.47_AM.png" />

Another pop-up window will appear and ask for you to input the verification code which is **1234** for sandbox requests.

After inputting the verification code, a webhook will be sent. You should be able to see that an **event** has occurred on Pipedream, which will appear on the left hand side of the screen:

<Image align="center" width="0px" src="https://files.readme.io/e7e33aa-screencapture-pipedream-sources-dc-zquDxp3-2023-05-15-10_49_43-edit.png" />

9. On the next screen titled, “**Choose the best plan for you,**” which populates the options for payment terms, select any of the payment options followed by clicking "**Continue**” to complete this step.

<Image align="center" width="450px" src="https://files.readme.io/d0a736b-screencapture-jsfiddle-net-hbdarwc6-2023-05-15-10_52_28-edit.png" />

10. In our **final step** you will be prompted to “**Review your payment plan**” and review the “**Truth in Lending Disclosure**” and “**Loan Agreement**.” Once you have read through the disclosures and agreed to the terms, you will check the box, followed by clicking “**Confirm**” to complete the purchase.

<Image align="center" width="450px" src="https://files.readme.io/414a538-screencapture-jsfiddle-net-hbdarwc6-2023-05-15-10_55_57-edit.png" />

(After selecting “**Confirm**” another webhook will be sent, so in total the Affirm checkout process will send **2 webhooks**.)

**WooHoo**🎉 You have now completed the Affirm checkout process and sent a webhook! If you would like additional information on [webhooks](https://docs.affirm.com/developers/docs/development-webhooks) or anything developer related, feel free to visit [Affirm’s Developer Docs](https://docs.affirm.com/developers/docs) to get more acquainted.

> 📘 Subscribe to updates via RSS
>
> Subscribe to the Affirm Changelog via [RSS](https://docs.affirm.com/developers/changelog.rss) to stay up to date on new features, blog posts, API updates, and more!