react-payline
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
export { default as PaylineProvider, PaylineHead } from './src/PaylineProvider'; | ||
export { default as withPayline } from './src/withPayline'; | ||
export { default as usePayline } from './src/usePayline'; | ||
export * from './src/usePayline'; | ||
export * from './src/PaylineWidget'; |
32
index.js
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usePayline = exports.withPayline = exports.PaylineHead = exports.PaylineProvider = void 0; | ||
var PaylineProvider_1 = require("./src/PaylineProvider"); | ||
Object.defineProperty(exports, "PaylineProvider", { enumerable: true, get: function () { return __importDefault(PaylineProvider_1).default; } }); | ||
Object.defineProperty(exports, "PaylineHead", { enumerable: true, get: function () { return PaylineProvider_1.PaylineHead; } }); | ||
exports.PaylineProvider = PaylineProvider_1.default; | ||
exports.PaylineHead = PaylineProvider_1.PaylineHead; | ||
var withPayline_1 = require("./src/withPayline"); | ||
Object.defineProperty(exports, "withPayline", { enumerable: true, get: function () { return __importDefault(withPayline_1).default; } }); | ||
var usePayline_1 = require("./src/usePayline"); | ||
Object.defineProperty(exports, "usePayline", { enumerable: true, get: function () { return __importDefault(usePayline_1).default; } }); | ||
__exportStar(require("./src/PaylineWidget"), exports); | ||
exports.withPayline = withPayline_1.default; | ||
__export(require("./src/usePayline")); | ||
__export(require("./src/PaylineWidget")); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-payline", | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"license": "MIT", | ||
@@ -20,2 +20,3 @@ "author": "alex-pex", | ||
"devDependencies": { | ||
"@types/jquery": "^3.5.16", | ||
"@types/react": "^16.9.19", | ||
@@ -22,0 +23,0 @@ "react": "^16.12.0", |
@@ -47,7 +47,7 @@ # react-payline | ||
import { useEffect } from 'react'; | ||
import { usePayline } from 'react-payline'; | ||
import { usePaylineApi } from 'react-payline'; | ||
import Payment from './Payment'; | ||
function PaymentWrapper(props) { | ||
const paylineApi = usePayline(); | ||
const paylineApi = usePaylineApi(); | ||
useEffect(() => { | ||
@@ -54,0 +54,0 @@ if (props.show) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PaylineHead = void 0; | ||
var react_1 = __importStar(require("react")); | ||
@@ -31,4 +14,4 @@ var getBaseUrl = function (production) { | ||
}; | ||
var getScriptUrl = function (production) { return "".concat(getBaseUrl(production), "/scripts/widget-min.js"); }; | ||
var getStylesheetUrl = function (production) { return "".concat(getBaseUrl(production), "/styles/widget-min.css"); }; | ||
var getScriptUrl = function (production) { return getBaseUrl(production) + "/scripts/widget-min.js"; }; | ||
var getStylesheetUrl = function (production) { return getBaseUrl(production) + "/styles/widget-min.css"; }; | ||
function PaylineHead(_a) { | ||
@@ -45,5 +28,5 @@ var _b = _a.production, production = _b === void 0 ? false : _b; | ||
var scriptUrl = getScriptUrl(production); | ||
var _c = (0, react_1.useState)(window.Payline !== undefined), setIsLoaded = _c[1]; | ||
(0, react_1.useLayoutEffect)(function () { | ||
var script = document.querySelector("script[src=\"".concat(scriptUrl, "\"]")); | ||
var _c = react_1.useState(window.Payline !== undefined), setIsLoaded = _c[1]; | ||
react_1.useLayoutEffect(function () { | ||
var script = document.querySelector("script[src=\"" + scriptUrl + "\"]"); | ||
if (!script) { | ||
@@ -63,4 +46,4 @@ script = document.createElement('script'); | ||
var stylesheetUrl = getStylesheetUrl(production); | ||
(0, react_1.useLayoutEffect)(function () { | ||
var stylesheet = document.querySelector("link[href=\"".concat(stylesheetUrl, "\"]")); | ||
react_1.useLayoutEffect(function () { | ||
var stylesheet = document.querySelector("link[href=\"" + stylesheetUrl + "\"]"); | ||
if (!stylesheet) { | ||
@@ -67,0 +50,0 @@ stylesheet = document.createElement('link'); |
import React from 'react'; | ||
declare type StateType = 'ACTIVE_WAITING' | 'BROWSER_NOT_SUPPORTED' | 'MANAGE_WEB_WALLET' | 'PAYMENT_CANCELED_WITH_RETRY' | 'PAYMENT_CANCELED' | 'PAYMENT_FAILURE_WITH_RETRY' | 'PAYMENT_FAILURE' | 'PAYMENT_METHOD_NEEDS_MORE_INFOS' | 'PAYMENT_METHODS_LIST_SHORTCUT' | 'PAYMENT_METHODS_LIST' | 'PAYMENT_ONHOLD_PARTNER' | 'PAYMENT_REDIRECT_NO_RESPONSE' | 'PAYMENT_SUCCESS_FORCE_TICKET_DISPLAY' | 'PAYMENT_SUCCESS' | 'PAYMENT_TRANSITIONAL_SHORTCUT' | 'TOKEN_EXPIRED'; | ||
export declare type StateType = 'ACTIVE_WAITING' | 'BROWSER_NOT_SUPPORTED' | 'MANAGE_WEB_WALLET' | 'PAYMENT_CANCELED_WITH_RETRY' | 'PAYMENT_CANCELED' | 'PAYMENT_FAILURE_WITH_RETRY' | 'PAYMENT_FAILURE' | 'PAYMENT_METHOD_NEEDS_MORE_INFOS' | 'PAYMENT_METHODS_LIST_SHORTCUT' | 'PAYMENT_METHODS_LIST' | 'PAYMENT_ONHOLD_PARTNER' | 'PAYMENT_REDIRECT_NO_RESPONSE' | 'PAYMENT_SUCCESS_FORCE_TICKET_DISPLAY' | 'PAYMENT_SUCCESS' | 'PAYMENT_TRANSITIONAL_SHORTCUT' | 'TOKEN_EXPIRED'; | ||
export declare type WillInitHandler = () => void; | ||
@@ -35,2 +35,1 @@ export declare type WillShowHandler = () => void; | ||
export declare const PaylineWidget: React.ComponentType<PaylineWidgetProps>; | ||
export {}; |
@@ -13,25 +13,2 @@ "use strict"; | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
@@ -48,11 +25,14 @@ var t = {}; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PaylineWidget = void 0; | ||
var react_1 = __importStar(require("react")); | ||
var usePayline_1 = __importDefault(require("./usePayline")); | ||
var usePayline_1 = require("./usePayline"); | ||
; | ||
var PaylineWidget = function (_a) { | ||
exports.PaylineWidget = function (_a) { | ||
var token = _a.token, _b = _a.template, template = _b === void 0 ? 'column' : _b, _c = _a.embeddedRedirectionAllowed, embeddedRedirectionAllowed = _c === void 0 ? false : _c, partnerReturnUrl = _a.partnerReturnUrl, onWillInit = _a.onWillInit, onWillShow = _a.onWillShow, onFinalStateHasBeenReached = _a.onFinalStateHasBeenReached, onDidShowState = _a.onDidShowState, onWillDisplayMessage = _a.onWillDisplayMessage, onWillRemoveMessage = _a.onWillRemoveMessage, onBeforePayment = _a.onBeforePayment, htmlAttributes = __rest(_a, ["token", "template", "embeddedRedirectionAllowed", "partnerReturnUrl", "onWillInit", "onWillShow", "onFinalStateHasBeenReached", "onDidShowState", "onWillDisplayMessage", "onWillRemoveMessage", "onBeforePayment"]); | ||
@@ -68,8 +48,8 @@ var eventHandlers = { | ||
}; | ||
var eventHandlersRef = (0, react_1.useRef)(eventHandlers); | ||
var eventHandlersRef = react_1.useRef(eventHandlers); | ||
eventHandlersRef.current = eventHandlers; | ||
(0, react_1.useEffect)(function () { | ||
react_1.useEffect(function () { | ||
var propNames = Object.keys(eventHandlersRef.current); | ||
propNames.forEach(function (propName) { | ||
window["Payline_".concat(propName)] = function () { | ||
window["Payline_" + propName] = function () { | ||
var args = []; | ||
@@ -88,8 +68,8 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
propNames.forEach(function (propName) { | ||
delete window["Payline_".concat(propName)]; | ||
delete window["Payline_" + propName]; | ||
}); | ||
}; | ||
}, []); | ||
var payline = (0, usePayline_1.default)(); | ||
(0, react_1.useEffect)(function () { | ||
var payline = usePayline_1.usePaylineApi(); | ||
react_1.useEffect(function () { | ||
if (payline) { | ||
@@ -102,3 +82,2 @@ payline.reset(); | ||
}; | ||
exports.PaylineWidget = PaylineWidget; | ||
//# sourceMappingURL=PaylineWidget.js.map |
@@ -0,1 +1,2 @@ | ||
/// <reference types="jquery" /> | ||
declare type PaylineApi = { | ||
@@ -29,6 +30,8 @@ endToken: (additionnalData: any, callback: () => void, spinner: any, handledByMerchant: boolean) => void; | ||
Api: PaylineApi; | ||
jQuery: JQuery; | ||
}; | ||
} | ||
} | ||
declare const usePayline: () => PaylineApi | undefined; | ||
export default usePayline; | ||
export declare const usePaylineApi: () => PaylineApi | undefined; | ||
export declare const usePaylineJQuery: () => JQuery<HTMLElement> | undefined; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
var usePayline = function () { | ||
if (typeof window === 'undefined') | ||
return undefined; | ||
if (!window.Payline) | ||
throw new Error('window.Payline is unavailable. Check if PaylineProvider is rendered within the component tree.'); | ||
return window.Payline.Api; | ||
react_1.useEffect(function () { | ||
if (!window.Payline && !document.querySelector('script[src$="payline.com/cdn/scripts/widget-min.js"]')) | ||
throw new Error("window.Payline is unavailable. Check if PaylineProvider is rendered within the component tree."); | ||
}, []); | ||
return window.Payline; | ||
}; | ||
exports.default = usePayline; | ||
exports.usePaylineApi = function () { var _a; return (_a = usePayline()) === null || _a === void 0 ? void 0 : _a.Api; }; | ||
exports.usePaylineJQuery = function () { var _a; return (_a = usePayline()) === null || _a === void 0 ? void 0 : _a.jQuery; }; | ||
//# sourceMappingURL=usePayline.js.map |
@@ -1,3 +0,3 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import React from 'react'; | ||
declare const withPayline: (production: boolean) => <TProps>(WrappedComponent: React.ComponentType<TProps>) => (props: React.PropsWithChildren<TProps>) => JSX.Element; | ||
export default withPayline; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23210
4
273