react-native-klarna-inapp-sdk 2.2.4 → 2.3.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.
Files changed (69) hide show
  1. package/README.md +3 -2
  2. package/android/build.gradle +12 -12
  3. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +3 -1
  4. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventHandler.java +32 -0
  5. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewEventSender.java +56 -0
  6. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewManager.java +147 -0
  7. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +59 -19
  8. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEvent.java +37 -0
  9. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSender.java +78 -0
  10. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtil.java +53 -0
  11. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/ResizeObserverWrapperView.java +79 -0
  12. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/WrapperView.java +32 -0
  13. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/{ArgumentsUtil.java → util/ArgumentsUtil.java} +1 -1
  14. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/util/ParserUtil.java +36 -0
  15. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/KlarnaPaymentViewManager.java +1 -1
  16. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/payments/PaymentViewWrapper.java +1 -1
  17. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/standalonewebview/KlarnaStandaloneWebViewEventSender.java +1 -1
  18. package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +31 -0
  19. package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaCheckoutViewSpec.java +20 -0
  20. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java +3 -1
  21. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSenderTest.java +85 -0
  22. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventTest.java +73 -0
  23. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/event/KlarnaEventHandlerEventsUtilTest.java +61 -0
  24. package/ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj +32 -0
  25. package/ios/Sources/KlarnaCheckoutViewManager.h +5 -0
  26. package/ios/Sources/KlarnaCheckoutViewManager.mm +65 -0
  27. package/ios/Sources/common/RNMobileSDKUtils.h +6 -0
  28. package/ios/Sources/common/RNMobileSDKUtils.mm +22 -0
  29. package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.h +26 -0
  30. package/ios/Sources/view/newarch/KlarnaCheckoutViewWrapper.mm +153 -0
  31. package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.h +37 -0
  32. package/ios/Sources/view/oldarch/KlarnaCheckoutViewWrapper.mm +116 -0
  33. package/lib/commonjs/KlarnaCheckoutView.js +84 -0
  34. package/lib/commonjs/KlarnaCheckoutView.js.map +1 -0
  35. package/lib/commonjs/index.js +11 -0
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js +16 -0
  38. package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
  39. package/lib/commonjs/types/common/KlarnaMobileSDKError.js +2 -0
  40. package/lib/commonjs/types/common/KlarnaMobileSDKError.js.map +1 -0
  41. package/lib/commonjs/types/common/KlarnaProductEvent.js +2 -0
  42. package/lib/commonjs/types/common/KlarnaProductEvent.js.map +1 -0
  43. package/lib/module/KlarnaCheckoutView.js +74 -0
  44. package/lib/module/KlarnaCheckoutView.js.map +1 -0
  45. package/lib/module/index.js +1 -0
  46. package/lib/module/index.js.map +1 -1
  47. package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js +7 -0
  48. package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -0
  49. package/lib/module/types/common/KlarnaMobileSDKError.js +2 -0
  50. package/lib/module/types/common/KlarnaMobileSDKError.js.map +1 -0
  51. package/lib/module/types/common/KlarnaProductEvent.js +2 -0
  52. package/lib/module/types/common/KlarnaProductEvent.js.map +1 -0
  53. package/lib/typescript/KlarnaCheckoutView.d.ts +24 -0
  54. package/lib/typescript/KlarnaCheckoutView.d.ts.map +1 -0
  55. package/lib/typescript/index.d.ts +1 -0
  56. package/lib/typescript/index.d.ts.map +1 -1
  57. package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts +33 -0
  58. package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts.map +1 -0
  59. package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts +6 -0
  60. package/lib/typescript/types/common/KlarnaMobileSDKError.d.ts.map +1 -0
  61. package/lib/typescript/types/common/KlarnaProductEvent.d.ts +7 -0
  62. package/lib/typescript/types/common/KlarnaProductEvent.d.ts.map +1 -0
  63. package/package.json +2 -2
  64. package/react-native-klarna-inapp-sdk.podspec +1 -1
  65. package/src/KlarnaCheckoutView.tsx +130 -0
  66. package/src/index.tsx +1 -0
  67. package/src/specs/KlarnaCheckoutViewNativeComponent.ts +58 -0
  68. package/src/types/common/KlarnaMobileSDKError.ts +5 -0
  69. package/src/types/common/KlarnaProductEvent.ts +4 -0
