Skip to content
Draft
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let package = Package(
),
.target(
name: "ShopifyAcceleratedCheckouts",
dependencies: ["ShopifyCheckoutKit"],
dependencies: ["ShopifyCheckoutKit", "ShopifyCheckoutProtocol"],
path: "platforms/swift/Sources/ShopifyAcceleratedCheckouts",
resources: [.process("Localizable.xcstrings"), .process("Media.xcassets")]
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Foundation
#if COCOAPODS
import ShopifyCheckoutKit

extension CheckoutProtocol.Client: @retroactive CheckoutCommunicationProtocol {}
#else
import ShopifyCheckoutProtocol

enum CheckoutProtocol {
typealias Client = EmbeddedCheckoutProtocol.Client

static let complete = EmbeddedCheckoutProtocol.Event.complete
static let error = EmbeddedCheckoutProtocol.Event.error
static let lineItemsChange = EmbeddedCheckoutProtocol.Event.lineItemsChange
static let messagesChange = EmbeddedCheckoutProtocol.Event.messagesChange
static let start = EmbeddedCheckoutProtocol.Event.start
static let totalsChange = EmbeddedCheckoutProtocol.Event.totalsChange
}
#endif

struct DispatchEnvelope<Payload: Encodable>: Encodable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import PassKit
import ShopifyCheckoutKit
#if !COCOAPODS
import ShopifyCheckoutProtocol
#endif
import SwiftUI

/// Render state for AcceleratedCheckoutButtons
Expand Down Expand Up @@ -230,7 +233,7 @@ extension AcceleratedCheckoutButtons {
return newView
}

public func connect(_ client: (any CheckoutCommunicationProtocol)?) -> AcceleratedCheckoutButtons {
public func connect(_ client: CheckoutProtocol.Client?) -> AcceleratedCheckoutButtons {
var newView = self
newView.clientContainer = CheckoutProtocolClientContainer(client)
return newView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#endif
import Foundation

public protocol CheckoutCommunicationProtocol: Sendable {
package protocol CheckoutCommunicationProtocol: Sendable {
func process(_ message: String) async -> String?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit

@MainActor
public class CheckoutViewController: UINavigationController {
public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) {
public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) {
let rootViewController = CheckoutWebViewController(checkoutURL: url, delegate: delegate, client: client, entryPoint: nil)
super.init(rootViewController: rootViewController)
presentationController?.delegate = rootViewController
Expand Down Expand Up @@ -62,7 +62,13 @@ public struct ShopifyCheckout: UIViewControllerRepresentable, CheckoutConfigurab
webViewController.onFail = onFailAction
}

@discardableResult public func connect(_ handler: any CheckoutCommunicationProtocol) -> Self {
@discardableResult public func connect(_ handler: CheckoutProtocol.Client) -> Self {
var copy = self
copy.client = handler
return copy
}

@discardableResult package func connect(_ handler: any CheckoutCommunicationProtocol) -> Self {
var copy = self
copy.client = handler
return copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl

// MARK: Initializers

public init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) {
init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) {
checkoutURL = url
self.delegate = delegate
self.client = client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ public func invalidate() {

@MainActor
@discardableResult
public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) -> CheckoutViewController {
public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) -> CheckoutViewController {
let decorated = CheckoutProtocol.url(for: url)
let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client)
from.present(viewController, animated: true)
return viewController
}

@MainActor
@discardableResult
package func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: any CheckoutCommunicationProtocol) -> CheckoutViewController {
let decorated = CheckoutProtocol.url(for: url)
let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client)
from.present(viewController, animated: true)
Expand Down
28 changes: 21 additions & 7 deletions platforms/swift/api/ShopifyAcceleratedCheckouts.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
"declKind": "Import",
"moduleName": "ShopifyAcceleratedCheckouts"
},
{
"kind": "Import",
"name": "ShopifyCheckoutProtocol",
"printedName": "ShopifyCheckoutProtocol",
"declKind": "Import",
"moduleName": "ShopifyAcceleratedCheckouts"
},
{
"kind": "Import",
"name": "SwiftOnoneSupport",
Expand Down Expand Up @@ -2220,21 +2227,28 @@
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?",
"children": [
{
"kind": "TypeNominal",
"name": "CheckoutCommunicationProtocol",
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
"kind": "TypeNameAlias",
"name": "Client",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client",
"children": [
{
"kind": "TypeNominal",
"name": "Client",
"printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client",
"usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV"
}
]
}
],
"usr": "s:Sq"
}
],
"declKind": "Func",
"usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF",
"mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF",
"usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol08EmbeddeddG0O6ClientVSgF",
"mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol08EmbeddeddG0O6ClientVSgF",
"moduleName": "ShopifyAcceleratedCheckouts",
"declAttributes": [
"Preconcurrency",
Expand Down
135 changes: 122 additions & 13 deletions platforms/swift/api/ShopifyCheckoutKit.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"moduleName": "ShopifyCheckoutKit",
"genericSig": "<Self where Self : ShopifyCheckoutKit.CheckoutCommunicationProtocol>",
"protocolReq": true,
"isInternal": true,
"reqNewWitnessTableEntry": true,
"funcSelfKind": "NonMutating"
}
Expand All @@ -162,6 +163,7 @@
"mangledName": "$s18ShopifyCheckoutKit0B21CommunicationProtocolP",
"moduleName": "ShopifyCheckoutKit",
"genericSig": "<Self : Swift.Sendable>",
"isInternal": true,
"conformances": [
{
"kind": "Conformance",
Expand Down Expand Up @@ -1833,22 +1835,29 @@
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?",
"children": [
{
"kind": "TypeNominal",
"name": "CheckoutCommunicationProtocol",
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
"kind": "TypeNameAlias",
"name": "Client",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client",
"children": [
{
"kind": "TypeNominal",
"name": "Client",
"printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client",
"usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV"
}
]
}
],
"hasDefaultArg": true,
"usr": "s:Sq"
}
],
"declKind": "Constructor",
"usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc",
"mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc",
"usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol08EmbeddedbL0O6ClientVSgtcfc",
"mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol08EmbeddedbL0O6ClientVSgtcfc",
"moduleName": "ShopifyCheckoutKit",
"declAttributes": [
"Custom"
Expand Down Expand Up @@ -2416,6 +2425,42 @@
],
"funcSelfKind": "NonMutating"
},
{
"kind": "Function",
"name": "connect",
"printedName": "connect(_:)",
"children": [
{
"kind": "TypeNominal",
"name": "ShopifyCheckout",
"printedName": "ShopifyCheckoutKit.ShopifyCheckout",
"usr": "s:18ShopifyCheckoutKit0aB0V"
},
{
"kind": "TypeNameAlias",
"name": "Client",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client",
"children": [
{
"kind": "TypeNominal",
"name": "Client",
"printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client",
"usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV"
}
]
}
],
"declKind": "Func",
"usr": "s:18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol08EmbeddedbE0O6ClientVF",
"mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol08EmbeddedbE0O6ClientVF",
"moduleName": "ShopifyCheckoutKit",
"declAttributes": [
"Preconcurrency",
"DiscardableResult",
"Custom"
],
"funcSelfKind": "NonMutating"
},
{
"kind": "Function",
"name": "connect",
Expand All @@ -2438,6 +2483,7 @@
"usr": "s:18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF",
"mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF",
"moduleName": "ShopifyCheckoutKit",
"isInternal": true,
"declAttributes": [
"Preconcurrency",
"DiscardableResult",
Expand Down Expand Up @@ -6492,23 +6538,86 @@
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?",
"children": [
{
"kind": "TypeNameAlias",
"name": "Client",
"printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client",
"children": [
{
"kind": "TypeNominal",
"name": "Client",
"printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client",
"usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV"
}
]
}
],
"hasDefaultArg": true,
"usr": "s:Sq"
}
],
"declKind": "Func",
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol08EmbeddedbO0O6ClientVSgtF",
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol08EmbeddedbO0O6ClientVSgtF",
"moduleName": "ShopifyCheckoutKit",
"declAttributes": [
"DiscardableResult",
"Custom"
],
"funcSelfKind": "NonMutating"
},
{
"kind": "Function",
"name": "present",
"printedName": "present(checkout:from:delegate:client:)",
"children": [
{
"kind": "TypeNominal",
"name": "CheckoutViewController",
"printedName": "ShopifyCheckoutKit.CheckoutViewController",
"usr": "c:@M@ShopifyCheckoutKit@objc(cs)CheckoutViewController"
},
{
"kind": "TypeNominal",
"name": "URL",
"printedName": "Foundation.URL",
"usr": "s:10Foundation3URLV"
},
{
"kind": "TypeNominal",
"name": "UIViewController",
"printedName": "UIKit.UIViewController",
"usr": "c:objc(cs)UIViewController"
},
{
"kind": "TypeNominal",
"name": "Optional",
"printedName": "(any ShopifyCheckoutKit.CheckoutDelegate)?",
"children": [
{
"kind": "TypeNominal",
"name": "CheckoutCommunicationProtocol",
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
"name": "CheckoutDelegate",
"printedName": "any ShopifyCheckoutKit.CheckoutDelegate",
"usr": "s:18ShopifyCheckoutKit0B8DelegateP"
}
],
"hasDefaultArg": true,
"usr": "s:Sq"
},
{
"kind": "TypeNominal",
"name": "CheckoutCommunicationProtocol",
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
}
],
"declKind": "Func",
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF",
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF",
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF",
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF",
"moduleName": "ShopifyCheckoutKit",
"isInternal": true,
"declAttributes": [
"DiscardableResult",
"Custom"
Expand Down
Loading