Skip to content

Commit aa537f4

Browse files
feat: update sample app to use new event handler parameters
- Add event parameter to onComplete callback to access order details - Add error parameter to onFail callback for better error logging - Update onWebPixelEvent to extract and display only the event name - Import ShopifyCheckoutSheetKit for access to event types
1 parent e5f8233 commit aa537f4

File tree

1 file changed

+29
-10
lines changed
  • Samples/ShopifyAcceleratedCheckoutsApp/ShopifyAcceleratedCheckoutsApp/Views/Components

1 file changed

+29
-10
lines changed

Samples/ShopifyAcceleratedCheckoutsApp/ShopifyAcceleratedCheckoutsApp/Views/Components/ButtonSet.swift

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import Apollo
2525
import ShopifyAcceleratedCheckouts
26+
import ShopifyCheckoutSheetKit
2627
import SwiftUI
2728

2829
struct ButtonSet: View {
@@ -35,11 +36,12 @@ struct ButtonSet: View {
3536
CheckoutSection(title: "AcceleratedCheckoutButtons(cartID:)") {
3637
// Cart-based checkout example with event handlers
3738
AcceleratedCheckoutButtons(cartID: cartID)
38-
.onComplete {
39+
.onComplete { event in
3940
print("✅ Checkout completed successfully")
41+
print(" Order ID: \(event.orderDetails.id)")
4042
}
41-
.onFail {
42-
print("❌ Checkout failed")
43+
.onFail { error in
44+
print("❌ Checkout failed: \(error)")
4345
}
4446
.onCancel {
4547
print("🚫 Checkout cancelled")
@@ -52,8 +54,16 @@ struct ButtonSet: View {
5254
.onClickLink { url in
5355
print("🔗 Link clicked: \(url)")
5456
}
55-
.onWebPixelEvent { _ in
56-
print("📊 Web pixel event received")
57+
.onWebPixelEvent { event in
58+
let eventName: String = {
59+
switch event {
60+
case let .customEvent(customEvent):
61+
return customEvent.name ?? "Unknown custom event"
62+
case let .standardEvent(standardEvent):
63+
return standardEvent.name ?? "Unknown standard event"
64+
}
65+
}()
66+
print("📊 Web pixel event: \(eventName)")
5767
}
5868
}
5969
}
@@ -69,11 +79,12 @@ struct ButtonSet: View {
6979
)
7080
.cornerRadius(24)
7181
.withWallets([.applepay, .shoppay])
72-
.onComplete {
82+
.onComplete { event in
7383
print("✅ Variant checkout completed")
84+
print(" Order ID: \(event.orderDetails.id)")
7485
}
75-
.onFail {
76-
print("❌ Variant checkout failed")
86+
.onFail { error in
87+
print("❌ Variant checkout failed: \(error)")
7788
}
7889
.onCancel {
7990
print("🚫 Variant checkout cancelled")
@@ -85,8 +96,16 @@ struct ButtonSet: View {
8596
.onClickLink { url in
8697
print("🔗 Variant - Link clicked: \(url)")
8798
}
88-
.onWebPixelEvent { _ in
89-
print("📊 Variant - Web pixel event received")
99+
.onWebPixelEvent { event in
100+
let eventName: String = {
101+
switch event {
102+
case let .customEvent(customEvent):
103+
return customEvent.name ?? "Unknown custom event"
104+
case let .standardEvent(standardEvent):
105+
return standardEvent.name ?? "Unknown standard event"
106+
}
107+
}()
108+
print("📊 Variant - Web pixel event: \(eventName)")
90109
}
91110
}
92111
}

0 commit comments

Comments
 (0)