Skip to content

Commit

Permalink
Merge branch 'feature_Twint' into twint_action_full_test
Browse files Browse the repository at this point in the history
  • Loading branch information
goergisn committed Mar 7, 2024
2 parents 10f33af + 201515b commit 56b1c98
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 48 deletions.
1 change: 1 addition & 0 deletions Adyen.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Pod::Spec.new do |s|
s.subspec 'AdyenTwint' do |plugin|
plugin.source_files = 'AdyenTwint/**/*.swift'
plugin.dependency 'Adyen/Core'
plugin.dependency 'Adyen/Actions'
plugin.dependency 'Adyen/TwintSDK'
end

Expand Down
32 changes: 23 additions & 9 deletions AdyenActions/AdyenActionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,31 @@ public final class AdyenActionComponent: ActionComponent, ActionHandlingComponen

public struct Twint {

// TODO: Add documentation
public let returnUrlScheme: String
/// The callback app scheme invoked once the Twint app is done with the payment
public var callbackAppScheme: String

public init(returnUrlScheme: String) {
guard let url = URL(string: returnUrlScheme), let scheme = url.scheme, scheme == returnUrlScheme else {
assertionFailure("Provided url scheme is not a scheme")
self.returnUrlScheme = returnUrlScheme
return
/// Initializes a new instance
///
/// - Parameter callbackAppScheme: The callback app scheme invoked once the Twint app is done with the payment
///
/// - Important: The value of ``callbackAppScheme`` is required to only provide the scheme,
/// without a host/path/... (e.g. "my-app", not a url "my-app://...")
public init(callbackAppScheme: String) {
if !Self.isCallbackSchemeValid(callbackAppScheme) {
assertionFailure("Format of provided callbackAppScheme '\(callbackAppScheme)' is incorrect.")
}

self.callbackAppScheme = callbackAppScheme
}

/// Validating whether or not the provided `callbackAppScheme` only contains a scheme
private static func isCallbackSchemeValid(_ callbackAppScheme: String) -> Bool {
if let url = URL(string: callbackAppScheme), url.scheme != nil {
// If the scheme is not nil it means that more information than just the scheme was provided
return false
}

self.returnUrlScheme = scheme
return true
}
}

Expand Down Expand Up @@ -232,7 +246,7 @@ public final class AdyenActionComponent: ActionComponent, ActionHandlingComponen
context: context,
configuration: .init(
style: configuration.style.awaitComponentStyle,
returnUrlScheme: twintConfiguration.returnUrlScheme,
callbackAppScheme: twintConfiguration.callbackAppScheme,
localizationParameters: configuration.localizationParameters
)
)
Expand Down
14 changes: 7 additions & 7 deletions AdyenActions/Components/SDK/TwintSDKActionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ import Foundation
/// The localization parameters, leave it nil to use the default parameters.
public var localizationParameters: LocalizationParameters?

/// The return url scheme
/// The callback app scheme invoked once the Twint app is done with the payment
///
/// - Important: This value is required to only provide the scheme, without a host/path/.... (e.g. "my-app", not a url "my-app://...")
public let returnUrlScheme: String
public let callbackAppScheme: String

/// Initializes an instance of `Configuration`
///
/// - Parameters:
/// - style: The Component UI style.
/// - returnUrlScheme: The url scheme of the app
/// - callbackAppScheme: The callback app scheme invoked once the Twint app is done with the payment
/// - localizationParameters: The localization parameters, leave it nil to use the default parameters.
///
/// - Important: This value of ``returnUrlScheme`` is required to only provide the scheme, without a host/path/... (e.g. "my-app", not a url "my-app://...")
/// - Important: The value of ``callbackAppScheme`` is required to only provide the scheme, without a host/path/... (e.g. "my-app", not a url "my-app://...")
public init(
style: AwaitComponentStyle = .init(),
returnUrlScheme: String,
callbackAppScheme: String,
localizationParameters: LocalizationParameters? = nil
) {
self.style = style
self.localizationParameters = localizationParameters
self.returnUrlScheme = returnUrlScheme
self.callbackAppScheme = callbackAppScheme
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ import Foundation
let error = twint.pay(
withCode: action.sdkData.token,
appConfiguration: app,
callback: configuration.returnUrlScheme
callback: configuration.callbackAppScheme
)

if let error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension InitialDataFlowProtocol {
requestorAppURL: ConfigurationConstants.returnUrl,
delegateAuthentication: ConfigurationConstants.delegatedAuthenticationConfigurations
),
twint: .init(returnUrlScheme: ConfigurationConstants.returnUrl.scheme!)
twint: .init(callbackAppScheme: ConfigurationConstants.returnUrl.scheme!)
)
)
return configuration
Expand Down
2 changes: 1 addition & 1 deletion Demo/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal struct DemoAppSettings: Codable {
if dropInSettings.cashAppPayEnabled {
dropInConfig.cashAppPay = .init(redirectURL: ConfigurationConstants.returnUrl)
}
dropInConfig.actionComponent.twint = .init(returnUrlScheme: ConfigurationConstants.returnUrl.scheme!)
dropInConfig.actionComponent.twint = .init(callbackAppScheme: ConfigurationConstants.returnUrl.scheme!)

return dropInConfig
}
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ let package = Package(
name: "AdyenTwint",
dependencies: [
.target(name: "Adyen"),
.target(name: "AdyenActions"),
.target(name: "TwintSDK")
],
path: "AdyenTwint"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,6 @@ import TwintSDK

#if canImport(TwintSDK)

extension TWAppConfiguration {
static var dummy: TWAppConfiguration {
let twintAppConfiguration = TWAppConfiguration()
twintAppConfiguration.appDisplayName = "Test App"
twintAppConfiguration.appURLScheme = "scheme://"
return twintAppConfiguration
}
}

extension TwintSDKActionComponent.Configuration {
static var dummy: Self {
.init(returnUrlScheme: "ui-host")
}
}

extension TwintSDKAction {
static var dummy: TwintSDKAction {
.init(
sdkData: .init(token: "token"),
paymentData: "paymentData",
paymentMethodType: "paymentMethodType",
type: "type"
)
}
}

final class TwintSDKActionTests: XCTestCase {

func testNoAppFound() throws {
Expand Down Expand Up @@ -110,7 +84,7 @@ final class TwintSDKActionTests: XCTestCase {
XCTAssertEqual(code, TwintSDKAction.dummy.sdkData.token)
XCTAssertEqual(appConfiguration.appDisplayName, TWAppConfiguration.dummy.appDisplayName)
XCTAssertEqual(appConfiguration.appURLScheme, TWAppConfiguration.dummy.appURLScheme)
XCTAssertEqual(callbackAppScheme, TwintSDKActionComponent.Configuration.dummy.returnUrl)
XCTAssertEqual(callbackAppScheme, TwintSDKActionComponent.Configuration.dummy.callbackAppScheme)
return nil
} handleController: { installedAppConfigurations, selectionHandler, cancelHandler in
XCTFail("Twint controller should not have been shown")
Expand All @@ -122,7 +96,8 @@ final class TwintSDKActionTests: XCTestCase {

let twintActionComponent = Self.actionComponent(
with: twintSpy,
presentationDelegate: Self.failingPresentationDelegateMock()
presentationDelegate: Self.failingPresentationDelegateMock(),
delegate: nil
)

// When
Expand Down Expand Up @@ -157,7 +132,7 @@ final class TwintSDKActionTests: XCTestCase {
XCTAssertEqual(code, TwintSDKAction.dummy.sdkData.token)
XCTAssertEqual(appConfiguration.appDisplayName, TWAppConfiguration.dummy.appDisplayName)
XCTAssertEqual(appConfiguration.appURLScheme, TWAppConfiguration.dummy.appURLScheme)
XCTAssertEqual(callbackAppScheme, TwintSDKActionComponent.Configuration.dummy.returnUrl)
XCTAssertEqual(callbackAppScheme, TwintSDKActionComponent.Configuration.dummy.callbackAppScheme)
return nil
} handleController: { installedAppConfigurations, selectionHandler, cancelHandler in
XCTAssertEqual(installedAppConfigurations, expectedAppConfigurations)
Expand All @@ -168,7 +143,7 @@ final class TwintSDKActionTests: XCTestCase {
XCTFail("Handle open should not have been called")
return false
}

let twintActionComponent = TwintSDKActionComponent(
context: Dummy.context,
configuration: .dummy,
Expand Down

0 comments on commit 56b1c98

Please sign in to comment.