Skip to content

Commit a9d307c

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 76944b2 commit a9d307c

File tree

1 file changed

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

1 file changed

+29
-11
lines changed

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

Lines changed: 29 additions & 11 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 {
@@ -36,12 +37,12 @@ struct ButtonSet: View {
3637
CheckoutSection(title: "AcceleratedCheckoutButtons(cartID:)") {
3738
// Cart-based checkout example with event handlers
3839
AcceleratedCheckoutButtons(cartID: cartID)
39-
.onComplete {
40-
print("✅ Checkout completed successfully")
40+
.onComplete { event in
41+
print("✅ Checkout completed successfully. Order ID: \(event.orderDetails.id)")
4142
onComplete()
4243
}
43-
.onFail {
44-
print("❌ Checkout failed")
44+
.onFail { error in
45+
print("❌ Checkout failed: \(error)")
4546
}
4647
.onCancel {
4748
print("🚫 Checkout cancelled")
@@ -54,8 +55,16 @@ struct ButtonSet: View {
5455
.onClickLink { url in
5556
print("🔗 Link clicked: \(url)")
5657
}
57-
.onWebPixelEvent { _ in
58-
print("📊 Web pixel event received")
58+
.onWebPixelEvent { event in
59+
let eventName: String = {
60+
switch event {
61+
case let .customEvent(customEvent):
62+
return customEvent.name ?? "Unknown custom event"
63+
case let .standardEvent(standardEvent):
64+
return standardEvent.name ?? "Unknown standard event"
65+
}
66+
}()
67+
print("📊 Web pixel event: \(eventName)")
5968
}
6069
}
6170
}
@@ -71,11 +80,12 @@ struct ButtonSet: View {
7180
)
7281
.cornerRadius(24)
7382
.withWallets([.applepay, .shoppay])
74-
.onComplete {
83+
.onComplete { event in
7584
print("✅ Variant checkout completed")
85+
print(" Order ID: \(event.orderDetails.id)")
7686
}
77-
.onFail {
78-
print("❌ Variant checkout failed")
87+
.onFail { error in
88+
print("❌ Variant checkout failed: \(error)")
7989
}
8090
.onCancel {
8191
print("🚫 Variant checkout cancelled")
@@ -87,8 +97,16 @@ struct ButtonSet: View {
8797
.onClickLink { url in
8898
print("🔗 Variant - Link clicked: \(url)")
8999
}
90-
.onWebPixelEvent { _ in
91-
print("📊 Variant - Web pixel event received")
100+
.onWebPixelEvent { event in
101+
let eventName: String = {
102+
switch event {
103+
case let .customEvent(customEvent):
104+
return customEvent.name ?? "Unknown custom event"
105+
case let .standardEvent(standardEvent):
106+
return standardEvent.name ?? "Unknown standard event"
107+
}
108+
}()
109+
print("📊 Variant - Web pixel event: \(eventName)")
92110
}
93111
}
94112
}

0 commit comments

Comments
 (0)