Skip to content

Commit

Permalink
Merge pull request #518 from checkout/release/4.3.2
Browse files Browse the repository at this point in the history
Integrate Risk SDK
  • Loading branch information
okhan-okbay-cko authored Mar 4, 2024
2 parents 6bcf57d + 568898c commit 5693ee1
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 27 deletions.
8 changes: 8 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.

#### 4.x Releases

## [4.3.2](https://github.com/checkout/frames-ios/releases/tag/4.3.2)

Released on 2024-03-01

Updates:

- Send risk data via Risk SDK for the opted-in customers. No public changes.

## [4.3.1](https://github.com/checkout/frames-ios/releases/tag/4.3.1)

Released on 2024-01-19
Expand Down
5 changes: 3 additions & 2 deletions Checkout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Checkout'
s.version = '4.3.0'
s.version = '4.3.2'
s.summary = 'Checkout SDK for iOS'

s.description = <<-DESC
Expand All @@ -13,12 +13,13 @@ Pod::Spec.new do |s|
s.author = { "Checkout.com Integration" => "[email protected]" }
s.source = { :git => "https://github.com/checkout/frames-ios.git", :tag => s.version }

s.ios.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
s.swift_version = "5.7"

s.source_files = 'Checkout/Source/**/*.swift'
s.exclude_files = "Checkout/Samples/**"

s.dependency 'CheckoutEventLoggerKit', '~> 1.2.4'
s.dependency 'Risk', '2.0.1'

end
2 changes: 1 addition & 1 deletion Checkout/Samples/CocoapodsSample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ target 'CheckoutCocoapodsSample' do
use_frameworks!

# Pods for CheckoutSDKCocoapodsSample
pod 'Checkout', '4.2.1'
pod 'Checkout', '4.3.2'

end
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/checkout/frames-ios";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.0.0;
kind = exactVersion;
version = 4.3.2;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@
"version" : "1.2.4"
}
},
{
"identity" : "checkout-risk-sdk-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/checkout/checkout-risk-sdk-ios.git",
"state" : {
"revision" : "4823f05166dca8392a41b56b975515c7e0f1a8da",
"version" : "2.0.1"
}
},
{
"identity" : "fingerprintjs-pro-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fingerprintjs/fingerprintjs-pro-ios",
"state" : {
"revision" : "ceb8b845ec99727ee9f78869a51688c6daa16bd8",
"version" : "2.2.0"
}
},
{
"identity" : "frames-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/checkout/frames-ios",
"state" : {
"revision" : "24a4585e5b7da1cc4b062e5aeadc63f1c9024db4",
"version" : "4.2.0"
"revision" : "2dae4f877e3a1882172c749e3bf4c32228b9d6a3",
"version" : "4.3.2"
}
},
{
Expand Down
43 changes: 38 additions & 5 deletions Checkout/Source/Tokenisation/CheckoutAPIService.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
//
// CheckoutAPIService.swift
//
//
//
// Created by Harry Brown on 23/11/2021.
//

import Foundation
import UIKit
import CheckoutEventLoggerKit
import Risk

public protocol CheckoutAPIProtocol {
func createToken(_ paymentSource: PaymentSource, completion: @escaping (Result<TokenDetails, TokenisationError.TokenRequest>) -> Void)
func createSecurityCodeToken(securityCode: String, completion: @escaping (Result<SecurityCodeResponse, TokenisationError.SecurityCodeError>) -> Void)
var correlationID: String { get }
}

protocol RiskProtocol: AnyObject {
func configure(completion: @escaping (Result<Void, RiskError.Configuration>) -> Void)
func publishData (cardToken: String?, completion: @escaping (Result<PublishRiskData, RiskError.Publish>) -> Void)
}

extension Risk: RiskProtocol {}

final public class CheckoutAPIService: CheckoutAPIProtocol {
private let requestExecutor: RequestExecuting
private let requestFactory: RequestProviding
private let tokenRequestFactory: TokenRequestProviding
private let tokenDetailsFactory: TokenDetailsProviding
private let logManager: LogManaging.Type
private var riskSDK: RiskProtocol

private let publicKey: String
private let environment: BaseURLProviding
Expand All @@ -41,7 +50,18 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
let tokenRequestFactory = TokenRequestFactory(cardValidator: cardValidator, decoder: snakeCaseJSONDecoder)
let tokenDetailsFactory = TokenDetailsFactory()
let logManager = LogManager.self


var riskEnvironment: RiskEnvironment
switch environment {
case .production:
riskEnvironment = .production
case .sandbox:
riskEnvironment = .sandbox
}

let riskConfig = RiskConfig(publicKey: publicKey, environment: riskEnvironment, framesMode: true)
let riskSDK = Risk.init(config: riskConfig)

logManager.setup(
environment: environment,
logger: CheckoutEventLogger(productName: Constants.Product.name),
Expand All @@ -57,7 +77,8 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
requestFactory: requestFactory,
tokenRequestFactory: tokenRequestFactory,
tokenDetailsFactory: tokenDetailsFactory,
logManager: logManager)
logManager: logManager,
riskSDK: riskSDK)
}

