react-native-klarna-inapp-sdk 2.4.10 → 2.5.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.
Files changed (167) hide show
  1. package/android/build.gradle +3 -1
  2. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackage.java +5 -1
  3. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/checkout/KlarnaCheckoutViewManager.java +4 -10
  4. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/WebViewResizeObserver.java +28 -0
  5. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/event/ComponentEventSender.java +5 -1
  6. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/ResizeObserverWrapperView.java +2 -2
  7. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/WrapperView.java +2 -2
  8. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/common/ui/YogaLayoutHelper.java +39 -0
  9. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewCallback.kt +30 -0
  10. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewEventSender.kt +80 -0
  11. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewManager.java +544 -0
  12. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventHandler.java +30 -0
  13. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventSender.java +64 -0
  14. package/android/src/main/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewManager.java +356 -0
  15. package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaExpressCheckoutViewSpec.java +31 -0
  16. package/android/src/newarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaOSMViewSpec.java +31 -0
  17. package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaExpressCheckoutViewSpec.java +36 -0
  18. package/android/src/oldarch/java/com/klarna/mobile/sdk/reactnative/spec/RNKlarnaOSMViewSpec.java +32 -0
  19. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/KlarnaMobileSDKPackageTest.java +5 -1
  20. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/common/ui/YogaLayoutHelperTest.java +79 -0
  21. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/expresscheckout/KlarnaExpressCheckoutViewManagerTest.java +259 -0
  22. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventHandlerTest.java +136 -0
  23. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewEventSenderTest.java +184 -0
  24. package/android/src/test/java/com/klarna/mobile/sdk/reactnative/osm/KlarnaOSMViewManagerTest.java +385 -0
  25. package/ios/RNKlarnaMobileSDK.xcodeproj/project.pbxproj +110 -52
  26. package/ios/Sources/KlarnaExpressCheckoutViewManager.h +5 -0
  27. package/ios/Sources/KlarnaExpressCheckoutViewManager.mm +39 -0
  28. package/ios/Sources/KlarnaOSMViewManager.h +5 -0
  29. package/ios/Sources/KlarnaOSMViewManager.mm +59 -0
  30. package/ios/Sources/view/KlarnaExpressCheckoutButtonDelegateProxy.swift +145 -0
  31. package/ios/Sources/view/KlarnaExpressCheckoutViewWrapper.h +41 -0
  32. package/ios/Sources/view/KlarnaOSMViewWrapper.h +48 -0
  33. package/ios/Sources/view/newarch/KlarnaExpressCheckoutViewWrapper.mm +228 -0
  34. package/ios/Sources/view/newarch/KlarnaOSMViewWrapper.mm +294 -0
  35. package/ios/Sources/view/newarch/KlarnaStandaloneWebViewWrapper.mm +20 -13
  36. package/ios/Sources/view/oldarch/KlarnaExpressCheckoutViewWrapper.mm +222 -0
  37. package/ios/Sources/view/oldarch/KlarnaOSMViewWrapper.mm +273 -0
  38. package/ios/Sources/view/oldarch/KlarnaStandaloneWebViewWrapper.mm +11 -13
  39. package/ios/Tests/KlarnaExpressCheckoutViewWrapperTests.m +391 -0
  40. package/ios/Tests/KlarnaOSMViewWrapperTests.m +450 -0
  41. package/ios/Tests/KlarnaStandaloneWebViewWrapperTests.m +105 -0
  42. package/lib/commonjs/KlarnaCheckoutView.js +2 -4
  43. package/lib/commonjs/KlarnaCheckoutView.js.map +1 -1
  44. package/lib/commonjs/KlarnaExpressCheckoutView.js +73 -0
  45. package/lib/commonjs/KlarnaExpressCheckoutView.js.map +1 -0
  46. package/lib/commonjs/KlarnaOSMView.js +92 -0
  47. package/lib/commonjs/KlarnaOSMView.js.map +1 -0
  48. package/lib/commonjs/KlarnaPaymentView.js +32 -55
  49. package/lib/commonjs/KlarnaPaymentView.js.map +1 -1
  50. package/lib/commonjs/KlarnaSignInSDK.js +1 -1
  51. package/lib/commonjs/KlarnaSignInSDK.js.map +1 -1
  52. package/lib/commonjs/KlarnaStandaloneWebView.js +2 -4
  53. package/lib/commonjs/KlarnaStandaloneWebView.js.map +1 -1
  54. package/lib/commonjs/index.js +128 -0
  55. package/lib/commonjs/index.js.map +1 -1
  56. package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js +3 -5
  57. package/lib/commonjs/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -1
  58. package/lib/commonjs/specs/KlarnaExpressCheckoutViewNativeComponent.js +10 -0
  59. package/lib/commonjs/specs/KlarnaExpressCheckoutViewNativeComponent.js.map +1 -0
  60. package/lib/commonjs/specs/KlarnaOSMViewNativeComponent.js +14 -0
  61. package/lib/commonjs/specs/KlarnaOSMViewNativeComponent.js.map +1 -0
  62. package/lib/commonjs/specs/KlarnaPaymentViewNativeComponent.js +3 -5
  63. package/lib/commonjs/specs/KlarnaPaymentViewNativeComponent.js.map +1 -1
  64. package/lib/commonjs/specs/KlarnaStandaloneWebViewNativeComponent.js +3 -5
  65. package/lib/commonjs/specs/KlarnaStandaloneWebViewNativeComponent.js.map +1 -1
  66. package/lib/commonjs/specs/NativeKlarnaSignIn.js +1 -2
  67. package/lib/commonjs/specs/NativeKlarnaSignIn.js.map +1 -1
  68. package/lib/commonjs/types/button/KlarnaButtonShape.js +13 -0
  69. package/lib/commonjs/types/button/KlarnaButtonShape.js.map +1 -0
  70. package/lib/commonjs/types/button/KlarnaButtonStyle.js +12 -0
  71. package/lib/commonjs/types/button/KlarnaButtonStyle.js.map +1 -0
  72. package/lib/commonjs/types/button/KlarnaButtonTheme.js +13 -0
  73. package/lib/commonjs/types/button/KlarnaButtonTheme.js.map +1 -0
  74. package/lib/commonjs/types/common/KlarnaEnvironment.js +1 -2
  75. package/lib/commonjs/types/common/KlarnaEnvironment.js.map +1 -1
  76. package/lib/commonjs/types/common/KlarnaExpressCheckoutSessionOptions.js +8 -0
  77. package/lib/commonjs/types/common/KlarnaExpressCheckoutSessionOptions.js.map +1 -0
  78. package/lib/commonjs/types/common/KlarnaMobileSDKError.js.map +1 -1
  79. package/lib/commonjs/types/common/KlarnaOSMPlacementKey.js +2 -0
  80. package/lib/commonjs/types/common/KlarnaOSMPlacementKey.js.map +1 -0
  81. package/lib/commonjs/types/common/KlarnaProductEvent.js.map +1 -1
  82. package/lib/commonjs/types/common/KlarnaRegion.js +1 -2
  83. package/lib/commonjs/types/common/KlarnaRegion.js.map +1 -1
  84. package/lib/commonjs/types/common/KlarnaTheme.js +13 -0
  85. package/lib/commonjs/types/common/KlarnaTheme.js.map +1 -0
  86. package/lib/module/KlarnaCheckoutView.js.map +1 -1
  87. package/lib/module/KlarnaExpressCheckoutView.js +64 -0
  88. package/lib/module/KlarnaExpressCheckoutView.js.map +1 -0
  89. package/lib/module/KlarnaOSMView.js +84 -0
  90. package/lib/module/KlarnaOSMView.js.map +1 -0
  91. package/lib/module/KlarnaPaymentView.js +30 -51
  92. package/lib/module/KlarnaPaymentView.js.map +1 -1
  93. package/lib/module/KlarnaSignInSDK.js.map +1 -1
  94. package/lib/module/KlarnaStandaloneWebView.js.map +1 -1
  95. package/lib/module/index.js +11 -0
  96. package/lib/module/index.js.map +1 -1
  97. package/lib/module/specs/KlarnaCheckoutViewNativeComponent.js.map +1 -1
  98. package/lib/module/specs/KlarnaExpressCheckoutViewNativeComponent.js +3 -0
  99. package/lib/module/specs/KlarnaExpressCheckoutViewNativeComponent.js.map +1 -0
  100. package/lib/module/specs/KlarnaOSMViewNativeComponent.js +7 -0
  101. package/lib/module/specs/KlarnaOSMViewNativeComponent.js.map +1 -0
  102. package/lib/module/specs/KlarnaPaymentViewNativeComponent.js.map +1 -1
  103. package/lib/module/specs/KlarnaStandaloneWebViewNativeComponent.js.map +1 -1
  104. package/lib/module/specs/NativeKlarnaSignIn.js.map +1 -1
  105. package/lib/module/types/button/KlarnaButtonShape.js +7 -0
  106. package/lib/module/types/button/KlarnaButtonShape.js.map +1 -0
  107. package/lib/module/types/button/KlarnaButtonStyle.js +6 -0
  108. package/lib/module/types/button/KlarnaButtonStyle.js.map +1 -0
  109. package/lib/module/types/button/KlarnaButtonTheme.js +7 -0
  110. package/lib/module/types/button/KlarnaButtonTheme.js.map +1 -0
  111. package/lib/module/types/common/KlarnaEnvironment.js.map +1 -1
  112. package/lib/module/types/common/KlarnaExpressCheckoutSessionOptions.js +2 -0
  113. package/lib/module/types/common/KlarnaExpressCheckoutSessionOptions.js.map +1 -0
  114. package/lib/module/types/common/KlarnaMobileSDKError.js.map +1 -1
  115. package/lib/module/types/common/KlarnaOSMPlacementKey.js +2 -0
  116. package/lib/module/types/common/KlarnaOSMPlacementKey.js.map +1 -0
  117. package/lib/module/types/common/KlarnaProductEvent.js.map +1 -1
  118. package/lib/module/types/common/KlarnaRegion.js.map +1 -1
  119. package/lib/module/types/common/KlarnaTheme.js +7 -0
  120. package/lib/module/types/common/KlarnaTheme.js.map +1 -0
  121. package/lib/typescript/KlarnaCheckoutView.d.ts.map +1 -1
  122. package/lib/typescript/KlarnaExpressCheckoutView.d.ts +47 -0
  123. package/lib/typescript/KlarnaExpressCheckoutView.d.ts.map +1 -0
  124. package/lib/typescript/KlarnaOSMView.d.ts +36 -0
  125. package/lib/typescript/KlarnaOSMView.d.ts.map +1 -0
  126. package/lib/typescript/KlarnaPaymentView.d.ts.map +1 -1
  127. package/lib/typescript/KlarnaStandaloneWebView.d.ts.map +1 -1
  128. package/lib/typescript/index.d.ts +11 -0
  129. package/lib/typescript/index.d.ts.map +1 -1
  130. package/lib/typescript/specs/KlarnaCheckoutViewNativeComponent.d.ts.map +1 -1
  131. package/lib/typescript/specs/KlarnaExpressCheckoutViewNativeComponent.d.ts +45 -0
  132. package/lib/typescript/specs/KlarnaExpressCheckoutViewNativeComponent.d.ts.map +1 -0
  133. package/lib/typescript/specs/KlarnaOSMViewNativeComponent.d.ts +35 -0
  134. package/lib/typescript/specs/KlarnaOSMViewNativeComponent.d.ts.map +1 -0
  135. package/lib/typescript/specs/KlarnaPaymentViewNativeComponent.d.ts.map +1 -1
  136. package/lib/typescript/specs/KlarnaStandaloneWebViewNativeComponent.d.ts.map +1 -1
  137. package/lib/typescript/specs/NativeKlarnaSignIn.d.ts +1 -1
  138. package/lib/typescript/specs/NativeKlarnaSignIn.d.ts.map +1 -1
  139. package/lib/typescript/types/button/KlarnaButtonShape.d.ts +6 -0
  140. package/lib/typescript/types/button/KlarnaButtonShape.d.ts.map +1 -0
  141. package/lib/typescript/types/button/KlarnaButtonStyle.d.ts +5 -0
  142. package/lib/typescript/types/button/KlarnaButtonStyle.d.ts.map +1 -0
  143. package/lib/typescript/types/button/KlarnaButtonTheme.d.ts +6 -0
  144. package/lib/typescript/types/button/KlarnaButtonTheme.d.ts.map +1 -0
  145. package/lib/typescript/types/common/KlarnaExpressCheckoutSessionOptions.d.ts +10 -0
  146. package/lib/typescript/types/common/KlarnaExpressCheckoutSessionOptions.d.ts.map +1 -0
  147. package/lib/typescript/types/common/KlarnaOSMPlacementKey.d.ts +2 -0
  148. package/lib/typescript/types/common/KlarnaOSMPlacementKey.d.ts.map +1 -0
  149. package/lib/typescript/types/common/KlarnaTheme.d.ts +6 -0
  150. package/lib/typescript/types/common/KlarnaTheme.d.ts.map +1 -0
  151. package/package.json +17 -16
  152. package/react-native-klarna-inapp-sdk.podspec +2 -1
  153. package/src/KlarnaExpressCheckoutView.tsx +169 -0
  154. package/src/KlarnaOSMView.tsx +157 -0
  155. package/src/KlarnaStandaloneWebView.tsx +1 -2
  156. package/src/index.tsx +11 -0
  157. package/src/specs/KlarnaExpressCheckoutViewNativeComponent.ts +66 -0
  158. package/src/specs/KlarnaOSMViewNativeComponent.ts +50 -0
  159. package/src/specs/NativeKlarnaSignIn.ts +1 -1
  160. package/src/types/button/KlarnaButtonShape.ts +5 -0
  161. package/src/types/button/KlarnaButtonStyle.ts +4 -0
  162. package/src/types/button/KlarnaButtonTheme.ts +5 -0
  163. package/src/types/common/KlarnaExpressCheckoutSessionOptions.ts +13 -0
  164. package/src/types/common/KlarnaOSMPlacementKey.ts +3 -0
  165. package/src/types/common/KlarnaTheme.ts +5 -0
  166. package/LICENSE +0 -201
  167. package/README.md +0 -93
