@speedlo/payments
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -83,5 +83,5 @@ 'use strict'; | ||
var noop = function () { return null; }; | ||
var useGoPay = function (queryPaymentStatus, redirectUrl, onError, onFinish) { | ||
if (onFinish === void 0) { onFinish = noop; } | ||
var _a = __read(React.useState(false), 2), paymentLoading = _a[0], setPaymentLoading = _a[1]; | ||
var useGoPay = function (queryPaymentStatus, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.onError, onError = _c === void 0 ? noop : _c, _d = _b.onFinish, onFinish = _d === void 0 ? noop : _d, redirectUrl = _b.redirectUrl; | ||
var _e = __read(React.useState(false), 2), paymentLoading = _e[0], setPaymentLoading = _e[1]; | ||
var reportErrors = function (paymentStatus) { | ||
@@ -99,18 +99,23 @@ // returns whether any error was reported | ||
}; | ||
var handlePaymentStatus = function (orderId) { return __awaiter(_this, void 0, void 0, function () { | ||
var paymentStatus, hasError; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, queryPaymentStatus(orderId)]; | ||
case 1: | ||
paymentStatus = _a.sent(); | ||
hasError = reportErrors(paymentStatus); | ||
if (!hasError) { | ||
onFinish(); | ||
location.replace(redirectUrl); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
var handlePaymentStatus = function (orderId) { | ||
if (orderId === void 0) { orderId = null; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var paymentStatus, hasError; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, queryPaymentStatus(orderId)]; | ||
case 1: | ||
paymentStatus = _a.sent(); | ||
hasError = reportErrors(paymentStatus); | ||
if (!hasError) { | ||
onFinish(); | ||
if (redirectUrl) { | ||
location.replace(redirectUrl); | ||
} | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
}; | ||
React.useEffect(function () { | ||
@@ -117,0 +122,0 @@ // retrieve orderId from the url |
@@ -1,8 +0,11 @@ | ||
declare type PaymentStatus = null | { | ||
interface PaymentStatus { | ||
readonly isSuccess: boolean; | ||
readonly userErrors: ReadonlyArray<string>; | ||
}; | ||
declare type QueryCallback = (orderId?: string) => Promise<PaymentStatus>; | ||
declare type ErrorHandler = (userErrors: ReadonlyArray<string>) => void; | ||
export declare const useGoPay: (queryPaymentStatus: QueryCallback, redirectUrl: string, onError: ErrorHandler, onFinish?: () => void) => { | ||
} | ||
interface IOptions { | ||
redirectUrl: string; | ||
onError: (userErrors: ReadonlyArray<string>) => void; | ||
onFinish: () => void; | ||
} | ||
export declare const useGoPay: (queryPaymentStatus: (orderId: string | null) => Promise<PaymentStatus | null>, { onError, onFinish, redirectUrl }?: Partial<IOptions>) => { | ||
executeGoPayPayment: (gatewayUrl: string) => Promise<void>; | ||
@@ -9,0 +12,0 @@ paymentLoading: boolean; |
{ | ||
"name": "@speedlo/payments", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"scripts": { | ||
@@ -34,3 +34,3 @@ "prepublish": "node ../../util/builder.js" | ||
}, | ||
"gitHead": "d0b62b18c5e6804861c69b52c79810b7cbd73a47" | ||
"gitHead": "0671127a16740a91ea37c9b97cc16e338a191256" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15178
183