init(
Expand All @@ -67,7 +88,8 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
requestFactory: RequestProviding,
tokenRequestFactory: TokenRequestProviding,
tokenDetailsFactory: TokenDetailsProviding,
logManager: LogManaging.Type
logManager: LogManaging.Type,
riskSDK: RiskProtocol
) {
self.publicKey = publicKey
self.environment = environment
Expand All @@ -76,6 +98,7 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
self.tokenRequestFactory = tokenRequestFactory
self.tokenDetailsFactory = tokenDetailsFactory
self.logManager = logManager
self.riskSDK = riskSDK
}

/// The create token method tokenises the user’s card details.
Expand Down Expand Up @@ -126,12 +149,22 @@ final public class CheckoutAPIService: CheckoutAPIProtocol {
requestParameters,
responseType: TokenResponse.self,
responseErrorType: TokenisationError.ServerError.self
) { [tokenDetailsFactory, logManager, logTokenResponse] tokenResponseResult, httpURLResponse in
) { [weak self, tokenDetailsFactory, logManager, logTokenResponse] tokenResponseResult, httpURLResponse in
logTokenResponse(tokenResponseResult, httpURLResponse)

switch tokenResponseResult {
case .response(let tokenResponse):
let tokenDetails = tokenDetailsFactory.create(tokenResponse: tokenResponse)

guard let self else { return }
self.riskSDK.configure { configurationResult in
switch configurationResult {
case .failure: break
case .success():
self.riskSDK.publishData(cardToken: tokenDetails.token) { _ in }
}
}

completion(.success(tokenDetails))
case .errorResponse(let errorResponse):
completion(.failure(.serverError(errorResponse)))
Expand Down
2 changes: 1 addition & 1 deletion Checkout/Source/Validation/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum Constants {
}

enum Product {
static let version = "4.3.0"
static let version = "4.3.2"
static let name = "checkout-ios-sdk"
static let userAgent = "checkout-sdk-ios/\(version)"
}
Expand Down
28 changes: 28 additions & 0 deletions CheckoutTests/Stubs/StubRisk.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// StubRisk.swift
//
//
// Created by Precious Ossai on 20/02/2024.
//

import Foundation
@testable import Risk
@testable import Checkout

// swiftlint:disable large_tuple
class StubRisk: RiskProtocol {

var configureCalledCount = 0
var publishDataCalledCount = 0

func configure(completion: @escaping (Result<Void, RiskError.Configuration>) -> Void) {
configureCalledCount += 1
completion(.success(()))
}

func publishData (cardToken: String? = nil, completion: @escaping (Result<PublishRiskData, RiskError.Publish>) -> Void) {
publishDataCalledCount += 1
completion(.success(PublishRiskData(deviceSessionId: "dsid_testDeviceSessionId")))
}
}

10 changes: 8 additions & 2 deletions CheckoutTests/Tokenisation/CheckoutAPIServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class CheckoutAPIServiceTests: XCTestCase {
private var stubRequestFactory: StubRequestFactory! = StubRequestFactory()
private var stubTokenRequestFactory: StubTokenRequestFactory! = StubTokenRequestFactory()
private var stubTokenDetailsFactory: StubTokenDetailsFactory! = StubTokenDetailsFactory()
private var stubRisk: StubRisk! = .init()


override func setUp() {
Expand All @@ -36,7 +37,8 @@ final class CheckoutAPIServiceTests: XCTestCase {
requestFactory: stubRequestFactory,
tokenRequestFactory: stubTokenRequestFactory,
tokenDetailsFactory: stubTokenDetailsFactory,
logManager: StubLogManager.self
logManager: StubLogManager.self,
riskSDK: stubRisk
)
}

Expand All @@ -49,6 +51,7 @@ final class CheckoutAPIServiceTests: XCTestCase {
stubTokenRequestFactory = nil
stubSecurityCodeRequestExecutor = nil
stubTokenDetailsFactory = nil
stubRisk = nil

super.tearDown()
}
Expand Down Expand Up @@ -90,6 +93,8 @@ final class CheckoutAPIServiceTests: XCTestCase {
.init(tokenID: "token", scheme: "visa", httpStatusCode: 200, serverError: nil)
))

XCTAssertEqual(stubRisk.configureCalledCount, 1)
XCTAssertEqual(stubRisk.publishDataCalledCount, 1)
XCTAssertEqual(result, .success(tokenDetails))
}

Expand Down Expand Up @@ -213,7 +218,8 @@ extension CheckoutAPIServiceTests {
requestFactory: stubRequestFactory,
tokenRequestFactory: stubTokenRequestFactory,
tokenDetailsFactory: stubTokenDetailsFactory,
logManager: StubLogManager.self
logManager: StubLogManager.self,
riskSDK: stubRisk
)
}