@@ -0,0 +1,169 @@
1
+ import React, { Component, type RefObject } from 'react';
2
+ import type {
3
+ NativeMethods,
4
+ NativeSyntheticEvent,
5
+ ViewStyle,
6
+ } from 'react-native';
7
+ import type { KlarnaMobileSDKError } from './types/common/KlarnaMobileSDKError';
8
+ import type { KlarnaEnvironment } from './types/common/KlarnaEnvironment';
9
+ import type { KlarnaRegion } from './types/common/KlarnaRegion';
10
+ import type { KlarnaExpressCheckoutSessionOptions } from './types/common/KlarnaExpressCheckoutSessionOptions';
11
+ import type { KlarnaButtonTheme } from './types/button/KlarnaButtonTheme';
12
+ import type { KlarnaButtonShape } from './types/button/KlarnaButtonShape';
13
+ import type { KlarnaButtonStyle } from './types/button/KlarnaButtonStyle';
14
+ import RNKlarnaExpressCheckoutView, {
15
+ type RNKlarnaExpressCheckoutViewProps,
16
+ } from './specs/KlarnaExpressCheckoutViewNativeComponent';
17
+
18
+ export interface KlarnaExpressCheckoutAuthorizationResponse {
19
+ readonly showForm: boolean;
20
+ readonly approved: boolean;
21
+ readonly finalizedRequired: boolean;
22
+ readonly clientToken: string;
23
+ readonly authorizationToken: string;
24
+ readonly sessionId: string;
25
+ readonly collectedShippingAddress: string;
26
+ readonly merchantReference1: string;
27
+ readonly merchantReference2: string;
28
+ }
29
+
30
+ export interface KlarnaExpressCheckoutViewProps {
31
+ style?: ViewStyle;
32
+ // Session
33
+ readonly sessionOptions: KlarnaExpressCheckoutSessionOptions;
34
+ // Required
35
+ readonly locale: string;
36
+ readonly environment: KlarnaEnvironment;
37
+ readonly region: KlarnaRegion;
38
+ readonly returnUrl: string;
39
+ // Style
40
+ readonly theme?: KlarnaButtonTheme;
41
+ readonly shape?: KlarnaButtonShape;
42
+ readonly buttonStyle?: KlarnaButtonStyle;
43
+ // Optional
44
+ readonly autoFinalize?: boolean;
45
+ readonly collectShippingAddress?: boolean;
46
+ readonly sessionData?: string;
47
+ // Callbacks
48
+ readonly onAuthorized?: (
49
+ response: KlarnaExpressCheckoutAuthorizationResponse
50
+ ) => void;
51
+ readonly onError?: (error: KlarnaMobileSDKError) => void;
52
+ }
53
+
54
+ interface KlarnaExpressCheckoutViewState {
55
+ nativeViewHeight: number;
56
+ }
57
+
58
+ const normalizeSessionData = (sessionData?: string): string => {
59
+ if (sessionData?.trim()) {
60
+ return sessionData;
61
+ }
62
+ return '';
63
+ };
64
+
65
+ export class KlarnaExpressCheckoutView extends Component<
66
+ KlarnaExpressCheckoutViewProps,
67
+ KlarnaExpressCheckoutViewState
68
+ > {
69
+ viewRef: RefObject<
70
+ Component<RNKlarnaExpressCheckoutViewProps> & Readonly<NativeMethods>
71
+ >;
72
+
73
+ constructor(props: KlarnaExpressCheckoutViewProps) {
74
+ super(props);
75
+ this.state = {
76
+ nativeViewHeight: 0,
77
+ };
78
+ this.viewRef = React.createRef();
79
+ }
80
+
81
+ render() {
82
+ return (
83
+ <RNKlarnaExpressCheckoutView
84
+ ref={this.viewRef}
85
+ /* eslint-disable-next-line react-native/no-inline-styles */
86
+ style={{
87
+ width: '100%',
88
+ height:
89
+ this.state.nativeViewHeight > 0 ? this.state.nativeViewHeight : 48,
90
+ ...this.props.style,
91
+ }}
92
+ sessionType={
93
+ 'clientId' in this.props.sessionOptions ? 'clientId' : 'clientToken'
94
+ }
95
+ clientId={
96
+ 'clientId' in this.props.sessionOptions
97
+ ? this.props.sessionOptions.clientId
98
+ : ''
99
+ }
100
+ clientToken={
101
+ 'clientToken' in this.props.sessionOptions
102
+ ? this.props.sessionOptions.clientToken
103
+ : ''
104
+ }
105
+ locale={this.props.locale}
106
+ environment={this.props.environment}
107
+ region={this.props.region}
108
+ returnUrl={this.props.returnUrl}
109
+ theme={this.props.theme ?? ''}
110
+ shape={this.props.shape ?? ''}
111
+ buttonStyle={this.props.buttonStyle ?? ''}
112
+ autoFinalize={this.props.autoFinalize ?? true}
113
+ collectShippingAddress={this.props.collectShippingAddress ?? false}
114
+ sessionData={normalizeSessionData(this.props.sessionData)}
115
+ onAuthorized={(
116
+ event: NativeSyntheticEvent<
117
+ Readonly<{
118
+ readonly authorizationResponse: Readonly<{
119
+ readonly showForm: boolean;
120
+ readonly approved: boolean;
121
+ readonly finalizedRequired: boolean;
122
+ readonly clientToken: string;
123
+ readonly authorizationToken: string;
124
+ readonly sessionId: string;
125
+ readonly collectedShippingAddress: string;
126
+ readonly merchantReference1: string;
127
+ readonly merchantReference2: string;
128
+ }>;
129
+ }>
130
+ >
131
+ ) => {
132
+ this.props.onAuthorized?.(event.nativeEvent.authorizationResponse);
133
+ }}
134
+ onError={(
135
+ event: NativeSyntheticEvent<
136
+ Readonly<{
137
+ readonly error: Readonly<{
138
+ readonly isFatal: boolean;
139
+ readonly message: string;
140
+ readonly name: string;
141
+ }>;
142
+ }>
143
+ >
144
+ ) => {
145
+ const mobileSdkError: KlarnaMobileSDKError = {
146
+ isFatal: event.nativeEvent.error.isFatal,
147
+ message: event.nativeEvent.error.message,
148
+ name: event.nativeEvent.error.name,
149
+ };
150
+ this.props.onError?.(mobileSdkError);
151
+ }}
152
+ onResized={(
153
+ event: NativeSyntheticEvent<
154
+ Readonly<{
155
+ readonly height: string;
156
+ }>
157
+ >
158
+ ) => {
159
+ const newHeight = Number(event.nativeEvent.height);
160
+ if (newHeight !== this.state.nativeViewHeight) {
161
+ this.setState({ nativeViewHeight: newHeight });
162
+ }
163
+ }}
164
+ />
165
+ );
166
+ }
167
+ }
168
+
169
+ export default KlarnaExpressCheckoutView;
@@ -0,0 +1,157 @@
1
+ import React, { Component, type RefObject } from 'react';
2
+ import {
3
+ type NativeMethods,
4
+ type NativeSyntheticEvent,
5
+ StyleSheet,
6
+ type ViewStyle,
7
+ } from 'react-native';
8
+ import type { KlarnaMobileSDKError } from './types/common/KlarnaMobileSDKError';
9
+ import type { KlarnaOSMPlacementKey } from './types/common/KlarnaOSMPlacementKey';
10
+ import { KlarnaEnvironment } from './types/common/KlarnaEnvironment';
11
+ import { KlarnaRegion } from './types/common/KlarnaRegion';
12
+ import { KlarnaTheme } from './types/common/KlarnaTheme';
13
+ import RNKlarnaOSMView, {
14
+ Commands as RNKlarnaOSMViewCommands,
15
+ type RNKlarnaOSMViewProps,
16
+ } from './specs/KlarnaOSMViewNativeComponent';
17
+
18
+ export interface KlarnaOSMViewProps {
19
+ style?: ViewStyle;
20
+ readonly clientId: string;
21
+ readonly placementKey: KlarnaOSMPlacementKey;
22
+ readonly locale: string;
23
+ readonly purchaseAmount: string;
24
+ readonly environment: KlarnaEnvironment;
25
+ readonly region: KlarnaRegion;
26
+ readonly theme?: KlarnaTheme;
27
+ readonly backgroundColor?: string;
28
+ readonly textColor?: string;
29
+ readonly returnUrl?: string;
30
+ readonly onError?: (error: KlarnaMobileSDKError) => void;
31
+ }
32
+
33
+ interface KlarnaOSMViewState {
34
+ nativeViewHeight: number;
35
+ }
36
+
37
+ export class KlarnaOSMView extends Component<
38
+ KlarnaOSMViewProps,
39
+ KlarnaOSMViewState
40
+ > {
41
+ private osmViewRef: RefObject<
42
+ Component<RNKlarnaOSMViewProps> & Readonly<NativeMethods>
43
+ >;
44
+ private isOSMViewReady = false;
45
+ private hasError = false;
46
+
47
+ constructor(props: KlarnaOSMViewProps) {
48
+ super(props);
49
+ this.state = {
50
+ nativeViewHeight: 0,
51
+ };
52
+ this.osmViewRef = React.createRef();
53
+ }
54
+
55
+ componentDidUpdate(prevProps: KlarnaOSMViewProps) {
56
+ if (
57
+ this.isOSMViewReady &&
58
+ (prevProps.clientId !== this.props.clientId ||
59
+ prevProps.placementKey !== this.props.placementKey ||
60
+ prevProps.locale !== this.props.locale ||
61
+ prevProps.purchaseAmount !== this.props.purchaseAmount ||
62
+ prevProps.environment !== this.props.environment ||
63
+ prevProps.region !== this.props.region ||
64
+ prevProps.theme !== this.props.theme ||
65
+ prevProps.backgroundColor !== this.props.backgroundColor ||
66
+ prevProps.textColor !== this.props.textColor)
67
+ ) {
68
+ this.renderNative();
69
+ }
70
+ }
71
+
72
+ componentWillUnmount() {
73
+ this.isOSMViewReady = false;
74
+ }
75
+
76
+ render() {
77
+ return (
78
+ <RNKlarnaOSMView
79
+ ref={this.osmViewRef}
80
+ style={[
81
+ styles.container,
82
+ this.props.style,
83
+ { height: this.state.nativeViewHeight },
84
+ ]}
85
+ clientId={this.props.clientId}
86
+ placementKey={this.props.placementKey}
87
+ locale={this.props.locale}
88
+ purchaseAmount={this.props.purchaseAmount}
89
+ environment={this.props.environment}
90
+ region={this.props.region}
91
+ theme={this.props.theme ?? KlarnaTheme.Automatic}
92
+ backgroundColor={this.props.backgroundColor ?? ''}
93
+ textColor={this.props.textColor ?? ''}
94
+ returnUrl={this.props.returnUrl ?? ''}
95
+ onError={(
96
+ event: NativeSyntheticEvent<
97
+ Readonly<{
98
+ readonly error: Readonly<{
99
+ readonly isFatal: boolean;
100
+ readonly message: string;
101
+ readonly name: string;
102
+ }>;
103
+ }>
104
+ >
105
+ ) => {
106
+ const mobileSdkError: KlarnaMobileSDKError = {
107
+ isFatal: event.nativeEvent.error.isFatal,
108
+ message: event.nativeEvent.error.message,
109
+ name: event.nativeEvent.error.name,
110
+ };
111
+ this.hasError = true;
112
+ this.setState({ nativeViewHeight: 0 });
113
+ this.props.onError?.(mobileSdkError);
114
+ }}
115
+ onResized={(
116
+ event: NativeSyntheticEvent<
117
+ Readonly<{
118
+ readonly height: string;
119
+ }>
120
+ >
121
+ ) => {
122
+ if (this.hasError) {
123
+ return;
124
+ }
125
+ const newHeight = Number(event.nativeEvent.height);
126
+ if (
127
+ !Number.isNaN(newHeight) &&
128
+ newHeight !== this.state.nativeViewHeight
129
+ ) {
130
+ this.setState({ nativeViewHeight: newHeight });
131
+ }
132
+ }}
133
+ onOSMViewReady={() => {
134
+ this.isOSMViewReady = true;
135
+ setTimeout(() => this.renderNative(), 0);
136
+ }}
137
+ />
138
+ );
139
+ }
140
+
141
+ private renderNative = () => {
142
+ this.hasError = false;
143
+ const view = this.osmViewRef.current;
144
+ if (view != null) {
145
+ RNKlarnaOSMViewCommands.render(view);
146
+ }
147
+ };
148
+ }
149
+
150
+ const styles = StyleSheet.create({
151
+ container: {
152
+ width: '100%',
153
+ overflow: 'hidden',
154
+ },
155
+ });
156
+
157
+ export default KlarnaOSMView;
@@ -201,8 +201,7 @@ interface KlarnaWebViewNativeEvent {
201
201
  readonly canGoForward: boolean;
202
202
  }
