react-native-klarna-inapp-sdk 2.1.12 → 2.2.0
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 +100 -270
- package/android/build.gradle +85 -107
- package/android/gradle.properties +7 -0
- package/android/src/main/AndroidManifest.xml +2 -1
- package/android/src/main/AndroidManifestNew.xml +4 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +33 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ArgumentsUtil.java +62 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +100 -0
- package/android/src/main/java/com/klarna/{inapp/sdk → mobile/sdk/reactnative/payments}/KlarnaPaymentEvent.java +9 -19
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/KlarnaPaymentViewManager.java +346 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/PaymentViewWrapper.java +78 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEvent.java +67 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEventSender.java +139 -0
- package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewManager.java +205 -0
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaPaymentViewSpec.java +32 -0
- package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaStandaloneWebViewSpec.java +33 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaPaymentViewSpec.java +25 -0
- package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaStandaloneWebViewSpec.java +19 -0
- package/android/src/test/java/com/klarna/{inapp/sdk/KlarnaPaymentViewPackageTest.java → mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java} +9 -4
- package/android/src/test/java/com/klarna/{inapp/sdk → mobile/sdk/reactnative/payments}/KlarnaPaymentEventTest.java +17 -20
- package/android/src/test/java/com/klarna/{inapp/sdk → mobile/sdk/reactnative/payments}/KlarnaPaymentViewManagerTest.java +72 -29
- package/ios/{KlarnaInAppSDK.xcodeproj → RNKlarnaMobileSDK.xcodeproj}/project.pbxproj +147 -87
- package/ios/{KlarnaInAppSDK.xcodeproj/xcshareddata/xcschemes/KlarnaInAppSDK.xcscheme → RNKlarnaMobileSDK.xcodeproj/xcshareddata/xcschemes/RNKlarnaMobileSDK.xcscheme} +9 -9
- package/ios/{KlarnaInAppSDK.xcodeproj/xcshareddata/xcschemes/KlarnaInAppSDKTests.xcscheme → RNKlarnaMobileSDK.xcodeproj/xcshareddata/xcschemes/RNKlarnaMobileSDKTests.xcscheme} +3 -3
- package/ios/Sources/KlarnaPaymentViewManager.h +5 -0
- package/ios/Sources/{KlarnaPaymentView.m → KlarnaPaymentViewManager.mm} +10 -15
- package/ios/Sources/KlarnaStandaloneWebViewManager.h +5 -0
- package/ios/Sources/KlarnaStandaloneWebViewManager.mm +77 -0
- package/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.h +29 -0
- package/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +265 -0
- package/ios/Sources/view/newarch/PaymentViewWrapper.h +33 -0
- package/ios/Sources/view/newarch/PaymentViewWrapper.mm +240 -0
- package/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.h +42 -0
- package/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +195 -0
- package/ios/Sources/view/{PaymentViewWrapper.h → oldarch/PaymentViewWrapper.h} +9 -7
- package/ios/Sources/view/{PaymentViewWrapper.m → oldarch/PaymentViewWrapper.mm} +40 -27
- package/ios/Tests/PaymentViewWrapperTests.m +8 -10
- package/lib/commonjs/KlarnaPaymentView.js +192 -0
- package/lib/commonjs/KlarnaPaymentView.js.map +1 -0
- package/lib/commonjs/KlarnaStandaloneWebView.js +81 -0
- package/lib/commonjs/KlarnaStandaloneWebView.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/specs/KlarnaPaymentViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KlarnaPaymentViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/KlarnaStandaloneWebViewNativeComponent.js +16 -0
- package/lib/commonjs/specs/KlarnaStandaloneWebViewNativeComponent.js.map +1 -0
- package/lib/module/KlarnaPaymentView.js +182 -0
- package/lib/module/KlarnaPaymentView.js.map +1 -0
- package/lib/module/KlarnaStandaloneWebView.js +71 -0
- package/lib/module/KlarnaStandaloneWebView.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/KlarnaPaymentViewNativeComponent.js +7 -0
- package/lib/module/specs/KlarnaPaymentViewNativeComponent.js.map +1 -0
- package/lib/module/specs/KlarnaStandaloneWebViewNativeComponent.js +7 -0
- package/lib/module/specs/KlarnaStandaloneWebViewNativeComponent.js.map +1 -0
- package/lib/typescript/KlarnaPaymentView.d.ts +51 -0
- package/lib/typescript/KlarnaPaymentView.d.ts.map +1 -0
- package/lib/typescript/KlarnaStandaloneWebView.d.ts +46 -0
- package/lib/typescript/KlarnaStandaloneWebView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/KlarnaPaymentViewNativeComponent.d.ts +49 -0
- package/lib/typescript/specs/KlarnaPaymentViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/KlarnaStandaloneWebViewNativeComponent.d.ts +65 -0
- package/lib/typescript/specs/KlarnaStandaloneWebViewNativeComponent.d.ts.map +1 -0
- package/package.json +92 -16
- package/react-native-klarna-inapp-sdk.podspec +32 -13
- package/src/KlarnaPaymentView.tsx +323 -0
- package/src/KlarnaStandaloneWebView.tsx +217 -0
- package/src/index.tsx +2 -0
- package/src/specs/KlarnaPaymentViewNativeComponent.ts +99 -0
- package/src/specs/KlarnaStandaloneWebViewNativeComponent.ts +96 -0
- package/.gitattributes +0 -3
- package/CHANGELOG.md +0 -111
- package/android/README.md +0 -14
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradlew +0 -172
- package/android/gradlew.bat +0 -84
- package/android/src/main/java/com/klarna/inapp/sdk/HeightListener.java +0 -159
- package/android/src/main/java/com/klarna/inapp/sdk/KlarnaPaymentViewManager.java +0 -282
- package/android/src/main/java/com/klarna/inapp/sdk/KlarnaPaymentViewPackage.java +0 -25
- package/android/src/main/java/com/klarna/inapp/sdk/Mappable.java +0 -10
- package/android/src/main/java/com/klarna/inapp/sdk/MappableKlarnaPaymentsSDKError.java +0 -31
- package/android/src/main/java/com/klarna/inapp/sdk/PaymentViewWrapper.java +0 -131
- package/android/src/test/java/com/klarna/inapp/sdk/MappableKlarnaPaymentsSDKErrorTest.java +0 -45
- package/index.js +0 -72
- package/integration-tests/build.gradle +0 -59
- package/integration-tests/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/integration-tests/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/integration-tests/gradlew +0 -172
- package/integration-tests/gradlew.bat +0 -84
- package/integration-tests/settings.gradle +0 -2
- package/integration-tests/src/test/resources/junit-platform.properties +0 -4
- package/ios/KlarnaInAppSDK.xcworkspace/contents.xcworkspacedata +0 -10
- package/ios/KlarnaInAppSDK.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Podfile +0 -73
- package/ios/Sources/KlarnaPaymentView.h +0 -5
- package/scripts/examples_postinstall.js +0 -111
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
package com.klarna.inapp.sdk;
|
|
2
|
-
|
|
3
|
-
import android.app.Application;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
7
|
-
import com.facebook.react.common.MapBuilder;
|
|
8
|
-
import com.facebook.react.uimanager.SimpleViewManager;
|
|
9
|
-
import com.facebook.react.uimanager.ThemedReactContext;
|
|
10
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
11
|
-
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
12
|
-
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
13
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentView;
|
|
14
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentViewCallback;
|
|
15
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentsSDKError;
|
|
16
|
-
|
|
17
|
-
import org.jetbrains.annotations.NotNull;
|
|
18
|
-
|
|
19
|
-
import java.lang.ref.WeakReference;
|
|
20
|
-
import java.util.HashMap;
|
|
21
|
-
import java.util.Map;
|
|
22
|
-
|
|
23
|
-
import javax.annotation.Nonnull;
|
|
24
|
-
import javax.annotation.Nullable;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Wraps the Payment Views being exposed to JS.
|
|
28
|
-
*/
|
|
29
|
-
public class KlarnaPaymentViewManager extends SimpleViewManager<PaymentViewWrapper> implements KlarnaPaymentViewCallback {
|
|
30
|
-
|
|
31
|
-
// Commands that can be triggered from RN
|
|
32
|
-
public static final int COMMAND_INITIALIZE = 1;
|
|
33
|
-
public static final int COMMAND_LOAD = 2;
|
|
34
|
-
public static final int COMMAND_LOAD_PAYMENT_REVIEW = 3;
|
|
35
|
-
public static final int COMMAND_AUTHORIZE = 4;
|
|
36
|
-
public static final int COMMAND_REAUTHORIZE = 5;
|
|
37
|
-
public static final int COMMAND_FINALIZE = 6;
|
|
38
|
-
|
|
39
|
-
public static final String REACT_CLASS = "KlarnaPaymentView";
|
|
40
|
-
|
|
41
|
-
private final ReactApplicationContext reactAppContext;
|
|
42
|
-
|
|
43
|
-
// Store a list of views to event dispatchers so we send up events via the right views.
|
|
44
|
-
private Map<WeakReference<PaymentViewWrapper>, EventDispatcher> viewToDispatcher;
|
|
45
|
-
|
|
46
|
-
KlarnaPaymentViewManager(ReactApplicationContext reactApplicationContext, Application app) {
|
|
47
|
-
super();
|
|
48
|
-
this.viewToDispatcher = new HashMap<>();
|
|
49
|
-
this.reactAppContext = reactApplicationContext;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Override
|
|
53
|
-
public String getName() {
|
|
54
|
-
return REACT_CLASS;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@Override
|
|
58
|
-
public PaymentViewWrapper createViewInstance(ThemedReactContext context) {
|
|
59
|
-
PaymentViewWrapper view = new PaymentViewWrapper(reactAppContext, null);
|
|
60
|
-
|
|
61
|
-
// Each view has its own event dispatcher.
|
|
62
|
-
EventDispatcher dispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
63
|
-
viewToDispatcher.put(new WeakReference<>(view), dispatcher);
|
|
64
|
-
|
|
65
|
-
return view;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Commads are methods that RN will expose on the JS side for a view. They can be called via
|
|
70
|
-
* `UIManager.dispatchViewManagerCommand` from react.
|
|
71
|
-
*
|
|
72
|
-
* @return a map of command names to command IDs
|
|
73
|
-
*/
|
|
74
|
-
@Nullable
|
|
75
|
-
@Override
|
|
76
|
-
public Map<String, Integer> getCommandsMap() {
|
|
77
|
-
return MapBuilder.of(
|
|
78
|
-
"initialize", COMMAND_INITIALIZE,
|
|
79
|
-
"load", COMMAND_LOAD,
|
|
80
|
-
"loadPaymentReview", COMMAND_LOAD_PAYMENT_REVIEW,
|
|
81
|
-
"authorize", COMMAND_AUTHORIZE,
|
|
82
|
-
"reauthorize", COMMAND_REAUTHORIZE,
|
|
83
|
-
"finalize", COMMAND_FINALIZE
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Handles commands received from RN to a specific view.
|
|
89
|
-
*
|
|
90
|
-
* @param root
|
|
91
|
-
* @param commandId
|
|
92
|
-
* @param args
|
|
93
|
-
*/
|
|
94
|
-
@Override
|
|
95
|
-
public void receiveCommand(@Nonnull PaymentViewWrapper root, int commandId, @Nullable ReadableArray args) {
|
|
96
|
-
String sessionData = null;
|
|
97
|
-
|
|
98
|
-
switch (commandId) {
|
|
99
|
-
case COMMAND_INITIALIZE:
|
|
100
|
-
if (args != null) {
|
|
101
|
-
final String token = args.getString(0);
|
|
102
|
-
final String returnUrl = args.getString(1);
|
|
103
|
-
|
|
104
|
-
if (token != null && returnUrl != null) {
|
|
105
|
-
root.paymentView.initialize(token, returnUrl);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
|
|
110
|
-
case COMMAND_LOAD:
|
|
111
|
-
if (args != null) {
|
|
112
|
-
sessionData = args.getString(0);
|
|
113
|
-
}
|
|
114
|
-
root.load(sessionData);
|
|
115
|
-
break;
|
|
116
|
-
|
|
117
|
-
case COMMAND_LOAD_PAYMENT_REVIEW:
|
|
118
|
-
root.paymentView.loadPaymentReview();
|
|
119
|
-
break;
|
|
120
|
-
|
|
121
|
-
case COMMAND_AUTHORIZE:
|
|
122
|
-
if (args != null) {
|
|
123
|
-
final boolean autoFinalize = args.getBoolean(0);
|
|
124
|
-
sessionData = args.getString(1);
|
|
125
|
-
|
|
126
|
-
root.paymentView.authorize(autoFinalize, sessionData);
|
|
127
|
-
}
|
|
128
|
-
break;
|
|
129
|
-
|
|
130
|
-
case COMMAND_REAUTHORIZE:
|
|
131
|
-
if (args != null) {
|
|
132
|
-
sessionData = args.getString(0);
|
|
133
|
-
}
|
|
134
|
-
root.paymentView.reauthorize(sessionData);
|
|
135
|
-
break;
|
|
136
|
-
|
|
137
|
-
case COMMAND_FINALIZE:
|
|
138
|
-
if (args != null) {
|
|
139
|
-
sessionData = args.getString(0);
|
|
140
|
-
}
|
|
141
|
-
root.paymentView.finalize(sessionData);
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Exposes direct event types that will be accessible as prop "callbacks" from RN.
|
|
148
|
-
*
|
|
149
|
-
* Structure must follow:
|
|
150
|
-
* { "<eventName>": {"registrationName": "<eventName>"} }
|
|
151
|
-
*/
|
|
152
|
-
@Nullable
|
|
153
|
-
@Override
|
|
154
|
-
public Map getExportedCustomDirectEventTypeConstants() {
|
|
155
|
-
return MapBuilder.of(
|
|
156
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_INITIALIZE, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_INITIALIZE),
|
|
157
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_LOAD, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_LOAD),
|
|
158
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_LOAD_PAYMENT_REVIEW, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_LOAD_PAYMENT_REVIEW),
|
|
159
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_AUTHORIZE, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_AUTHORIZE),
|
|
160
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_REAUTHORIZE, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_REAUTHORIZE),
|
|
161
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_FINALIZE, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_FINALIZE),
|
|
162
|
-
KlarnaPaymentEvent.EVENT_NAME_ON_ERROR, MapBuilder.of("registrationName", KlarnaPaymentEvent.EVENT_NAME_ON_ERROR)
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Payment View's payment method category (e.g: "pay_later", "pay_over_time").
|
|
168
|
-
*
|
|
169
|
-
* @param view
|
|
170
|
-
* @param category
|
|
171
|
-
*/
|
|
172
|
-
@ReactProp(name = "category")
|
|
173
|
-
public void setCategory(PaymentViewWrapper view, String category) {
|
|
174
|
-
view.paymentView.registerPaymentViewCallback(this);
|
|
175
|
-
view.paymentView.setCategory(category);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Creates an event from event name and a map of params. Sends it via the right dispatcher.
|
|
180
|
-
* @param eventName
|
|
181
|
-
* @param additionalParams
|
|
182
|
-
* @param view
|
|
183
|
-
*/
|
|
184
|
-
private void postEventForView(String eventName, Map additionalParams, KlarnaPaymentView view) {
|
|
185
|
-
PaymentViewWrapper wrapper = wrapperForPaymentView(view);
|
|
186
|
-
EventDispatcher foundDispatcher = null;
|
|
187
|
-
for (WeakReference<PaymentViewWrapper> wrapperRef : viewToDispatcher.keySet()) {
|
|
188
|
-
if (wrapperRef.get() == wrapper) {
|
|
189
|
-
foundDispatcher = viewToDispatcher.get(wrapperRef);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
KlarnaPaymentEvent event = new KlarnaPaymentEvent(wrapper.getId(), eventName, additionalParams);
|
|
194
|
-
foundDispatcher.dispatchEvent(event);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Calls requestLayout on the wrapper to fetch height of the contents.
|
|
199
|
-
* @param view
|
|
200
|
-
*/
|
|
201
|
-
private void requestLayout(KlarnaPaymentView view) {
|
|
202
|
-
if (view != null) {
|
|
203
|
-
PaymentViewWrapper wrapper = wrapperForPaymentView(view);
|
|
204
|
-
if (wrapper != null) {
|
|
205
|
-
wrapper.requestLayout();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
/* -- KlarnaPaymentView callback methods -- */
|
|
212
|
-
|
|
213
|
-
@Override
|
|
214
|
-
public void onInitialized(@NotNull KlarnaPaymentView paymentView) {
|
|
215
|
-
requestLayout(paymentView);
|
|
216
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_INITIALIZE, null, paymentView);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
@Override
|
|
220
|
-
public void onLoaded(@NotNull KlarnaPaymentView paymentView) {
|
|
221
|
-
requestLayout(paymentView);
|
|
222
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_LOAD, null, paymentView);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
@Override
|
|
226
|
-
public void onLoadPaymentReview(@NotNull KlarnaPaymentView paymentView, boolean b) {
|
|
227
|
-
requestLayout(paymentView);
|
|
228
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_LOAD_PAYMENT_REVIEW, null, paymentView);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
@Override
|
|
232
|
-
public void onAuthorized(@NotNull KlarnaPaymentView paymentView, boolean approved, @org.jetbrains.annotations.Nullable String authToken, @org.jetbrains.annotations.Nullable Boolean finalizeRequired) {
|
|
233
|
-
requestLayout(paymentView);
|
|
234
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_AUTHORIZE,
|
|
235
|
-
MapBuilder.<String, Object>of(
|
|
236
|
-
"approved", approved,
|
|
237
|
-
"authToken", authToken,
|
|
238
|
-
"finalizeRequired", finalizeRequired),
|
|
239
|
-
paymentView);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
@Override
|
|
243
|
-
public void onReauthorized(@NotNull KlarnaPaymentView paymentView, boolean approved, @org.jetbrains.annotations.Nullable String authToken) {
|
|
244
|
-
requestLayout(paymentView);
|
|
245
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_REAUTHORIZE,
|
|
246
|
-
MapBuilder.<String, Object>of(
|
|
247
|
-
"approved", approved,
|
|
248
|
-
"authToken", authToken),
|
|
249
|
-
paymentView);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
@Override
|
|
253
|
-
public void onFinalized(@NotNull KlarnaPaymentView paymentView, boolean approved, @org.jetbrains.annotations.Nullable String authToken) {
|
|
254
|
-
requestLayout(paymentView);
|
|
255
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_FINALIZE,
|
|
256
|
-
MapBuilder.<String, Object>of(
|
|
257
|
-
"approved", approved,
|
|
258
|
-
"authToken", authToken),
|
|
259
|
-
paymentView);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
@Override
|
|
263
|
-
public void onErrorOccurred(@NotNull KlarnaPaymentView klarnaPaymentView, @NotNull KlarnaPaymentsSDKError klarnaPaymentsSDKError) {
|
|
264
|
-
requestLayout(klarnaPaymentView);
|
|
265
|
-
MappableKlarnaPaymentsSDKError sdkError = new MappableKlarnaPaymentsSDKError(klarnaPaymentsSDKError);
|
|
266
|
-
postEventForView(KlarnaPaymentEvent.EVENT_NAME_ON_ERROR,
|
|
267
|
-
MapBuilder.<String, Object>of("error", sdkError.buildMap()),
|
|
268
|
-
klarnaPaymentView);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
private PaymentViewWrapper wrapperForPaymentView(KlarnaPaymentView paymentView) {
|
|
272
|
-
for (WeakReference<PaymentViewWrapper> reference : viewToDispatcher.keySet()) {
|
|
273
|
-
PaymentViewWrapper wrapper = reference.get();
|
|
274
|
-
|
|
275
|
-
if (wrapper != null && wrapper.paymentView == paymentView) {
|
|
276
|
-
return wrapper;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.klarna.inapp.sdk;
|
|
2
|
-
|
|
3
|
-
import android.app.Application;
|
|
4
|
-
|
|
5
|
-
import java.util.Arrays;
|
|
6
|
-
import java.util.Collections;
|
|
7
|
-
import java.util.List;
|
|
8
|
-
|
|
9
|
-
import com.facebook.react.ReactPackage;
|
|
10
|
-
import com.facebook.react.bridge.NativeModule;
|
|
11
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
13
|
-
|
|
14
|
-
public class KlarnaPaymentViewPackage implements ReactPackage {
|
|
15
|
-
|
|
16
|
-
@Override
|
|
17
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
18
|
-
return Collections.emptyList();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Override
|
|
22
|
-
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
23
|
-
return Arrays.<ViewManager>asList(new KlarnaPaymentViewManager(reactContext, (Application) reactContext.getApplicationContext()));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
package com.klarna.inapp.sdk;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.common.MapBuilder;
|
|
6
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentsSDKError;
|
|
7
|
-
|
|
8
|
-
import java.util.Map;
|
|
9
|
-
|
|
10
|
-
class MappableKlarnaPaymentsSDKError implements Mappable {
|
|
11
|
-
|
|
12
|
-
@NonNull
|
|
13
|
-
private KlarnaPaymentsSDKError klarnaPaymentsSDKError;
|
|
14
|
-
|
|
15
|
-
MappableKlarnaPaymentsSDKError(@NonNull KlarnaPaymentsSDKError klarnaPaymentsSDKError) {
|
|
16
|
-
this.klarnaPaymentsSDKError = klarnaPaymentsSDKError;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@NonNull
|
|
20
|
-
@Override
|
|
21
|
-
public Map<String, Object> buildMap() {
|
|
22
|
-
return MapBuilder.<String, Object>builder()
|
|
23
|
-
.put("action", klarnaPaymentsSDKError.getAction())
|
|
24
|
-
.put("isFatal", klarnaPaymentsSDKError.isFatal())
|
|
25
|
-
.put("message", klarnaPaymentsSDKError.getMessage())
|
|
26
|
-
.put("name", klarnaPaymentsSDKError.getName())
|
|
27
|
-
.put("invalidFields", klarnaPaymentsSDKError.getInvalidFields())
|
|
28
|
-
.put("sessionId", klarnaPaymentsSDKError.getSessionId())
|
|
29
|
-
.build();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
package com.klarna.inapp.sdk;
|
|
2
|
-
|
|
3
|
-
import android.util.AttributeSet;
|
|
4
|
-
import android.view.View;
|
|
5
|
-
import android.webkit.WebView;
|
|
6
|
-
import android.widget.LinearLayout;
|
|
7
|
-
|
|
8
|
-
import com.facebook.react.bridge.GuardedRunnable;
|
|
9
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
11
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentView;
|
|
12
|
-
|
|
13
|
-
/***
|
|
14
|
-
* Wraps the KlarnaPaymentView so we can see when a requestLayout() has been triggered.
|
|
15
|
-
*/
|
|
16
|
-
public class PaymentViewWrapper extends LinearLayout implements HeightListener.HeightListenerCallback {
|
|
17
|
-
private float displayDensity = 1;
|
|
18
|
-
public KlarnaPaymentView paymentView;
|
|
19
|
-
private boolean loadCalled = false;
|
|
20
|
-
private HeightListener heightListener;
|
|
21
|
-
|
|
22
|
-
public PaymentViewWrapper(ReactApplicationContext context, AttributeSet attrs) {
|
|
23
|
-
super(context, attrs);
|
|
24
|
-
// Get density for resizing.
|
|
25
|
-
displayDensity = context.getResources().getDisplayMetrics().density;
|
|
26
|
-
// Add KlarnaPaymentView
|
|
27
|
-
LinearLayout.LayoutParams webViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
28
|
-
paymentView = new KlarnaPaymentView(getReactAppContext().getCurrentActivity(), attrs); // Insure we use activity and not application context for dialogs.
|
|
29
|
-
addView(paymentView, webViewParams);
|
|
30
|
-
heightListener = new HeightListener(getPaymentViewWebView(), this);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public void load(String sessionData) {
|
|
34
|
-
paymentView.load(sessionData);
|
|
35
|
-
loadCalled = true;
|
|
36
|
-
heightListener.injectListener(getPaymentViewWebView());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@Override
|
|
40
|
-
public void requestLayout() {
|
|
41
|
-
super.requestLayout();
|
|
42
|
-
if (isReady() && loadCalled) {
|
|
43
|
-
heightListener.fetchHeight(getPaymentViewWebView());
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The web view inside the KlarnaPaymentView will trigger requestLayout(), but there is no way
|
|
49
|
-
* to get the KlarnaPaymentView's correct height.
|
|
50
|
-
* <p>
|
|
51
|
-
* Attempts include:
|
|
52
|
-
* - Using Android's measure() and co. methods
|
|
53
|
-
* - Getting the WebView's getContentHeight()
|
|
54
|
-
* - Using a variety of layout listeners.
|
|
55
|
-
* <p>
|
|
56
|
-
* So instead we're:
|
|
57
|
-
* 1. Evaluating some JS (yes, making things even more fragile).
|
|
58
|
-
* 2. Triggering a size change via the UIManagerModule. This will effectively apply a fixed size
|
|
59
|
-
* via width and height style attributes on the React side of things.
|
|
60
|
-
* <p>
|
|
61
|
-
* Note: We can apply style by setting props with uimm.updateView() to just set a height (and
|
|
62
|
-
* no width), but it doesn't update immediately or with the right height.
|
|
63
|
-
* <p>
|
|
64
|
-
* The width will be whatever the parent component's width is.
|
|
65
|
-
*/
|
|
66
|
-
private void setHeight(String height) {
|
|
67
|
-
if (height == null || height.equals("null") || height.equals("undefined")) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
final int width = getParentViewWidth();
|
|
72
|
-
final float contentHeight = Float.parseFloat(height);
|
|
73
|
-
final float scaledHeight = contentHeight * displayDensity;
|
|
74
|
-
getReactAppContext().runOnNativeModulesQueueThread(new GuardedRunnable(getReactAppContext()) {
|
|
75
|
-
@Override
|
|
76
|
-
public void runGuarded() {
|
|
77
|
-
UIManagerModule uimm = getReactAppContext().getNativeModule(UIManagerModule.class);
|
|
78
|
-
uimm.updateNodeSize(getId(), width, (int) scaledHeight);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
} catch (Throwable t) {
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Returns true if the payment view is part of the hierarchy (the first requestLayout() is
|
|
87
|
-
* triggered before) and the whole view is part of the RN hierarchy.
|
|
88
|
-
*
|
|
89
|
-
* @return true if ready
|
|
90
|
-
*/
|
|
91
|
-
private boolean isReady() {
|
|
92
|
-
return paymentView != null && getId() != -1;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Returns the parent view's width.
|
|
97
|
-
*/
|
|
98
|
-
private int getParentViewWidth() {
|
|
99
|
-
View parentReactView = (View) getParent();
|
|
100
|
-
if (parentReactView == null || !(parentReactView instanceof View)) {
|
|
101
|
-
return 0;
|
|
102
|
-
}
|
|
103
|
-
return parentReactView.getWidth();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Attempts to retrieve the web view from within the KlarnaPaymentView. This is really fragile.
|
|
108
|
-
*/
|
|
109
|
-
private WebView getPaymentViewWebView() {
|
|
110
|
-
for (int i = 0; i < paymentView.getChildCount(); i++) {
|
|
111
|
-
View child = paymentView.getChildAt(i);
|
|
112
|
-
|
|
113
|
-
if (child instanceof WebView) {
|
|
114
|
-
return (WebView) child;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Returns the app context the wrapper was initialized with.
|
|
122
|
-
*/
|
|
123
|
-
private ReactApplicationContext getReactAppContext() {
|
|
124
|
-
return (ReactApplicationContext) getContext();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
@Override
|
|
128
|
-
public void onNewHeight(String value) {
|
|
129
|
-
setHeight(value);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
package com.klarna.inapp.sdk;
|
|
2
|
-
|
|
3
|
-
import com.klarna.mobile.sdk.api.payments.KlarnaPaymentsSDKError;
|
|
4
|
-
|
|
5
|
-
import org.junit.Assert;
|
|
6
|
-
import org.junit.Test;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.Collection;
|
|
10
|
-
import java.util.Collections;
|
|
11
|
-
import java.util.Map;
|
|
12
|
-
|
|
13
|
-
public class MappableKlarnaPaymentsSDKErrorTest {
|
|
14
|
-
|
|
15
|
-
@Test
|
|
16
|
-
public void testMapFieldsAndValues() {
|
|
17
|
-
KlarnaPaymentsSDKError error = new KlarnaPaymentsSDKError(
|
|
18
|
-
"testName",
|
|
19
|
-
"testMessage",
|
|
20
|
-
false,
|
|
21
|
-
"testAction",
|
|
22
|
-
Collections.singletonList("testInvalidField"),
|
|
23
|
-
"testSessionId"
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
MappableKlarnaPaymentsSDKError writableError = new MappableKlarnaPaymentsSDKError(error);
|
|
27
|
-
|
|
28
|
-
Map map = writableError.buildMap();
|
|
29
|
-
|
|
30
|
-
Assert.assertEquals("testName", map.get("name"));
|
|
31
|
-
Assert.assertEquals("testMessage", map.get("message"));
|
|
32
|
-
Assert.assertEquals(false, map.get("isFatal"));
|
|
33
|
-
Assert.assertEquals("testAction", map.get("action"));
|
|
34
|
-
|
|
35
|
-
Object inv = map.get("invalidFields");
|
|
36
|
-
Assert.assertTrue(inv instanceof Collection);
|
|
37
|
-
Collection invalidFields = (Collection) inv;
|
|
38
|
-
|
|
39
|
-
Assert.assertNotNull(invalidFields);
|
|
40
|
-
Assert.assertEquals(1, invalidFields.size());
|
|
41
|
-
Assert.assertEquals("testInvalidField", new ArrayList(invalidFields).get(0));
|
|
42
|
-
|
|
43
|
-
Assert.assertEquals("testSessionId", map.get("sessionId"));
|
|
44
|
-
}
|
|
45
|
-
}
|
package/index.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React, {Component}from 'react';
|
|
2
|
-
import { requireNativeComponent, UIManager, findNodeHandle } from 'react-native';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
|
-
class KlarnaReactPaymentView extends Component {
|
|
6
|
-
|
|
7
|
-
render() {
|
|
8
|
-
return <KlarnaPaymentView {...this.props} />
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
initialize = (sessionToken, returnUrl) => {
|
|
12
|
-
UIManager.dispatchViewManagerCommand(
|
|
13
|
-
findNodeHandle(this),
|
|
14
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.initialize,
|
|
15
|
-
[sessionToken, returnUrl]
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
load = (sessionData) => {
|
|
20
|
-
UIManager.dispatchViewManagerCommand(
|
|
21
|
-
findNodeHandle(this),
|
|
22
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.load,
|
|
23
|
-
[sessionData || null]
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
loadPaymentReview = () => {
|
|
28
|
-
UIManager.dispatchViewManagerCommand(
|
|
29
|
-
findNodeHandle(this),
|
|
30
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.loadPaymentReview,
|
|
31
|
-
[]
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
authorize = (autoFinalize, sessionData) => {
|
|
36
|
-
UIManager.dispatchViewManagerCommand(
|
|
37
|
-
findNodeHandle(this),
|
|
38
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.authorize,
|
|
39
|
-
[autoFinalize || true, sessionData || null]
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
reauthorize = (sessionData) => {
|
|
44
|
-
UIManager.dispatchViewManagerCommand(
|
|
45
|
-
findNodeHandle(this),
|
|
46
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.reauthorize,
|
|
47
|
-
[sessionData || null]
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
finalize = (sessionData) => {
|
|
52
|
-
UIManager.dispatchViewManagerCommand(
|
|
53
|
-
findNodeHandle(this),
|
|
54
|
-
UIManager.getViewManagerConfig('KlarnaPaymentView').Commands.finalize,
|
|
55
|
-
[sessionData || null]
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
KlarnaReactPaymentView.propTypes = {
|
|
61
|
-
category: PropTypes.string,
|
|
62
|
-
onInitialized: PropTypes.func,
|
|
63
|
-
onLoaded: PropTypes.func,
|
|
64
|
-
onAuthorized: PropTypes.func,
|
|
65
|
-
onReauthorized: PropTypes.func,
|
|
66
|
-
onFinalized: PropTypes.func,
|
|
67
|
-
onError: PropTypes.func,
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const KlarnaPaymentView = requireNativeComponent('KlarnaPaymentView', KlarnaReactPaymentView);
|
|
71
|
-
|
|
72
|
-
export default KlarnaReactPaymentView;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
plugins {
|
|
2
|
-
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
group 'testapp.com'
|
|
6
|
-
version '1.0-SNAPSHOT'
|
|
7
|
-
|
|
8
|
-
java {
|
|
9
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
|
10
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
|
14
|
-
kotlinOptions {
|
|
15
|
-
jvmTarget = "1.8"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
test {
|
|
20
|
-
// system properties that are read from gradle input to run integration tests on Browserstack.
|
|
21
|
-
// tests will be executed on local Appium test if these properties are not provided
|
|
22
|
-
systemProperty 'browserstack.username', System.getProperty('browserstack.username')
|
|
23
|
-
systemProperty 'browserstack.password', System.getProperty('browserstack.password')
|
|
24
|
-
systemProperty 'build.name', System.getProperty('build.name')
|
|
25
|
-
systemProperty 'build.platform', System.getProperty('build.platform')
|
|
26
|
-
|
|
27
|
-
testLogging {
|
|
28
|
-
events "skipped", "failed", "passed"
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// JUnit 5
|
|
32
|
-
useJUnitPlatform {
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
repositories {
|
|
37
|
-
mavenCentral()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
dependencies {
|
|
41
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
|
|
42
|
-
testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
|
|
43
|
-
|
|
44
|
-
testImplementation 'io.appium:java-client:7.4.1'
|
|
45
|
-
testImplementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
|
|
46
|
-
|
|
47
|
-
testImplementation 'com.google.code.gson:gson:2.8.5'
|
|
48
|
-
testImplementation 'org.json:json:20200518'
|
|
49
|
-
testImplementation 'com.squareup.okhttp3:okhttp:3.12.1'
|
|
50
|
-
|
|
51
|
-
testImplementation 'org.apache.commons:commons-lang3:3.0'
|
|
52
|
-
|
|
53
|
-
// JUnit
|
|
54
|
-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
|
|
55
|
-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
|
56
|
-
implementation 'org.junit.platform:junit-platform-suite-engine:1.8.1'
|
|
57
|
-
testImplementation 'org.junit-pioneer:junit-pioneer:1.5.0'
|
|
58
|
-
testImplementation 'io.github.artsok:rerunner-jupiter:2.1.6'
|
|
59
|
-
}
|
|
Binary file
|