react-native-klarna-inapp-sdk
Version:
This library wraps Klarna Mobile SDK and exposes its functionality as React Native components.
193 lines (192 loc) • 8.1 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 _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 = (() => {
var _this = this;
return function (clientToken) {
let returnUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
const view = _this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.initialize(view, clientToken, returnUrl || '');
}
};
})();
load = (() => {
var _this2 = this;
return function () {
let sessionData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
const view = _this2.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.load(view, sessionData || '');
}
};
})();
loadPaymentReview = () => {
const view = this.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.loadPaymentReview(view);
}
};
authorize = (() => {
var _this3 = this;
return function () {
let autoFinalize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
let sessionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
const view = _this3.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.authorize(view, autoFinalize || true, sessionData || '');
}
};
})();
reauthorize = (() => {
var _this4 = this;
return function () {
let sessionData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
const view = _this4.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.reauthorize(view, sessionData || '');
}
};
})();
finalize = (() => {
var _this5 = this;
return function () {
let sessionData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
const view = _this5.paymentViewRef.current;
if (view != null) {
_KlarnaPaymentViewNativeComponent.Commands.finalize(view, sessionData || '');
}
};
})();
}
exports.KlarnaPaymentView = KlarnaPaymentView;
var _default = KlarnaPaymentView;
exports.default = _default;
//# sourceMappingURL=KlarnaPaymentView.js.map