Skip to content

Commit 2186cc3

Browse files
committed
hide communication client
Assisted-By: devx/6488e3d0-f47f-4171-a1c4-d2432b2a653c
1 parent f420c55 commit 2186cc3

10 files changed

Lines changed: 147 additions & 27 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let package = Package(
4343
),
4444
.target(
4545
name: "ShopifyAcceleratedCheckouts",
46-
dependencies: ["ShopifyCheckoutKit"],
46+
dependencies: ["ShopifyCheckoutKit", "ShopifyCheckoutProtocol"],
4747
path: "platforms/swift/Sources/ShopifyAcceleratedCheckouts",
4848
resources: [.process("Localizable.xcstrings"), .process("Media.xcassets")]
4949
),

platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/test/java/com/shopify/reactnative/checkoutkit/ProtocolRelayTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ private data class SnakePayload(
180180
@SerialName("line_items") val lineItems: List<String>,
181181
)
182182

183+
private fun CheckoutProtocol.Client.processForTest(message: String): String? {
184+
val processMethod = javaClass.declaredMethods.first {
185+
it.name.startsWith("process") &&
186+
it.parameterTypes.contentEquals(arrayOf(String::class.java))
187+
}
188+
processMethod.isAccessible = true
189+
return processMethod.invoke(this, message) as? String
190+
}
191+
183192
private fun checkoutNotificationFixture(method: String) = ecStartNotificationFixture.replace(
184193
"\"method\": \"ec.start\"",
185194
"\"method\": \"$method\"",

platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ProtocolRelay.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Foundation
22
#if COCOAPODS
33
import ShopifyCheckoutKit
4-
5-
extension CheckoutProtocol.Client: @retroactive CheckoutCommunicationProtocol {}
64
#else
75
import ShopifyCheckoutProtocol
86
#endif

platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/AcceleratedCheckoutButtons.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import PassKit
22
import ShopifyCheckoutKit
3+
#if !COCOAPODS
4+
import ShopifyCheckoutProtocol
5+
#endif
36
import SwiftUI
47

58
/// Render state for AcceleratedCheckoutButtons
@@ -232,7 +235,7 @@ extension AcceleratedCheckoutButtons {
232235
return newView
233236
}
234237

235-
public func connect(_ client: (any CheckoutCommunicationProtocol)?) -> AcceleratedCheckoutButtons {
238+
public func connect(_ client: CheckoutProtocol.Client?) -> AcceleratedCheckoutButtons {
236239
var newView = self
237240
newView.clientContainer = CheckoutProtocolClientContainer(client)
238241
return newView

platforms/swift/Sources/ShopifyCheckoutKit/CheckoutCommunicationProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#endif
44
import Foundation
55

6-
public protocol CheckoutCommunicationProtocol: Sendable {
6+
package protocol CheckoutCommunicationProtocol: Sendable {
77
func process(_ message: String) async -> String?
88
}
99

platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import UIKit
66

77
@MainActor
88
public class CheckoutViewController: UINavigationController {
9-
public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) {
9+
public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) {
1010
let rootViewController = CheckoutWebViewController(checkoutURL: url, delegate: delegate, client: client, entryPoint: nil)
1111
super.init(rootViewController: rootViewController)
1212
presentationController?.delegate = rootViewController
@@ -62,7 +62,13 @@ public struct ShopifyCheckout: UIViewControllerRepresentable, CheckoutConfigurab
6262
webViewController.onFail = onFailAction
6363
}
6464

65-
@discardableResult public func connect(_ handler: any CheckoutCommunicationProtocol) -> Self {
65+
@discardableResult public func connect(_ handler: CheckoutProtocol.Client) -> Self {
66+
var copy = self
67+
copy.client = handler
68+
return copy
69+
}
70+
71+
@discardableResult package func connect(_ handler: any CheckoutCommunicationProtocol) -> Self {
6672
var copy = self
6773
copy.client = handler
6874
return copy

platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl
5555

5656
// MARK: Initializers
5757

58-
public init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) {
58+
init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) {
5959
checkoutURL = url
6060
self.delegate = delegate
6161
self.client = client

platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ public func invalidate() {
6060

6161
@MainActor
6262
@discardableResult
63-
public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) -> CheckoutViewController {
63+
public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) -> CheckoutViewController {
64+
let decorated = CheckoutProtocol.url(for: url)
65+
let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client)
66+
from.present(viewController, animated: true)
67+
return viewController
68+
}
69+
70+
@MainActor
71+
@discardableResult
72+
package func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: any CheckoutCommunicationProtocol) -> CheckoutViewController {
6473
let decorated = CheckoutProtocol.url(for: url)
6574
let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client)
6675
from.present(viewController, animated: true)

platforms/swift/api/ShopifyAcceleratedCheckouts.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@
6060
"declKind": "Import",
6161
"moduleName": "ShopifyAcceleratedCheckouts"
6262
},
63+
{
64+
"kind": "Import",
65+
"name": "ShopifyCheckoutProtocol",
66+
"printedName": "ShopifyCheckoutProtocol",
67+
"declKind": "Import",
68+
"moduleName": "ShopifyAcceleratedCheckouts"
69+
},
6370
{
6471
"kind": "Import",
6572
"name": "SwiftOnoneSupport",
@@ -2220,21 +2227,21 @@
22202227
{
22212228
"kind": "TypeNominal",
22222229
"name": "Optional",
2223-
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
2230+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client?",
22242231
"children": [
22252232
{
22262233
"kind": "TypeNominal",
2227-
"name": "CheckoutCommunicationProtocol",
2228-
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
2229-
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
2234+
"name": "Client",
2235+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client",
2236+
"usr": "s:23ShopifyCheckoutProtocol0bC0O6ClientV"
22302237
}
22312238
],
22322239
"usr": "s:Sq"
22332240
}
22342241
],
22352242
"declKind": "Func",
2236-
"usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF",
2237-
"mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF",
2243+
"usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol0dG0O6ClientVSgF",
2244+
"mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol0dG0O6ClientVSgF",
22382245
"moduleName": "ShopifyAcceleratedCheckouts",
22392246
"declAttributes": [
22402247
"Preconcurrency",

platforms/swift/api/ShopifyCheckoutKit.json

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"moduleName": "ShopifyCheckoutKit",
154154
"genericSig": "<Self where Self : ShopifyCheckoutKit.CheckoutCommunicationProtocol>",
155155
"protocolReq": true,
156+
"isInternal": true,
156157
"reqNewWitnessTableEntry": true,
157158
"funcSelfKind": "NonMutating"
158159
}
@@ -162,6 +163,7 @@
162163
"mangledName": "$s18ShopifyCheckoutKit0B21CommunicationProtocolP",
163164
"moduleName": "ShopifyCheckoutKit",
164165
"genericSig": "<Self : Swift.Sendable>",
166+
"isInternal": true,
165167
"conformances": [
166168
{
167169
"kind": "Conformance",
@@ -1229,22 +1231,22 @@
12291231
{
12301232
"kind": "TypeNominal",
12311233
"name": "Optional",
1232-
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
1234+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client?",
12331235
"children": [
12341236
{
12351237
"kind": "TypeNominal",
1236-
"name": "CheckoutCommunicationProtocol",
1237-
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
1238-
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
1238+
"name": "Client",
1239+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client",
1240+
"usr": "s:23ShopifyCheckoutProtocol0bC0O6ClientV"
12391241
}
12401242
],
12411243
"hasDefaultArg": true,
12421244
"usr": "s:Sq"
12431245
}
12441246
],
12451247
"declKind": "Constructor",
1246-
"usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc",
1247-
"mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc",
1248+
"usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol0bL0O6ClientVSgtcfc",
1249+
"mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol0bL0O6ClientVSgtcfc",
12481250
"moduleName": "ShopifyCheckoutKit",
12491251
"declAttributes": [
12501252
"Custom"
@@ -1812,6 +1814,35 @@
18121814
],
18131815
"funcSelfKind": "NonMutating"
18141816
},
1817+
{
1818+
"kind": "Function",
1819+
"name": "connect",
1820+
"printedName": "connect(_:)",
1821+
"children": [
1822+
{
1823+
"kind": "TypeNominal",
1824+
"name": "ShopifyCheckout",
1825+
"printedName": "ShopifyCheckoutKit.ShopifyCheckout",
1826+
"usr": "s:18ShopifyCheckoutKit0aB0V"
1827+
},
1828+
{
1829+
"kind": "TypeNominal",
1830+
"name": "Client",
1831+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client",
1832+
"usr": "s:23ShopifyCheckoutProtocol0bC0O6ClientV"
1833+
}
1834+
],
1835+
"declKind": "Func",
1836+
"usr": "s:18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol0bE0O6ClientVF",
1837+
"mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol0bE0O6ClientVF",
1838+
"moduleName": "ShopifyCheckoutKit",
1839+
"declAttributes": [
1840+
"Preconcurrency",
1841+
"DiscardableResult",
1842+
"Custom"
1843+
],
1844+
"funcSelfKind": "NonMutating"
1845+
},
18151846
{
18161847
"kind": "Function",
18171848
"name": "connect",
@@ -1834,6 +1865,7 @@
18341865
"usr": "s:18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF",
18351866
"mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF",
18361867
"moduleName": "ShopifyCheckoutKit",
1868+
"isInternal": true,
18371869
"declAttributes": [
18381870
"Preconcurrency",
18391871
"DiscardableResult",
@@ -5888,29 +5920,85 @@
58885920
{
58895921
"kind": "TypeNominal",
58905922
"name": "Optional",
5891-
"printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?",
5923+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client?",
58925924
"children": [
58935925
{
58945926
"kind": "TypeNominal",
5895-
"name": "CheckoutCommunicationProtocol",
5896-
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
5897-
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
5927+
"name": "Client",
5928+
"printedName": "ShopifyCheckoutProtocol.CheckoutProtocol.Client",
5929+
"usr": "s:23ShopifyCheckoutProtocol0bC0O6ClientV"
58985930
}
58995931
],
59005932
"hasDefaultArg": true,
59015933
"usr": "s:Sq"
59025934
}
59035935
],
59045936
"declKind": "Func",
5905-
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF",
5906-
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF",
5937+
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol0bO0O6ClientVSgtF",
5938+
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol0bO0O6ClientVSgtF",
59075939
"moduleName": "ShopifyCheckoutKit",
59085940
"declAttributes": [
59095941
"DiscardableResult",
59105942
"Custom"
59115943
],
59125944
"funcSelfKind": "NonMutating"
59135945
},
5946+
{
5947+
"kind": "Function",
5948+
"name": "present",
5949+
"printedName": "present(checkout:from:delegate:client:)",
5950+
"children": [
5951+
{
5952+
"kind": "TypeNominal",
5953+
"name": "CheckoutViewController",
5954+
"printedName": "ShopifyCheckoutKit.CheckoutViewController",
5955+
"usr": "c:@M@ShopifyCheckoutKit@objc(cs)CheckoutViewController"
5956+
},
5957+
{
5958+
"kind": "TypeNominal",
5959+
"name": "URL",
5960+
"printedName": "Foundation.URL",
5961+
"usr": "s:10Foundation3URLV"
5962+
},
5963+
{
5964+
"kind": "TypeNominal",
5965+
"name": "UIViewController",
5966+
"printedName": "UIKit.UIViewController",
5967+
"usr": "c:objc(cs)UIViewController"
5968+
},
5969+
{
5970+
"kind": "TypeNominal",
5971+
"name": "Optional",
5972+
"printedName": "(any ShopifyCheckoutKit.CheckoutDelegate)?",
5973+
"children": [
5974+
{
5975+
"kind": "TypeNominal",
5976+
"name": "CheckoutDelegate",
5977+
"printedName": "any ShopifyCheckoutKit.CheckoutDelegate",
5978+
"usr": "s:18ShopifyCheckoutKit0B8DelegateP"
5979+
}
5980+
],
5981+
"hasDefaultArg": true,
5982+
"usr": "s:Sq"
5983+
},
5984+
{
5985+
"kind": "TypeNominal",
5986+
"name": "CheckoutCommunicationProtocol",
5987+
"printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol",
5988+
"usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP"
5989+
}
5990+
],
5991+
"declKind": "Func",
5992+
"usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF",
5993+
"mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF",
5994+
"moduleName": "ShopifyCheckoutKit",
5995+
"isInternal": true,
5996+
"declAttributes": [
5997+
"DiscardableResult",
5998+
"Custom"
5999+
],
6000+
"funcSelfKind": "NonMutating"
6001+
},
59146002
{
59156003
"kind": "Function",
59166004
"name": "present",

0 commit comments

Comments
 (0)