Welcome to the documentation for the Affirm SDK. This documentation will guide you through the process of integrating Affirm’s financing functionality into your application. The Affirm SDK provides you with the tools and resources you need to enhance your customer’s shopping experience by offering them affordable payment options.
Prerequisites
- An active Affirm account
- Basic knowledge of iOS or Android development
- Xcode and Android Studio installed
- Your project set up with Cocoapods or Gradle
Installation
iOS
- Open your Podfile and add the following line:
“`ruby
pod ‘AffirmSDK’
“`
- Save the file and run the following command:
“`bash
pod install
“`
Android
- Open your app-level build.gradle file and add the following line:
“`groovy
implementation ‘com.affirm:affirm-sdk:3.0.0’
“`
- Save the file and sync your project.
Initialization
Before you can use the Affirm SDK, you need to initialize it with your Affirm public API key. This allows the SDK to connect to the Affirm servers and authenticate your requests. Follow the steps below to initialize the SDK:
iOS
- In your
AppDelegate.swift
file, add the following import statement:
“`swift
import AffirmSDK
“`
- Add the following code snippet to your
application(_:didFinishLaunchingWithOptions:)
method:
“`swift
AffirmConfiguration.configure(withPublicKey: “your_public_api_key”)
“`
Android
- In your
Application
class, add the following import statement:
“`java
import com.affirm.android.Affirm;
“`
- Add the following code snippet to the
onCreate()
method of yourApplication
class:
“`java
Affirm.initialize(this, “your_public_api_key”);
“`
Usage
Now that you have completed the installation and initialization steps, you are ready to start using the Affirm SDK in your app. Below are some examples of common tasks you may want to perform:
1. Displaying Affirm promotional messaging
To display Affirm promotional messaging in your app, you can use the following code:
“`swift
let view = AffirmAsLowAsButtonView(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
view.stringValue = “$100” // Set the price
view.setProductPage(url: “your_product_page_url”) // Set the URL of your product page
yourView.addSubview(view) // Add the view to your desired location
“`
Conclusion
Congratulations! You have successfully integrated the Affirm SDK into your app. You can now offer your customers affordable financing options using the power of Affirm’s platform. If you have any further questions or need assistance, please refer to the official Affirm documentation or contact their support.