Skip to content

Commit e5e1492

Browse files
fix: issues with inconsistent names of events
1 parent 37f95c9 commit e5e1492

File tree

3 files changed

+23
-125
lines changed

3 files changed

+23
-125
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ of this software and associated documentation files (the "Software"), to deal
3737
import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutCompleteEvent;
3838
import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutStartEvent;
3939
import com.fasterxml.jackson.databind.ObjectMapper;
40+
import com.shopify.checkoutsheetkit.rpc.events.CheckoutAddressChangeStart;
41+
4042
import java.io.IOException;
4143
import java.util.HashMap;
4244
import java.util.Map;
@@ -108,7 +110,7 @@ public void onGeolocationPermissionsHidePrompt() {
108110
}
109111

110112
@Override
111-
public void onFail(CheckoutException checkoutError) {
113+
public void onFail(@NonNull CheckoutException checkoutError) {
112114
try {
113115
String data = mapper.writeValueAsString(populateErrorDetails(checkoutError));
114116
sendEventWithStringData("error", data);
@@ -123,7 +125,7 @@ public void onCancel() {
123125
}
124126

125127
@Override
126-
public void onCheckoutCompleted(@NonNull CheckoutCompleteEvent event) {
128+
public void onComplete(@NonNull CheckoutCompleteEvent event) {
127129
try {
128130
String data = mapper.writeValueAsString(event);
129131
sendEventWithStringData("complete", data);
@@ -143,7 +145,7 @@ public void onStart(@NonNull CheckoutStartEvent event) {
143145
}
144146

145147
@Override
146-
public void onAddressChangeRequested(CheckoutAddressChangeRequestedEvent event) {
148+
public void onCheckoutAddressChangeStart(@NonNull CheckoutAddressChangeStart event) {
147149
// For modal presentation, we don't currently support address changes
148150
// The WebView component handles this internally
149151
// Just cancel the request by not responding

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

Lines changed: 16 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ of this software and associated documentation files (the "Software"), to deal
2323

2424
package com.shopify.reactnative.checkoutsheetkit;
2525

26+
import android.app.Activity;
2627
import android.content.Context;
27-
import android.net.Uri;
2828
import android.os.Handler;
2929
import android.os.Looper;
3030
import android.util.AttributeSet;
@@ -34,32 +34,28 @@ of this software and associated documentation files (the "Software"), to deal
3434
import androidx.annotation.NonNull;
3535

3636
import com.facebook.react.bridge.Arguments;
37+
import com.facebook.react.bridge.ReactApplicationContext;
3738
import com.facebook.react.bridge.ReactContext;
3839
import com.facebook.react.bridge.WritableMap;
40+
import com.facebook.react.uimanager.ThemedReactContext;
3941
import com.facebook.react.uimanager.events.RCTEventEmitter;
4042

41-
import com.fasterxml.jackson.core.type.TypeReference;
42-
import com.shopify.checkoutsheetkit.CheckoutAddressChangeRequestedEvent;
43-
import com.shopify.checkoutsheetkit.CheckoutException;
43+
import com.shopify.checkoutsheetkit.Authentication;
4444
import com.shopify.checkoutsheetkit.CheckoutOptions;
4545
import com.shopify.checkoutsheetkit.CheckoutWebView;
4646
import com.shopify.checkoutsheetkit.CheckoutWebViewEventProcessor;
47-
import com.shopify.checkoutsheetkit.DefaultCheckoutEventProcessor;
48-
import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutCompleteEvent;
49-
import com.shopify.checkoutsheetkit.pixelevents.PixelEvent;
5047

51-
import com.fasterxml.jackson.core.JsonProcessingException;
5248
import com.fasterxml.jackson.databind.ObjectMapper;
5349

54-
import java.util.Map;
5550
import java.util.Objects;
5651

5752
import kotlin.Unit;
5853

5954
public class RCTCheckoutWebView extends FrameLayout {
6055
private static final String TAG = "RCTCheckoutWebView";
56+
private final ThemedReactContext context;
6157

62-
private CheckoutWebView checkoutWebView;
58+
private CheckoutWebView checkoutWebView;
6359
private String checkoutUrl;
6460
private String auth;
6561
private boolean pendingSetup = false;
@@ -80,14 +76,16 @@ public boolean equals(Object obj) {
8076
}
8177
}
8278

83-
public RCTCheckoutWebView(Context context) {
79+
public RCTCheckoutWebView(ThemedReactContext context) {
8480
super(context);
81+
this.context = context;
8582
Log.d(TAG, "RCTCheckoutWebView constructor called");
8683
init();
8784
}
8885

89-
public RCTCheckoutWebView(Context context, AttributeSet attrs) {
86+
public RCTCheckoutWebView(ThemedReactContext context, AttributeSet attrs) {
9087
super(context, attrs);
88+
this.context = context;
9189
Log.d(TAG, "RCTCheckoutWebView constructor with attrs called");
9290
init();
9391
}
@@ -166,7 +164,7 @@ private void setupCheckoutWebView(String url, CheckoutConfiguration configuratio
166164
// Configure authentication if provided
167165
CheckoutOptions options = null;
168166
if (auth != null && !auth.isEmpty()) {
169-
options = new CheckoutOptions(auth);
167+
options = new CheckoutOptions(new Authentication.Token(auth));
170168
}
171169

172170
// Add to view hierarchy
@@ -177,7 +175,7 @@ private void setupCheckoutWebView(String url, CheckoutConfiguration configuratio
177175
addView(checkoutWebView, params);
178176

179177
// Load the URL with options
180-
checkoutWebView.loadCheckout(url, false, options);
178+
checkoutWebView.loadCheckout(url, options);
181179
checkoutWebView.notifyPresented();
182180

183181
// Send onLoad event
@@ -190,8 +188,11 @@ private void setupCheckoutWebView(String url, CheckoutConfiguration configuratio
190188

191189
@NonNull
192190
private CheckoutWebViewEventProcessor getCheckoutWebViewEventProcessor() {
191+
Activity currentActivity = this.context.getCurrentActivity();
192+
ReactApplicationContext reactAppContext = this.context.getReactApplicationContext();
193+
193194
return new CheckoutWebViewEventProcessor(
194-
new CheckoutWebEventProcessor(),
195+
new CustomCheckoutEventProcessor(currentActivity, reactAppContext),
195196
(visible) -> Unit.INSTANCE, // toggleHeader
196197
(error) -> Unit.INSTANCE, // closeCheckoutDialogWithError
197198
(visibility) -> Unit.INSTANCE, // setProgressBarVisibility
@@ -250,108 +251,4 @@ private void sendEvent(String eventName, WritableMap params) {
250251
reactContext.getJSModule(RCTEventEmitter.class)
251252
.receiveEvent(getId(), eventName, params);
252253
}
253-
254-
private class CheckoutWebEventProcessor extends DefaultCheckoutEventProcessor {
255-
256-
public CheckoutWebEventProcessor() {
257-
super(getContext());
258-
}
259-
260-
@Override
261-
public void onCheckoutCompleted(CheckoutCompleteEvent event) {
262-
try {
263-
String eventJson = mapper.writeValueAsString(event);
264-
WritableMap params = Arguments.createMap();
265-
// Parse the JSON to extract fields
266-
Map<String, Object> eventMap = mapper.readValue(eventJson, new TypeReference<>(){ });
267-
for (Map.Entry<String, Object> entry : eventMap.entrySet()) {
268-
if (entry.getValue() instanceof String) {
269-
params.putString(entry.getKey(), (String) entry.getValue());
270-
} else if (entry.getValue() instanceof Number) {
271-
params.putDouble(entry.getKey(), ((Number) entry.getValue()).doubleValue());
272-
} else if (entry.getValue() instanceof Boolean) {
273-
params.putBoolean(entry.getKey(), (Boolean) entry.getValue());
274-
} else if (entry.getValue() != null) {
275-
params.putString(entry.getKey(), mapper.writeValueAsString(entry.getValue()));
276-
}
277-
}
278-
279-
sendEvent("onComplete", params);
280-
} catch (JsonProcessingException e) {
281-
Log.e(TAG, "Failed to serialize completed event", e);
282-
}
283-
}
284-
285-
@Override
286-
public void onCheckoutFailed(CheckoutException error) {
287-
WritableMap params = Arguments.createMap();
288-
params.putString("message", error.getMessage());
289-
params.putString("code", error.getErrorCode());
290-
params.putBoolean("recoverable", error.isRecoverable());
291-
sendEvent("onError", params);
292-
}
293-
294-
@Override
295-
public void onCheckoutCanceled() {
296-
sendEvent("onCancel", Arguments.createMap());
297-
}
298-
299-
@Override
300-
public void onWebPixelEvent(PixelEvent event) {
301-
try {
302-
String eventJson = mapper.writeValueAsString(event);
303-
WritableMap params = Arguments.createMap();
304-
305-
// Parse the JSON to extract fields
306-
Map<String, Object> eventMap = mapper.readValue(eventJson, new TypeReference<>(){ });
307-
for (Map.Entry<String, Object> entry : eventMap.entrySet()) {
308-
if (entry.getValue() instanceof String) {
309-
params.putString(entry.getKey(), (String) entry.getValue());
310-
} else if (entry.getValue() != null) {
311-
params.putString(entry.getKey(), mapper.writeValueAsString(entry.getValue()));
312-
}
313-
}
314-
315-
sendEvent("onPixelEvent", params);
316-
} catch (JsonProcessingException e) {
317-
Log.e(TAG, "Failed to serialize pixel event", e);
318-
}
319-
}
320-
321-
@Override
322-
public void onCheckoutLinkClicked(Uri url) {
323-
WritableMap params = Arguments.createMap();
324-
params.putString("url", url.toString());
325-
sendEvent("onClickLink", params);
326-
}
327-
328-
@Override
329-
public void onAddressChangeRequested(CheckoutAddressChangeRequestedEvent event) {
330-
String eventId = event.getId();
331-
if (eventId == null) {
332-
Log.e(TAG, "Event ID is null for address change event");
333-
return;
334-
}
335-
336-
WritableMap params = Arguments.createMap();
337-
params.putString("id", eventId);
338-
params.putString("type", "addressChangeIntent");
339-
params.putString("addressType", event.getAddressType());
340-
341-
// Include selected address if available
342-
if (event.getSelectedAddress() != null) {
343-
try {
344-
String selectedAddressJson = mapper.writeValueAsString(event.getSelectedAddress());
345-
params.putString("selectedAddress", selectedAddressJson);
346-
} catch (JsonProcessingException e) {
347-
Log.e(TAG, "Failed to serialize selected address", e);
348-
}
349-
}
350-
351-
sendEvent("onAddressChangeIntent", params);
352-
}
353-
354-
// Note: Payment change events are not yet supported in Android SDK
355-
// This will be added when the SDK supports it
356-
}
357254
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
8989
events.put("onError", createEventMap("onError"));
9090
events.put("onComplete", createEventMap("onComplete"));
9191
events.put("onCancel", createEventMap("onCancel"));
92-
events.put("onPixelEvent", createEventMap("onPixelEvent"));
9392
events.put("onClickLink", createEventMap("onClickLink"));
94-
events.put("onAddressChangeIntent", createEventMap("onAddressChangeIntent"));
95-
events.put("onPaymentChangeIntent", createEventMap("onPaymentChangeIntent"));
93+
events.put("onAddressChangeStart", createEventMap("onAddressChangeStart"));
94+
events.put("onPaymentMethodChangeStart", createEventMap("onPaymentMethodChangeStart"));
9695
return events;
9796
}
9897

0 commit comments

Comments
 (0)