Skip to content

Commit 28d1f12

Browse files
committed
Refactor AcceleratedCheckoutError interface
1 parent b59c79d commit 28d1f12

File tree

25 files changed

+1739
-995
lines changed

25 files changed

+1739
-995
lines changed

Samples/MobileBuyIntegration/MobileBuyIntegration.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 56;
6+
objectVersion = 70;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -69,6 +69,10 @@
6969
CB05E6C32D4954E400466376 /* Storefront.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storefront.swift; sourceTree = "<group>"; };
7070
/* End PBXFileReference section */
7171

72+
/* Begin PBXFileSystemSynchronizedRootGroup section */
73+
6A4895F72E4E069C00D4AE90 /* Common */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Common; sourceTree = "<group>"; };
74+
/* End PBXFileSystemSynchronizedRootGroup section */
75+
7276
/* Begin PBXFrameworksBuildPhase section */
7377
4EBBA7642A5F0CE200193E19 /* Frameworks */ = {
7478
isa = PBXFrameworksBuildPhase;
@@ -126,6 +130,7 @@
126130
4EBBA77F2A5F0DA300193E19 /* Application */ = {
127131
isa = PBXGroup;
128132
children = (
133+
6A4895F72E4E069C00D4AE90 /* Common */,
129134
86250DE32AD5521C002E45C2 /* AppConfiguration.swift */,
130135
4EBBA76A2A5F0CE200193E19 /* AppDelegate.swift */,
131136
4EF54F232A6F456B00F5E407 /* CartManager.swift */,
@@ -214,6 +219,9 @@
214219
);
215220
dependencies = (
216221
);
222+
fileSystemSynchronizedGroups = (
223+
6A4895F72E4E069C00D4AE90 /* Common */,
224+
);
217225
name = MobileBuyIntegration;
218226
packageProductDependencies = (
219227
4EBBA7A22A5F0F5600193E19 /* Buy */,

Samples/MobileBuyIntegration/MobileBuyIntegration/AppConfiguration.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ public final class AppConfiguration: ObservableObject {
3939
// Configure ShopifyAcceleratedCheckouts
4040
let acceleratedCheckoutsStorefrontConfig = ShopifyAcceleratedCheckouts.Configuration(
4141
storefrontDomain: InfoDictionary.shared.domain,
42-
storefrontAccessToken: InfoDictionary.shared.accessToken
42+
storefrontAccessToken: InfoDictionary.shared.accessToken,
43+
customer: ShopifyAcceleratedCheckouts.Customer(
44+
email: InfoDictionary.shared.email,
45+
phoneNumber: InfoDictionary.shared.phone
46+
)
4347
)
4448

4549
let acceleratedCheckoutsApplePayConfig = ShopifyAcceleratedCheckouts.ApplePayConfiguration(
4650
merchantIdentifier: InfoDictionary.shared.merchantIdentifier,
47-
contactFields: [.email]
51+
contactFields: [.email, .phone]
4852
)
4953
}
5054

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
import ShopifyCheckoutSheetKit
26+
27+
class Analytics {
28+
static func getUserId() -> String {
29+
// return ID for user used in your existing analytics system
30+
return "123"
31+
}
32+
33+
static func record(_ event: PixelEvent) {
34+
switch event {
35+
case let .customEvent(customEvent):
36+
if let genericEvent = AnalyticsEvent.from(customEvent, userId: getUserId()) {
37+
Analytics.record(genericEvent)
38+
}
39+
case let .standardEvent(standardEvent):
40+
Analytics.record(AnalyticsEvent.from(standardEvent, userId: getUserId()))
41+
}
42+
}
43+
44+
static func record(_ event: AnalyticsEvent) {
45+
ShopifyCheckoutSheetKit.configuration.logger.log("[Web Pixel Event (\(event.type)] \(event.name)")
46+
// send the event to an analytics system, e.g. via an analytics sdk
47+
appConfiguration.webPixelsLogger.log(event.name)
48+
}
49+
}
50+
51+
// example type, e.g. that may be defined by an analytics sdk
52+
struct AnalyticsEvent {
53+
var type: PixelEvent
54+
var name = ""
55+
var userId = ""
56+
var timestamp = ""
57+
var checkoutTotal: Double? = 0.0
58+
59+
static func from(_ event: StandardEvent, userId: String) -> AnalyticsEvent {
60+
return AnalyticsEvent(
61+
type: .standardEvent(event),
62+
name: event.name!,
63+
userId: userId,
64+
timestamp: event.timestamp!,
65+
checkoutTotal: event.data?.checkout?.totalPrice?.amount ?? 0.0
66+
)
67+
}
68+
69+
static func from(_ event: CustomEvent, userId: String) -> AnalyticsEvent? {
70+
guard event.name != nil else {
71+
print("Failed to parse custom event", event)
72+
return nil
73+
}
74+
75+
return AnalyticsEvent(
76+
type: .customEvent(event),
77+
name: event.name!,
78+
userId: userId,
79+
timestamp: event.timestamp!,
80+
checkoutTotal: nil
81+
)
82+
}
83+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 ShopifyAcceleratedCheckouts
25+
26+
/**
27+
* Common event handlers that can be used across instances of AcceleratedCheckoutButtons()
28+
*
29+
* @example
30+
* AcceleratedCheckoutButtons(cartID: cartId)
31+
* .checkout(delegate: checkoutDelegate)
32+
* .onError(AcceleratedCheckoutHandlers.handleError)
33+
*/
34+
enum AcceleratedCheckoutHandlers {
35+
static func handleError(error: AcceleratedCheckoutError) {
36+
print("[AcceleratedCheckoutHandlers] handleError: \(error)")
37+
}
38+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
import ShopifyAcceleratedCheckouts
26+
import ShopifyCheckoutSheetKit
27+
import UIKit
28+
29+
/**
30+
* Common CheckoutDelegate instance which can be reused across instances of Checkout Sheet Kit and Accelerated Checkouts.
31+
*
32+
* Use overrides to override the default behaviour.
33+
*/
34+
class CustomCheckoutDelegate: UIViewController, CheckoutDelegate {
35+
func checkoutDidComplete(event _: CheckoutCompletedEvent) {
36+
dismiss(animated: true)
37+
}
38+
39+
func checkoutDidClickLink(url: URL) {
40+
if UIApplication.shared.canOpenURL(url) {
41+
UIApplication.shared.open(url)
42+
}
43+
}
44+
45+
func checkoutDidFail(error: ShopifyCheckoutSheetKit.CheckoutError) {
46+
ShopifyCheckoutSheetKit.configuration.logger.log("Checkout failed: \(error.localizedDescription), Recoverable: \(error.isRecoverable)")
47+
}
48+
49+
func checkoutDidEmitWebPixelEvent(event: ShopifyCheckoutSheetKit.PixelEvent) {
50+
Analytics.record(event)
51+
}
52+
53+
func checkoutDidCancel() {
54+
dismiss(animated: true)
55+
}
56+
}

0 commit comments

Comments
 (0)