react-native-klarna-inapp-sdk
Version:
This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.
170 lines (169 loc) • 6.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.KlarnaPaymentView = void 0;
var _react = _interopRequireWildcard(require("react"));
var _KlarnaPaymentViewNativeComponent = _interopRequireWildcard(require("./specs/KlarnaPaymentViewNativeComponent"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
class KlarnaPaymentView extends _react.Component {
constructor(props) {
super(props);
this.state = {
nativeViewHeight: 0
};
this.paymentViewRef = /*#__PURE__*/_react.default.createRef();
}
render() {
return /*#__PURE__*/_react.default.createElement(_KlarnaPaymentViewNativeComponent.default, {
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) {
_KlarnaPaymentViewNativeComponent.Commands.initialize(view, clientToken, returnUrl || '');
}
};
load = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.load(view, sessionData || '');
}
};
loadPaymentReview = () => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.loadPaymentReview(view);
}
};
authorize = (autoFinalize = true, sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.authorize(view, autoFinalize || true, sessionData || '');
}
};
reauthorize = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.reauthorize(view, sessionData || '');
}
};
finalize = (sessionData = null) => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.finalize(view, sessionData || '');
}
};
}
exports.KlarnaPaymentView = KlarnaPaymentView;
var _default = exports.default = KlarnaPaymentView;
//# sourceMappingURL=KlarnaPaymentView.js.map