Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 284 additions & 1 deletion Adyen.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Adyen/Assets/Generated/LocalizationKey.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//
// Copyright (c) 2023 Adyen N.V.
// Copyright (c) 2021 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
// This file is autogenerated. Please do not modify it.
//

// swiftlint:disable all
Expand Down
49 changes: 49 additions & 0 deletions Adyen/CheckoutConfiguration/CheckoutConfiguration+Callbacks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation

// TODO: Finalize all the parameters of the callbacks
// Move Action to core module?
// Add Resultcode enum
public typealias PaymentsResponseHandler = (_ resultCode: String, _ action: String) -> Void
public typealias SubmitHandler = (_ data: PaymentComponentData, _ handler: PaymentsResponseHandler?) -> Void
public typealias AdditionalDetailsHandler = (_ data: ActionComponentData, _ handler: PaymentsResponseHandler?) -> Void
// TODO: Have a checkout error object?
public typealias CheckoutErrorHandler = (_ error: Error) -> Void
public typealias CheckoutSuccessHandler = (_ resultCode: String) -> Void

public extension CheckoutConfiguration {

// TODO: Add function descriptions

func onSubmit(_ onSubmit: @escaping SubmitHandler) -> Self {
var copy = self
copy.onSubmit = onSubmit
return copy
}

// TODO: Mutating func or copy
mutating func onAdditionalDetails(_ onAdditionalDetails: @escaping AdditionalDetailsHandler) -> Self {
self.onAdditionalDetails = onAdditionalDetails
return self
}

func onError(_ onError: @escaping CheckoutErrorHandler) -> Self {
var copy = self
copy.onError = onError
return copy
}

func onComplete(_ onComplete: @escaping CheckoutSuccessHandler) -> Self {
var copy = self
copy.onComplete = onComplete
return copy
}

// add other callbacks that multiple components can use
// balance check, order
}
52 changes: 52 additions & 0 deletions Adyen/CheckoutConfiguration/CheckoutConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation

public struct CheckoutConfiguration {

internal var amount: Amount

@_spi(AdyenInternal)
public var apiContext: APIContext

// TODO: how we store configurations may change
internal var configurations: [String: CheckoutConfigurable]

internal var onSubmit: SubmitHandler?
internal var onAdditionalDetails: AdditionalDetailsHandler?
internal var onError: CheckoutErrorHandler?
internal var onComplete: CheckoutSuccessHandler?

/// Creates a CheckoutConfiguration instance.
/// - Parameters:
/// - environment: The environment to retrieve internal resources from.
/// - amount: Payment amount.
/// - clientKey: The client key that corresponds to the web service user you will use for initiating the payment.
/// - content: Configuration builder to provide the desired configuration instances.
/// See https://docs.adyen.com/user-management/client-side-authentication for more information.
/// - Throws: `ClientKeyError.invalidClientKey` if the client key is invalid.
// swiftlint:disable vertical_parameter_alignment
public init(
environment: Environment,
amount: Amount,
clientKey: String,
@CheckoutConfigurationBuilder content: () -> CheckoutConfigurable
) throws {
self.apiContext = try APIContext(environment: environment, clientKey: clientKey)
self.amount = amount

let content = content()
let configArray = (content as? CompositeCheckoutConfiguration)?.configurations ?? [content]
var configDictionary: [String: CheckoutConfigurable] = [:]

// Should dictionary hold ALL configs beforehand and update new ones?
for configuration in configArray {
configDictionary[String(describing: configuration.self)] = configuration
}
self.configurations = configDictionary
}
}
31 changes: 31 additions & 0 deletions Adyen/CheckoutConfiguration/ConfigurationBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import Foundation

@resultBuilder
public struct CheckoutConfigurationBuilder {
public static func buildBlock(_ components: CheckoutConfigurable...) -> CheckoutConfigurable {
CompositeCheckoutConfiguration(configurations: components)
}

public static func buildEither(first component: any CheckoutConfigurable) -> any CheckoutConfigurable {
component
}

public static func buildEither(second component: any CheckoutConfigurable) -> any CheckoutConfigurable {
component
}
}

public protocol CheckoutConfigurable {
// static func makeDefaultConfig() -> Self
}

internal struct CompositeCheckoutConfiguration: CheckoutConfigurable {

internal var configurations: [CheckoutConfigurable]
}
13 changes: 13 additions & 0 deletions AdyenCheckout/AdyenCheckout.docc/AdyenCheckout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ``AdyenCheckout``

<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@-->

## Overview

<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->

## Topics

### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@-->

- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->
17 changes: 17 additions & 0 deletions AdyenCheckout/AdyenCheckout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

#import <Foundation/Foundation.h>

//! Project version number for AdyenCheckout.
FOUNDATION_EXPORT double AdyenCheckoutVersionNumber;

//! Project version string for AdyenCheckout.
FOUNDATION_EXPORT const unsigned char AdyenCheckoutVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <AdyenCheckout/PublicHeader.h>


69 changes: 69 additions & 0 deletions AdyenCheckout/AdyenCheckout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

@_spi(AdyenInternal) import Adyen
@_spi(AdyenInternal) import AdyenDropIn
@_spi(AdyenInternal) import AdyenSession
@_spi(AdyenInternal) import AdyenNetworking

public class AdyenCheckout {

internal var session: AdyenSession?
internal var checkoutAttemptId: String?
internal var apiClient: APIClient?
internal var paymentMethods: PaymentMethods?

/// Sets up the checkout object for the default flow
/// with the values from your backend's `/session` call.
/// - Parameters:
/// - sessionId: sessionId from the `/session` call response.
/// - sessionData: session data from the `/session` call response.
/// - configuration: The `CheckoutConfiguration` instance.
/// - completion: A closure that is called when the setup is complete, containing the checkout object.
public static func setup(
with sessionId: String,
sessionData: String,
configuration: CheckoutConfiguration,
completion: @escaping (AdyenCheckout) -> Void
) {
// session
// analytics
var checkout = AdyenCheckout()
let apiClient = APIClient(apiContext: configuration.apiContext)

let group = DispatchGroup()
group.enter()
// create and store session and paymentmethods
group.leave()

group.enter()
// fetch and store checkout attempt id
group.leave()

group.notify(queue: .main) {
completion(checkout)
}
}

/// Sets up the checkout object for the advanced flow
/// with the values from your backend's `/paymentMethods` call.
/// - Parameters:
/// - paymentMethods: The `PaymentMethods` response from the `/paymentMethods` call.
/// - configuration: The `CheckoutConfiguration` instance.
/// - completion: A closure that is called when the setup is complete, containing the checkout object.
public static func setup(
with paymentMethods: PaymentMethods,
configuration: CheckoutConfiguration,
completion: @escaping (AdyenCheckout) -> Void
) {
var checkout = AdyenCheckout()
checkout.paymentMethods = paymentMethods
let apiClient = APIClient(apiContext: configuration.apiContext)

// fetch and store checkout attempt id
completion(checkout)
}
}
Loading