Skip to content

Commit 244f103

Browse files
feat: add onPaymentMethodChangeStart to inline event processor
1 parent f0f8bb9 commit 244f103

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ of this software and associated documentation files (the "Software"), to deal
4242

4343
import com.shopify.checkoutsheetkit.Authentication;
4444
import com.shopify.checkoutsheetkit.CheckoutException;
45+
import com.shopify.checkoutsheetkit.CheckoutPaymentMethodChangeStartParams;
4546
import com.shopify.checkoutsheetkit.DefaultCheckoutEventProcessor;
4647
import com.shopify.checkoutsheetkit.CheckoutOptions;
4748
import com.shopify.checkoutsheetkit.CheckoutWebView;
@@ -58,7 +59,9 @@ of this software and associated documentation files (the "Software"), to deal
5859

5960
import com.fasterxml.jackson.core.type.TypeReference;
6061
import com.fasterxml.jackson.databind.ObjectMapper;
62+
import com.shopify.checkoutsheetkit.rpc.events.CheckoutPaymentMethodChangeStart;
6163

64+
import java.io.IOException;
6265
import java.util.HashMap;
6366
import java.util.Map;
6467
import java.util.Objects;
@@ -351,6 +354,22 @@ public void onAddressChangeStart(@NonNull CheckoutAddressChangeStart event) {
351354
}
352355
}
353356

357+
@Override
358+
public void onPaymentMethodChangeStart(@NonNull CheckoutPaymentMethodChangeStart event) {
359+
try {
360+
CheckoutPaymentMethodChangeStartParams params = event.getParams();
361+
362+
Map<String, Object> eventData = new HashMap<>();
363+
eventData.put("id", event.getId());
364+
eventData.put("type", "paymentMethodChangeStart");
365+
eventData.put("cart", params.getCart());
366+
367+
sendEvent("paymentMethodChangeStart", serializeToWritableMap(eventData));
368+
} catch (Exception e) {
369+
Log.e(TAG, "Error processing address change start event", e);
370+
}
371+
}
372+
354373
@Override
355374
public void onLinkClick(@NonNull Uri uri) {
356375
WritableMap params = Arguments.createMap();

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ of this software and associated documentation files (the "Software"), to deal
3232

3333
import com.shopify.checkoutsheetkit.CheckoutException;
3434
import com.shopify.checkoutsheetkit.CheckoutExpiredException;
35+
import com.shopify.checkoutsheetkit.CheckoutPaymentMethodChangeStartParams;
3536
import com.shopify.checkoutsheetkit.CheckoutSheetKitException;
3637
import com.shopify.checkoutsheetkit.ClientException;
3738
import com.shopify.checkoutsheetkit.ConfigurationException;
@@ -45,6 +46,7 @@ of this software and associated documentation files (the "Software"), to deal
4546
import com.shopify.checkoutsheetkit.rpc.events.CheckoutAddressChangeStart;
4647
import com.shopify.checkoutsheetkit.rpc.events.CheckoutAddressChangeStartEvent;
4748
import com.fasterxml.jackson.databind.ObjectMapper;
49+
import com.shopify.checkoutsheetkit.rpc.events.CheckoutPaymentMethodChangeStart;
4850

4951
import java.io.IOException;
5052
import java.util.HashMap;
@@ -172,8 +174,24 @@ public void onAddressChangeStart(@NonNull CheckoutAddressChangeStart event) {
172174
}
173175
}
174176

175-
// Private
177+
@Override
178+
public void onPaymentMethodChangeStart(@NonNull CheckoutPaymentMethodChangeStart event) {
179+
try {
180+
CheckoutPaymentMethodChangeStartParams params = event.getParams();
181+
182+
Map<String, Object> eventData = new HashMap<>();
183+
eventData.put("id", event.getId());
184+
eventData.put("type", "paymentMethodChangeStart");
185+
eventData.put("cart", params.getCart());
176186

187+
String data = mapper.writeValueAsString(eventData);
188+
sendEventWithStringData("paymentMethodChangeStart", data);
189+
} catch (IOException e) {
190+
Log.e(TAG, "Error processing address change start event", e);
191+
}
192+
}
193+
194+
// Private
177195
private Map<String, Object> populateErrorDetails(CheckoutException error) {
178196
Map<String, Object> errorMap = new HashMap<>(Map.of(
179197
"__typename", getErrorTypeName(error),

0 commit comments

Comments
 (0)