Skip to content

Commit

Permalink
Remove 3DS version 1 fallback (#11)
Browse files Browse the repository at this point in the history
* Remove 3DS version 1 fallback
  • Loading branch information
veselincholakov-paysafe authored May 3, 2023
1 parent aeb6fc7 commit 458ee83
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 486 deletions.
10 changes: 7 additions & 3 deletions Example-ObjC/Add card/PSAddCardViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ @implementation PSAddCardViewController

- (NSDictionary *)cards {
return @{ @"4000000000001091": @"3DS 2",
@"4000000000001000": @"3DS 2 Frictionless",
@"4111111111111111": @"3DS 1.0"
@"4000000000001000": @"3DS 2 Frictionless"
};
}

Expand Down Expand Up @@ -117,7 +116,12 @@ - (void)viewDidLoad {
action:@selector(didTapPickCard)];
self.cardNumberTextField.text = @"4000000000001091";
self.monthTextField.text = @"01";
self.yearTextField.text = @"2022";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy"];
NSString *yearString = [NSString stringWithFormat:@"%d",[[formatter stringFromDate:[NSDate date]] intValue] + 3];
self.cvvTextField.text = @"123";

self.yearTextField.text = yearString;
self.nameOnCardTextField.text = @"MR. JOHN SMITH";
self.street1TextField.text = @"100 Queen Street West";
self.street2TextField.text = @"Unit 201";
Expand Down
5 changes: 2 additions & 3 deletions Example/AddCardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class AddCardViewController: UIViewController {

private let cards: [(number: String, name: String)] = [
("4000000000001091", "3DS 2"),
("4000000000001000", "3DS 2 Frictionless"),
("4111111111111111", "3DS 1.0"),
("4000000000001000", "3DS 2 Frictionless")
]

@IBOutlet private var cardNumberTextField: UITextField!
Expand Down Expand Up @@ -115,7 +114,7 @@ class AddCardViewController: UIViewController {
cardNumberTextField.text = "4000000000001091"

monthTextField.text = "01"
yearTextField.text = "2022"
yearTextField.text = String(Calendar.current.component(.year, from: Date()) + 3)
nameOnCardTextField.text = "MR. JOHN SMITH"
cvvTextField.text = "123"
street1TextField.text = "100 Queen Street West"
Expand Down
2 changes: 1 addition & 1 deletion Paysafe_SDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Paysafe_SDK"
s.version = "2.4.0"
s.version = "2.5.0"
s.summary = "Paysafe SDK handling 3DS 2 and Apple Pay"

s.license = "MIT"
Expand Down
22 changes: 6 additions & 16 deletions Paysafe_SDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@
64173AB3230848EA00642D95 /* PSApplePayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 64173AAF2307087700642D95 /* PSApplePayViewController.m */; };
64297AB7237AE39000EDEED2 /* Paysafe_SDK.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 2BCCA98322D4DF9B00C7772A /* Paysafe_SDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6480993122F4351E00E9C9D6 /* UIViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 6480993022F4351E00E9C9D6 /* UIViewController+Utils.m */; };
6480993322F48EA500E9C9D6 /* paysafe_sdk_test_index.html in Resources */ = {isa = PBXBuildFile; fileRef = 6480993222F48EA500E9C9D6 /* paysafe_sdk_test_index.html */; };
6480994922F8680400E9C9D6 /* UIResponder+FirstResponder.m in Sources */ = {isa = PBXBuildFile; fileRef = 6480994822F8680400E9C9D6 /* UIResponder+FirstResponder.m */; };
64AE64F02354822000C63243 /* ApplePayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AE64EF2354822000C63243 /* ApplePayTests.swift */; };
64AE64F22355C38500C63243 /* ApplePayHelperProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AE64F12355C38500C63243 /* ApplePayHelperProtocols.swift */; };
64AE64F4235865B700C63243 /* WebViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AE64F3235865B700C63243 /* WebViewControllerTests.swift */; };
64B1A0A22379B6A2009BC690 /* Paysafe_SDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BCCA98322D4DF9B00C7772A /* Paysafe_SDK.framework */; };
64B3908023324F7E007ED4B0 /* paysafe_sdk_versioning-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 64B3907F23324F7E007ED4B0 /* paysafe_sdk_versioning-Info.plist */; };
64CA5AB022DE14CB00CE4222 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64CA5AAF22DE14CB00CE4222 /* WebViewController.swift */; };
64CA5AB322DF463900CE4222 /* paysafe_sdk_index.html in Resources */ = {isa = PBXBuildFile; fileRef = 64CA5AB122DF311100CE4222 /* paysafe_sdk_index.html */; };
64CA5AB722E1ACFE00CE4222 /* UIConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64CA5AB622E1ACFE00CE4222 /* UIConfiguration.swift */; };
64CA5ABB22E20B8D00CE4222 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64CA5ABA22E20B8D00CE4222 /* Utils.swift */; };
64DD2FCC22DBB7E5007F9B42 /* WebServiceHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DD2FCB22DBB7E5007F9B42 /* WebServiceHandler.swift */; };
Expand Down Expand Up @@ -195,15 +191,11 @@
64173AB423084D5100642D95 /* PSApplePayViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PSApplePayViewController.h; sourceTree = "<group>"; };
6480992F22F4350C00E9C9D6 /* UIViewController+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Utils.h"; sourceTree = "<group>"; };
6480993022F4351E00E9C9D6 /* UIViewController+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Utils.m"; sourceTree = "<group>"; };
6480993222F48EA500E9C9D6 /* paysafe_sdk_test_index.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = paysafe_sdk_test_index.html; sourceTree = "<group>"; };
6480994722F867A500E9C9D6 /* UIResponder+FirstResponder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIResponder+FirstResponder.h"; sourceTree = "<group>"; };
6480994822F8680400E9C9D6 /* UIResponder+FirstResponder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIResponder+FirstResponder.m"; sourceTree = "<group>"; };
64AE64EF2354822000C63243 /* ApplePayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplePayTests.swift; sourceTree = "<group>"; };
64AE64F12355C38500C63243 /* ApplePayHelperProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplePayHelperProtocols.swift; sourceTree = "<group>"; };
64AE64F3235865B700C63243 /* WebViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewControllerTests.swift; sourceTree = "<group>"; };
64B3907F23324F7E007ED4B0 /* paysafe_sdk_versioning-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "paysafe_sdk_versioning-Info.plist"; sourceTree = SOURCE_ROOT; };
64CA5AAF22DE14CB00CE4222 /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
64CA5AB122DF311100CE4222 /* paysafe_sdk_index.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = paysafe_sdk_index.html; sourceTree = "<group>"; };
64CA5AB622E1ACFE00CE4222 /* UIConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIConfiguration.swift; sourceTree = "<group>"; };
64CA5ABA22E20B8D00CE4222 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
64DD2FCB22DBB7E5007F9B42 /* WebServiceHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebServiceHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,9 +269,6 @@
64EFD70B2303EDEB00BB1C9A /* Merchandise.swift */,
64DD2FCB22DBB7E5007F9B42 /* WebServiceHandler.swift */,
2BA3016C22F994CB002BC174 /* WebServiceHandlerErrorMapper.swift */,
64CA5AAF22DE14CB00CE4222 /* WebViewController.swift */,
64CA5AB122DF311100CE4222 /* paysafe_sdk_index.html */,
6480993222F48EA500E9C9D6 /* paysafe_sdk_test_index.html */,
2B858F2B230463EF00AFA53C /* CardinalSessionProtocol.swift */,
2B858F2D2304640B00AFA53C /* ThreeDSecureWebService.swift */,
);
Expand Down Expand Up @@ -323,7 +312,6 @@
2B5A7F8C22FDAE3400665E6E /* ThreeDSecureServiceTests.swift */,
2B73D5682355CB3B000EC320 /* CustomerVaultServiceTests.swift */,
2B73D56A2355E98D000EC320 /* WebServiceHandlerTests.swift */,
64AE64F3235865B700C63243 /* WebViewControllerTests.swift */,
64AE64EF2354822000C63243 /* ApplePayTests.swift */,
);
path = Paysafe_SDKTests;
Expand Down Expand Up @@ -651,8 +639,6 @@
buildActionMask = 2147483647;
files = (
64B3908023324F7E007ED4B0 /* paysafe_sdk_versioning-Info.plist in Resources */,
6480993322F48EA500E9C9D6 /* paysafe_sdk_test_index.html in Resources */,
64CA5AB322DF463900CE4222 /* paysafe_sdk_index.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -692,7 +678,6 @@
files = (
2B73D5692355CB3B000EC320 /* CustomerVaultServiceTests.swift in Sources */,
2B73D56B2355E98E000EC320 /* WebServiceHandlerTests.swift in Sources */,
64AE64F4235865B700C63243 /* WebViewControllerTests.swift in Sources */,
2B5A7F8D22FDAE3400665E6E /* ThreeDSecureServiceTests.swift in Sources */,
64AE64F02354822000C63243 /* ApplePayTests.swift in Sources */,
);
Expand All @@ -712,7 +697,6 @@
2B858F2C230463EF00AFA53C /* CardinalSessionProtocol.swift in Sources */,
64CA5ABB22E20B8D00CE4222 /* Utils.swift in Sources */,
64EFD6F222FAB2D000BB1C9A /* Logger.swift in Sources */,
64CA5AB022DE14CB00CE4222 /* WebViewController.swift in Sources */,
2B858F2E2304640B00AFA53C /* ThreeDSecureWebService.swift in Sources */,
64DD2FCF22DBB803007F9B42 /* ThreeDSecureService.swift in Sources */,
64DD2FDC22DCBA1F007F9B42 /* ChallengePayload.swift in Sources */,
Expand Down Expand Up @@ -870,6 +854,9 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Paysafe.Paysafe-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -889,6 +876,9 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Paysafe.Paysafe-SDKTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
3 changes: 2 additions & 1 deletion Paysafe_SDK/Apple Pay/ApplePayService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ extension ApplePayService: ApplePayServiceProtocol {
applePaymentDidSucceed = false

let request = PKPaymentRequest()

request.merchantIdentifier = merchantIdentifier
request.supportedNetworks = supportedPaymentNetworks
request.merchantCapabilities = .capability3DS
Expand All @@ -198,7 +199,7 @@ extension ApplePayService: ApplePayServiceProtocol {
for shippingMethod in cartDetails.shippingOptions {
let method = PKShippingMethod(label: shippingMethod.title, amount: shippingMethod.price)
method.identifier = shippingMethod.title
method.detail = shippingMethod.description
method.detail = shippingMethod.shippingDescription
shippingMethods.append(method)
}

Expand Down
28 changes: 0 additions & 28 deletions Paysafe_SDK/Configuration/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ extension PaysafeSDK {
return currentEnvironment.getBaseUrlPath()
}

static func getEnvironmentNameForWebSDK() -> String {
return currentEnvironment.getEnvironmentNameForWebSDK()
}

static func getEnvironmentURLPath() -> URL? {
return currentEnvironment.getEnvironmentURLPath()
}

@objc(PaysafeSDKEnvironment) public enum Environment: Int, CaseIterable {
case test
case production
Expand All @@ -36,25 +28,5 @@ extension PaysafeSDK {
return "https://api.paysafe.com"
}
}

fileprivate func getEnvironmentNameForWebSDK() -> String {
switch currentEnvironment {
case .test:
return "TEST"
case .production:
return "LIVE"
}
}

fileprivate func getEnvironmentURLPath() -> URL? {
let bundle = Bundle(for: PaysafeSDK.self)

switch currentEnvironment {
case .test:
return bundle.url(forResource: "paysafe_sdk_test_index", withExtension: "html")
case .production:
return bundle.url(forResource: "paysafe_sdk_index", withExtension: "html")
}
}
}
}
77 changes: 5 additions & 72 deletions Paysafe_SDK/threeDSecure/ThreeDSecureService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import CardinalMobile

