Credify serviceX iOS SDK.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding Credify as a dependency is as easy as adding it to the dependencies value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/credify-pte-ltd/credify-ios-sdk", .upToNextMajor(from: "0.1.0"))
]
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Alamofire into your Xcode project using CocoaPods, specify it in your Podfile
:
pod "Credify"
import UIKit
import Credify
import Alamofire // This is not requred, but used for demo
let API_KEY = "your api key"
let APP_NAME = "your app name"
let API_PUSH_CLAIMS = "your API endpoint to push claim tokens"
class SampleViewController: UIViewController {
private let offer = serviceX.Offer()
private var user: CredifyUserModel!
private var offerList: [OfferData] = [OfferData](https://raw.github.com/credify-pte-ltd/credify-ios-sdk/master/)
override func viewDidLoad() {
super.viewDidLoad()
let config = serviceXConfig(apiKey: API_KEY, env: .sandbox, appName: APP_NAME)
serviceX.configure(config)
user = CredifyUserModel(id: "internal ID in your system", firstName: "Vũ", lastName: "Nguyển", email: "vu.nguyen@gmail.com", credifyId: nil, countryCode: "+84", phoneNumber: "0381239876")
}
/// This loads offers list. Please call this whenever you want.
func loadOffers() {
offer.getOffers(user: user, productTypes: []) { [weak self] result in
switch result {
case .success(let offers):
self?.offerList = offers
case .failure(let error):
print(error)
}
}
}
/// This starts Credify SDK
func startOffer(_ offerData: OfferData) {
let task: ((String, ((Bool) -> Void)?) -> Void) = { credifyId, result in
AF.request(API_PUSH_CLAIMS,
method: .post,
parameters: ["id": self.user.id, "credify_id": credifyId],
encoding: JSONEncoding.default).responseJSON { data in
switch data.result {
case .success:
result?(true)
case .failure:
result?(false)
}
}
}
offer.presentModally(from: self, offer: offerData, userProfile: user, pushClaimTokensTask: task) { [weak self] result in
self?.dismiss(animated: true) {
print("Done")
}
}
}
}
Important: For the
pushClaimTokensTask
callback, you need to keepcredifyId
on your side. You have to send thecredifyId
to Credify SDK when you use the methods that requirecredifyId
. E.g: calloffer.presentModally
method or createCredifyUserModel
model.
import UIKit
import Credify
class SampleViewController: UIViewController {
private let passport = serviceX.Passport()
private var user: CredifyUserModel!
override func viewDidLoad() {
super.viewDidLoad()
let config = serviceXConfig(apiKey: API_KEY, env: .sandbox, appName: APP_NAME)
serviceX.configure(config)
user = CredifyUserModel(id: "internal ID in your system", firstName: "Vũ", lastName: "Nguyển", email: "vu.nguyen@gmail.com", credifyId: nil, countryCode: "+84", phoneNumber: "0381239876")
}
/// This renders passport page
func showPassport() {
let task: ((String, ((Bool) -> Void)?) -> Void) = { credifyId, result in
AF.request(API_PUSH_CLAIMS,
method: .post,
parameters: ["id": self.user.id, "credify_id": credifyId],
encoding: JSONEncoding.default).responseJSON { data in
switch data.result {
case .success:
result?(true)
case .failure:
result?(false)
}
}
}
passport.showMypage(from: self, user: user, pushClaimTokensTask: task) {
print("page dismissed")
}
}
}
import UIKit
import Credify
class SampleViewController: UIViewController {
private let bnpl = serviceX.BNPL()
private var user: CredifyUserModel!
override func viewDidLoad() {
super.viewDidLoad()
let config = serviceXConfig(apiKey: API_KEY, env: .sandbox, appName: APP_NAME)
serviceX.configure(config)
user = CredifyUserModel(id: "internal ID in your system", firstName: "Vũ", lastName: "Nguyển", email: "vu.nguyen@gmail.com", credifyId: nil, countryCode: "+84", phoneNumber: "0381239876")
}
/// This will check whether BNPL is available or not
/// You need to create "orderId" on your side.
func getBNPLAvailability(orderId: String) {
bnpl.getBNPLAvailability(user: self.user) { result in
switch result {
case .success((let isAvailable, let credifyId)):
if isAvailable {
// This will start BNPL flow
self.startBNPL(orderId: orderId)
return
}
// BNPL is not available
case .failure(let error):
// Error
break
}
}
}
/// This starts Credify SDK
/// You need to create "orderId" on your side.
func startBNPL(orderId: String) {
let task: ((String, ((Bool) -> Void)?) -> Void) = { credifyId, result in
// Using Alamofire
AF.request(API_PUSH_CLAIMS,
method: .post,
parameters: ["id": self.user.id, "credify_id": credifyId],
encoding: JSONEncoding.default).responseJSON { data in
switch data.result {
case .success:
result?(true)
case .failure:
result?(false)
}
}
}
bnpl.presentModally(
from: self,
userProfile: self.user,
orderId: orderId,
pushClaimTokensTask: task
) { [weak self] status, orderId, isPaymentCompleted in
self?.dismiss(animated: false) {
print("Status: \(status.rawValue), order id: \(orderId), payment completed: \(isPaymentCompleted)")
}
}
}
}
Important: For the
pushClaimTokensTask
callback, you need to keepcredifyId
on your side. You have to send thecredifyId
to Credify SDK when you use the methods that requirecredifyId
. E.g: callbnpl.presentModally
method or createCredifyUserModel
model.
Using serviceX.setLanguage
to setup the language that will be used for the localization in the SDK.
serviceX.setLanguage(Language)
Credify iOS SDK is released under the MIT License. See LICENSE for details.
link |
Stars: 0 |
Last commit: 23 hours ago |
Full Changelog: https://github.com/credify-pte-ltd/credify-ios-sdk/compare/0.5.0...0.5.1
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics