In this article, we will learn how to integrate the Affirm payment method in Swift.
Affirm payment method allows user to pay the cost of the purchase in simple EMI’s.
If you are having a e-commerce based application you can integrate the Affirm payment method for the large amount purchases.
So lets begin with the article.
Overview of Affirm Payment method in Swift
Affirm checkout process involves selecting the payment method at the checkout.
Affirm SDK interacts with the merchant site, a checkout object is created and redirected to the Affirm server.
A checkout object contains the cart information. This opens a UI for the Affirm payments.
Setting up Affirm Payment method in Swift
If you have Cocoapods installed then you can use the below commands to get the SDK into your project.
Open your terminal and navigate to the project directory. Then run below commands.
1 |
pod init |
1 |
open Podfile |
A podfile will be opened in the TextEdit, add below code in the file.
1 |
pod 'AffirmSDK' |
Save the file and hit below command.
1 |
pod install |
Now, the SDK will be installed in your project.
Affirm Checkout
You need to have a developer account with Affirm, from where you can check the sales of your product. Also you will get a PUBLIC KEY.
After that, use this public key in your AppDelegate inside the didFinishLaunchingWithOptions as
1 |
AffirmConfiguration.shared.configure(publicKey: "PUBLIC KEY", environment: .production, merchantName: "MERCHANT NAME") |
Do not forget to import the SDK on your ViewController
Now use collect the Shipping information from the checkout and use below code to initialze the checkout object.
1 2 3 4 5 6 7 |
let dollarPrice = NSDecimalNumber(string: "PRICE") let item = AffirmItem(name: "Test Item", sku: "test_item", unitPrice: dollarPrice, quantity: 1, url: URL(string: "http://sandbox.affirm.com/item")!) let shipping = AffirmShippingDetail.shippingDetail(name: "Chester Cheetah", line1: "633 Folsom Street", line2: "", city: "San Francisco", state: "CA", zipCode: "94107", countryCode: "USA") let checkout = AffirmCheckout(items: [item], shipping: shipping, taxAmount: NSDecimalNumber.zero, shippingAmount: NSDecimalNumber.zero, discounts: nil, metadata: nil, financingProgram: nil, orderId: "ORDER ID FROM YOUR SERVER") let controller = AffirmCheckoutViewController.start(checkout: checkout, useVCN: false, delegate: self) present(controller, animated: true, completion: nil) |
After that, you will see the SDK response like below
Conclusion
You can aditionally show the promotional message at your Product description page.
Use Promotional button to reflect the EMI options. For more details refer here
To read more articles please visit here.