- Get Started
- Guides
- Integrations
- References
- API Reference
- Basic Payment
- Forex
- Authentication
- Card Account
- Apple Pay
- Virtual Account
- Bank Account
- Token Account
- Customer
- Billing Address
- Merchant Billing Address
- Shipping Address
- Merchant Shipping Address
- Merchant
- Corporate
- Recipient
- Marketplace & Cart
- Airline
- Lodging
- Passenger
- Tokenization
- Recurring Migration
- 3D Secure
- Custom Parameters
- Async Payments
- Webhook notifications
- Job
- Risk
- Point of Sale
- Response Parameters
- Card On File
- Chargeback
- Result Codes
- Payment Methods
- Transaction Flows
- Regression Testing
- Data Retention Policy
- API Reference
- Support
- Impressum
Affirm
Follow this guide to add Affirm to your checkout.
Brand constants to be used:
- AFFIRM - Affirm
Payment methods availability:
- Affirm since mSDK version 6.15.0
iOS
Android
Configuration
To integrate Affirm you need to add the AffirmSDK dependency as cocoapods in your project.
- Open terminal at your project folder.
- Type pod init commond in it. It will create a podfile in your project directory.
- Open podfile and add pod AffirmSDK under your project target.
- Run pod install in terminal.
Open the build.gradle file located in the app module and add the following to the dependencies block.
implementation "com.affirm:affirm-android-sdk:2.0.25"
Ready-to-Use UI
When you use our ready-to-use UI, everything works out-of-box. Just set AFFIRM payment brands and shopper result url in the Checkout Settings class and you are done. Proceed with the presenting checkout as for standard transaction.
OPPCheckoutSettings *checkoutSettings = [[OPPCheckoutSettings alloc] init];
// Set Affirm payment methods
checkoutSettings.paymentBrands = @"AFFIRM";
// Set shopper result URL
checkoutSettings.shopperResultURL = @"com.companyname.appname.payments://result";
let checkoutSettings = OPPCheckoutSettings()
// Set Affirm payment methods
checkoutSettings.paymentBrands = "AFFIRM"
// Set shopper result URL
checkoutSettings.shopperResultURL = "com.companyname.appname.payments://result"
Set<String> paymentBrands = new LinkedHashSet<String>();
paymentBrands.add("AFFIRM");
CheckoutSettings checkoutSettings = new CheckoutSettings(checkoutId, paymentBrands, Connect.ProviderMode.TEST);
val paymentBrands = hashSetOf("AFFIRM")
val checkoutSettings = CheckoutSettings(checkoutId, paymentBrands, Connect.ProviderMode.TEST)
SDK & Your Own UI
This guide assumes that you have already completed all steps necessary for performing a standard mSDK transaction.
Here are the steps that you have to follow to integrate Affirm:
1. Create Affirm payment param
Use checkoutId to create Affirm Payment params.
NSError *error;
OPPAffirmPaymentParams *params = [OPPAffirmPaymentParams affirmPaymentParamsWithCheckoutId:checkoutId
error:&error];
do {
let params = try OPPAffirmPaymentParams.affirmPaymentParamsWith(checkoutId: checkoutId)
} catch let error as NSError {
}
2. Create transaction object
Use AffirmPaymentParams to create transaction object.
OPPTransaction *transaction = [[OPPTransaction alloc] initWithPaymentParams:params];
let transaction = OPPTransaction.init(paymentParams: params)
3. Create Affirm processor object to process transaction.
To do Affirm transaction you have to create AffirmProcessor object and you have to call 'process' method on it to process the transaction.
NSError *error;
OPPAffirmProcessor *processor = [[OPPAffirmProcessor alloc] initWithTransaction:transaction
mode:providerMode
error:&error];
if (error) {
// Handle error
} else {
[processor process:presentingController with:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
if (error) {
// Handle error
} else {
// Submit transaction
}
}];
}
}
do {
let processor = try OPPAffirmProcessor(transaction: transaction, mode: providerMode)
processor?.process(presentingController, with: { transaction, error in
if let error = error {
// Handle error
} else {
// Submit transaction
}
})
} catch {
// Handle error
}
4. Submit transaction
Create a payment provider object and call submit transaction.
OPPPaymentProvider *provider = [OPPPaymentProvider paymentProviderWithMode:providerMode];
[provider submitTransaction:transaction completionHandler:^(OPPTransaction * _Nonnull transaction, NSError * _Nullable error) {
// Get payment status
}];
let provider = OPPPaymentProvider(mode: providerMode)
provider.submitTransaction(transaction, completionHandler: {(transaction, error) in
// Get payment status
})
5. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.
1. Create Affirm payment param
Use checkoutId and ProviderMode to create Affirm payment params.
AffirmPaymentParams affirmPaymentParams = new AffirmPaymentParams(checkoutId,
Connect.ProviderMode.TEST);
affirmPaymentParams.setShopperResultUrl("com.companyname.appname.payments://result");
val affirmPaymentParams = AffirmPaymentParams(checkoutId, Connect.ProviderMode.TEST)
affirmPaymentParams.shopperResultUrl = "com.companyname.appname.payments://result"
2. Register ActivityResultLauncher to launch Affirm processor
private final ActivityResultLauncher affirmLauncher = registerForActivityResult(
new AffirmProcessorResultContract(),
this::handleAffirmTransactionLauncherResult);
val affirmLauncher: ActivityResultLauncher =
registerForActivityResult(AffirmProcessorResultContract()) {
handleAffirmTransactionLauncherResult(it)
}
3. Launch Affirm processor
Use ActivityResultLauncher to launch Affirm Processor. Affirm Processor need to be launch before submit transaction.
if ("AFFIRM".equals(paymentBrand)) {
affirmLauncher.launch(transaction);
} else {
// other payment brand
paymentProvider.submitTransaction(transaction, this)
}
if ("AFFIRM" == paymentBrand) {
affirmLauncher.launch(transaction);
} else {
// other payment brand
paymentProvider.submitTransaction(transaction, this)
}
4. Handle Affirm processor result
Use Transaction object received in result to launch Affirm Processor. Affirm Processor need to be launch before submit transaction.
private void handleAffirmTransactionLauncherResult(ProcessorActivityResult processorActivityResult) {
if (processorActivityResult.getPaymentError() != null) {
//hide progress
//error handling
return;
}
if (processorActivityResult.getTransaction() != null) {
//submit Transaction
paymentProvider.submitTransaction(transaction, this);
}
}
private fun handleAffirmTransactionLauncherResult(ProcessorActivityResult processorActivityResult) {
if (processorActivityResult.getPaymentError() != null) {
//hide progress
//error handling
return;
}
processorActivityResult.transaction?.let {
paymentProvider!!.submitTransaction(it, this)
}
}
5. Get the payment status
Finally your app should request the payment status from your server.
For more details you can refer to this document.