Skip to content

Commit 5370832

Browse files
committed
updates
1 parent 21d60eb commit 5370832

File tree

10 files changed

+705
-76
lines changed

10 files changed

+705
-76
lines changed

modules/@shopify/checkout-sheet-kit/android/src/main/java/com/shopify/reactnative/checkoutsheetkit/RCTCheckoutWebView.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ of this software and associated documentation files (the "Software"), to deal
6262
import java.util.Map;
6363
import java.util.Objects;
6464

65-
import kotlin.Unit;
66-
6765
public class RCTCheckoutWebView extends FrameLayout {
6866
private static final String TAG = "RCTCheckoutWebView";
6967
private final ThemedReactContext context;
@@ -195,13 +193,7 @@ private CheckoutWebViewEventProcessor getCheckoutWebViewEventProcessor() {
195193
Activity currentActivity = this.context.getCurrentActivity();
196194
InlineCheckoutEventProcessor eventProcessor = new InlineCheckoutEventProcessor(currentActivity);
197195

198-
return new CheckoutWebViewEventProcessor(
199-
eventProcessor,
200-
(visible) -> Unit.INSTANCE, // toggleHeader
201-
(error) -> Unit.INSTANCE, // closeCheckoutDialogWithError
202-
(visibility) -> Unit.INSTANCE, // setProgressBarVisibility
203-
(percentage) -> Unit.INSTANCE // updateProgressBarPercentage
204-
);
196+
return new CheckoutWebViewEventProcessor(eventProcessor);
205197
}
206198

207199
void removeCheckout() {

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
110110
self.sendEvent(withName: "close", body: nil)
111111
}
112112

113-
// self.checkoutSheet?.dismiss(animated: true)
113+
self.checkoutSheet?.dismiss(animated: true)
114114
}
115115
}
116116

modules/@shopify/checkout-sheet-kit/src/components/Checkout.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ import type {
3838
CheckoutStartEvent,
3939
CheckoutSubmitStartEvent,
4040
} from '../events';
41-
import type {CheckoutException} from '../errors';
41+
import {
42+
parseCheckoutError,
43+
type CheckoutException,
44+
type CheckoutNativeError,
45+
} from '../errors.d';
4246

