react-native-klarna-inapp-sdk 2.1.13 → 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 +84 -106
- 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 +86 -14
- 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/.watchmanconfig +0 -1
- package/.yarnrc +0 -5
- package/CHANGELOG.md +0 -116
- 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/babel.config.js +0 -3
- 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/bootstrap.js +0 -29
- package/src/index.js +0 -72
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import React, { Component, type RefObject } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
NativeMethods,
|
|
4
|
+
NativeSyntheticEvent,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import RNKlarnaPaymentView, {
|
|
8
|
+
RNKlarnaPaymentViewCommands,
|
|
9
|
+
type RNKlarnaPaymentViewProps,
|
|
10
|
+
} from './specs/KlarnaPaymentViewNativeComponent';
|
|
11
|
+
|
|
12
|
+
export interface KlarnaPaymentViewProps {
|
|
13
|
+
style: ViewStyle;
|
|
14
|
+
readonly category: string;
|
|
15
|
+
readonly returnUrl: string;
|
|
16
|
+
readonly onInitialized: () => void;
|
|
17
|
+
readonly onLoaded: () => void;
|
|
18
|
+
readonly onLoadedPaymentReview: () => void;
|
|
19
|
+
readonly onAuthorized: (
|
|
20
|
+
approved: boolean,
|
|
21
|
+
authToken: string | null,
|
|
22
|
+
finalizeRequired: boolean | null
|
|
23
|
+
) => void;
|
|
24
|
+
readonly onReauthorized: (
|
|
25
|
+
approved: boolean,
|
|
26
|
+
authToken: string | null
|
|
27
|
+
) => void;
|
|
28
|
+
readonly onFinalized: (approved: boolean, authToken: string | null) => void;
|
|
29
|
+
readonly onError: (error: KlarnaPaymentsSDKError) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface KlarnaReactPaymentViewOldProps {
|
|
33
|
+
style: ViewStyle;
|
|
34
|
+
readonly category: string;
|
|
35
|
+
readonly returnUrl?: string;
|
|
36
|
+
readonly onInitialized?: (event: any) => void;
|
|
37
|
+
readonly onLoaded?: (event: any) => void;
|
|
38
|
+
readonly onLoadedPaymentReview?: (event: any) => void;
|
|
39
|
+
readonly onAuthorized?: (event: any) => void;
|
|
40
|
+
readonly onReauthorized?: (event: any) => void;
|
|
41
|
+
readonly onFinalized?: (event: any) => void;
|
|
42
|
+
readonly onError?: (event: any) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type KlarnaPaymentViewPropsAny =
|
|
46
|
+
| KlarnaPaymentViewProps
|
|
47
|
+
| KlarnaReactPaymentViewOldProps;
|
|
48
|
+
|
|
49
|
+
interface KlarnaPaymentViewState {
|
|
50
|
+
nativeViewHeight: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class KlarnaPaymentView extends Component<
|
|
54
|
+
KlarnaPaymentViewPropsAny,
|
|
55
|
+
KlarnaPaymentViewState
|
|
56
|
+
> {
|
|
57
|
+
paymentViewRef: RefObject<
|
|
58
|
+
Component<RNKlarnaPaymentViewProps> & Readonly<NativeMethods>
|
|
59
|
+
>;
|
|
60
|
+
|
|
61
|
+
constructor(props: KlarnaPaymentViewPropsAny) {
|
|
62
|
+
super(props);
|
|
63
|
+
this.state = {
|
|
64
|
+
nativeViewHeight: 0,
|
|
65
|
+
};
|
|
66
|
+
this.paymentViewRef = React.createRef();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
render() {
|
|
70
|
+
return (
|
|
71
|
+
<RNKlarnaPaymentView
|
|
72
|
+
ref={this.paymentViewRef}
|
|
73
|
+
/* eslint-disable-next-line react-native/no-inline-styles */
|
|
74
|
+
style={{
|
|
75
|
+
width: '100%',
|
|
76
|
+
height: this.state.nativeViewHeight,
|
|
77
|
+
}}
|
|
78
|
+
category={this.props.category || ''}
|
|
79
|
+
returnUrl={this.props.returnUrl || ''}
|
|
80
|
+
onInitialized={(_event: NativeSyntheticEvent<any>) => {
|
|
81
|
+
if (this.props.onInitialized != null) {
|
|
82
|
+
/**
|
|
83
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
84
|
+
*/
|
|
85
|
+
if (
|
|
86
|
+
typeof this.props.onInitialized === 'function' &&
|
|
87
|
+
this.props.onInitialized.length === 1
|
|
88
|
+
) {
|
|
89
|
+
this.props.onInitialized(_event);
|
|
90
|
+
} else {
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
this.props.onInitialized();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}}
|
|
96
|
+
onLoaded={(_event: NativeSyntheticEvent<any>) => {
|
|
97
|
+
if (this.props.onLoaded != null) {
|
|
98
|
+
/**
|
|
99
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
100
|
+
*/
|
|
101
|
+
if (
|
|
102
|
+
typeof this.props.onLoaded === 'function' &&
|
|
103
|
+
this.props.onLoaded.length === 1
|
|
104
|
+
) {
|
|
105
|
+
this.props.onLoaded(_event);
|
|
106
|
+
} else {
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
this.props.onLoaded();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}}
|
|
112
|
+
onLoadedPaymentReview={(_event: NativeSyntheticEvent<any>) => {
|
|
113
|
+
if (this.props.onLoadedPaymentReview != null) {
|
|
114
|
+
/**
|
|
115
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
116
|
+
*/
|
|
117
|
+
if (
|
|
118
|
+
typeof this.props.onLoadedPaymentReview === 'function' &&
|
|
119
|
+
this.props.onLoadedPaymentReview.length === 1
|
|
120
|
+
) {
|
|
121
|
+
this.props.onLoadedPaymentReview(_event);
|
|
122
|
+
} else {
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
this.props.onLoadedPaymentReview();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}}
|
|
128
|
+
onAuthorized={(
|
|
129
|
+
event: NativeSyntheticEvent<
|
|
130
|
+
Readonly<{
|
|
131
|
+
readonly approved: boolean;
|
|
132
|
+
readonly authToken: string | null;
|
|
133
|
+
readonly finalizeRequired: boolean;
|
|
134
|
+
}>
|
|
135
|
+
>
|
|
136
|
+
) => {
|
|
137
|
+
if (this.props.onAuthorized != null) {
|
|
138
|
+
/**
|
|
139
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
140
|
+
*/
|
|
141
|
+
if (
|
|
142
|
+
typeof this.props.onAuthorized === 'function' &&
|
|
143
|
+
this.props.onAuthorized.length === 1
|
|
144
|
+
) {
|
|
145
|
+
// @ts-ignore
|
|
146
|
+
this.props.onAuthorized(event);
|
|
147
|
+
} else {
|
|
148
|
+
this.props.onAuthorized(
|
|
149
|
+
event.nativeEvent.approved,
|
|
150
|
+
event.nativeEvent.authToken === ''
|
|
151
|
+
? null
|
|
152
|
+
: event.nativeEvent.authToken,
|
|
153
|
+
event.nativeEvent.finalizeRequired
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}}
|
|
158
|
+
onReauthorized={(
|
|
159
|
+
event: NativeSyntheticEvent<
|
|
160
|
+
Readonly<{
|
|
161
|
+
readonly approved: boolean;
|
|
162
|
+
readonly authToken: string | null;
|
|
163
|
+
}>
|
|
164
|
+
>
|
|
165
|
+
) => {
|
|
166
|
+
if (this.props.onReauthorized != null) {
|
|
167
|
+
/**
|
|
168
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
169
|
+
*/
|
|
170
|
+
if (
|
|
171
|
+
typeof this.props.onReauthorized === 'function' &&
|
|
172
|
+
this.props.onReauthorized.length === 1
|
|
173
|
+
) {
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
this.props.onReauthorized(event);
|
|
176
|
+
} else {
|
|
177
|
+
this.props.onReauthorized(
|
|
178
|
+
event.nativeEvent.approved,
|
|
179
|
+
event.nativeEvent.authToken === ''
|
|
180
|
+
? null
|
|
181
|
+
: event.nativeEvent.authToken
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}}
|
|
186
|
+
onFinalized={(
|
|
187
|
+
event: NativeSyntheticEvent<
|
|
188
|
+
Readonly<{
|
|
189
|
+
readonly approved: boolean;
|
|
190
|
+
readonly authToken: string | null;
|
|
191
|
+
}>
|
|
192
|
+
>
|
|
193
|
+
) => {
|
|
194
|
+
if (this.props.onFinalized != null) {
|
|
195
|
+
/**
|
|
196
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
197
|
+
*/
|
|
198
|
+
if (
|
|
199
|
+
typeof this.props.onFinalized === 'function' &&
|
|
200
|
+
this.props.onFinalized.length === 1
|
|
201
|
+
) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
this.props.onFinalized(event);
|
|
204
|
+
} else {
|
|
205
|
+
this.props.onFinalized(
|
|
206
|
+
event.nativeEvent.approved,
|
|
207
|
+
event.nativeEvent.authToken === ''
|
|
208
|
+
? null
|
|
209
|
+
: event.nativeEvent.authToken
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}}
|
|
214
|
+
onError={(
|
|
215
|
+
event: NativeSyntheticEvent<
|
|
216
|
+
Readonly<{
|
|
217
|
+
readonly error: Readonly<{
|
|
218
|
+
readonly action: string;
|
|
219
|
+
readonly isFatal: boolean;
|
|
220
|
+
readonly message: string;
|
|
221
|
+
readonly name: string;
|
|
222
|
+
// readonly invalidFields: Array<string>;
|
|
223
|
+
readonly sessionId: string;
|
|
224
|
+
}>;
|
|
225
|
+
}>
|
|
226
|
+
>
|
|
227
|
+
) => {
|
|
228
|
+
if (this.props.onError != null) {
|
|
229
|
+
/**
|
|
230
|
+
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
|
|
231
|
+
*/
|
|
232
|
+
if (
|
|
233
|
+
typeof this.props.onAuthorized === 'function' &&
|
|
234
|
+
this.props.onAuthorized.length === 1
|
|
235
|
+
) {
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
this.props.onError(event);
|
|
238
|
+
} else {
|
|
239
|
+
this.props.onError(event.nativeEvent.error);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}}
|
|
243
|
+
onResized={(
|
|
244
|
+
event: NativeSyntheticEvent<
|
|
245
|
+
Readonly<{
|
|
246
|
+
readonly height: string;
|
|
247
|
+
}>
|
|
248
|
+
>
|
|
249
|
+
) => {
|
|
250
|
+
const newHeight = Number(event.nativeEvent.height);
|
|
251
|
+
if (newHeight !== this.state.nativeViewHeight) {
|
|
252
|
+
console.log('onResized', newHeight);
|
|
253
|
+
this.setState({ nativeViewHeight: newHeight });
|
|
254
|
+
}
|
|
255
|
+
}}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
initialize = (clientToken: string, returnUrl: string | null = null) => {
|
|
261
|
+
const view = this.paymentViewRef.current;
|
|
262
|
+
if (view != null) {
|
|
263
|
+
RNKlarnaPaymentViewCommands.initialize(
|
|
264
|
+
view,
|
|
265
|
+
clientToken,
|
|
266
|
+
returnUrl || ''
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
load = (sessionData: string | null = null) => {
|
|
272
|
+
const view = this.paymentViewRef.current;
|
|
273
|
+
if (view != null) {
|
|
274
|
+
RNKlarnaPaymentViewCommands.load(view, sessionData || '');
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
loadPaymentReview = () => {
|
|
279
|
+
const view = this.paymentViewRef.current;
|
|
280
|
+
if (view != null) {
|
|
281
|
+
RNKlarnaPaymentViewCommands.loadPaymentReview(view);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
authorize = (
|
|
286
|
+
autoFinalize: boolean | null = true,
|
|
287
|
+
sessionData: string | null = null
|
|
288
|
+
) => {
|
|
289
|
+
const view = this.paymentViewRef.current;
|
|
290
|
+
if (view != null) {
|
|
291
|
+
RNKlarnaPaymentViewCommands.authorize(
|
|
292
|
+
view,
|
|
293
|
+
autoFinalize || true,
|
|
294
|
+
sessionData || ''
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
reauthorize = (sessionData: string | null = null) => {
|
|
300
|
+
const view = this.paymentViewRef.current;
|
|
301
|
+
if (view != null) {
|
|
302
|
+
RNKlarnaPaymentViewCommands.reauthorize(view, sessionData || '');
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
finalize = (sessionData: string | null = null) => {
|
|
307
|
+
const view = this.paymentViewRef.current;
|
|
308
|
+
if (view != null) {
|
|
309
|
+
RNKlarnaPaymentViewCommands.finalize(view, sessionData || '');
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface KlarnaPaymentsSDKError {
|
|
315
|
+
readonly action: string;
|
|
316
|
+
readonly isFatal: boolean;
|
|
317
|
+
readonly message: string;
|
|
318
|
+
readonly name: string;
|
|
319
|
+
// readonly invalidFields: Array<string>;
|
|
320
|
+
readonly sessionId: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export default KlarnaPaymentView;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import React, { Component, type RefObject } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
NativeMethods,
|
|
4
|
+
NativeSyntheticEvent,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import RNKlarnaStandaloneWebView, {
|
|
8
|
+
RNKlarnaStandaloneWebViewCommands,
|
|
9
|
+
type RNKlarnaStandaloneWebViewProps,
|
|
10
|
+
} from './specs/KlarnaStandaloneWebViewNativeComponent';
|
|
11
|
+
import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
|
|
12
|
+
|
|
13
|
+
export interface KlarnaWebViewProps {
|
|
14
|
+
style?: ViewStyle;
|
|
15
|
+
readonly returnUrl: string;
|
|
16
|
+
readonly onLoadStart?: (
|
|
17
|
+
navigationEvent: KlarnaWebViewNavigationEvent
|
|
18
|
+
) => void;
|
|
19
|
+
readonly onLoadEnd?: (navigationEvent: KlarnaWebViewNavigationEvent) => void;
|
|
20
|
+
readonly onError?: (navigationError: KlarnaWebViewError) => void;
|
|
21
|
+
readonly onLoadProgress?: (progressEvent: KlarnaWebViewProgressEvent) => void;
|
|
22
|
+
readonly onKlarnaMessage?: (
|
|
23
|
+
klarnaMessageEvent: KlarnaWebViewKlarnaMessageEvent
|
|
24
|
+
) => void;
|
|
25
|
+
/* Android only */
|
|
26
|
+
readonly onRenderProcessGone?: (
|
|
27
|
+
renderProcessGoneEvent: KlarnaWebViewRenderProcessGoneEvent
|
|
28
|
+
) => void;
|
|
29
|
+
/* End of Android only */
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class KlarnaStandaloneWebView extends Component<
|
|
33
|
+
KlarnaWebViewProps,
|
|
34
|
+
any
|
|
35
|
+
> {
|
|
36
|
+
standaloneWebViewRef: RefObject<
|
|
37
|
+
Component<RNKlarnaStandaloneWebViewProps> & Readonly<NativeMethods>
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
constructor(props: KlarnaWebViewProps) {
|
|
41
|
+
super(props);
|
|
42
|
+
this.standaloneWebViewRef = React.createRef();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
render() {
|
|
46
|
+
return (
|
|
47
|
+
<RNKlarnaStandaloneWebView
|
|
48
|
+
ref={this.standaloneWebViewRef}
|
|
49
|
+
style={this.props.style}
|
|
50
|
+
returnUrl={this.props.returnUrl || ''}
|
|
51
|
+
onLoadStart={(
|
|
52
|
+
event: NativeSyntheticEvent<
|
|
53
|
+
Readonly<{
|
|
54
|
+
readonly navigationEvent: Readonly<{
|
|
55
|
+
readonly url: string;
|
|
56
|
+
readonly loading: boolean;
|
|
57
|
+
readonly title: string;
|
|
58
|
+
readonly canGoBack: boolean;
|
|
59
|
+
readonly canGoForward: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
}>
|
|
62
|
+
>
|
|
63
|
+
) => {
|
|
64
|
+
if (this.props.onLoadStart != null) {
|
|
65
|
+
this.props.onLoadStart(event.nativeEvent.navigationEvent);
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
onLoadEnd={(
|
|
69
|
+
event: NativeSyntheticEvent<
|
|
70
|
+
Readonly<{
|
|
71
|
+
readonly navigationEvent: Readonly<{
|
|
72
|
+
readonly url: string;
|
|
73
|
+
readonly loading: boolean;
|
|
74
|
+
readonly title: string;
|
|
75
|
+
readonly canGoBack: boolean;
|
|
76
|
+
readonly canGoForward: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
}>
|
|
79
|
+
>
|
|
80
|
+
) => {
|
|
81
|
+
if (this.props.onLoadEnd != null) {
|
|
82
|
+
this.props.onLoadEnd(event.nativeEvent.navigationEvent);
|
|
83
|
+
}
|
|
84
|
+
}}
|
|
85
|
+
onError={(
|
|
86
|
+
event: NativeSyntheticEvent<
|
|
87
|
+
Readonly<{
|
|
88
|
+
readonly error: Readonly<{
|
|
89
|
+
readonly url: string;
|
|
90
|
+
readonly loading: boolean;
|
|
91
|
+
readonly title: string;
|
|
92
|
+
readonly canGoBack: boolean;
|
|
93
|
+
readonly canGoForward: boolean;
|
|
94
|
+
readonly code: number;
|
|
95
|
+
readonly description: string;
|
|
96
|
+
}>;
|
|
97
|
+
}>
|
|
98
|
+
>
|
|
99
|
+
) => {
|
|
100
|
+
if (this.props.onError != null) {
|
|
101
|
+
this.props.onError(event.nativeEvent.error);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onLoadProgress={(
|
|
105
|
+
event: NativeSyntheticEvent<
|
|
106
|
+
Readonly<{
|
|
107
|
+
readonly progressEvent: Readonly<{
|
|
108
|
+
readonly url: string;
|
|
109
|
+
readonly loading: boolean;
|
|
110
|
+
readonly title: string;
|
|
111
|
+
readonly canGoBack: boolean;
|
|
112
|
+
readonly canGoForward: boolean;
|
|
113
|
+
readonly progress: Double;
|
|
114
|
+
}>;
|
|
115
|
+
}>
|
|
116
|
+
>
|
|
117
|
+
) => {
|
|
118
|
+
if (this.props.onLoadProgress != null) {
|
|
119
|
+
this.props.onLoadProgress(event.nativeEvent.progressEvent);
|
|
120
|
+
}
|
|
121
|
+
}}
|
|
122
|
+
onKlarnaMessage={(
|
|
123
|
+
event: NativeSyntheticEvent<
|
|
124
|
+
Readonly<{
|
|
125
|
+
readonly klarnaMessageEvent: Readonly<{
|
|
126
|
+
readonly action: string;
|
|
127
|
+
// Dictionary is not support for events
|
|
128
|
+
// readonly params: { [key: string]: any };
|
|
129
|
+
}>;
|
|
130
|
+
}>
|
|
131
|
+
>
|
|
132
|
+
) => {
|
|
133
|
+
if (this.props.onKlarnaMessage != null) {
|
|
134
|
+
this.props.onKlarnaMessage(event.nativeEvent.klarnaMessageEvent);
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
onRenderProcessGone={(
|
|
138
|
+
event: NativeSyntheticEvent<
|
|
139
|
+
Readonly<{
|
|
140
|
+
readonly renderProcessGoneEvent: Readonly<{
|
|
141
|
+
readonly didCrash: boolean;
|
|
142
|
+
}>;
|
|
143
|
+
}>
|
|
144
|
+
>
|
|
145
|
+
) => {
|
|
146
|
+
if (this.props.onRenderProcessGone != null) {
|
|
147
|
+
this.props.onRenderProcessGone(
|
|
148
|
+
event.nativeEvent.renderProcessGoneEvent
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
load = (url: string) => {
|
|
157
|
+
const view = this.standaloneWebViewRef.current;
|
|
158
|
+
if (view != null) {
|
|
159
|
+
RNKlarnaStandaloneWebViewCommands.load(view, url);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
goForward = () => {
|
|
164
|
+
const view = this.standaloneWebViewRef.current;
|
|
165
|
+
if (view != null) {
|
|
166
|
+
RNKlarnaStandaloneWebViewCommands.goForward(view);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
goBack = () => {
|
|
171
|
+
const view = this.standaloneWebViewRef.current;
|
|
172
|
+
if (view != null) {
|
|
173
|
+
RNKlarnaStandaloneWebViewCommands.goBack(view);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
reload = () => {
|
|
178
|
+
const view = this.standaloneWebViewRef.current;
|
|
179
|
+
if (view != null) {
|
|
180
|
+
RNKlarnaStandaloneWebViewCommands.reload(view);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface KlarnaWebViewNativeEvent {
|
|
186
|
+
readonly url: string;
|
|
187
|
+
readonly loading: boolean;
|
|
188
|
+
readonly title: string;
|
|
189
|
+
readonly canGoBack: boolean;
|
|
190
|
+
readonly canGoForward: boolean;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface KlarnaWebViewNavigationEvent
|
|
194
|
+
extends KlarnaWebViewNativeEvent {}
|
|
195
|
+
|
|
196
|
+
export interface KlarnaWebViewError extends KlarnaWebViewNativeEvent {
|
|
197
|
+
readonly code: number;
|
|
198
|
+
readonly description: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface KlarnaWebViewProgressEvent extends KlarnaWebViewNativeEvent {
|
|
202
|
+
readonly progress: number;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface KlarnaWebViewKlarnaMessageEvent {
|
|
206
|
+
readonly action: string;
|
|
207
|
+
// Dictionary is not supported for events
|
|
208
|
+
// readonly params: { [key: string]: any };
|
|
209
|
+
// TODO What is a KlarnaWebViewComponent?
|
|
210
|
+
// readonly component: KlarnaWebViewComponent;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface KlarnaWebViewRenderProcessGoneEvent {
|
|
214
|
+
readonly didCrash: boolean;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export default KlarnaStandaloneWebView;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
2
|
+
import type { HostComponent } from 'react-native';
|
|
3
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
4
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
5
|
+
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
export interface RNKlarnaPaymentViewProps extends ViewProps {
|
|
9
|
+
readonly category: string;
|
|
10
|
+
readonly returnUrl: string;
|
|
11
|
+
readonly onInitialized: DirectEventHandler<null>;
|
|
12
|
+
readonly onLoaded: DirectEventHandler<null>;
|
|
13
|
+
readonly onLoadedPaymentReview: DirectEventHandler<null>;
|
|
14
|
+
readonly onAuthorized: DirectEventHandler<
|
|
15
|
+
Readonly<{
|
|
16
|
+
readonly approved: boolean;
|
|
17
|
+
readonly authToken: string | null;
|
|
18
|
+
readonly finalizeRequired: boolean;
|
|
19
|
+
}>
|
|
20
|
+
>;
|
|
21
|
+
readonly onReauthorized: DirectEventHandler<
|
|
22
|
+
Readonly<{
|
|
23
|
+
readonly approved: boolean;
|
|
24
|
+
readonly authToken: string | null;
|
|
25
|
+
}>
|
|
26
|
+
>;
|
|
27
|
+
readonly onFinalized: DirectEventHandler<
|
|
28
|
+
Readonly<{
|
|
29
|
+
readonly approved: boolean;
|
|
30
|
+
readonly authToken: string | null;
|
|
31
|
+
}>
|
|
32
|
+
>;
|
|
33
|
+
readonly onError: DirectEventHandler<
|
|
34
|
+
Readonly<{
|
|
35
|
+
readonly error: Readonly<{
|
|
36
|
+
readonly action: string;
|
|
37
|
+
readonly isFatal: boolean;
|
|
38
|
+
readonly message: string;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
// not supported yet https://github.com/facebook/react-native/issues/36817#issuecomment-1697107218
|
|
41
|
+
// readonly invalidFields: Array<string>;
|
|
42
|
+
readonly sessionId: string;
|
|
43
|
+
}>;
|
|
44
|
+
}>
|
|
45
|
+
>;
|
|
46
|
+
readonly onResized: DirectEventHandler<
|
|
47
|
+
Readonly<{
|
|
48
|
+
// number not supported for events
|
|
49
|
+
readonly height: string;
|
|
50
|
+
}>
|
|
51
|
+
>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type KlarnaPaymentViewNativeComponentType =
|
|
55
|
+
HostComponent<RNKlarnaPaymentViewProps>;
|
|
56
|
+
|
|
57
|
+
interface RNKlarnaPaymentViewNativeCommands {
|
|
58
|
+
initialize: (
|
|
59
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>,
|
|
60
|
+
clientToken: string,
|
|
61
|
+
returnUrl: string | null
|
|
62
|
+
) => void;
|
|
63
|
+
load: (
|
|
64
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>,
|
|
65
|
+
sessionData: string | null
|
|
66
|
+
) => void;
|
|
67
|
+
loadPaymentReview: (
|
|
68
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>
|
|
69
|
+
) => void;
|
|
70
|
+
authorize: (
|
|
71
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>,
|
|
72
|
+
autoFinalize: boolean,
|
|
73
|
+
sessionData: string | null
|
|
74
|
+
) => void;
|
|
75
|
+
reauthorize: (
|
|
76
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>,
|
|
77
|
+
sessionData: string | null
|
|
78
|
+
) => void;
|
|
79
|
+
finalize: (
|
|
80
|
+
viewRef: React.ElementRef<KlarnaPaymentViewNativeComponentType>,
|
|
81
|
+
sessionData: string | null
|
|
82
|
+
) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const RNKlarnaPaymentViewCommands: RNKlarnaPaymentViewNativeCommands =
|
|
86
|
+
codegenNativeCommands<RNKlarnaPaymentViewNativeCommands>({
|
|
87
|
+
supportedCommands: [
|
|
88
|
+
'initialize',
|
|
89
|
+
'load',
|
|
90
|
+
'loadPaymentReview',
|
|
91
|
+
'authorize',
|
|
92
|
+
'reauthorize',
|
|
93
|
+
'finalize',
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export default codegenNativeComponent<RNKlarnaPaymentViewProps>(
|
|
98
|
+
'RNKlarnaPaymentView'
|
|
99
|
+
) as KlarnaPaymentViewNativeComponentType;
|