react-native-klarna-inapp-sdk
Version:
This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.
162 lines • 5.82 kB
JavaScript
import React, { Component } from 'react';
import RNKlarnaPaymentView, { Commands as RNKlarnaPaymentViewCommands } from './specs/KlarnaPaymentViewNativeComponent';
export class KlarnaPaymentView extends Component {
constructor(props) {
super(props);
this.state = {
nativeViewHeight: 0
};
this.paymentViewRef = /*#__PURE__*/React.createRef();
}
render() {
return /*#__PURE__*/React.createElement(RNKlarnaPaymentView, {
ref: this.paymentViewRef
/* eslint-disable-next-line react-native/no-inline-styles */,
style: {
width: '100%',
height: this.state.nativeViewHeight,
flexShrink: 1
},
category: this.props.category || '',
returnUrl: this.props.returnUrl || '',
onInitialized: _event => {
if (this.props.onInitialized != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onInitialized === 'function' && this.props.onInitialized.length === 1) {
this.props.onInitialized(_event);
} else {
// @ts-ignore
this.props.onInitialized();
}
}
},
onLoaded: _event => {
if (this.props.onLoaded != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onLoaded === 'function' && this.props.onLoaded.length === 1) {
this.props.onLoaded(_event);
} else {
// @ts-ignore
this.props.onLoaded();
}
}
},
onLoadedPaymentReview: _event => {
if (this.props.onLoadedPaymentReview != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onLoadedPaymentReview === 'function' && this.props.onLoadedPaymentReview.length === 1) {
this.props.onLoadedPaymentReview(_event);
} else {
// @ts-ignore
this.props.onLoadedPaymentReview();
}
}
},
onAuthorized: event => {
if (this.props.onAuthorized != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onAuthorized === 'function' && this.props.onAuthorized.length === 1) {
// @ts-ignore
this.props.onAuthorized(event);
} else {
this.props.onAuthorized(event.nativeEvent.approved, event.nativeEvent.authToken === '' ? null : event.nativeEvent.authToken, event.nativeEvent.finalizeRequired);
}
}
},
onReauthorized: event => {
if (this.props.onReauthorized != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onReauthorized === 'function' && this.props.onReauthorized.length === 1) {
// @ts-ignore
this.props.onReauthorized(event);
} else {
this.props.onReauthorized(event.nativeEvent.approved, event.nativeEvent.authToken === '' ? null : event.nativeEvent.authToken);
}
}
},
onFinalized: event => {
if (this.props.onFinalized != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onFinalized === 'function' && this.props.onFinalized.length === 1) {
// @ts-ignore
this.props.onFinalized(event);
} else {
this.props.onFinalized(event.nativeEvent.approved, event.nativeEvent.authToken === '' ? null : event.nativeEvent.authToken);
}
}
},
onError: event => {
if (this.props.onError != null) {
/**
* if props is the old spec {@link KlarnaReactPaymentViewOldProps}
*/
if (typeof this.props.onAuthorized === 'function' && this.props.onAuthorized.length === 1) {
// @ts-ignore
this.props.onError(event);
} else {
this.props.onError(event.nativeEvent.error);
}
}
},
onResized: event => {
const newHeight = Number(event.nativeEvent.height);
if (newHeight !== this.state.nativeViewHeight) {
console.log('onResized', newHeight);
this.setState({
nativeViewHeight: newHeight
});
}
}
});
}
initialize = (clientToken, returnUrl = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.initialize(view, clientToken, returnUrl || '');
}
};
load = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.load(view, sessionData || '');
}
};
loadPaymentReview = () => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.loadPaymentReview(view);
}
};
authorize = (autoFinalize = true, sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.authorize(view, autoFinalize || true, sessionData || '');
}
};
reauthorize = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.reauthorize(view, sessionData || '');
}
};
finalize = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
RNKlarnaPaymentViewCommands.finalize(view, sessionData || '');
}
};
}
export default KlarnaPaymentView;
//# sourceMappingURL=KlarnaPaymentView.js.map