4347
export interface ShopifyCheckoutProps {
4448
/**
@@ -125,7 +129,7 @@ interface NativeShopifyCheckoutWebViewProps {
125129
style?: ViewStyle;
126130
testID?: string;
127131
onStart?: (event: {nativeEvent: CheckoutStartEvent}) => void;
128-
onError?: (event: {nativeEvent: CheckoutException}) => void;
132+
onError?: (event: {nativeEvent: CheckoutNativeError}) => void;
129133
onComplete?: (event: {nativeEvent: CheckoutCompleteEvent}) => void;
130134
onCancel?: () => void;
131135
onLinkClick?: (event: {nativeEvent: {url: string}}) => void;
@@ -231,7 +235,8 @@ export const ShopifyCheckout = forwardRef<
231235
Required<NativeShopifyCheckoutWebViewProps>['onError']
232236
>(
233237
event => {
234-
onError?.(event.nativeEvent);
238+
const transformedError = parseCheckoutError(event.nativeEvent);
239+
onError?.(transformedError);
235240
},
236241
[onError],
237242
);

modules/@shopify/checkout-sheet-kit/src/errors.d.ts

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,118 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24+
/**
25+
* Error codes that can be returned from checkout errors.
26+
*/
2427
export enum CheckoutErrorCode {
28+
// ============================================================================
29+
// Configuration errors
30+
// ============================================================================
31+
32+
/**
33+
* The app authentication payload passed could not be decoded.
34+
*/
35+
invalidPayload = 'invalid_payload',
36+
37+
/**
38+
* The app authentication JWT signature or encrypted token signature was invalid.
39+
*/
40+
invalidSignature = 'invalid_signature',
41+
42+
/**
43+
* The app authentication access token was not valid for the shop.
44+
*/
45+
notAuthorized = 'not_authorized',
46+
47+
/**
48+
* The provided app authentication payload has expired.
49+
*/
50+
payloadExpired = 'payload_expired',
51+
52+
/**
53+
* The buyer must be logged in to a customer account to proceed with checkout.
54+
*/
55+
customerAccountRequired = 'customer_account_required',
56+
57+
/**
58+
* The storefront requires a password to access checkout.
59+
*/
2560
storefrontPasswordRequired = 'storefront_password_required',
26-
cartExpired = 'cart_expired',
61+
62+
// ============================================================================
63+
// Cart errors
64+
// ============================================================================
65+
66+
/**
67+
* The cart associated with the checkout has already been completed.
68+
*/
2769
cartCompleted = 'cart_completed',
70+
71+
/**
72+
* The cart is invalid or no longer exists.
73+
*/
2874
invalidCart = 'invalid_cart',
75+
76+
// ============================================================================
77+
// Client errors
78+
// ============================================================================
79+
80+
/**
81+
* Checkout preloading has been temporarily disabled via killswitch.
82+
*/
83+
killswitchEnabled = 'killswitch_enabled',
84+
85+
/**
86+
* An unrecoverable error occurred during checkout.
87+
*/
88+
unrecoverableFailure = 'unrecoverable_failure',
89+
90+
/**
91+
* A policy violation was detected during checkout.
92+
*/
93+
policyViolation = 'policy_violation',
94+
95+
/**
96+
* An error occurred processing a vaulted payment method.
97+
*/
98+
vaultedPaymentError = 'vaulted_payment_error',
99+
100+
// ============================================================================
101+
// Internal errors
102+
// ============================================================================
103+
104+
/**
105+
* A client-side error occurred in the SDK.
106+
*/
29107
clientError = 'client_error',
108+
109+
/**
110+
* An HTTP error occurred while communicating with the checkout.
111+
*/
30112
httpError = 'http_error',
113+
114+
/**
115+
* Failed to send a message to the checkout bridge.
116+
*/
31117
sendingBridgeEventError = 'error_sending_message',
118+
119+
/**
120+
* Failed to receive a message from the checkout bridge.
121+
*/
32122
receivingBridgeEventError = 'error_receiving_message',
123+
124+
/**
125+
* The WebView render process has terminated unexpectedly (Android only).
126+
*/
33127
renderProcessGone = 'render_process_gone',
128+
129+
// ============================================================================
130+
// Fallback
131+
// ============================================================================
132+
133+
/**
134+
* An unknown or unrecognized error code was received.
135+
*/
34136
unknown = 'unknown',
35137
}
36138

@@ -44,20 +146,27 @@ export enum CheckoutNativeErrorType {
44146
}
45147

46148
/**
47-
* @important TODO: Fix mapping here.
48-
* Currently "unknown" is returned for every code
149+
* Maps a native error code string to a CheckoutErrorCode enum value.
49150
*/
50151
function getCheckoutErrorCode(code: string | undefined): CheckoutErrorCode {
152+
if (!code) {
153+
return CheckoutErrorCode.unknown;
154+
}
155+
156+
const normalizedCode = code.toLowerCase();
157+
51158
const codeKey = Object.keys(CheckoutErrorCode).find(
52-
key => CheckoutErrorCode[key as keyof typeof CheckoutErrorCode] === code,
159+
key => CheckoutErrorCode[key as keyof typeof CheckoutErrorCode] === normalizedCode,
53160
);
54161

55-
return codeKey ? CheckoutErrorCode[codeKey] : CheckoutErrorCode.unknown;
162+
return codeKey
163+
? CheckoutErrorCode[codeKey as keyof typeof CheckoutErrorCode]
164+
: CheckoutErrorCode.unknown;
56165
}
57166

58167
type BridgeError = {
59168
__typename: CheckoutNativeErrorType;
60-
code: CheckoutErrorCode;
169+
code: string;
61170
message: string;
62171
recoverable: boolean;
63172
};
@@ -119,11 +228,13 @@ export class InternalError {
119228
code: CheckoutErrorCode;
120229
message: string;
121230
recoverable: boolean;
231+
name: string;
122232

123233
constructor(exception: CheckoutNativeError) {
124234
this.code = getCheckoutErrorCode(exception.code);
125235
this.message = exception.message;
126236
this.recoverable = exception.recoverable;
237+
this.name = this.constructor.name;
127238
}
128239
}
129240

@@ -134,3 +245,29 @@ export type CheckoutException =
134245
| ConfigurationError
135246
| GenericError
136247
| InternalError;
248+
249+
/**
250+
* Transforms a native error object into the appropriate CheckoutException class.
251+
* Maps __typename to the correct error class and normalizes error codes.
252+
*
253+
* @param exception Raw error object from native bridge
254+
* @returns Appropriate CheckoutException instance
255+
*/
256+
export function parseCheckoutError(
257+
exception: CheckoutNativeError,
258+
): CheckoutException {
259+
switch (exception?.__typename) {
260+
case CheckoutNativeErrorType.InternalError:
261+
return new InternalError(exception);
262+
case CheckoutNativeErrorType.ConfigurationError:
263+
return new ConfigurationError(exception);
264+
case CheckoutNativeErrorType.CheckoutClientError:
265+
return new CheckoutClientError(exception);
266+
case CheckoutNativeErrorType.CheckoutHTTPError:
267+
return new CheckoutHTTPError(exception);
268+
case CheckoutNativeErrorType.CheckoutExpiredError:
269+
return new CheckoutExpiredError(exception);
270+
default:
271+
return new GenericError(exception);
272+
}
273+
}

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,18 @@ import type {
4747
ShopifyCheckoutSheetKit,
4848
} from './index.d';
4949
import {AcceleratedCheckoutWallet} from './index.d';
50-
import type {CheckoutException, CheckoutNativeError} from './errors.d';
50+
import type {CheckoutException} from './errors.d';
5151
import {
52-
CheckoutExpiredError,
5352
CheckoutClientError,
53+
CheckoutErrorCode,
54+
CheckoutExpiredError,
5455
CheckoutHTTPError,
55-
ConfigurationError,
56-
InternalError,
5756
CheckoutNativeErrorType,
57+
ConfigurationError,
5858
GenericError,
59+
InternalError,
60+
parseCheckoutError,
5961
} from './errors.d';
60-
import {CheckoutErrorCode} from './errors.d';
6162
import {ApplePayLabel} from './components/AcceleratedCheckoutButtons';
6263

6364
const RNShopifyCheckoutSheetKit = NativeModules.ShopifyCheckoutSheetKit;
@@ -198,7 +199,7 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
198199
eventCallback = this.interceptEventEmission(
199200
'error',
200201
callback,
201-
this.parseCheckoutError,
202+
parseCheckoutError,
202203
);
203204
break;
204205
case 'geolocationRequest':
@@ -383,30 +384,6 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
383384
return status === 'granted';
384385
}
385386

386-
/**
387-
* Converts native checkout errors into appropriate error class instances
388-
* @param exception The native error to parse
389-
* @returns Appropriate CheckoutException instance
390-
*/
391-
private parseCheckoutError(
392-
exception: CheckoutNativeError,
393-
): CheckoutException {
394-
switch (exception?.__typename) {
395-
case CheckoutNativeErrorType.InternalError:
396-
return new InternalError(exception);
397-
case CheckoutNativeErrorType.ConfigurationError:
398-
return new ConfigurationError(exception);
399-
case CheckoutNativeErrorType.CheckoutClientError:
400-
return new CheckoutClientError(exception);
401-
case CheckoutNativeErrorType.CheckoutHTTPError:
402-
return new CheckoutHTTPError(exception);
403-
case CheckoutNativeErrorType.CheckoutExpiredError:
404-
return new CheckoutExpiredError(exception);
405-
default:
406-
return new GenericError(exception);
407-
}
408-
}
409-
410387
/**
411388
* Handles event emission parsing and transformation
412389
* @param event The type of event being intercepted

0 commit comments

Comments
 (0)