react-native-klarna-inapp-sdk 2.2.5 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/android/build.gradle +10 -10
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +3 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventHandler.java +32 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventSender.java +56 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewManager.java +147 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +59 -19
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEvent.java +37 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSender.java +78 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtil.java +53 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/ResizeObserverWrapperView.java +79 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/WrapperView.java +32 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/{ArgumentsUtil.java → util/ArgumentsUtil.java} +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/util/ParserUtil.java +36 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/KlarnaPaymentViewManager.java +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/PaymentViewWrapper.java +1 -1
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEventSender.java +1 -1
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +31 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +20 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java +3 -1
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSenderTest.java +85 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventTest.java +73 -0
- package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtilTest.java +61 -0
- package/ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj +32 -0
- package/ios/Sources/KlarnaCheckoutViewManager.h +5 -0
- package/ios/Sources/KlarnaCheckoutViewManager.mm +65 -0
- package/ios/Sources/common/RNMobileSDKUtils.h +6 -0
- package/ios/Sources/common/RNMobileSDKUtils.mm +22 -0
- package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.h +26 -0
- package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.mm +153 -0
- package/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +22 -1
- package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.h +37 -0
- package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.mm +116 -0
- package/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +22 -1
- package/lib/commonjs/KlarnaCheckoutView.js +84 -0
- package/lib/commonjs/KlarnaCheckoutView.js.map +1 -0
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaMobileSDKError.js +2 -0
- package/lib/commonjs/types/common/KlarnaMobileSDKError.js.map +1 -0
- package/lib/commonjs/types/common/KlarnaProductEvent.js +2 -0
- package/lib/commonjs/types/common/KlarnaProductEvent.js.map +1 -0
- package/lib/module/KlarnaCheckoutView.js +74 -0
- package/lib/module/KlarnaCheckoutView.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js +7 -0
- package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
- package/lib/module/types/common/KlarnaMobileSDKError.js +2 -0
- package/lib/module/types/common/KlarnaMobileSDKError.js.map +1 -0
- package/lib/module/types/common/KlarnaProductEvent.js +2 -0
- package/lib/module/types/common/KlarnaProductEvent.js.map +1 -0
- package/lib/typescript/KlarnaCheckoutView.d.ts +24 -0
- package/lib/typescript/KlarnaCheckoutView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts +33 -0
- package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts +6 -0
- package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts.map +1 -0
- package/lib/typescript/types/common/KlarnaProductEvent.d.ts +7 -0
- package/lib/typescript/types/common/KlarnaProductEvent.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/KlarnaCheckoutView.tsx +130 -0
- package/src/index.tsx +1 -0
- package/src/specs/KlarnaCheckoutViewNativeComponent.ts +58 -0
- package/src/types/common/KlarnaMobileSDKError.ts +5 -0
- package/src/types/common/KlarnaProductEvent.ts +4 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.common.ui;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.AttributeSet;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
import android.view.ViewGroup;
|
|
7
|
+
import android.widget.FrameLayout;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.annotation.Nullable;
|
|
11
|
+
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
13
|
+
|
|
14
|
+
public class WrapperView<T extends View> extends FrameLayout {
|
|
15
|
+
|
|
16
|
+
private T view;
|
|
17
|
+
|
|
18
|
+
public WrapperView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
19
|
+
super(context, attrs, defStyleAttr);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public WrapperView(ReactApplicationContext context, AttributeSet attrs, T view) {
|
|
23
|
+
super(context, attrs);
|
|
24
|
+
this.view = view;
|
|
25
|
+
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
26
|
+
addView(view, layoutParams);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public T getView() {
|
|
30
|
+
return view;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.common.util;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
|
|
5
|
+
import com.google.gson.Gson;
|
|
6
|
+
import com.google.gson.GsonBuilder;
|
|
7
|
+
|
|
8
|
+
public class ParserUtil {
|
|
9
|
+
public static final Gson gson = new GsonBuilder().create();
|
|
10
|
+
|
|
11
|
+
public static String toJson(Object obj) {
|
|
12
|
+
return gson.toJson(obj);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static String toJsonSafe(Object obj) {
|
|
16
|
+
try {
|
|
17
|
+
return gson.toJson(obj);
|
|
18
|
+
} catch (Throwable t) {
|
|
19
|
+
Log.e(ParserUtil.class.getSimpleName(), "Failed to serialize object to string with Gson: " + t.getMessage());
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static <T> T fromJson(String json, Class<T> cls) {
|
|
25
|
+
return gson.fromJson(json, cls);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static <T> T fromJsonSafe(String json, Class<T> cls) {
|
|
29
|
+
try {
|
|
30
|
+
return gson.fromJson(json, cls);
|
|
31
|
+
} catch (Throwable t) {
|
|
32
|
+
Log.e(ParserUtil.class.getSimpleName(), "Failed to deserialize object from string with Gson: " + t.getMessage());
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -16,7 +16,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
|
|
16
16
|
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentView;
|
|
17
17
|
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentViewCallback;
|
|
18
18
|
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentsSDKError;
|
|
19
|
-
import com.klarna.mobile.sdk.reactnative.common.ArgumentsUtil;
|
|
19
|
+
import com.klarna.mobile.sdk.reactnative.common.util.ArgumentsUtil;
|
|
20
20
|
import com.klarna.mobile.sdk.reactnative.spec.RNKlarnaPaymentViewSpec;
|
|
21
21
|
|
|
22
22
|
import org.jetbrains.annotations.NotNull;
|
package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/PaymentViewWrapper.java
CHANGED
|
@@ -33,7 +33,7 @@ public class PaymentViewWrapper extends LinearLayout implements WebViewResizeObs
|
|
|
33
33
|
paymentView = new KlarnaPaymentView(getReactAppContext().getCurrentActivity(), attrs); // Insure we use activity and not application context for dialogs.
|
|
34
34
|
paymentView.registerPaymentViewCallback(paymentViewCallback);
|
|
35
35
|
addView(paymentView, webViewParams);
|
|
36
|
-
resizeObserver = new WebViewResizeObserver(this);
|
|
36
|
+
resizeObserver = new WebViewResizeObserver(this, WebViewResizeObserver.TargetElement.PAYMENT_CONTAINER);
|
|
37
37
|
WebView webView = getPaymentViewWebView();
|
|
38
38
|
if (webView != null) {
|
|
39
39
|
resizeObserver.addInterface(webView);
|
|
@@ -11,7 +11,7 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
|
|
11
11
|
import com.google.gson.Gson;
|
|
12
12
|
import com.klarna.mobile.sdk.api.KlarnaProductEvent;
|
|
13
13
|
import com.klarna.mobile.sdk.api.standalonewebview.KlarnaStandaloneWebView;
|
|
14
|
-
import com.klarna.mobile.sdk.reactnative.common.ArgumentsUtil;
|
|
14
|
+
import com.klarna.mobile.sdk.reactnative.common.util.ArgumentsUtil;
|
|
15
15
|
|
|
16
16
|
import java.lang.ref.WeakReference;
|
|
17
17
|
import java.util.HashMap;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.spec;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
9
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
10
|
+
import com.facebook.react.uimanager.ViewManagerDelegate;
|
|
11
|
+
import com.facebook.react.viewmanagers.RNKlarnaCheckoutViewManagerDelegate;
|
|
12
|
+
import com.facebook.react.viewmanagers.RNKlarnaCheckoutViewManagerInterface;
|
|
13
|
+
|
|
14
|
+
public abstract class RNKlarnaCheckoutViewSpec<T extends View> extends SimpleViewManager<T> implements RNKlarnaCheckoutViewManagerInterface<T> {
|
|
15
|
+
private final ViewManagerDelegate<T> mDelegate;
|
|
16
|
+
|
|
17
|
+
public RNKlarnaCheckoutViewSpec() {
|
|
18
|
+
mDelegate = new RNKlarnaCheckoutViewManagerDelegate<>(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Nullable
|
|
22
|
+
@Override
|
|
23
|
+
protected ViewManagerDelegate<T> getDelegate() {
|
|
24
|
+
return mDelegate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public void receiveCommand(@NonNull T root, String commandId, @Nullable ReadableArray args) {
|
|
29
|
+
mDelegate.receiveCommand(root, commandId, args);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.spec;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
8
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
9
|
+
import com.klarna.mobile.sdk.api.checkout.KlarnaCheckoutView;
|
|
10
|
+
|
|
11
|
+
public abstract class RNKlarnaCheckoutViewSpec<T extends View> extends SimpleViewManager<T> {
|
|
12
|
+
|
|
13
|
+
public abstract void setReturnUrl(T view, @Nullable String value);
|
|
14
|
+
|
|
15
|
+
public abstract void setSnippet(T view, String snippet);
|
|
16
|
+
|
|
17
|
+
public abstract void suspend(T view);
|
|
18
|
+
|
|
19
|
+
public abstract void resume(T view);
|
|
20
|
+
}
|
package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java
CHANGED
|
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.NativeModule;
|
|
|
8
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
9
|
import com.facebook.react.uimanager.ViewManager;
|
|
10
10
|
import com.klarna.mobile.sdk.reactnative.KlarnaMobileSDKPackage;
|
|
11
|
+
import com.klarna.mobile.sdk.reactnative.checkout.KlarnaCheckoutViewManager;
|
|
11
12
|
import com.klarna.mobile.sdk.reactnative.payments.KlarnaPaymentViewManager;
|
|
12
13
|
import com.klarna.mobile.sdk.reactnative.standalonewebview.KlarnaStandaloneWebViewManager;
|
|
13
14
|
|
|
@@ -45,8 +46,9 @@ public class KlarnaMobileSDKPackageTest {
|
|
|
45
46
|
List<ViewManager> nativeModules = paymentViewPackage.createViewManagers(reactContext);
|
|
46
47
|
Assert.assertNotNull(nativeModules);
|
|
47
48
|
Assert.assertFalse(nativeModules.isEmpty());
|
|
48
|
-
Assert.assertEquals(
|
|
49
|
+
Assert.assertEquals(3, nativeModules.size());
|
|
49
50
|
Assert.assertTrue(nativeModules.get(0) instanceof KlarnaPaymentViewManager);
|
|
50
51
|
Assert.assertTrue(nativeModules.get(1) instanceof KlarnaStandaloneWebViewManager);
|
|
52
|
+
Assert.assertTrue(nativeModules.get(2) instanceof KlarnaCheckoutViewManager);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.common.event;
|
|
2
|
+
|
|
3
|
+
import android.os.SystemClock;
|
|
4
|
+
import android.view.View;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.WritableMap;
|
|
7
|
+
import com.facebook.react.uimanager.UIManagerHelper;
|
|
8
|
+
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
9
|
+
|
|
10
|
+
import org.junit.Assert;
|
|
11
|
+
import org.junit.Before;
|
|
12
|
+
import org.junit.Test;
|
|
13
|
+
import org.junit.runner.RunWith;
|
|
14
|
+
import org.mockito.Mockito;
|
|
15
|
+
import org.powermock.api.mockito.PowerMockito;
|
|
16
|
+
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
17
|
+
import org.powermock.modules.junit4.PowerMockRunner;
|
|
18
|
+
|
|
19
|
+
import java.lang.ref.WeakReference;
|
|
20
|
+
import java.util.Arrays;
|
|
21
|
+
import java.util.Collection;
|
|
22
|
+
import java.util.HashMap;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
|
|
25
|
+
@RunWith(PowerMockRunner.class)
|
|
26
|
+
@PrepareForTest({UIManagerHelper.class, SystemClock.class})
|
|
27
|
+
public class ComponentEventSenderTest {
|
|
28
|
+
|
|
29
|
+
private TestEventSender testEventSender;
|
|
30
|
+
private View view;
|
|
31
|
+
private EventDispatcher eventDispatcher;
|
|
32
|
+
private Map<WeakReference<View>, EventDispatcher> viewToDispatcher;
|
|
33
|
+
|
|
34
|
+
@Before
|
|
35
|
+
public void setUp() {
|
|
36
|
+
view = Mockito.mock(View.class);
|
|
37
|
+
eventDispatcher = Mockito.mock(EventDispatcher.class);
|
|
38
|
+
viewToDispatcher = new HashMap<>() {{
|
|
39
|
+
put(new WeakReference<>(view), eventDispatcher);
|
|
40
|
+
}};
|
|
41
|
+
testEventSender = new TestEventSender(viewToDispatcher);
|
|
42
|
+
|
|
43
|
+
PowerMockito.mockStatic(UIManagerHelper.class);
|
|
44
|
+
Mockito.when(UIManagerHelper.getEventDispatcherForReactTag(Mockito.any(), Mockito.anyInt())).thenAnswer(invocation -> eventDispatcher);
|
|
45
|
+
PowerMockito.mockStatic(SystemClock.class);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test
|
|
49
|
+
public void exportedCustomDirectEventTypeConstants() {
|
|
50
|
+
// When
|
|
51
|
+
Map<String, Object> customDirectEventTypeConstants = testEventSender.getExportedCustomDirectEventTypeConstants();
|
|
52
|
+
|
|
53
|
+
// Then
|
|
54
|
+
Assert.assertEquals(1, customDirectEventTypeConstants.size());
|
|
55
|
+
Assert.assertTrue(customDirectEventTypeConstants.containsKey("onTestEvent"));
|
|
56
|
+
Assert.assertEquals("onTestEvent", ((Map<String, String>) customDirectEventTypeConstants.get("onTestEvent")).get("registrationName"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Test
|
|
60
|
+
public void testPostTestEventForView() {
|
|
61
|
+
// Given
|
|
62
|
+
WritableMap params = null;
|
|
63
|
+
|
|
64
|
+
// When
|
|
65
|
+
testEventSender.postTestEventForView(view, params);
|
|
66
|
+
|
|
67
|
+
// Then
|
|
68
|
+
Mockito.verify(eventDispatcher).dispatchEvent(Mockito.any(ComponentEvent.class));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private class TestEventSender extends ComponentEventSender<View> {
|
|
72
|
+
public TestEventSender(Map<WeakReference<View>, EventDispatcher> viewToDispatcher) {
|
|
73
|
+
super(viewToDispatcher);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
public Collection<String> getCallbackEventNames() {
|
|
78
|
+
return Arrays.asList("onTestEvent");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public void postTestEventForView(View view, WritableMap params) {
|
|
82
|
+
postEventForView(view, "onTestEvent", params);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventTest.java
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.common.event;
|
|
2
|
+
|
|
3
|
+
import android.os.SystemClock;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.Arguments;
|
|
6
|
+
import com.facebook.react.bridge.JavaOnlyArray;
|
|
7
|
+
import com.facebook.react.bridge.JavaOnlyMap;
|
|
8
|
+
import com.facebook.react.bridge.WritableMap;
|
|
9
|
+
|
|
10
|
+
import org.junit.After;
|
|
11
|
+
import org.junit.Assert;
|
|
12
|
+
import org.junit.Before;
|
|
13
|
+
import org.junit.Test;
|
|
14
|
+
import org.junit.runner.RunWith;
|
|
15
|
+
import org.powermock.api.mockito.PowerMockito;
|
|
16
|
+
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
17
|
+
import org.powermock.modules.junit4.PowerMockRunner;
|
|
18
|
+
|
|
19
|
+
@RunWith(PowerMockRunner.class)
|
|
20
|
+
@PrepareForTest({Arguments.class, SystemClock.class})
|
|
21
|
+
public class ComponentEventTest {
|
|
22
|
+
|
|
23
|
+
@Before
|
|
24
|
+
public void setup() {
|
|
25
|
+
PowerMockito.mockStatic(Arguments.class);
|
|
26
|
+
PowerMockito.when(Arguments.createArray())
|
|
27
|
+
.thenAnswer(invocation -> {
|
|
28
|
+
return new JavaOnlyArray();
|
|
29
|
+
});
|
|
30
|
+
PowerMockito.when(Arguments.createMap())
|
|
31
|
+
.thenAnswer(invocation -> {
|
|
32
|
+
return new JavaOnlyMap();
|
|
33
|
+
});
|
|
34
|
+
PowerMockito.mockStatic(SystemClock.class);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@After
|
|
38
|
+
public void teardown() {
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
public void testEventName() {
|
|
44
|
+
// When
|
|
45
|
+
ComponentEvent event = new ComponentEvent(1, "test", null);
|
|
46
|
+
|
|
47
|
+
// Then
|
|
48
|
+
Assert.assertEquals("test", event.getEventName());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Test
|
|
52
|
+
public void testEventData() {
|
|
53
|
+
// Given
|
|
54
|
+
WritableMap map = new JavaOnlyMap();
|
|
55
|
+
map.putString("key", "value");
|
|
56
|
+
|
|
57
|
+
// When
|
|
58
|
+
ComponentEvent event = new ComponentEvent(1, "test", map);
|
|
59
|
+
|
|
60
|
+
// Then
|
|
61
|
+
Assert.assertEquals(map, event.getEventData());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
public void testEventDataNull() {
|
|
66
|
+
// When
|
|
67
|
+
ComponentEvent event = new ComponentEvent(1, "test", null);
|
|
68
|
+
|
|
69
|
+
// Then
|
|
70
|
+
Assert.assertNotNull(event.getEventData());
|
|
71
|
+
Assert.assertFalse(event.getEventData().keySetIterator().hasNextKey());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package com.klarna.mobile.sdk.reactnative.common.event;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import com.klarna.mobile.sdk.KlarnaMobileSDKError;
|
|
6
|
+
import com.klarna.mobile.sdk.api.KlarnaProduct;
|
|
7
|
+
import com.klarna.mobile.sdk.api.KlarnaProductEvent;
|
|
8
|
+
import com.klarna.mobile.sdk.reactnative.common.util.ArgumentsUtil;
|
|
9
|
+
|
|
10
|
+
import org.junit.Before;
|
|
11
|
+
import org.junit.Test;
|
|
12
|
+
import org.junit.runner.RunWith;
|
|
13
|
+
import org.mockito.Mockito;
|
|
14
|
+
import org.powermock.api.mockito.PowerMockito;
|
|
15
|
+
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
16
|
+
import org.powermock.modules.junit4.PowerMockRunner;
|
|
17
|
+
|
|
18
|
+
import java.util.HashMap;
|
|
19
|
+
import java.util.HashSet;
|
|
20
|
+
import java.util.List;
|
|
21
|
+
|
|
22
|
+
@RunWith(PowerMockRunner.class)
|
|
23
|
+
@PrepareForTest({ArgumentsUtil.class})
|
|
24
|
+
public class KlarnaEventHandlerEventsUtilTest {
|
|
25
|
+
|
|
26
|
+
private ComponentEventSender componentEventSender;
|
|
27
|
+
private View view;
|
|
28
|
+
|
|
29
|
+
@Before
|
|
30
|
+
public void setUp() {
|
|
31
|
+
componentEventSender = Mockito.mock(ComponentEventSender.class);
|
|
32
|
+
view = Mockito.mock(View.class);
|
|
33
|
+
|
|
34
|
+
PowerMockito.mockStatic(ArgumentsUtil.class);
|
|
35
|
+
Mockito.when(ArgumentsUtil.createMap(Mockito.anyMap())).thenAnswer(invocation -> null);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
public void sendKlarnaProductEvent() {
|
|
40
|
+
// Given
|
|
41
|
+
KlarnaProductEvent klarnaProductEvent = new KlarnaProductEvent("action", new HashSet<>(List.of(KlarnaProduct.KLARNA_CHECKOUT)), new HashMap<>(), "testSessionId");
|
|
42
|
+
|
|
43
|
+
// When
|
|
44
|
+
KlarnaEventHandlerEventsUtil.sendKlarnaProductEvent(componentEventSender, view, klarnaProductEvent);
|
|
45
|
+
|
|
46
|
+
// Then
|
|
47
|
+
Mockito.verify(componentEventSender).postEventForView(view, KlarnaEventHandlerEventsUtil.EVENT_NAME_ON_EVENT, null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test
|
|
51
|
+
public void sendKlarnaMobileSDKError() {
|
|
52
|
+
// Given
|
|
53
|
+
KlarnaMobileSDKError klarnaMobileSDKError = new com.klarna.mobile.sdk.api.hybrid.KlarnaMobileSDKError("name", "message", true, "sessionId");
|
|
54
|
+
|
|
55
|
+
// When
|
|
56
|
+
KlarnaEventHandlerEventsUtil.sendKlarnaMobileSDKError(componentEventSender, view, klarnaMobileSDKError);
|
|
57
|
+
|
|
58
|
+
// Then
|
|
59
|
+
Mockito.verify(componentEventSender).postEventForView(view, KlarnaEventHandlerEventsUtil.EVENT_NAME_ON_EVENT, null);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
7917D757255C45FB00E16799 /* libRNKlarnaMobileSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134814201AA4EA6300B7C361 /* libRNKlarnaMobileSDK.a */; };
|
|
15
15
|
792F67C02AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 792F67BB2AB8AD7D00675E18 /* PaymentViewWrapper.mm */; };
|
|
16
16
|
792F67C12AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 792F67BE2AB8AD7D00675E18 /* PaymentViewWrapper.mm */; };
|
|
17
|
+
79BD25FA2BC97A3000D2D92A /* KlarnaCheckoutViewManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79BD25F92BC97A3000D2D92A /* KlarnaCheckoutViewManager.mm */; };
|
|
18
|
+
79BD25FC2BC97B0900D2D92A /* KlarnaCheckoutViewWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79BD25FB2BC97B0900D2D92A /* KlarnaCheckoutViewWrapper.mm */; };
|
|
19
|
+
79BD26002BCD4F6C00D2D92A /* KlarnaCheckoutViewWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79BD25FF2BCD4F6C00D2D92A /* KlarnaCheckoutViewWrapper.mm */; };
|
|
20
|
+
79BD26042BCD572600D2D92A /* RNMobileSDKUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79BD26032BCD572600D2D92A /* RNMobileSDKUtils.mm */; };
|
|
17
21
|
B3E7B58A1CC2AC0600A0062D /* KlarnaPaymentViewManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* KlarnaPaymentViewManager.mm */; };
|
|
18
22
|
C950FFE559BF35928E94BF8D /* libPods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F7837F2C76927FD0EC420C40 /* libPods-RNKlarnaMobileSDK-RNKlarnaMobileSDKTests.a */; };
|
|
19
23
|
DF4C69429315E34435B953E8 /* libPods-RNKlarnaMobileSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FF5062264E440DC969A15ACA /* libPods-RNKlarnaMobileSDK.a */; };
|
|
@@ -58,6 +62,14 @@
|
|
|
58
62
|
792F67BC2AB8AD7D00675E18 /* PaymentViewWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaymentViewWrapper.h; sourceTree = "<group>"; };
|
|
59
63
|
792F67BE2AB8AD7D00675E18 /* PaymentViewWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PaymentViewWrapper.mm; sourceTree = "<group>"; };
|
|
60
64
|
792F67BF2AB8AD7D00675E18 /* PaymentViewWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaymentViewWrapper.h; sourceTree = "<group>"; };
|
|
65
|
+
79BD25F82BC97A0100D2D92A /* KlarnaCheckoutViewManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaCheckoutViewManager.h; sourceTree = "<group>"; };
|
|
66
|
+
79BD25F92BC97A3000D2D92A /* KlarnaCheckoutViewManager.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KlarnaCheckoutViewManager.mm; sourceTree = "<group>"; };
|
|
67
|
+
79BD25FB2BC97B0900D2D92A /* KlarnaCheckoutViewWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KlarnaCheckoutViewWrapper.mm; sourceTree = "<group>"; };
|
|
68
|
+
79BD25FD2BC97B2200D2D92A /* KlarnaCheckoutViewWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaCheckoutViewWrapper.h; sourceTree = "<group>"; };
|
|
69
|
+
79BD25FE2BCD4F5A00D2D92A /* KlarnaCheckoutViewWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KlarnaCheckoutViewWrapper.h; sourceTree = "<group>"; };
|
|
70
|
+
79BD25FF2BCD4F6C00D2D92A /* KlarnaCheckoutViewWrapper.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KlarnaCheckoutViewWrapper.mm; sourceTree = "<group>"; };
|
|
71
|
+
79BD26022BCD56D400D2D92A /* RNMobileSDKUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMobileSDKUtils.h; sourceTree = "<group>"; };
|
|
72
|
+
79BD26032BCD572600D2D92A /* RNMobileSDKUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RNMobileSDKUtils.mm; sourceTree = "<group>"; };
|
|
61
73
|
7A4208B9D3B0F45669A2E06F /* Pods-RNKlarnaMobileSDK.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNKlarnaMobileSDK.release.xcconfig"; path = "Target Support Files/Pods-RNKlarnaMobileSDK/Pods-RNKlarnaMobileSDK.release.xcconfig"; sourceTree = "<group>"; };
|
|
62
74
|
B074D4744315BBCD94D119E9 /* Pods-RNKlarnaMobileSDK.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNKlarnaMobileSDK.debug.xcconfig"; path = "Target Support Files/Pods-RNKlarnaMobileSDK/Pods-RNKlarnaMobileSDK.debug.xcconfig"; sourceTree = "<group>"; };
|
|
63
75
|
B3E7B5881CC2AC0600A0062D /* KlarnaPaymentViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KlarnaPaymentViewManager.h; sourceTree = "<group>"; };
|
|
@@ -122,6 +134,9 @@
|
|
|
122
134
|
7917D74C255C445E00E16799 /* Sources */ = {
|
|
123
135
|
isa = PBXGroup;
|
|
124
136
|
children = (
|
|
137
|
+
79BD26012BCD56C000D2D92A /* common */,
|
|
138
|
+
79BD25F82BC97A0100D2D92A /* KlarnaCheckoutViewManager.h */,
|
|
139
|
+
79BD25F92BC97A3000D2D92A /* KlarnaCheckoutViewManager.mm */,
|
|
125
140
|
B3E7B5881CC2AC0600A0062D /* KlarnaPaymentViewManager.h */,
|
|
126
141
|
B3E7B5891CC2AC0600A0062D /* KlarnaPaymentViewManager.mm */,
|
|
127
142
|
42BC05FD2AC57D950044A9FE /* KlarnaStandaloneWebViewManager.h */,
|
|
@@ -158,6 +173,8 @@
|
|
|
158
173
|
792F67BA2AB8AD7D00675E18 /* newarch */ = {
|
|
159
174
|
isa = PBXGroup;
|
|
160
175
|
children = (
|
|
176
|
+
79BD25FE2BCD4F5A00D2D92A /* KlarnaCheckoutViewWrapper.h */,
|
|
177
|
+
79BD25FF2BCD4F6C00D2D92A /* KlarnaCheckoutViewWrapper.mm */,
|
|
161
178
|
792F67BB2AB8AD7D00675E18 /* PaymentViewWrapper.mm */,
|
|
162
179
|
792F67BC2AB8AD7D00675E18 /* PaymentViewWrapper.h */,
|
|
163
180
|
42BC06012AC5866B0044A9FE /* KlarnaStandaloneWebViewWrapper.h */,
|
|
@@ -169,6 +186,8 @@
|
|
|
169
186
|
792F67BD2AB8AD7D00675E18 /* oldarch */ = {
|
|
170
187
|
isa = PBXGroup;
|
|
171
188
|
children = (
|
|
189
|
+
79BD25FD2BC97B2200D2D92A /* KlarnaCheckoutViewWrapper.h */,
|
|
190
|
+
79BD25FB2BC97B0900D2D92A /* KlarnaCheckoutViewWrapper.mm */,
|
|
172
191
|
792F67BE2AB8AD7D00675E18 /* PaymentViewWrapper.mm */,
|
|
173
192
|
792F67BF2AB8AD7D00675E18 /* PaymentViewWrapper.h */,
|
|
174
193
|
42BC06002AC585950044A9FE /* KlarnaStandaloneWebViewWrapper.h */,
|
|
@@ -177,6 +196,15 @@
|
|
|
177
196
|
path = oldarch;
|
|
178
197
|
sourceTree = "<group>";
|
|
179
198
|
};
|
|
199
|
+
79BD26012BCD56C000D2D92A /* common */ = {
|
|
200
|
+
isa = PBXGroup;
|
|
201
|
+
children = (
|
|
202
|
+
79BD26022BCD56D400D2D92A /* RNMobileSDKUtils.h */,
|
|
203
|
+
79BD26032BCD572600D2D92A /* RNMobileSDKUtils.mm */,
|
|
204
|
+
);
|
|
205
|
+
path = common;
|
|
206
|
+
sourceTree = "<group>";
|
|
207
|
+
};
|
|
180
208
|
9CDEDC2923475BAC006C9C97 /* view */ = {
|
|
181
209
|
isa = PBXGroup;
|
|
182
210
|
children = (
|
|
@@ -381,9 +409,13 @@
|
|
|
381
409
|
buildActionMask = 2147483647;
|
|
382
410
|
files = (
|
|
383
411
|
42BC06032AC586C50044A9FE /* KlarnaStandaloneWebViewWrapper.mm in Sources */,
|
|
412
|
+
79BD25FC2BC97B0900D2D92A /* KlarnaCheckoutViewWrapper.mm in Sources */,
|
|
413
|
+
79BD26002BCD4F6C00D2D92A /* KlarnaCheckoutViewWrapper.mm in Sources */,
|
|
414
|
+
79BD26042BCD572600D2D92A /* RNMobileSDKUtils.mm in Sources */,
|
|
384
415
|
B3E7B58A1CC2AC0600A0062D /* KlarnaPaymentViewManager.mm in Sources */,
|
|
385
416
|
792F67C02AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */,
|
|
386
417
|
42BC06052AC588180044A9FE /* KlarnaStandaloneWebViewWrapper.mm in Sources */,
|
|
418
|
+
79BD25FA2BC97A3000D2D92A /* KlarnaCheckoutViewManager.mm in Sources */,
|
|
387
419
|
42BC05FF2AC57E110044A9FE /* KlarnaStandaloneWebViewManager.mm in Sources */,
|
|
388
420
|
792F67C12AB8AD7D00675E18 /* PaymentViewWrapper.mm in Sources */,
|
|
389
421
|
);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#import "KlarnaCheckoutViewManager.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTUIManager.h>
|
|
4
|
+
#import <React/RCTLog.h>
|
|
5
|
+
|
|
6
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
7
|
+
#import "view/newarch/KlarnaCheckoutViewWrapper.h"
|
|
8
|
+
#else
|
|
9
|
+
#import "view/oldarch/KlarnaCheckoutViewWrapper.h"
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
@implementation KlarnaCheckoutViewManager
|
|
13
|
+
|
|
14
|
+
RCT_EXPORT_MODULE(RNKlarnaCheckoutView)
|
|
15
|
+
|
|
16
|
+
#pragma mark - View
|
|
17
|
+
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(returnUrl, NSString)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(onEvent, RCTDirectEventBlock)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
|
|
21
|
+
RCT_EXPORT_VIEW_PROPERTY(onResized, RCTDirectEventBlock)
|
|
22
|
+
|
|
23
|
+
- (UIView *)view
|
|
24
|
+
{
|
|
25
|
+
KlarnaCheckoutViewWrapper* wrapper = [KlarnaCheckoutViewWrapper new];
|
|
26
|
+
wrapper.uiManager = self.bridge.uiManager;
|
|
27
|
+
return wrapper;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#pragma mark - Exported Methods
|
|
31
|
+
|
|
32
|
+
RCT_EXPORT_METHOD(setSnippet:(nonnull NSNumber*)reactTag snippet:(NSString*)snippet) {
|
|
33
|
+
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
34
|
+
KlarnaCheckoutViewWrapper* view = (KlarnaCheckoutViewWrapper*) viewRegistry[reactTag];
|
|
35
|
+
if (!view || ![view isKindOfClass:KlarnaCheckoutViewWrapper.class]) {
|
|
36
|
+
RCTLogError(@"Can't find KlarnaCheckoutViewWrapper with tag #%@", reactTag);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
[view setSnippet:snippet];
|
|
40
|
+
}];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
RCT_EXPORT_METHOD(suspend:(nonnull NSNumber*)reactTag) {
|
|
44
|
+
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
45
|
+
KlarnaCheckoutViewWrapper* view = (KlarnaCheckoutViewWrapper*) viewRegistry[reactTag];
|
|
46
|
+
if (!view || ![view isKindOfClass:KlarnaCheckoutViewWrapper.class]) {
|
|
47
|
+
RCTLogError(@"Can't find KlarnaCheckoutViewWrapper with tag #%@", reactTag);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
[view suspend];
|
|
51
|
+
}];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
RCT_EXPORT_METHOD(resume:(nonnull NSNumber*)reactTag) {
|
|
55
|
+
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
56
|
+
KlarnaCheckoutViewWrapper* view = (KlarnaCheckoutViewWrapper*) viewRegistry[reactTag];
|
|
57
|
+
if (!view || ![view isKindOfClass:KlarnaCheckoutViewWrapper.class]) {
|
|
58
|
+
RCTLogError(@"Can't find KlarnaCheckoutViewWrapper with tag #%@", reactTag);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
[view resume];
|
|
62
|
+
}];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#import "RNMobileSDKUtils.h"
|
|
2
|
+
|
|
3
|
+
@implementation SerializationUtil
|
|
4
|
+
|
|
5
|
+
+ (id)serializeDictionaryToJsonString:(id)dictionary {
|
|
6
|
+
if (!dictionary) {
|
|
7
|
+
NSLog(@"Dictionary is nil");
|
|
8
|
+
return @"{}";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
NSError *error;
|
|
12
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&error];
|
|
13
|
+
|
|
14
|
+
if (!jsonData) {
|
|
15
|
+
return @"{}";
|
|
16
|
+
} else {
|
|
17
|
+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
18
|
+
return jsonString;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#if RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import <React/RCTUIManager.h>
|
|
4
|
+
#import <React/RCTViewComponentView.h>
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
8
|
+
|
|
9
|
+
@interface KlarnaCheckoutViewWrapper : RCTViewComponentView
|
|
10
|
+
|
|
11
|
+
#pragma mark - React Native Overrides
|
|
12
|
+
|
|
13
|
+
@property (nonatomic, weak) RCTUIManager* uiManager;
|
|
14
|
+
|
|
15
|
+
- (void)setSnippet:(NSString*)snippet;
|
|
16
|
+
|
|
17
|
+
- (void)suspend;
|
|
18
|
+
|
|
19
|
+
- (void)resume;
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
NS_ASSUME_NONNULL_END
|
|
25
|
+
|
|
26
|
+
#endif
|