@@ -0,0 +1,33 @@
1
+ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
2
+ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
3
+ import type { HostComponent } from 'react-native';
4
+ import React from 'react';
5
+ export interface RNKlarnaCheckoutViewProps extends ViewProps {
6
+ readonly returnUrl: string;
7
+ readonly onEvent: DirectEventHandler<Readonly<{
8
+ readonly productEvent: Readonly<{
9
+ readonly action: string;
10
+ readonly params: string;
11
+ }>;
12
+ }>>;
13
+ readonly onError: DirectEventHandler<Readonly<{
14
+ readonly error: Readonly<{
15
+ readonly isFatal: boolean;
16
+ readonly message: string;
17
+ readonly name: string;
18
+ }>;
19
+ }>>;
20
+ readonly onResized: DirectEventHandler<Readonly<{
21
+ readonly height: string;
22
+ }>>;
23
+ }
24
+ type KlarnaCheckoutViewNativeComponentType = HostComponent<RNKlarnaCheckoutViewProps>;
25
+ interface RNKlarnaCheckoutViewNativeCommands {
26
+ setSnippet: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>, snippet: string) => void;
27
+ suspend: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>) => void;
28
+ resume: (viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>) => void;
29
+ }
30
+ export declare const RNKlarnaCheckoutViewCommands: RNKlarnaCheckoutViewNativeCommands;
31
+ declare const _default: KlarnaCheckoutViewNativeComponentType;
32
+ export default _default;
33
+ //# sourceMappingURL=KlarnaCheckoutViewNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KlarnaCheckoutViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/specs/KlarnaCheckoutViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAClC,QAAQ,CAAC;QACP,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC;YAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;YACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;SACzB,CAAC,CAAC;KACJ,CAAC,CACH,CAAC;IACF,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAClC,QAAQ,CAAC;QACP,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;YACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;YAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;YACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;SACvB,CAAC,CAAC;KACJ,CAAC,CACH,CAAC;IACF,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CACpC,QAAQ,CAAC;QAEP,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB,CAAC,CACH,CAAC;CACH;AAED,KAAK,qCAAqC,GACxC,aAAa,CAAC,yBAAyB,CAAC,CAAC;AAE3C,UAAU,kCAAkC;IAC1C,UAAU,EAAE,CACV,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,qCAAqC,CAAC,EAChE,OAAO,EAAE,MAAM,KACZ,IAAI,CAAC;IACV,OAAO,EAAE,CACP,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,qCAAqC,CAAC,KAC7D,IAAI,CAAC;IACV,MAAM,EAAE,CACN,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,qCAAqC,CAAC,KAC7D,IAAI,CAAC;CACX;AAED,eAAO,MAAM,4BAA4B,EAAE,kCAGvC,CAAC;;AAEL,wBAE2C"}
@@ -0,0 +1,6 @@
1
+ export interface KlarnaMobileSDKError {
2
+ readonly isFatal: boolean;
3
+ readonly message: string;
4
+ readonly name: string;
5
+ }
6
+ //# sourceMappingURL=KlarnaMobileSDKError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KlarnaMobileSDKError.d.ts","sourceRoot":"","sources":["../../../../src/types/common/KlarnaMobileSDKError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,7 @@
1
+ export interface KlarnaProductEvent {
2
+ readonly action: string;
3
+ readonly params: {
4
+ [key: string]: any;
5
+ };
6
+ }
7
+ //# sourceMappingURL=KlarnaProductEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KlarnaProductEvent.d.ts","sourceRoot":"","sources":["../../../../src/types/common/KlarnaProductEvent.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACzC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-klarna-inapp-sdk",
3
3
  "title": "Klarna Mobile SDK React Native",
4
- "version": "2.2.4",
4
+ "version": "2.3.0",
5
5
  "description": "This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.",
6
6
  "main": "lib/commonjs/index",
7
7
  "module": "lib/module/index",