203
203
 
204
- export interface KlarnaWebViewNavigationEvent
205
- extends KlarnaWebViewNativeEvent {}
204
+ export interface KlarnaWebViewNavigationEvent extends KlarnaWebViewNativeEvent {}
206
205
 
207
206
  export interface KlarnaWebViewError extends KlarnaWebViewNativeEvent {
208
207
  readonly code: number;
package/src/index.tsx CHANGED
@@ -2,3 +2,14 @@ export * from './KlarnaPaymentView';
2
2
  export * from './KlarnaStandaloneWebView';
3
3
  export * from './KlarnaCheckoutView';
4
4
  export * from './KlarnaSignInSDK';
5
+ export * from './KlarnaExpressCheckoutView';
6
+ export * from './types/common/KlarnaEnvironment';
7
+ export * from './types/common/KlarnaRegion';
8
+ export * from './types/common/KlarnaExpressCheckoutSessionOptions';
9
+ export * from './types/button/KlarnaButtonTheme';
10
+ export * from './types/button/KlarnaButtonShape';
11
+ export * from './types/button/KlarnaButtonStyle';
12
+ export * from './KlarnaOSMView';
13
+ export * from './types/common/KlarnaTheme';
14
+ export { KlarnaEnvironment } from './types/common/KlarnaEnvironment';
15
+ export { KlarnaRegion } from './types/common/KlarnaRegion';
@@ -0,0 +1,66 @@
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 codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
5
+
6
+ export interface RNKlarnaExpressCheckoutViewProps extends ViewProps {
7
+ // Session configuration
8
+ readonly sessionType: string;
9
+ readonly clientId: string;
10
+ readonly clientToken: string;
11
+
12
+ // Required configuration
13
+ readonly locale: string;
14
+ readonly environment: string;
15
+ readonly region: string;
16
+ readonly returnUrl: string;
17
+
18
+ // Style props
19
+ readonly theme: string;
20
+ readonly shape: string;
21
+ readonly buttonStyle: string;
22
+
23
+ // Optional configuration
24
+ readonly autoFinalize: boolean;
25
+ readonly collectShippingAddress: boolean;
26
+ readonly sessionData: string;
27
+
28
+ // Events
29
+ readonly onAuthorized: DirectEventHandler<
30
+ Readonly<{
31
+ readonly authorizationResponse: Readonly<{
32
+ readonly showForm: boolean;
33
+ readonly approved: boolean;
34
+ readonly finalizedRequired: boolean;
35
+ readonly clientToken: string;
36
+ readonly authorizationToken: string;
37
+ readonly sessionId: string;
38
+ readonly collectedShippingAddress: string;
39
+ readonly merchantReference1: string;
40
+ readonly merchantReference2: string;
41
+ }>;
42
+ }>
43
+ >;
44
+ readonly onError: DirectEventHandler<
45
+ Readonly<{
46
+ readonly error: Readonly<{
47
+ readonly isFatal: boolean;
48
+ readonly message: string;
49
+ readonly name: string;
50
+ }>;
51
+ }>
52
+ >;
53
+ readonly onResized: DirectEventHandler<
54
+ Readonly<{
55
+ // number not supported for events
56
+ readonly height: string;
57
+ }>
58
+ >;
59
+ }
60
+
61
+ type KlarnaExpressCheckoutViewNativeComponentType =
62
+ HostComponent<RNKlarnaExpressCheckoutViewProps>;
63
+
64
+ export default codegenNativeComponent<RNKlarnaExpressCheckoutViewProps>(
65
+ 'RNKlarnaExpressCheckoutView'
66
+ ) as KlarnaExpressCheckoutViewNativeComponentType;
@@ -0,0 +1,50 @@
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 RNKlarnaOSMViewProps extends ViewProps {
9
+ readonly clientId: string;
10
+ readonly placementKey: string;
11
+ readonly locale: string;
12
+ readonly purchaseAmount: string;
13
+ readonly environment: string;
14
+ readonly region: string;
15
+ readonly theme: string;
16
+ readonly backgroundColor: string;
17
+ readonly textColor: string;
18
+ readonly returnUrl?: string;
19
+ readonly onError: DirectEventHandler<
20
+ Readonly<{
21
+ readonly error: Readonly<{
22
+ readonly isFatal: boolean;
23
+ readonly message: string;
24
+ readonly name: string;
25
+ }>;
26
+ }>
27
+ >;
28
+ readonly onResized: DirectEventHandler<
29
+ Readonly<{
30
+ // number not supported for events
31
+ readonly height: string;
32
+ }>
33
+ >;
34
+ readonly onOSMViewReady?: DirectEventHandler<{}>;
35
+ }
36
+
37
+ type KlarnaOSMViewNativeComponentType = HostComponent<RNKlarnaOSMViewProps>;
38
+
39
+ interface RNKlarnaOSMViewNativeCommands {
40
+ render: (viewRef: React.ElementRef<KlarnaOSMViewNativeComponentType>) => void;
41
+ }
42
+
43
+ export const Commands: RNKlarnaOSMViewNativeCommands =
44
+ codegenNativeCommands<RNKlarnaOSMViewNativeCommands>({
45
+ supportedCommands: ['render'],
46
+ });
47
+
48
+ export default codegenNativeComponent<RNKlarnaOSMViewProps>(
49
+ 'RNKlarnaOSMView'
50
+ ) as KlarnaOSMViewNativeComponentType;
@@ -1,6 +1,6 @@
1
1
  import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
- import type { KlarnaProductEvent } from 'src/types/common/KlarnaProductEvent';
3
+ import { KlarnaProductEvent } from '../types/common/KlarnaProductEvent';
4
4
 
5
5
  export interface Spec extends TurboModule {
6
6
  init(
@@ -0,0 +1,5 @@
1
+ export enum KlarnaButtonShape {
2
+ RoundedRect = 'roundedRect',
3
+ Pill = 'pill',
4
+ Rectangle = 'rectangle',
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum KlarnaButtonStyle {
2
+ Filled = 'filled',
3
+ Outlined = 'outlined',
4
+ }
@@ -0,0 +1,5 @@
1
+ export enum KlarnaButtonTheme {
2
+ Light = 'light',
3
+ Dark = 'dark',
4
+ Auto = 'auto',
5
+ }
@@ -0,0 +1,13 @@
1
+ export namespace KlarnaExpressCheckoutSessionOptions {
2
+ export interface ClientSideSession {
3
+ readonly clientId: string;
4
+ }
5
+
6
+ export interface ServerSideSession {
7
+ readonly clientToken: string;
8
+ }
9
+ }
10
+
11
+ export type KlarnaExpressCheckoutSessionOptions =
12
+ | KlarnaExpressCheckoutSessionOptions.ClientSideSession
13
+ | KlarnaExpressCheckoutSessionOptions.ServerSideSession;
@@ -0,0 +1,3 @@
1
+ export type KlarnaOSMPlacementKey =
2
+ | 'credit-promotion-auto-size'
3
+ | 'credit-promotion-badge';
@@ -0,0 +1,5 @@
1
+ export enum KlarnaTheme {
2
+ Light = 'light',
3
+ Dark = 'dark',
4
+ Automatic = 'automatic',
5
+ }