Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ of this software and associated documentation files (the "Software"), to deal
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.ReactApplicationContext;
import com.shopify.checkoutkit.lifecycleevents.CheckoutCompletedEvent;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class CustomCheckoutEventProcessor extends DefaultCheckoutEventProcessor {
public class CustomCheckoutListener extends DefaultCheckoutListener {
private final ReactApplicationContext reactContext;
private final ObjectMapper mapper = new ObjectMapper();

Expand All @@ -49,7 +48,7 @@ public class CustomCheckoutEventProcessor extends DefaultCheckoutEventProcessor
private String geolocationOrigin;
private GeolocationPermissions.Callback geolocationCallback;

public CustomCheckoutEventProcessor(Context context, ReactApplicationContext reactContext) {
public CustomCheckoutListener(Context context, ReactApplicationContext reactContext) {
this.reactContext = reactContext;
}

Expand Down Expand Up @@ -120,16 +119,6 @@ public void onCheckoutCanceled() {
sendEvent("close", null);
}

@Override
public void onCheckoutCompleted(@NonNull CheckoutCompletedEvent event) {
try {
String data = mapper.writeValueAsString(event);
sendEventWithStringData("completed", data);
} catch (IOException e) {
Log.e("ShopifyCheckoutKit", "Error processing completed event", e);
}
}

// Private

private Map<String, Object> populateErrorDetails(CheckoutException checkoutError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ShopifyCheckoutKitModule extends NativeShopifyCheckoutKitSpec {

private CheckoutKitDialog checkoutSheet;

private CustomCheckoutEventProcessor checkoutEventProcessor;
private CustomCheckoutListener checkoutListener;

public ShopifyCheckoutKitModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -83,10 +83,10 @@ public void removeListeners(double count) {
public void present(String checkoutURL) {
Activity currentActivity = getCurrentActivity();
if (currentActivity instanceof ComponentActivity) {
checkoutEventProcessor = new CustomCheckoutEventProcessor(currentActivity, this.reactContext);
checkoutListener = new CustomCheckoutListener(currentActivity, this.reactContext);
currentActivity.runOnUiThread(() -> {
checkoutSheet = ShopifyCheckoutKit.present(checkoutURL, (ComponentActivity) currentActivity,
checkoutEventProcessor);
checkoutListener);
});
}
}
Expand Down Expand Up @@ -189,8 +189,8 @@ public boolean isApplePayAvailable() {

@ReactMethod
public void initiateGeolocationRequest(boolean allow) {
if (checkoutEventProcessor != null) {
checkoutEventProcessor.invokeGeolocationCallback(allow);
if (checkoutListener != null) {
checkoutListener.invokeGeolocationCallback(allow);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RCTShopifyCheckoutKit: RCTEventEmitter {
}

// TODO: re-enable when iOS CheckoutDelegate (or equivalent) lands upstream —
// parallels Android's DefaultCheckoutEventProcessor.onCheckoutCanceled / onCheckoutFailed.
// parallels Android's DefaultCheckoutListener.onCheckoutCanceled / onCheckoutFailed.
// Until then, the JS "error" and "close" events stay declared in supportedEvents()
// but native never emits them.
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"android/proguard-rules.pro",
"android/src/main/AndroidManifest.xml",
"android/src/main/AndroidManifestNew.xml",
"android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutEventProcessor.java",
"android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutListener.java",
"android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java",
"android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitPackage.java",
"ios/AcceleratedCheckoutButtons.swift",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
import com.shopify.checkoutkit.Preloading;
import com.shopify.checkoutkit.ColorScheme;
import com.shopify.checkoutkit.LogLevel;
import com.shopify.checkoutkit.lifecycleevents.CheckoutCompletedEvent;
import com.shopify.checkoutkit.lifecycleevents.OrderDetails;
import com.shopify.checkoutkit.lifecycleevents.CartInfo;
import com.shopify.checkoutkit.lifecycleevents.Price;
import com.shopify.reactnative.checkoutkit.ShopifyCheckoutKitModule;
import com.shopify.reactnative.checkoutkit.CustomCheckoutEventProcessor;
import com.shopify.reactnative.checkoutkit.CustomCheckoutListener;

import org.junit.After;
import org.junit.Before;
Expand All @@ -41,8 +37,6 @@

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

@RunWith(MockitoJUnitRunner.class)
public class ShopifyCheckoutKitModuleTest {
Expand Down Expand Up @@ -468,38 +462,13 @@ public void testGetConfigReturnsDefaultLogLevel() {
* Events
*/

@Test
public void testCanProcessCheckoutCompletedEvents() {
CustomCheckoutEventProcessor processor = new CustomCheckoutEventProcessor(mockContext, mockReactContext);

CartInfo cartInfo = new CartInfo(new ArrayList<>(), new Price(), "cart-token");
OrderDetails orderDetails = new OrderDetails(
null, // billingAddress
cartInfo,
new ArrayList<>(), // deliveries
"test@example.com", // email
"order-123", // id
new ArrayList<>(), // paymentMethods
"+1234567890" // phone
);

CheckoutCompletedEvent completedEvent = new CheckoutCompletedEvent(orderDetails);

processor.onCheckoutCompleted(completedEvent);

verify(mockEventEmitter).emit(eq("completed"), stringCaptor.capture());

assertThat(stringCaptor.getValue())
.contains("order-123", "test@example.com", "cart-token");
}

/**
* Errors
*/

@Test
public void testCanProcessCheckoutExpiredErrors() {
CustomCheckoutEventProcessor processor = new CustomCheckoutEventProcessor(mockContext, mockReactContext);
CustomCheckoutListener processor = new CustomCheckoutListener(mockContext, mockReactContext);

// Use minimal mocking - just enough to test the processing logic
CheckoutExpiredException mockException = mock(CheckoutExpiredException.class);
Expand All @@ -517,7 +486,7 @@ public void testCanProcessCheckoutExpiredErrors() {

@Test
public void testCanProcessClientErrors() {
CustomCheckoutEventProcessor processor = new CustomCheckoutEventProcessor(mockContext, mockReactContext);
CustomCheckoutListener processor = new CustomCheckoutListener(mockContext, mockReactContext);

ClientException mockException = mock(ClientException.class);
when(mockException.getErrorDescription()).thenReturn("Customer account required");
Expand All @@ -535,7 +504,7 @@ public void testCanProcessClientErrors() {

@Test
public void testCanProcessHttpErrors() {
CustomCheckoutEventProcessor processor = new CustomCheckoutEventProcessor(mockContext, mockReactContext);
CustomCheckoutListener processor = new CustomCheckoutListener(mockContext, mockReactContext);

HttpException mockException = mock(HttpException.class);
when(mockException.getErrorDescription()).thenReturn("Not Found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class ShopifyCheckoutKitTests: XCTestCase {
}

// TODO: re-enable when iOS CheckoutDelegate (or equivalent) lands upstream —
// parallels Android's DefaultCheckoutEventProcessor.onCheckoutCanceled / onCheckoutFailed.
// parallels Android's DefaultCheckoutListener.onCheckoutCanceled / onCheckoutFailed.
/*
/// checkoutDidComplete
func testCheckoutDidCompleteSendsEvent() {
Expand Down
Loading