Expand Down
4 changes: 2 additions & 2 deletions Frames.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Frames"
s.version = "4.3.1"
s.version = "4.3.2"
s.summary = "Checkout API Client, Payment Form UI and Utilities in Swift"
s.description = <<-DESC
Checkout API Client and Payment Form Utilities in Swift.
Expand All @@ -21,6 +21,6 @@ Pod::Spec.new do |s|

s.dependency 'PhoneNumberKit'
s.dependency 'CheckoutEventLoggerKit', '~> 1.2.4'
s.dependency 'Checkout', '4.3.0'
s.dependency 'Checkout', '4.3.2'

end
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
"version" : "1.2.4"
}
},
{
"identity" : "checkout-risk-sdk-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/checkout/checkout-risk-sdk-ios.git",
"state" : {
"revision" : "4823f05166dca8392a41b56b975515c7e0f1a8da",
"version" : "2.0.1"
}
},
{
"identity" : "fingerprintjs-pro-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fingerprintjs/fingerprintjs-pro-ios",
"state" : {
"revision" : "ceb8b845ec99727ee9f78869a51688c6daa16bd8",
"version" : "2.2.0"
}
},
{
"identity" : "phonenumberkit",
"kind" : "remoteSourceControl",
Expand Down
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ let package = Package(
.package(
url: "https://github.com/marmelroy/PhoneNumberKit.git",
exact: "3.5.9"),
.package(
url: "https://github.com/checkout/checkout-risk-sdk-ios.git",
exact: "2.0.1"),
.package(
url: "https://github.com/checkout/checkout-event-logger-ios-framework.git",
from: "1.2.4"
Expand All @@ -29,6 +32,7 @@ let package = Package(
dependencies: [
.product(name: "CheckoutEventLoggerKit",
package: "checkout-event-logger-ios-framework"),
.product(name: "Risk", package: "checkout-risk-sdk-ios"),
"PhoneNumberKit",
"Checkout"
],
Expand All @@ -43,6 +47,7 @@ let package = Package(
dependencies: [
.product(name: "CheckoutEventLoggerKit",
package: "checkout-event-logger-ios-framework"),
.product(name: "Risk", package: "checkout-risk-sdk-ios"),
],
path: "Checkout/Source"
),
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
enum Constants {

static let productName = "frames-ios-sdk"
static let version = "4.3.1"
static let version = "4.3.2"
static let userAgent = "checkout-sdk-frames-ios/\(version)"

enum Logging {
Expand Down
Loading

0 comments on commit 5693ee1

Please sign in to comment.