## Overview

Starting a payment with Affirm on an iOS client consists of creating a checkout form, tokenizing customer information to transmit it securely to your server, and using that token to initiate a charge.

This guide walks you through setting up the iOS client on your checkout page.

The [iOS SDK](🔗) is available on Github.

## 1. Set up Affirm on iOS

### With CocoaPods

1\. If you haven't already, install the latest version of [CocoaPods](🔗). 2\. If you don't have an existing [Podfile](🔗), run the following command to create one:



3\. Add this line to your Podfile:



4\. Run the following command:



5\. Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out. 6\. In the future, to update to the latest version of the SDK, just run:



### With Carthage

1\. If you haven't already, install the latest version of [Carthage](🔗). 2\. Add this line to your Cartfile:



3\. Follow the Carthage [installation instructions](🔗). 4\. In the future, to update to the latest version of the SDK, run the following command:





For details on the latest SDK release and past versions, see the [Releases page](🔗) on GitHub. To receive notifications when a new release is published, watch [releases for the repository](🔗).

## 2. Initialize Affirm

Configure the SDK with your Affirm public API key to send requests to the Affirm server.



## 3. Render Affirm checkout

Checkout creation is the process in which a customer uses Affirm to pay for a purchase in your app. You can create a `checkout` object and launch the Affirm checkout using the `Checkout` function.



## 4. Add Affirm promotional messaging

Affirm promotional messaging components---monthly payment messaging and educational modals---show customers how they can use Affirm to finance their purchases. Promos consist of promotional messaging, which appears directly in your app, and a modal, which offers users an ability to prequalify.

To create a promotional messaging view, we provided the `AffirmPromotionalButton` class, which only requires you to configure and add to your view for implementation.

To implement the 'AffirmPromotionalButton':



Use the following to display or refresh promotional messaging:



Use the following steps to use local fonts:

1\. Add the font files to your project (make sure that the files are targeted properly to your application). 2\. Add the font files to your `App-Info.plist`. 3\. Use the font in your CSS file. For example:





If no promotional message is returned, the button will be hidden automatically.

Tapping on the _Promotional_ button automatically opens a modal in an `AffirmPrequalModalViewController` with more information, including (if you have it configured) a button that prompts the user to prequalify for Affirm financing.

### Retrieve raw string from 'As low as' message

You can retrieve raw string using `AffirmDataHandler`.



After that, you could present promo modal using the following:


  • `initWithPromoId` - Affirm provides this Promo ID

    • `showCTA` - To display link to modal

    • `pageType` - Affirm provides this Page type

  • Configure Button:

    • `configureWithAmount`: The price of the product or cart in NSDecimalNumber format

    • `affirmLogoType`: Set as either `AffirmDisplayTypeLogo`, `AffirmDisplayTypeText`, `AffirmDisplayTypeSymbol`, or `AffirmDisplayTypeSymbolHollow`

    • `affirmColor`: Set as either `AffirmColorTypeBlue`, `AffirmColorTypeBlack`, or `AffirmColorTypeWhite`

### Add an educational modal

Tapping on `AffirmAsLowAsButton` opens an educational modal based on the following:

  • When `alaEnabled` is set to `true` and the amount is greater than or equal to 50, the customer sees a product modal with pricing information

  • When `alaEnabled` is set to `true` and the amount is less than 50, the customer sees a site modal without pricing information

  • When `alaEnabled` is set to `false`, the customer sees a site modal without pricing information

To display a modal elsewhere in the application, initialize and display an instance of the modal VC as follows:

Tapping on the _Promotional_ button automatically opens a modal in an `AffirmPrequalModalViewController` with more information, including (if you have it configured) a button that prompts the user to prequalify for Affirm financing.


  • `amount`: The price of the product or cart in NSDecimal (value less than 50 opens a site modal with no pricing information)

  • `promoId`: Affirm provides this Promo ID

### Track Order Confirmed

The trackOrderConfirmed event triggers when a customer completes their purchase. The SDK provides the AffirmOrderTrackerViewController class to track it, it requires AffirmOrder and an array with AffirmProduct.





This feature will be improved after the endpoint is ready for app and will disappear after 5 seconds.

## 5. Handle callbacks

The `AffirmCheckoutDelegate` object which receives messages at various stages in the checkout process. It will return `checkout_token` from this delegate.



For more callbacks, please see the [code reference](🔗).



Once the checkout has been successfully confirmed by the user, the `AffirmCheckoutDelegate` object will receive a `checkout_token`. This token should be forwarded to your server, which should then be used to [authorize a charge](🔗) on the user's account.

## 6. Create a charge

When a customer successfully completes a checkout, it is recorded as a new purchase attempt. This needs to be handled on your server-side to be fulfilled via our [Charges API](🔗).