react-nomba-checkout-sdk 1.0.3 → 2.0.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.
- package/README.md +57 -27
- package/dist/apis/useNombaCheckout.d.ts +2 -2
- package/dist/assets/CloseIcon.d.ts +1 -1
- package/dist/components/NombaCheckoutModal.d.ts +2 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.esm.js +37 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +37 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/apis/useNombaCheckout.ts +6 -12
- package/src/assets/CloseIcon.tsx +11 -11
- package/src/components/NombaCheckoutModal.tsx +22 -7
- package/src/index.tsx +12 -12
package/dist/index.js
CHANGED
|
@@ -4038,40 +4038,34 @@ var EventBus = /** @class */ (function () {
|
|
|
4038
4038
|
var eventBus = new EventBus();
|
|
4039
4039
|
|
|
4040
4040
|
var useNombaCheckout = function (payload) { return __awaiter(undefined, undefined, undefined, function () {
|
|
4041
|
-
var
|
|
4042
|
-
var _a, _b, _c
|
|
4043
|
-
return __generator(this, function (
|
|
4044
|
-
switch (
|
|
4041
|
+
var response, error_1;
|
|
4042
|
+
var _a, _b, _c;
|
|
4043
|
+
return __generator(this, function (_d) {
|
|
4044
|
+
switch (_d.label) {
|
|
4045
4045
|
case 0:
|
|
4046
|
-
|
|
4047
|
-
return [4 /*yield*/, useGenerateToken({
|
|
4048
|
-
clientId: payload.clientId,
|
|
4049
|
-
clientSecret: payload.clientSecret,
|
|
4050
|
-
accountId: payload.accountId,
|
|
4051
|
-
environment: payload.environment,
|
|
4052
|
-
})];
|
|
4053
|
-
case 1:
|
|
4054
|
-
tokenResponse = _f.sent();
|
|
4046
|
+
_d.trys.push([0, 2, , 3]);
|
|
4055
4047
|
return [4 /*yield*/, handleNombaApiCall('/checkout/order', 'POST', {
|
|
4056
4048
|
order: __assign(__assign({}, payload.order), { accountId: payload.accountId }),
|
|
4057
4049
|
tokenizeCard: payload.tokenizeCard,
|
|
4058
4050
|
}, {
|
|
4059
|
-
Authorization: "Bearer ".concat((_b = (_a = tokenResponse === null || tokenResponse === undefined ? undefined : tokenResponse.data) === null || _a === undefined ? undefined : _a.data) === null || _b === undefined ? undefined : _b.access_token),
|
|
4060
4051
|
accountId: payload.accountId,
|
|
4052
|
+
public_key: payload.clientId,
|
|
4053
|
+
'X-Nomba-Integration': 'react-sdk',
|
|
4061
4054
|
}, payload.environment)];
|
|
4062
|
-
case
|
|
4063
|
-
response =
|
|
4055
|
+
case 1:
|
|
4056
|
+
response = _d.sent();
|
|
4064
4057
|
eventBus.emit('openModal', {
|
|
4065
|
-
orderId: (
|
|
4058
|
+
orderId: (_b = (_a = response === null || response === undefined ? undefined : response.data) === null || _a === undefined ? undefined : _a.data) === null || _b === undefined ? undefined : _b.orderReference,
|
|
4066
4059
|
onClose: payload.onClose,
|
|
4060
|
+
onPaymentSuccess: payload.onPaymentSuccess,
|
|
4067
4061
|
environment: payload.environment,
|
|
4068
4062
|
});
|
|
4069
|
-
return [2 /*return*/, response.data];
|
|
4070
|
-
case
|
|
4071
|
-
error_1 =
|
|
4072
|
-
(
|
|
4063
|
+
return [2 /*return*/, payload.onCreateOrder(response.data)];
|
|
4064
|
+
case 2:
|
|
4065
|
+
error_1 = _d.sent();
|
|
4066
|
+
(_c = payload.onFailure) === null || _c === undefined ? undefined : _c.call(payload, error_1);
|
|
4073
4067
|
return [2 /*return*/, error_1];
|
|
4074
|
-
case
|
|
4068
|
+
case 3: return [2 /*return*/];
|
|
4075
4069
|
}
|
|
4076
4070
|
});
|
|
4077
4071
|
}); };
|
|
@@ -4079,9 +4073,9 @@ var useNombaCheckout = function (payload) { return __awaiter(undefined, undefine
|
|
|
4079
4073
|
var Loader = function () { return (React.createElement("svg", { width: "18", height: "21", viewBox: "0 0 18 21", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
4080
4074
|
React.createElement("path", { d: "M10.3203 8.49095L12.002 7.47669L13.6836 6.46243L15.3652 5.44817L17.0468 4.43393V0.545959L15.3652 1.56021L13.6836 2.57447L12.002 3.58872L10.3203 4.60297L8.63871 5.6172V7.56118L6.95709 6.54697L5.27546 5.53271L3.50974 4.51845L1.82811 3.5042L0.146484 2.48994V6.37789L1.82811 7.39215L3.50974 8.40641L5.19136 9.42067L6.87298 10.4349L8.5546 11.4492L6.87298 12.4634L5.19136 13.4777L3.50974 14.4919L1.82811 15.5062L0.146484 16.3514V20.2394L1.82811 19.2251L3.50974 18.2108L5.19136 17.1966L6.87298 16.1824L8.5546 15.1681V13.2241L10.2362 14.2383L11.9179 15.2526L13.5995 16.2669L15.2811 17.2811L16.9628 18.2954V14.4074L15.2811 13.3932L13.5995 12.3789L11.9179 11.3646L10.2362 10.3504L8.5546 9.33613L10.3203 8.49095Z", fill: "#121212" }))); };
|
|
4081
4075
|
|
|
4082
|
-
var CloseIcon = function () { return (React.createElement("svg", { width:
|
|
4083
|
-
React.createElement("rect", { width:
|
|
4084
|
-
React.createElement("path", {
|
|
4076
|
+
var CloseIcon = function () { return (React.createElement("svg", { width: '32', height: '32', viewBox: '0 0 32 32', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
4077
|
+
React.createElement("rect", { width: '32', height: '32', rx: '16', fill: '#F2F2F2', fillOpacity: '0.64' }),
|
|
4078
|
+
React.createElement("path", { fillRule: 'evenodd', clipRule: 'evenodd', d: 'M11.7646 11.7646C11.8948 11.6344 12.1059 11.6344 12.236 11.7646L16.0003 15.5289L19.7646 11.7646C19.8948 11.6344 20.1059 11.6344 20.236 11.7646C20.3662 11.8948 20.3662 12.1059 20.236 12.236L16.4717 16.0003L20.236 19.7646C20.3662 19.8948 20.3662 20.1059 20.236 20.236C20.1059 20.3662 19.8948 20.3662 19.7646 20.236L16.0003 16.4717L12.236 20.236C12.1059 20.3662 11.8948 20.3662 11.7646 20.236C11.6344 20.1059 11.6344 19.8948 11.7646 19.7646L15.5289 16.0003L11.7646 12.236C11.6344 12.1059 11.6344 11.8948 11.7646 11.7646Z', fill: '#0D0D0D' }))); };
|
|
4085
4079
|
|
|
4086
4080
|
var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
4087
4081
|
__extends(NombaCheckoutModal, _super);
|
|
@@ -4098,26 +4092,41 @@ var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
|
4098
4092
|
_this.handleIframeLoad = function () {
|
|
4099
4093
|
_this.setState({ isLoading: false });
|
|
4100
4094
|
};
|
|
4095
|
+
_this.handleMessage = function (event) {
|
|
4096
|
+
var _a, _b, _c;
|
|
4097
|
+
if (((_a = event.data) === null || _a === undefined ? undefined : _a.type) === 'onSuccess') {
|
|
4098
|
+
(_b = _this.state) === null || _b === undefined ? undefined : _b.onPaymentSuccess((_c = event.data) === null || _c === undefined ? undefined : _c.orderDetails);
|
|
4099
|
+
}
|
|
4100
|
+
};
|
|
4101
4101
|
_this.state = {
|
|
4102
4102
|
orderId: '',
|
|
4103
4103
|
isLoading: true,
|
|
4104
4104
|
isOpen: false,
|
|
4105
4105
|
onClose: function () { },
|
|
4106
|
+
onPaymentSuccess: function () { },
|
|
4106
4107
|
environment: 'live',
|
|
4107
4108
|
};
|
|
4108
4109
|
return _this;
|
|
4109
4110
|
}
|
|
4110
4111
|
NombaCheckoutModal.prototype.componentDidMount = function () {
|
|
4111
4112
|
var _this = this;
|
|
4113
|
+
window.addEventListener('message', this.handleMessage);
|
|
4112
4114
|
eventBus.on('openModal', function (_a) {
|
|
4113
|
-
var orderId = _a.orderId, onClose = _a.onClose, environment = _a.environment;
|
|
4114
|
-
_this.setState({
|
|
4115
|
+
var orderId = _a.orderId, onClose = _a.onClose, environment = _a.environment, onPaymentSuccess = _a.onPaymentSuccess;
|
|
4116
|
+
_this.setState({
|
|
4117
|
+
isOpen: true,
|
|
4118
|
+
orderId: orderId,
|
|
4119
|
+
onClose: onClose,
|
|
4120
|
+
environment: environment,
|
|
4121
|
+
onPaymentSuccess: onPaymentSuccess,
|
|
4122
|
+
});
|
|
4115
4123
|
});
|
|
4116
4124
|
eventBus.on('closeModal', function () {
|
|
4117
4125
|
_this.setState({ isOpen: false });
|
|
4118
4126
|
});
|
|
4119
4127
|
};
|
|
4120
4128
|
NombaCheckoutModal.prototype.componentWillUnmount = function () {
|
|
4129
|
+
window.removeEventListener('message', this.handleMessage);
|
|
4121
4130
|
eventBus.off('openModal', this.handleOpen);
|
|
4122
4131
|
eventBus.off('closeModal', this.handleClose);
|
|
4123
4132
|
};
|
|
@@ -4133,7 +4142,7 @@ var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
|
4133
4142
|
React.createElement(Loader, null))),
|
|
4134
4143
|
React.createElement("button", { style: modalStyles.closeButton, onClick: this.handleClose },
|
|
4135
4144
|
React.createElement(CloseIcon, null)),
|
|
4136
|
-
React.createElement("iframe", { src: "https://checkout.nomba.com/".concat(this.state.environment === 'sandbox' ? 'sandbox' : 'pay', "/").concat(orderId), allow: 'clipboard-write clipboard-read', width: '100%', height: '80vh', style: modalStyles.iframe, title: 'Nomba checkout', onLoad: this.handleIframeLoad })))));
|
|
4145
|
+
React.createElement("iframe", { src: "https://checkout.nomba.com/".concat(this.state.environment === 'sandbox' ? 'sandbox' : 'pay', "/").concat(orderId), allow: 'clipboard-write clipboard-read', width: '100%', height: '80vh', style: modalStyles.iframe, title: 'Nomba checkout', onLoad: this.handleIframeLoad, id: 'checkout-sdk-iframe', name: 'react-sdk' })))));
|
|
4137
4146
|
};
|
|
4138
4147
|
return NombaCheckoutModal;
|
|
4139
4148
|
}(React.Component));
|