private var responseDict: [String: Any]?
private var challengePayload: ChallengePayload?
private var webNavigationController: UINavigationController?
private var merchantConfiguration: PaysafeSDK.MerchantConfiguration?

private lazy var correlationId: String = {
Expand All @@ -45,7 +44,6 @@ import CardinalMobile
}

config.renderType = [CardinalSessionRenderTypeOTP, CardinalSessionRenderTypeHTML]
config.enableQuickAuth = true
config.enableDFSync = true
session.configure(config)

Expand Down Expand Up @@ -93,17 +91,6 @@ import CardinalMobile
return UUID().uuidString.lowercased()
}

private func createWebController(_ accountId: String,
threeDSecureAuthId: String,
merchantConfiguration: PaysafeSDK.MerchantConfiguration) -> WebViewController {
let webController = WebViewController(merchantConfiguration: merchantConfiguration)
webController.title = PaysafeSDK.uiConfiguration?.toolbarConfiguration?.headerText ?? "Secure Checkout"
webController.cancelCallback = { [weak self] in
self?.callFinalize(validateResponse: nil, accountID: accountId, threeDSecureAuthID: threeDSecureAuthId, serverJWT: nil)
}
return webController
}

private func getJWTForCardinal(cardBin: String, completion: @escaping (Result<String, Error>) -> Void) {
guard let merchantConfiguration = self.merchantConfiguration else {
completion(.failure(Errors.invalidMerchantConfigurationError))
Expand Down Expand Up @@ -310,67 +297,13 @@ extension ThreeDSecureService {
}

onChallengeCompleted = completion

self.challengePayload = challengePayload

if challengePayload.threeDSecureVersion.hasPrefix("2.") {
self.challengePayload = challengePayload

session.continueWith(transactionId: challengePayload.transactionId,
payload: challengePayload.payload,
validationDelegate: self)
} else {
webNavigationController = nil
handleThreeDSecure1Challenge(challengePayload,
sdkChallengePayload: sdkChallengePayload,
completion: completion)
}
}

private func handleThreeDSecure1Challenge(_ challengePayload: ChallengePayload,
sdkChallengePayload: String,
completion: @escaping ((Result<String, Error>) -> Void)) {
guard let merchantConfiguration = self.merchantConfiguration else {
completion(.failure(Errors.invalidMerchantConfigurationError))
return
}

let webController = createWebController(challengePayload.accountId,
threeDSecureAuthId: challengePayload.id,
merchantConfiguration: merchantConfiguration)
webNavigationController = UINavigationController(rootViewController: webController)

let challengeCorrelationId = correlationId
webController.continueWith(payload: sdkChallengePayload) { [weak self] result in
self?.dismissWebview()
session.continueWith(transactionId: challengePayload.transactionId,
payload: challengePayload.payload,
validationDelegate: self)

switch result {
case .failure(let error):
completion(.failure(error))

case .success(let authenticationID):
guard let authenticationID = authenticationID as? String else {
self?.logger.log(message: Errors.ErrorType.internalSDKError, eventType: .internalSDKError, correlationId: challengeCorrelationId)
completion(.failure(Errors.internalSDKError))
return
}

completion(.success(authenticationID))
}
}

guard let webNavigationController = webNavigationController else {
return
}

if #available(iOS 13.0, *) {
webNavigationController.isModalInPresentation = true
} else {
webNavigationController.modalPresentationStyle = .fullScreen
}

UIApplication.shared.topmostController?.present(webNavigationController, animated: true, completion: nil)
}

private func dismissWebview() {
webNavigationController?.dismiss(animated: true, completion: nil)
}
}
Loading

0 comments on commit 458ee83

Please sign in to comment.