@@ -86,10 +86,10 @@
86
86
  "turbo": "^1.10.7",
87
87
  "typescript": "^5.0.2"
88
88
  },
89
- "dependencies": {},
90
89
  "engines": {
91
90
  "node": ">=16"
92
91
  },
92
+ "packageManager": "yarn@1.22.22",
93
93
  "react-native-builder-bob": {
94
94
  "source": "src",
95
95
  "output": "lib",
@@ -46,5 +46,5 @@ Pod::Spec.new do |s|
46
46
  end
47
47
  end
48
48
 
49
- s.dependency 'KlarnaMobileSDK', '2.6.17'
49
+ s.dependency 'KlarnaMobileSDK', '2.6.19'
50
50
  end
@@ -0,0 +1,130 @@
1
+ import React, { Component, type RefObject } from 'react';
2
+ import type {
3
+ NativeMethods,
4
+ NativeSyntheticEvent,
5
+ ViewStyle,
6
+ } from 'react-native';
7
+ import type { KlarnaProductEvent } from './types/common/KlarnaProductEvent';
8
+ import type { KlarnaMobileSDKError } from './types/common/KlarnaMobileSDKError';
9
+ import RNKlarnaCheckoutView, {
10
+ RNKlarnaCheckoutViewCommands,
11
+ type RNKlarnaCheckoutViewProps,
12
+ } from './specs/KlarnaCheckoutViewNativeComponent';
13
+
14
+ export interface KlarnaCheckoutViewProps {
15
+ style?: ViewStyle;
16
+ readonly returnUrl: string;
17
+ readonly onEvent?: (klarnaProductEvent: KlarnaProductEvent) => void;
18
+ readonly onError?: (error: KlarnaMobileSDKError) => void;
19
+ }
20
+
21
+ interface KlarnaCheckoutViewState {
22
+ nativeViewHeight: number;
23
+ }
24
+
25
+ export class KlarnaCheckoutView extends Component<
26
+ KlarnaCheckoutViewProps,
27
+ KlarnaCheckoutViewState
28
+ > {
29
+ checkoutViewRef: RefObject<
30
+ Component<RNKlarnaCheckoutViewProps> & Readonly<NativeMethods>
31
+ >;
32
+
33
+ constructor(props: KlarnaCheckoutViewProps) {
34
+ super(props);
35
+ this.state = {
36
+ nativeViewHeight: 0,
37
+ };
38
+ this.checkoutViewRef = React.createRef();
39
+ }
40
+
41
+ render() {
42
+ return (
43
+ <RNKlarnaCheckoutView
44
+ ref={this.checkoutViewRef}
45
+ /* eslint-disable-next-line react-native/no-inline-styles */
46
+ style={{
47
+ width: '100%',
48
+ height: this.state.nativeViewHeight,
49
+ }}
50
+ returnUrl={this.props.returnUrl || ''}
51
+ onEvent={(
52
+ event: NativeSyntheticEvent<
53
+ Readonly<{
54
+ readonly productEvent: Readonly<{
55
+ readonly action: string;
56
+ readonly params: string;
57
+ }>;
58
+ }>
59
+ >
60
+ ) => {
61
+ let params = {};
62
+ try {
63
+ params = JSON.parse(event.nativeEvent.productEvent.params);
64
+ } catch (e) {
65
+ console.error('Failed to parse productEvent.params', e);
66
+ }
67
+ const productEvent: KlarnaProductEvent = {
68
+ action: event.nativeEvent.productEvent.action,
69
+ params: params,
70
+ };
71
+ this.props.onEvent?.(productEvent);
72
+ }}
73
+ onError={(
74
+ event: NativeSyntheticEvent<
75
+ Readonly<{
76
+ readonly error: Readonly<{
77
+ readonly isFatal: boolean;
78
+ readonly message: string;
79
+ readonly name: string;
80
+ }>;
81
+ }>
82
+ >
83
+ ) => {
84
+ const mobileSdkError: KlarnaMobileSDKError = {
85
+ isFatal: event.nativeEvent.error.isFatal,
86
+ message: event.nativeEvent.error.message,
87
+ name: event.nativeEvent.error.name,
88
+ };
89
+ this.props.onError?.(mobileSdkError);
90
+ }}
91
+ onResized={(
92
+ event: NativeSyntheticEvent<
93
+ Readonly<{
94
+ readonly height: string;
95
+ }>
96
+ >
97
+ ) => {
98
+ const newHeight = Number(event.nativeEvent.height);
99
+ if (newHeight !== this.state.nativeViewHeight) {
100
+ console.log('onResized', newHeight);
101
+ this.setState({ nativeViewHeight: newHeight });
102
+ }
103
+ }}
104
+ />
105
+ );
106
+ }
107
+
108
+ setSnippet = (snippet: string) => {
109
+ const view = this.checkoutViewRef.current;
110
+ if (view != null) {
111
+ RNKlarnaCheckoutViewCommands.setSnippet(view, snippet);
112
+ }
113
+ };
114
+
115
+ suspend = () => {
116
+ const view = this.checkoutViewRef.current;
117
+ if (view != null) {
118
+ RNKlarnaCheckoutViewCommands.suspend(view);
119
+ }
120
+ };
121
+
122
+ resume = () => {
123
+ const view = this.checkoutViewRef.current;
124
+ if (view != null) {
125
+ RNKlarnaCheckoutViewCommands.resume(view);
126
+ }
127
+ };
128
+ }
129
+
130
+ export default KlarnaCheckoutView;
package/src/index.tsx CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './KlarnaPaymentView';
2
2
  export * from './KlarnaStandaloneWebView';
3
+ export * from './KlarnaCheckoutView';
@@ -0,0 +1,58 @@
1
+ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
2
+ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
3
+ import type { HostComponent } from 'react-native';
4
+ import React from 'react';
5
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
6
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
7
+
8
+ export interface RNKlarnaCheckoutViewProps extends ViewProps {
9
+ readonly returnUrl: string;
10
+ readonly onEvent: DirectEventHandler<
11
+ Readonly<{
12
+ readonly productEvent: Readonly<{
13
+ readonly action: string;
14
+ readonly params: string;
15
+ }>;
16
+ }>
17
+ >;
18
+ readonly onError: DirectEventHandler<
19
+ Readonly<{
20
+ readonly error: Readonly<{
21
+ readonly isFatal: boolean;
22
+ readonly message: string;
23
+ readonly name: string;
24
+ }>;
25
+ }>
26
+ >;
27
+ readonly onResized: DirectEventHandler<
28
+ Readonly<{
29
+ // number not supported for events
30
+ readonly height: string;
31
+ }>
32
+ >;
33
+ }
34
+
35
+ type KlarnaCheckoutViewNativeComponentType =
36
+ HostComponent<RNKlarnaCheckoutViewProps>;
37
+
38
+ interface RNKlarnaCheckoutViewNativeCommands {
39
+ setSnippet: (
40
+ viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>,
41
+ snippet: string
42
+ ) => void;
43
+ suspend: (
44
+ viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>
45
+ ) => void;
46
+ resume: (
47
+ viewRef: React.ElementRef<KlarnaCheckoutViewNativeComponentType>
48
+ ) => void;
49
+ }
50
+
51
+ export const RNKlarnaCheckoutViewCommands: RNKlarnaCheckoutViewNativeCommands =
52
+ codegenNativeCommands<RNKlarnaCheckoutViewNativeCommands>({
53
+ supportedCommands: ['setSnippet', 'suspend', 'resume'],
54
+ });
55
+
56
+ export default codegenNativeComponent<RNKlarnaCheckoutViewProps>(
57
+ 'RNKlarnaCheckoutView'
58
+ ) as KlarnaCheckoutViewNativeComponentType;
@@ -0,0 +1,5 @@
1
+ export interface KlarnaMobileSDKError {
2
+ readonly isFatal: boolean;
3
+ readonly message: string;
4
+ readonly name: string;
5
+ }
@@ -0,0 +1,4 @@
1
+ export interface KlarnaProductEvent {
2
+ readonly action: string;
3
+ readonly params: { [key: string]: any };
4
+ }