Skip to content

Commit 782815b

Browse files
Juanita-Dashclaude
andcommitted
[Swift] Stop emitting ec_color_scheme query param
Part of https://github.com/shop/issues-checkout-kit/issues/906. The Checkout Kits will no longer thread color scheme through ECP. This PR strips ec_color_scheme emission from the Swift kit: - CheckoutProtocol.url(for:): drop the colorScheme parameter and the ec_color_scheme queryItem; ec_version still emitted - CheckoutViewController.init and ShopifyCheckoutKit.preload/present: drop the colorScheme argument at the 4 call sites CheckoutProtocol.url(for:colorScheme:) is public but PR #65 has not yet been released (no 3.8.0 tag), so removing the parameter outright is safe. Android equivalent landed in #95. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 554d3b1 commit 782815b

4 files changed

Lines changed: 61 additions & 8 deletions

File tree

platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public struct CheckoutSheet: UIViewControllerRepresentable, CheckoutConfigurable
5757
var onFailAction: ((CheckoutError) -> Void)?
5858

5959
public init(checkout url: URL) {
60-
checkoutURL = CheckoutProtocol.url(for: url, colorScheme: ShopifyCheckoutKit.configuration.colorScheme.rawValue)
60+
checkoutURL = CheckoutProtocol.url(for: url)
6161

6262
ShopifyCheckoutKit.invalidateOnConfigurationChange = false
6363
}

platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public func preload(checkout url: URL) {
5252
return
5353
}
5454

55-
let url = CheckoutProtocol.url(for: url, colorScheme: configuration.colorScheme.rawValue)
55+
let url = CheckoutProtocol.url(for: url)
5656
CheckoutWebView.preloadingActivatedByClient = true
5757
CheckoutWebView.for(checkout: url).load(checkout: url, isPreload: true)
5858
}
@@ -64,15 +64,15 @@ public func invalidate() {
6464

6565
@discardableResult
6666
public func present(checkout url: URL, from: UIViewController, client: (any CheckoutCommunicationProtocol)? = nil) -> CheckoutViewController {
67-
let decorated = CheckoutProtocol.url(for: url, colorScheme: configuration.colorScheme.rawValue)
67+
let decorated = CheckoutProtocol.url(for: url)
6868
let viewController = CheckoutViewController(checkout: decorated, client: client)
6969
from.present(viewController, animated: true)
7070
return viewController
7171
}
7272

7373
@discardableResult
7474
package func present(checkout url: URL, from: UIViewController, entryPoint: MetaData.EntryPoint, client: (any CheckoutCommunicationProtocol)? = nil) -> CheckoutViewController {
75-
let decorated = CheckoutProtocol.url(for: url, colorScheme: configuration.colorScheme.rawValue)
75+
let decorated = CheckoutProtocol.url(for: url)
7676
let viewController = CheckoutViewController(checkout: decorated, client: client, entryPoint: entryPoint)
7777
from.present(viewController, animated: true)
7878
return viewController

platforms/swift/Sources/ShopifyCheckoutProtocol/CheckoutProtocol+URL.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ import Foundation
2525

2626
extension CheckoutProtocol {
2727
/// Returns the given checkout URL with the query parameters required to
28-
/// initiate the Embedded Checkout Protocol handshake (`ec_version`,
29-
/// `ec_color_scheme`).
30-
public static func url(for url: URL, colorScheme: String) -> URL {
28+
/// initiate the Embedded Checkout Protocol handshake (`ec_version`).
29+
public static func url(for url: URL) -> URL {
3130
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
3231
return url
3332
}
3433
var queryItems = components.queryItems ?? []
3534
queryItems.append(URLQueryItem(name: "ec_version", value: specVersion))
36-
queryItems.append(URLQueryItem(name: "ec_color_scheme", value: colorScheme))
3735
components.queryItems = queryItems
3836
return components.url ?? url
3937
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
MIT License
3+
4+
Copyright 2023 - Present, Shopify Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
import Foundation
25+
@testable import ShopifyCheckoutProtocol
26+
import Testing
27+
28+
@Suite("CheckoutProtocol URL Tests")
29+
struct CheckoutProtocolURLTests {
30+
private let baseURL = URL(string: "https://shop.com/cart/c/abc")!
31+
32+
private func queryItems(_ url: URL) -> [URLQueryItem] {
33+
URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems ?? []
34+
}
35+
36+
@Test func appendsEcVersion() {
37+
let result = CheckoutProtocol.url(for: baseURL)
38+
let items = queryItems(result)
39+
#expect(items.contains(URLQueryItem(name: "ec_version", value: CheckoutProtocol.specVersion)))
40+
}
41+
42+
@Test func doesNotEmitEcColorScheme() {
43+
let result = CheckoutProtocol.url(for: baseURL)
44+
let names = queryItems(result).map(\.name)
45+
#expect(names.contains("ec_color_scheme") == false)
46+
}
47+
48+
@Test func preservesExistingQueryItems() throws {
49+
let url = try #require(URL(string: "https://shop.com/cart/c/abc?key=cart_token&utm_source=email"))
50+
let items = queryItems(CheckoutProtocol.url(for: url))
51+
#expect(items.contains(URLQueryItem(name: "key", value: "cart_token")))
52+
#expect(items.contains(URLQueryItem(name: "utm_source", value: "email")))
53+
#expect(items.contains(URLQueryItem(name: "ec_version", value: CheckoutProtocol.specVersion)))
54+
}
55+
}

0 commit comments

Comments
 (0)