UNPKG

react-native-klarna-inapp-sdk

Version:

This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.

64 lines 2.7 kB
import React, { Component } from 'react'; import RNKlarnaExpressCheckoutView from './specs/KlarnaExpressCheckoutViewNativeComponent'; const normalizeSessionData = sessionData => { if (sessionData !== null && sessionData !== void 0 && sessionData.trim()) { return sessionData; } return ''; }; export class KlarnaExpressCheckoutView extends Component { constructor(props) { super(props); this.state = { nativeViewHeight: 0 }; this.viewRef = /*#__PURE__*/React.createRef(); } render() { return /*#__PURE__*/React.createElement(RNKlarnaExpressCheckoutView, { ref: this.viewRef /* eslint-disable-next-line react-native/no-inline-styles */, style: { width: '100%', height: this.state.nativeViewHeight > 0 ? this.state.nativeViewHeight : 48, ...this.props.style }, sessionType: 'clientId' in this.props.sessionOptions ? 'clientId' : 'clientToken', clientId: 'clientId' in this.props.sessionOptions ? this.props.sessionOptions.clientId : '', clientToken: 'clientToken' in this.props.sessionOptions ? this.props.sessionOptions.clientToken : '', locale: this.props.locale, environment: this.props.environment, region: this.props.region, returnUrl: this.props.returnUrl, theme: this.props.theme ?? '', shape: this.props.shape ?? '', buttonStyle: this.props.buttonStyle ?? '', autoFinalize: this.props.autoFinalize ?? true, collectShippingAddress: this.props.collectShippingAddress ?? false, sessionData: normalizeSessionData(this.props.sessionData), onAuthorized: event => { var _this$props$onAuthori, _this$props; (_this$props$onAuthori = (_this$props = this.props).onAuthorized) === null || _this$props$onAuthori === void 0 || _this$props$onAuthori.call(_this$props, event.nativeEvent.authorizationResponse); }, onError: event => { var _this$props$onError, _this$props2; const mobileSdkError = { isFatal: event.nativeEvent.error.isFatal, message: event.nativeEvent.error.message, name: event.nativeEvent.error.name }; (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 || _this$props$onError.call(_this$props2, mobileSdkError); }, onResized: event => { const newHeight = Number(event.nativeEvent.height); if (newHeight !== this.state.nativeViewHeight) { this.setState({ nativeViewHeight: newHeight }); } } }); } } export default KlarnaExpressCheckoutView; //# sourceMappingURL=KlarnaExpressCheckoutView.js.map