@juspay-tech/react-hyper-js 0.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/.babelrc +3 -0
- package/bsconfig.json +19 -0
- package/build.js +29 -0
- package/index.js +1 -0
- package/package.json +65 -0
- package/src/Context.bs.js +134 -0
- package/src/Context.res +177 -0
- package/src/Index.bs.js +243 -0
- package/src/Index.res +155 -0
- package/src/Index.resi +73 -0
- package/src/OrcaJs.bs.js +58 -0
- package/src/OrcaJs.res +66 -0
- package/src/Window.bs.js +11 -0
- package/src/Window.res +26 -0
- package/webpack.config.js +34 -0
package/.babelrc
ADDED
package/bsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-orca-js",
|
|
3
|
+
"sources": [
|
|
4
|
+
{
|
|
5
|
+
"dir": "src",
|
|
6
|
+
"subdirs": true
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"package-specs": [
|
|
10
|
+
{
|
|
11
|
+
"module": "es6",
|
|
12
|
+
"in-source": true
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"suffix": ".bs.js",
|
|
16
|
+
"reason": { "react-jsx": 3 },
|
|
17
|
+
"bs-dependencies": ["@rescript/react","@ryyppy/rescript-promise", "bs-fetch"]
|
|
18
|
+
|
|
19
|
+
}
|
package/build.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const esbuild = require("esbuild");
|
|
2
|
+
const inlineImage = require("esbuild-plugin-inline-image");
|
|
3
|
+
const postcss = require("esbuild-postcss");
|
|
4
|
+
//const { copy } = require("esbuild-plugin-copy");
|
|
5
|
+
|
|
6
|
+
esbuild
|
|
7
|
+
.build({
|
|
8
|
+
entryPoints: ["./src/Index.bs.js"],
|
|
9
|
+
outfile: "index.js",
|
|
10
|
+
minify: true,
|
|
11
|
+
bundle: true,
|
|
12
|
+
loader: {
|
|
13
|
+
".js": "jsx",
|
|
14
|
+
},
|
|
15
|
+
format: "esm",
|
|
16
|
+
external: ["react", "react-dom"],
|
|
17
|
+
plugins: [
|
|
18
|
+
inlineImage(),
|
|
19
|
+
postcss(),
|
|
20
|
+
// copy({
|
|
21
|
+
// assets: {
|
|
22
|
+
// from: ["./public/**/*"],
|
|
23
|
+
// to: ["../"],
|
|
24
|
+
// keepStructure: true,
|
|
25
|
+
// },
|
|
26
|
+
// }),
|
|
27
|
+
],
|
|
28
|
+
})
|
|
29
|
+
.catch(() => process.exit(1));
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function A(e,n,t){for(var i=new Array(t),r=0,u=n;r<t;)i[r]=e[u],r=r+1|0,u=u+1|0;return i}function R(e,n){for(;;){var t=n,i=e,r=i.length,u=r===0?1:r,o=t.length,c=u-o|0;if(c===0)return i.apply(null,t);if(c>=0)return function(a,f){return function(s){return R(a,f.concat([s]))}}(i,t);n=A(t,u,-c|0),e=i.apply(null,A(t,0,u))}}function p(e,n){var t=e.length;if(t===1)return e(n);switch(t){case 1:return e(n);case 2:return function(i){return e(n,i)};case 3:return function(i,r){return e(n,i,r)};case 4:return function(i,r,u){return e(n,i,r,u)};case 5:return function(i,r,u,o){return e(n,i,r,u,o)};case 6:return function(i,r,u,o,c){return e(n,i,r,u,o,c)};case 7:return function(i,r,u,o,c,a){return e(n,i,r,u,o,c,a)};default:return R(e,[n])}}function w(e){var n=e.length;return n===1?e:function(t){return p(e,t)}}function m(e,n,t){var i=e.length;if(i===2)return e(n,t);switch(i){case 1:return R(e(n),[t]);case 2:return e(n,t);case 3:return function(r){return e(n,t,r)};case 4:return function(r,u){return e(n,t,r,u)};case 5:return function(r,u,o){return e(n,t,r,u,o)};case 6:return function(r,u,o,c){return e(n,t,r,u,o,c)};case 7:return function(r,u,o,c,a){return e(n,t,r,u,o,c,a)};default:return R(e,[n,t])}}import*as l from"react";import*as V from"react";function te(e,n){}function re(e){}function ue(e){}function ie(e){}function oe(e){}function ce(e){}function le(e){}function fe(e){}function ae(e){}var M={on:te,collapse:re,blur:ue,update:ie,destroy:oe,unmount:ce,mount:le,focus:fe,clear:ae};function _(e){return e===void 0?{BS_PRIVATE_NESTED_SOME_NONE:0}:e!==null&&e.BS_PRIVATE_NESTED_SOME_NONE!==void 0?{BS_PRIVATE_NESTED_SOME_NONE:e.BS_PRIVATE_NESTED_SOME_NONE+1|0}:e}function T(e){if(!(e!==null&&e.BS_PRIVATE_NESTED_SOME_NONE!==void 0))return e;var n=e.BS_PRIVATE_NESTED_SOME_NONE;if(n!==0)return{BS_PRIVATE_NESTED_SOME_NONE:n-1|0}}function S(e,n){if(n in e)return _(e[n])}function U(e){if(typeof e=="string")return e}function F(e){if(typeof e=="object"&&!Array.isArray(e)&&e!==null)return _(e)}function W(e){if(Array.isArray(e))return e}function ve(e,n){if(e!==void 0)return n(T(e))}function O(e,n){return ve(e,w(n))}function y(e,n){return e!==void 0?T(e):n}function _e(e){return Promise.resolve({})}function ye(e,n,t){return Promise.resolve({})}function Ce(e){return Promise.resolve({})}function Ee(e){return e}var b={clientSecret:"",confirmPayment:_e,confirmCardPayment:ye,retrievePaymentIntent:Ce,paymentRequest:Ee},C=V.createContext(b);function he(e,n,t){return{value:e,children:n}}var ge=C.Provider,I={makeProps:he,make:ge};function k(e,n,t){return y(O(S(e,n),U),t)}function $(e){var n=y(F(e),{});return{fonts:y(O(S(n,"fonts"),W),[]),locale:k(n,"locale",""),clientSecret:k(n,"clientSecret",""),appearance:y(O(S(n,"appearance"),F),{}),loader:k(n,"loader","auto")}}function Re(e){}function we(e){}function Se(e){return new Promise(function(n,t){setTimeout(function(i){n({})},1e3)})}function Oe(e,n){return M}var Ne={fonts:[],locale:"",clientSecret:"",appearance:{},loader:""},P={options:Ne,update:Re,getElement:we,fetchUpdates:Se,create:Oe},E=V.createContext(P);function Ae(e,n,t){return{value:e,children:n}}var Be=E.Provider,D={makeProps:Ae,make:Be};function q(e,n){return n.then(w(e))}function Fe(e){var n=e.children,t=e.stripe,i=e.options,r=$(i),u=l.useState(function(){return b}),o=u[1],c=l.useState(function(){return P}),a=c[1];return l.useEffect(function(){q(function(f){var s=p(f.elements,i),v=s.update,g=s.getElement,d=s.fetchUpdates,N=s.create,G={options:r,update:v,getElement:g,fetchUpdates:d,create:N},De=r.clientSecret,X=f.confirmPayment,z=f.confirmCardPayment,H=f.retrievePaymentIntent,L=f.paymentRequest,j=r.clientSecret,K=X,Q=z,Y=H,Z=L,J={clientSecret:j,confirmPayment:K,confirmCardPayment:Q,retrievePaymentIntent:Y,paymentRequest:Z};return p(o,function(ee){return J}),p(a,function(ee){return G}),Promise.resolve(J)},t)},[]),l.createElement(I.make,I.makeProps(u[0],l.createElement(D.make,D.makeProps(c[0],n,void 0)),void 0))}function Me(e){return l.useContext(C)}function Ue(e){return console.warn("useStripe() is deprecated. Use useHyper() instead"),l.useContext(C)}function We(e){return l.useContext(E)}function $e(e){return console.warn("useElements() is deprecated. Use useWidgets() instead"),l.useContext(E)}function h(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.componentType,o=e.onFocus,c=e.onBlur,a=e.onClick,f=n!==void 0?n:"payment-Element",s=l.useContext(C),v=l.useContext(E),g=l.useRef(null),d=m(v.create,u,t);return l.useEffect(function(){var N=m(v.create,u,t);p(N.mount,"#orca-elements-payment-element-"+f)},[g,v]),l.useEffect(function(){m(d.on,"ready",r),m(d.on,"focus",o),m(d.on,"blur",c),m(d.on,"clickTriggered",a),m(d.on,"change",i)},[v,s]),l.createElement("div",{ref:g,id:"orca-elements-payment-element-"+f})}function ke(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.onFocus,o=e.onBlur,c=e.onClick;return l.createElement(h,{id:n,options:t,onChange:i,onReady:r,componentType:"payment",onFocus:u,onBlur:o,onClick:c})}function Ve(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.onFocus,o=e.onBlur,c=e.onClick;return l.createElement(h,{id:n,options:t,onChange:i,onReady:r,componentType:"card",onFocus:u,onBlur:o,onClick:c})}function be(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.onFocus,o=e.onBlur,c=e.onClick;return l.createElement(h,{id:n,options:t,onChange:i,onReady:r,componentType:"cardNumberElement",onFocus:u,onBlur:o,onClick:c})}function Ie(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.onFocus,o=e.onBlur,c=e.onClick;return l.createElement(h,{id:n,options:t,onChange:i,onReady:r,componentType:"cardCVCElement",onFocus:u,onBlur:o,onClick:c})}function Pe(e){var n=e.id,t=e.options,i=e.onChange,r=e.onReady,u=e.onFocus,o=e.onBlur,c=e.onClick;return l.createElement(h,{id:n,options:t,onChange:i,onReady:r,componentType:"cardExpiryElement",onFocus:u,onBlur:o,onClick:c})}var qe=Fe,Ge=ke,Xe=Ve,ze=be,He=Pe,Le=Ie;export{Le as CardCVCElement,Xe as CardElement,He as CardExpiryElement,ze as CardNumberElement,qe as Elements,Ge as PaymentElement,$e as useElements,Me as useHyper,Ue as useStripe,We as useWidgets};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@juspay-tech/react-hyper-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@rescript/react": "^0.10.3",
|
|
7
|
+
"@ryyppy/rescript-promise": "^2.1.0",
|
|
8
|
+
"bs-fetch": "^0.6.2",
|
|
9
|
+
"bs-webapi": "^0.19.1",
|
|
10
|
+
"postcss": "^8.4.19",
|
|
11
|
+
"react-scripts": "^3.4.0"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "webpack-dev-server --open",
|
|
15
|
+
"build": "webpack --mode development; cp dist/index.js index.js",
|
|
16
|
+
"build:es": "node build.js",
|
|
17
|
+
"re:build": "rescript",
|
|
18
|
+
"re:start": "rescript build -w",
|
|
19
|
+
"publish:public": "npm publish --access public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": "^16.14.0",
|
|
23
|
+
"react-dom": "^16.9.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/cli": "^7.7.0",
|
|
27
|
+
"@babel/core": "^7.7.2",
|
|
28
|
+
"@babel/plugin-transform-react-jsx": "^7.10.1",
|
|
29
|
+
"@babel/preset-env": "^7.7.1",
|
|
30
|
+
"@babel/preset-react": "^7.7.0",
|
|
31
|
+
"babel-cli": "^6.26.0",
|
|
32
|
+
"babel-core": "^6.26.3",
|
|
33
|
+
"babel-eslint": "^10.0.3",
|
|
34
|
+
"babel-jest": "^24.9.0",
|
|
35
|
+
"babel-loader": "^8.0.6",
|
|
36
|
+
"babel-preset-env": "^1.7.0",
|
|
37
|
+
"babel-preset-react": "^6.24.1",
|
|
38
|
+
"babel-preset-stage-2": "^6.24.1",
|
|
39
|
+
"css-loader": "^0.28.11",
|
|
40
|
+
"esbuild": "^0.15.9",
|
|
41
|
+
"esbuild-plugin-copy": "^1.3.0",
|
|
42
|
+
"esbuild-plugin-inline-image": "0.0.8",
|
|
43
|
+
"esbuild-postcss": "0.0.4",
|
|
44
|
+
"node-sass": "^4.9.0",
|
|
45
|
+
"react-hot-loader": "^4.3.3",
|
|
46
|
+
"rescript": "^10.0.1",
|
|
47
|
+
"rollup-plugin-babel": "^4.3.3",
|
|
48
|
+
"sass-loader": "^7.0.3",
|
|
49
|
+
"style-loader": "^0.21.0"
|
|
50
|
+
},
|
|
51
|
+
"directories": {
|
|
52
|
+
"lib": "lib"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+ssh://git@bitbucket.org/juspay/react-orca-js.git"
|
|
57
|
+
},
|
|
58
|
+
"author": "",
|
|
59
|
+
"license": "ISC",
|
|
60
|
+
"homepage": "https://bitbucket.org/juspay/react-orca-js#readme",
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://bitbucket.org/juspay/react-orca-js/issues"
|
|
63
|
+
},
|
|
64
|
+
"description": ""
|
|
65
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as OrcaJs from "./OrcaJs.bs.js";
|
|
5
|
+
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
6
|
+
import * as Js_json from "rescript/lib/es6/js_json.js";
|
|
7
|
+
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
|
|
8
|
+
|
|
9
|
+
function confirmPaymentFn(_elements) {
|
|
10
|
+
return Promise.resolve({});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function confirmCardPaymentFn(_clientSecretId, _data, _options) {
|
|
14
|
+
return Promise.resolve({});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function retrievePaymentIntentFn(_paymentIntentId) {
|
|
18
|
+
return Promise.resolve({});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function paymentRequest(options) {
|
|
22
|
+
return options;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var defaultSwitchContext = {
|
|
26
|
+
clientSecret: "",
|
|
27
|
+
confirmPayment: confirmPaymentFn,
|
|
28
|
+
confirmCardPayment: confirmCardPaymentFn,
|
|
29
|
+
retrievePaymentIntent: retrievePaymentIntentFn,
|
|
30
|
+
paymentRequest: paymentRequest
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var switchContext = React.createContext(defaultSwitchContext);
|
|
34
|
+
|
|
35
|
+
function makeProps(value, children, param) {
|
|
36
|
+
return {
|
|
37
|
+
value: value,
|
|
38
|
+
children: children
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var make = switchContext.Provider;
|
|
43
|
+
|
|
44
|
+
var SwitchContextProvider = {
|
|
45
|
+
makeProps: makeProps,
|
|
46
|
+
make: make
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function getString(dict, key, defaultVal) {
|
|
50
|
+
return Belt_Option.getWithDefault(Belt_Option.flatMap(Js_dict.get(dict, key), Js_json.decodeString), defaultVal);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function elementsOptionObjMapper(options) {
|
|
54
|
+
var dict = Belt_Option.getWithDefault(Js_json.decodeObject(options), {});
|
|
55
|
+
return {
|
|
56
|
+
fonts: Belt_Option.getWithDefault(Belt_Option.flatMap(Js_dict.get(dict, "fonts"), Js_json.decodeArray), []),
|
|
57
|
+
locale: getString(dict, "locale", ""),
|
|
58
|
+
clientSecret: getString(dict, "clientSecret", ""),
|
|
59
|
+
appearance: Belt_Option.getWithDefault(Belt_Option.flatMap(Js_dict.get(dict, "appearance"), Js_json.decodeObject), {}),
|
|
60
|
+
loader: getString(dict, "loader", "auto")
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function update(_options) {
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getElement(_componentName) {
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function fetchUpdates(param) {
|
|
73
|
+
return new Promise((function (resolve, param) {
|
|
74
|
+
setTimeout((function (param) {
|
|
75
|
+
resolve({});
|
|
76
|
+
}), 1000);
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function create(_componentType, _options) {
|
|
81
|
+
return OrcaJs.defaultPaymentElement;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var defaultElementsContext_options = {
|
|
85
|
+
fonts: [],
|
|
86
|
+
locale: "",
|
|
87
|
+
clientSecret: "",
|
|
88
|
+
appearance: {},
|
|
89
|
+
loader: ""
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var defaultElementsContext = {
|
|
93
|
+
options: defaultElementsContext_options,
|
|
94
|
+
update: update,
|
|
95
|
+
getElement: getElement,
|
|
96
|
+
fetchUpdates: fetchUpdates,
|
|
97
|
+
create: create
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
var elementsContext = React.createContext(defaultElementsContext);
|
|
101
|
+
|
|
102
|
+
function makeProps$1(value, children, param) {
|
|
103
|
+
return {
|
|
104
|
+
value: value,
|
|
105
|
+
children: children
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var make$1 = elementsContext.Provider;
|
|
110
|
+
|
|
111
|
+
var ElementsContextProvider = {
|
|
112
|
+
makeProps: makeProps$1,
|
|
113
|
+
make: make$1
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
confirmPaymentFn ,
|
|
118
|
+
confirmCardPaymentFn ,
|
|
119
|
+
retrievePaymentIntentFn ,
|
|
120
|
+
paymentRequest ,
|
|
121
|
+
defaultSwitchContext ,
|
|
122
|
+
switchContext ,
|
|
123
|
+
SwitchContextProvider ,
|
|
124
|
+
getString ,
|
|
125
|
+
elementsOptionObjMapper ,
|
|
126
|
+
update ,
|
|
127
|
+
getElement ,
|
|
128
|
+
fetchUpdates ,
|
|
129
|
+
create ,
|
|
130
|
+
defaultElementsContext ,
|
|
131
|
+
elementsContext ,
|
|
132
|
+
ElementsContextProvider ,
|
|
133
|
+
}
|
|
134
|
+
/* confirmCardPaymentFn Not a pure module */
|
package/src/Context.res
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
@get
|
|
2
|
+
external contentWindow: Js.nullable<Dom.element> => Js.nullable<Dom.element> = "contentWindow"
|
|
3
|
+
@send
|
|
4
|
+
external postMessage: (Js.nullable<Dom.element>, string, string) => unit = "postMessage"
|
|
5
|
+
external jsonToRef: Js.Json.t => React.ref<Js.nullable<Dom.element>> = "%identity"
|
|
6
|
+
@get external getClientSecret: 'a => string = "clientSecret"
|
|
7
|
+
external toJson: 'b => Js.Json.t = "%identity"
|
|
8
|
+
type func = (. unit) => string
|
|
9
|
+
external toFunc: 'c => func = "%identity"
|
|
10
|
+
|
|
11
|
+
type paymentElement
|
|
12
|
+
|
|
13
|
+
type address = {
|
|
14
|
+
city: option<string>,
|
|
15
|
+
country: option<string>,
|
|
16
|
+
line1: option<string>,
|
|
17
|
+
line2: option<string>,
|
|
18
|
+
postal_code: option<string>,
|
|
19
|
+
state: option<string>,
|
|
20
|
+
}
|
|
21
|
+
type confirmCardPaymentMethodType = String(string) | Obj(Js.Json.t)
|
|
22
|
+
type shipping = {
|
|
23
|
+
address: address,
|
|
24
|
+
name: string,
|
|
25
|
+
carrier: option<string>,
|
|
26
|
+
phone: option<string>,
|
|
27
|
+
tracking_number: option<string>,
|
|
28
|
+
}
|
|
29
|
+
type paymentMethodOptionsCard = {
|
|
30
|
+
cvc: React.element,
|
|
31
|
+
network: string,
|
|
32
|
+
}
|
|
33
|
+
type paymentMethodOptions = {card: paymentMethodOptionsCard}
|
|
34
|
+
type confirmCardPaymentDataType = {
|
|
35
|
+
payment_method: confirmCardPaymentMethodType,
|
|
36
|
+
shipping: shipping,
|
|
37
|
+
return_url: string,
|
|
38
|
+
receipt_email: string,
|
|
39
|
+
setup_future_usage: string,
|
|
40
|
+
payment_method_options: string,
|
|
41
|
+
}
|
|
42
|
+
type elementsOptions = {
|
|
43
|
+
fonts: Js.Array2.t<Js.Json.t>,
|
|
44
|
+
locale: string,
|
|
45
|
+
clientSecret: string,
|
|
46
|
+
appearance: Js.Dict.t<Js.Json.t>,
|
|
47
|
+
loader: string,
|
|
48
|
+
}
|
|
49
|
+
external optionsToJson: elementsOptions => Js.Json.t = "%identity"
|
|
50
|
+
type rec elementsType = {
|
|
51
|
+
options: elementsOptions,
|
|
52
|
+
update: Js.Json.t => unit,
|
|
53
|
+
getElement: Js.Dict.key => option<OrcaJs.paymentElement>,
|
|
54
|
+
fetchUpdates: unit => Js.Promise.t<Js.Json.t>,
|
|
55
|
+
create: (string, Js.Json.t) => OrcaJs.paymentElement, // return a react component instead by doing new Payment Element.
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type elementsContextType = {options: Js.Dict.t<Js.Json.t>}
|
|
59
|
+
type confirmPaymentParams = {return_url: string}
|
|
60
|
+
type switchContextType = {
|
|
61
|
+
clientSecret: string,
|
|
62
|
+
confirmPayment: Js.Json.t => Js.Promise.t<Js.Json.t>,
|
|
63
|
+
confirmCardPayment: Js_OO.Callback.arity4<
|
|
64
|
+
(OrcaJs.This.t, string, option<Js.Json.t>, option<Js.Json.t>) => Js.Promise.t<Js.Json.t>,
|
|
65
|
+
>,
|
|
66
|
+
retrievePaymentIntent: string => Js.Promise.t<Js.Json.t>,
|
|
67
|
+
paymentRequest: Js.Json.t => Js.Json.t,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let confirmPaymentFn = (_elements: Js.Json.t) => {
|
|
71
|
+
Js.Promise.resolve(Js.Dict.empty()->Js.Json.object_)
|
|
72
|
+
}
|
|
73
|
+
let confirmCardPaymentFn =
|
|
74
|
+
@this
|
|
75
|
+
(
|
|
76
|
+
_this: OrcaJs.This.t,
|
|
77
|
+
_clientSecretId: string,
|
|
78
|
+
_data: option<Js.Json.t>,
|
|
79
|
+
_options: option<Js.Json.t>,
|
|
80
|
+
) => {
|
|
81
|
+
Js.Promise.resolve(Js.Dict.empty()->Js.Json.object_)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let retrievePaymentIntentFn = _paymentIntentId => {
|
|
85
|
+
Js.Promise.resolve(Js.Dict.empty()->Js.Json.object_)
|
|
86
|
+
}
|
|
87
|
+
let paymentRequest = options => {
|
|
88
|
+
options
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let defaultSwitchContext = {
|
|
92
|
+
clientSecret: "",
|
|
93
|
+
confirmPayment: confirmPaymentFn,
|
|
94
|
+
confirmCardPayment: confirmCardPaymentFn,
|
|
95
|
+
retrievePaymentIntent: retrievePaymentIntentFn,
|
|
96
|
+
paymentRequest,
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let switchContext = React.createContext(defaultSwitchContext)
|
|
100
|
+
|
|
101
|
+
module SwitchContextProvider = {
|
|
102
|
+
let makeProps = (~value, ~children, ()) =>
|
|
103
|
+
{
|
|
104
|
+
"value": value,
|
|
105
|
+
"children": children,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let make = React.Context.provider(switchContext)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let getString = (dict, key, defaultVal) => {
|
|
112
|
+
dict
|
|
113
|
+
->Js.Dict.get(key)
|
|
114
|
+
->Belt.Option.flatMap(Js.Json.decodeString)
|
|
115
|
+
->Belt.Option.getWithDefault(defaultVal)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let elementsOptionObjMapper = (options: Js.Json.t) => {
|
|
119
|
+
let dict = options->Js.Json.decodeObject->Belt.Option.getWithDefault(Js.Dict.empty())
|
|
120
|
+
{
|
|
121
|
+
fonts: dict
|
|
122
|
+
->Js.Dict.get("fonts")
|
|
123
|
+
->Belt.Option.flatMap(Js.Json.decodeArray)
|
|
124
|
+
->Belt.Option.getWithDefault([]),
|
|
125
|
+
locale: dict->getString("locale", ""),
|
|
126
|
+
clientSecret: dict->getString("clientSecret", ""),
|
|
127
|
+
appearance: dict
|
|
128
|
+
->Js.Dict.get("appearance")
|
|
129
|
+
->Belt.Option.flatMap(Js.Json.decodeObject)
|
|
130
|
+
->Belt.Option.getWithDefault(Js.Dict.empty()),
|
|
131
|
+
loader: dict->getString("loader", "auto"),
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let update = _options => {
|
|
136
|
+
()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let getElement = _componentName => {
|
|
140
|
+
None
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let fetchUpdates = () => {
|
|
144
|
+
//add API call
|
|
145
|
+
Js.Promise.make((~resolve, ~reject as _) => {
|
|
146
|
+
Js.Global.setTimeout(() => resolve(. Js.Dict.empty()->Js.Json.object_), 1000)->ignore
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let create = (_componentType, _options) => {
|
|
151
|
+
OrcaJs.defaultPaymentElement
|
|
152
|
+
}
|
|
153
|
+
let defaultElementsContext = {
|
|
154
|
+
options: {
|
|
155
|
+
fonts: [],
|
|
156
|
+
locale: "",
|
|
157
|
+
clientSecret: "",
|
|
158
|
+
appearance: Js.Dict.empty(),
|
|
159
|
+
loader: "",
|
|
160
|
+
},
|
|
161
|
+
update,
|
|
162
|
+
getElement,
|
|
163
|
+
fetchUpdates,
|
|
164
|
+
create,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let elementsContext = React.createContext(defaultElementsContext)
|
|
168
|
+
|
|
169
|
+
module ElementsContextProvider = {
|
|
170
|
+
let makeProps = (~value, ~children, ()) =>
|
|
171
|
+
{
|
|
172
|
+
"value": value,
|
|
173
|
+
"children": children,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let make = React.Context.provider(elementsContext)
|
|
177
|
+
}
|
package/src/Index.bs.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Curry from "rescript/lib/es6/curry.js";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import * as Context from "./Context.bs.js";
|
|
6
|
+
import * as Js_promise from "rescript/lib/es6/js_promise.js";
|
|
7
|
+
|
|
8
|
+
function Index$Elements2(Props) {
|
|
9
|
+
var children = Props.children;
|
|
10
|
+
var stripe = Props.stripe;
|
|
11
|
+
var options = Props.options;
|
|
12
|
+
var elementOptions = Context.elementsOptionObjMapper(options);
|
|
13
|
+
var match = React.useState(function () {
|
|
14
|
+
return Context.defaultSwitchContext;
|
|
15
|
+
});
|
|
16
|
+
var setSwitchState = match[1];
|
|
17
|
+
var match$1 = React.useState(function () {
|
|
18
|
+
return Context.defaultElementsContext;
|
|
19
|
+
});
|
|
20
|
+
var setElementsState = match$1[1];
|
|
21
|
+
React.useEffect((function () {
|
|
22
|
+
Js_promise.then_((function (switchInstance) {
|
|
23
|
+
var orcaElementsConfig = Curry._1(switchInstance.elements, options);
|
|
24
|
+
var newElemValues_update = orcaElementsConfig.update;
|
|
25
|
+
var newElemValues_getElement = orcaElementsConfig.getElement;
|
|
26
|
+
var newElemValues_fetchUpdates = orcaElementsConfig.fetchUpdates;
|
|
27
|
+
var newElemValues_create = orcaElementsConfig.create;
|
|
28
|
+
var newElemValues = {
|
|
29
|
+
options: elementOptions,
|
|
30
|
+
update: newElemValues_update,
|
|
31
|
+
getElement: newElemValues_getElement,
|
|
32
|
+
fetchUpdates: newElemValues_fetchUpdates,
|
|
33
|
+
create: newElemValues_create
|
|
34
|
+
};
|
|
35
|
+
var newSwitchVal_clientSecret = elementOptions.clientSecret;
|
|
36
|
+
var newSwitchVal_confirmPayment = switchInstance.confirmPayment;
|
|
37
|
+
var newSwitchVal_confirmCardPayment = switchInstance.confirmCardPayment;
|
|
38
|
+
var newSwitchVal_retrievePaymentIntent = switchInstance.retrievePaymentIntent;
|
|
39
|
+
var newSwitchVal_paymentRequest = switchInstance.paymentRequest;
|
|
40
|
+
var switchValClone_clientSecret = elementOptions.clientSecret;
|
|
41
|
+
var switchValClone_confirmPayment = newSwitchVal_confirmPayment;
|
|
42
|
+
var switchValClone_confirmCardPayment = newSwitchVal_confirmCardPayment;
|
|
43
|
+
var switchValClone_retrievePaymentIntent = newSwitchVal_retrievePaymentIntent;
|
|
44
|
+
var switchValClone_paymentRequest = newSwitchVal_paymentRequest;
|
|
45
|
+
var switchValClone = {
|
|
46
|
+
clientSecret: switchValClone_clientSecret,
|
|
47
|
+
confirmPayment: switchValClone_confirmPayment,
|
|
48
|
+
confirmCardPayment: switchValClone_confirmCardPayment,
|
|
49
|
+
retrievePaymentIntent: switchValClone_retrievePaymentIntent,
|
|
50
|
+
paymentRequest: switchValClone_paymentRequest
|
|
51
|
+
};
|
|
52
|
+
Curry._1(setSwitchState, (function (param) {
|
|
53
|
+
return switchValClone;
|
|
54
|
+
}));
|
|
55
|
+
Curry._1(setElementsState, (function (param) {
|
|
56
|
+
return newElemValues;
|
|
57
|
+
}));
|
|
58
|
+
return Promise.resolve(switchValClone);
|
|
59
|
+
}), stripe);
|
|
60
|
+
}), []);
|
|
61
|
+
return React.createElement(Context.SwitchContextProvider.make, Context.SwitchContextProvider.makeProps(match[0], React.createElement(Context.ElementsContextProvider.make, Context.ElementsContextProvider.makeProps(match$1[0], children, undefined)), undefined));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function useHyper(param) {
|
|
65
|
+
return React.useContext(Context.switchContext);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function useStripe(param) {
|
|
69
|
+
console.warn("useStripe() is deprecated. Use useHyper() instead");
|
|
70
|
+
return React.useContext(Context.switchContext);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function useWidgets(param) {
|
|
74
|
+
return React.useContext(Context.elementsContext);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function useElements(param) {
|
|
78
|
+
console.warn("useElements() is deprecated. Use useWidgets() instead");
|
|
79
|
+
return React.useContext(Context.elementsContext);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function Index$PaymentElementsWrapper(Props) {
|
|
83
|
+
var idOpt = Props.id;
|
|
84
|
+
var options = Props.options;
|
|
85
|
+
var onChange = Props.onChange;
|
|
86
|
+
var onReady = Props.onReady;
|
|
87
|
+
var componentType = Props.componentType;
|
|
88
|
+
var onFocus = Props.onFocus;
|
|
89
|
+
var onBlur = Props.onBlur;
|
|
90
|
+
var onClick = Props.onClick;
|
|
91
|
+
var id = idOpt !== undefined ? idOpt : "payment-Element";
|
|
92
|
+
var hyperSwitch = React.useContext(Context.switchContext);
|
|
93
|
+
var elementsState = React.useContext(Context.elementsContext);
|
|
94
|
+
var divRef = React.useRef(null);
|
|
95
|
+
var paymentElement = Curry._2(elementsState.create, componentType, options);
|
|
96
|
+
React.useEffect((function () {
|
|
97
|
+
var paymentElement = Curry._2(elementsState.create, componentType, options);
|
|
98
|
+
Curry._1(paymentElement.mount, "#orca-elements-payment-element-" + id + "");
|
|
99
|
+
}), [
|
|
100
|
+
divRef,
|
|
101
|
+
elementsState
|
|
102
|
+
]);
|
|
103
|
+
React.useEffect((function () {
|
|
104
|
+
Curry._2(paymentElement.on, "ready", onReady);
|
|
105
|
+
Curry._2(paymentElement.on, "focus", onFocus);
|
|
106
|
+
Curry._2(paymentElement.on, "blur", onBlur);
|
|
107
|
+
Curry._2(paymentElement.on, "clickTriggered", onClick);
|
|
108
|
+
Curry._2(paymentElement.on, "change", onChange);
|
|
109
|
+
}), [
|
|
110
|
+
elementsState,
|
|
111
|
+
hyperSwitch
|
|
112
|
+
]);
|
|
113
|
+
return React.createElement("div", {
|
|
114
|
+
ref: divRef,
|
|
115
|
+
id: "orca-elements-payment-element-" + id + ""
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function Index$PaymentElement2(Props) {
|
|
120
|
+
var id = Props.id;
|
|
121
|
+
var options = Props.options;
|
|
122
|
+
var onChange = Props.onChange;
|
|
123
|
+
var onReady = Props.onReady;
|
|
124
|
+
var onFocus = Props.onFocus;
|
|
125
|
+
var onBlur = Props.onBlur;
|
|
126
|
+
var onClick = Props.onClick;
|
|
127
|
+
return React.createElement(Index$PaymentElementsWrapper, {
|
|
128
|
+
id: id,
|
|
129
|
+
options: options,
|
|
130
|
+
onChange: onChange,
|
|
131
|
+
onReady: onReady,
|
|
132
|
+
componentType: "payment",
|
|
133
|
+
onFocus: onFocus,
|
|
134
|
+
onBlur: onBlur,
|
|
135
|
+
onClick: onClick
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function Index$CardElement2(Props) {
|
|
140
|
+
var id = Props.id;
|
|
141
|
+
var options = Props.options;
|
|
142
|
+
var onChange = Props.onChange;
|
|
143
|
+
var onReady = Props.onReady;
|
|
144
|
+
var onFocus = Props.onFocus;
|
|
145
|
+
var onBlur = Props.onBlur;
|
|
146
|
+
var onClick = Props.onClick;
|
|
147
|
+
return React.createElement(Index$PaymentElementsWrapper, {
|
|
148
|
+
id: id,
|
|
149
|
+
options: options,
|
|
150
|
+
onChange: onChange,
|
|
151
|
+
onReady: onReady,
|
|
152
|
+
componentType: "card",
|
|
153
|
+
onFocus: onFocus,
|
|
154
|
+
onBlur: onBlur,
|
|
155
|
+
onClick: onClick
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function Index$CardNumber2(Props) {
|
|
160
|
+
var id = Props.id;
|
|
161
|
+
var options = Props.options;
|
|
162
|
+
var onChange = Props.onChange;
|
|
163
|
+
var onReady = Props.onReady;
|
|
164
|
+
var onFocus = Props.onFocus;
|
|
165
|
+
var onBlur = Props.onBlur;
|
|
166
|
+
var onClick = Props.onClick;
|
|
167
|
+
return React.createElement(Index$PaymentElementsWrapper, {
|
|
168
|
+
id: id,
|
|
169
|
+
options: options,
|
|
170
|
+
onChange: onChange,
|
|
171
|
+
onReady: onReady,
|
|
172
|
+
componentType: "cardNumberElement",
|
|
173
|
+
onFocus: onFocus,
|
|
174
|
+
onBlur: onBlur,
|
|
175
|
+
onClick: onClick
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function Index$CardCVC2(Props) {
|
|
180
|
+
var id = Props.id;
|
|
181
|
+
var options = Props.options;
|
|
182
|
+
var onChange = Props.onChange;
|
|
183
|
+
var onReady = Props.onReady;
|
|
184
|
+
var onFocus = Props.onFocus;
|
|
185
|
+
var onBlur = Props.onBlur;
|
|
186
|
+
var onClick = Props.onClick;
|
|
187
|
+
return React.createElement(Index$PaymentElementsWrapper, {
|
|
188
|
+
id: id,
|
|
189
|
+
options: options,
|
|
190
|
+
onChange: onChange,
|
|
191
|
+
onReady: onReady,
|
|
192
|
+
componentType: "cardCVCElement",
|
|
193
|
+
onFocus: onFocus,
|
|
194
|
+
onBlur: onBlur,
|
|
195
|
+
onClick: onClick
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function Index$CardExpiry2(Props) {
|
|
200
|
+
var id = Props.id;
|
|
201
|
+
var options = Props.options;
|
|
202
|
+
var onChange = Props.onChange;
|
|
203
|
+
var onReady = Props.onReady;
|
|
204
|
+
var onFocus = Props.onFocus;
|
|
205
|
+
var onBlur = Props.onBlur;
|
|
206
|
+
var onClick = Props.onClick;
|
|
207
|
+
return React.createElement(Index$PaymentElementsWrapper, {
|
|
208
|
+
id: id,
|
|
209
|
+
options: options,
|
|
210
|
+
onChange: onChange,
|
|
211
|
+
onReady: onReady,
|
|
212
|
+
componentType: "cardExpiryElement",
|
|
213
|
+
onFocus: onFocus,
|
|
214
|
+
onBlur: onBlur,
|
|
215
|
+
onClick: onClick
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
var Elements = Index$Elements2;
|
|
220
|
+
|
|
221
|
+
var PaymentElement = Index$PaymentElement2;
|
|
222
|
+
|
|
223
|
+
var CardElement = Index$CardElement2;
|
|
224
|
+
|
|
225
|
+
var CardNumberElement = Index$CardNumber2;
|
|
226
|
+
|
|
227
|
+
var CardExpiryElement = Index$CardExpiry2;
|
|
228
|
+
|
|
229
|
+
var CardCVCElement = Index$CardCVC2;
|
|
230
|
+
|
|
231
|
+
export {
|
|
232
|
+
Elements ,
|
|
233
|
+
PaymentElement ,
|
|
234
|
+
CardElement ,
|
|
235
|
+
CardNumberElement ,
|
|
236
|
+
CardExpiryElement ,
|
|
237
|
+
CardCVCElement ,
|
|
238
|
+
useStripe ,
|
|
239
|
+
useHyper ,
|
|
240
|
+
useElements ,
|
|
241
|
+
useWidgets ,
|
|
242
|
+
}
|
|
243
|
+
/* react Not a pure module */
|
package/src/Index.res
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
type eventData = {
|
|
2
|
+
iframeMounted: bool,
|
|
3
|
+
focusTriggered: bool,
|
|
4
|
+
blurTriggered: bool,
|
|
5
|
+
clickTriggered: bool,
|
|
6
|
+
elementType: string,
|
|
7
|
+
classChange: bool,
|
|
8
|
+
newClassType: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module Elements2 = {
|
|
12
|
+
@react.component
|
|
13
|
+
let make = (~children, ~stripe: Js.Promise.t<OrcaJs.switchInstance>, ~options: Js.Json.t) => {
|
|
14
|
+
let elementOptions = options->Context.elementsOptionObjMapper
|
|
15
|
+
let (switchState, setSwitchState) = React.useState(() => Context.defaultSwitchContext)
|
|
16
|
+
let (elementsState, setElementsState) = React.useState(() => Context.defaultElementsContext)
|
|
17
|
+
|
|
18
|
+
React.useEffect0(() => {
|
|
19
|
+
stripe->Js.Promise.then_((switchInstance: OrcaJs.switchInstance) => {
|
|
20
|
+
let orcaElementsConfig = switchInstance.elements(options)
|
|
21
|
+
let newElemValues: Context.elementsType = {
|
|
22
|
+
options: elementOptions,
|
|
23
|
+
update: orcaElementsConfig.update,
|
|
24
|
+
getElement: orcaElementsConfig.getElement,
|
|
25
|
+
fetchUpdates: orcaElementsConfig.fetchUpdates,
|
|
26
|
+
create: orcaElementsConfig.create,
|
|
27
|
+
}
|
|
28
|
+
let newSwitchVal: Context.switchContextType = {
|
|
29
|
+
confirmPayment: switchInstance.confirmPayment,
|
|
30
|
+
confirmCardPayment: switchInstance.confirmCardPayment,
|
|
31
|
+
retrievePaymentIntent: switchInstance.retrievePaymentIntent,
|
|
32
|
+
clientSecret: elementOptions.clientSecret,
|
|
33
|
+
paymentRequest: switchInstance.paymentRequest,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let switchValClone = {...newSwitchVal, clientSecret: elementOptions.clientSecret}
|
|
37
|
+
setSwitchState(_ => switchValClone)
|
|
38
|
+
setElementsState(_ => newElemValues)
|
|
39
|
+
Js.Promise.resolve(switchValClone)
|
|
40
|
+
}, _)->ignore
|
|
41
|
+
None
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
<Context.SwitchContextProvider value={switchState}>
|
|
45
|
+
<Context.ElementsContextProvider value={elementsState}>
|
|
46
|
+
{children}
|
|
47
|
+
</Context.ElementsContextProvider>
|
|
48
|
+
</Context.SwitchContextProvider>
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let \"Elements" = Elements2.make
|
|
53
|
+
|
|
54
|
+
let useHyper = () => {
|
|
55
|
+
React.useContext(Context.switchContext)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let useStripe = () => {
|
|
59
|
+
Js.Console.warn("useStripe() is deprecated. Use useHyper() instead")
|
|
60
|
+
useHyper()
|
|
61
|
+
}
|
|
62
|
+
let useWidgets = () => {
|
|
63
|
+
React.useContext(Context.elementsContext)
|
|
64
|
+
}
|
|
65
|
+
let useElements = () => {
|
|
66
|
+
Js.Console.warn("useElements() is deprecated. Use useWidgets() instead")
|
|
67
|
+
useWidgets()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module PaymentElementsWrapper = {
|
|
71
|
+
@react.component
|
|
72
|
+
let make = (
|
|
73
|
+
~id="payment-Element",
|
|
74
|
+
~options: Js.Json.t,
|
|
75
|
+
~onChange,
|
|
76
|
+
~onReady,
|
|
77
|
+
~componentType: string,
|
|
78
|
+
~onFocus,
|
|
79
|
+
~onBlur,
|
|
80
|
+
~onClick,
|
|
81
|
+
) => {
|
|
82
|
+
let hyperSwitch = React.useContext(Context.switchContext)
|
|
83
|
+
let elementsState = React.useContext(Context.elementsContext)
|
|
84
|
+
let divRef = React.useRef(Js.Nullable.null)
|
|
85
|
+
|
|
86
|
+
let paymentElement = elementsState.create(componentType, options)
|
|
87
|
+
|
|
88
|
+
React.useEffect2(() => {
|
|
89
|
+
let paymentElement = elementsState.create(componentType, options)
|
|
90
|
+
paymentElement.mount(`#orca-elements-payment-element-${id}`)
|
|
91
|
+
None
|
|
92
|
+
}, (divRef, elementsState))
|
|
93
|
+
|
|
94
|
+
React.useEffect2(() => {
|
|
95
|
+
paymentElement.on("ready", onReady)
|
|
96
|
+
paymentElement.on("focus", onFocus)
|
|
97
|
+
paymentElement.on("blur", onBlur)
|
|
98
|
+
paymentElement.on("clickTriggered", onClick)
|
|
99
|
+
paymentElement.on("change", onChange)
|
|
100
|
+
None
|
|
101
|
+
}, (elementsState, hyperSwitch))
|
|
102
|
+
|
|
103
|
+
<div ref={divRef->ReactDOM.Ref.domRef} id={`orca-elements-payment-element-${id}`} />
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module PaymentElement2 = {
|
|
108
|
+
@react.component
|
|
109
|
+
let make = (~id, ~options: Js.Json.t, ~onChange, ~onReady, ~onFocus, ~onBlur, ~onClick) => {
|
|
110
|
+
<PaymentElementsWrapper
|
|
111
|
+
id options onChange onReady onFocus onBlur onClick componentType="payment"
|
|
112
|
+
/>
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let \"PaymentElement" = PaymentElement2.make
|
|
116
|
+
|
|
117
|
+
module CardElement2 = {
|
|
118
|
+
@react.component
|
|
119
|
+
let make = (~id, ~options: Js.Json.t, ~onChange, ~onReady, ~onFocus, ~onBlur, ~onClick) => {
|
|
120
|
+
<PaymentElementsWrapper
|
|
121
|
+
id options onChange onReady onFocus onBlur onClick componentType="card"
|
|
122
|
+
/>
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
let \"CardElement" = CardElement2.make
|
|
126
|
+
|
|
127
|
+
module CardNumber2 = {
|
|
128
|
+
@react.component
|
|
129
|
+
let make = (~id, ~options: Js.Json.t, ~onChange, ~onReady, ~onFocus, ~onBlur, ~onClick) => {
|
|
130
|
+
<PaymentElementsWrapper
|
|
131
|
+
id options onChange onReady onFocus onBlur onClick componentType="cardNumberElement"
|
|
132
|
+
/>
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let \"CardNumberElement" = CardNumber2.make
|
|
136
|
+
|
|
137
|
+
module CardCVC2 = {
|
|
138
|
+
@react.component
|
|
139
|
+
let make = (~id, ~options: Js.Json.t, ~onChange, ~onReady, ~onFocus, ~onBlur, ~onClick) => {
|
|
140
|
+
<PaymentElementsWrapper
|
|
141
|
+
id options onChange onReady onFocus onBlur onClick componentType="cardCVCElement"
|
|
142
|
+
/>
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
let \"CardCVCElement" = CardCVC2.make
|
|
146
|
+
|
|
147
|
+
module CardExpiry2 = {
|
|
148
|
+
@react.component
|
|
149
|
+
let make = (~id, ~options: Js.Json.t, ~onChange, ~onReady, ~onFocus, ~onBlur, ~onClick) => {
|
|
150
|
+
<PaymentElementsWrapper
|
|
151
|
+
id options onChange onReady onFocus onBlur onClick componentType="cardExpiryElement"
|
|
152
|
+
/>
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
let \"CardExpiryElement" = CardExpiry2.make
|
package/src/Index.resi
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
type eventData = {
|
|
2
|
+
iframeMounted: bool,
|
|
3
|
+
focusTriggered: bool,
|
|
4
|
+
blurTriggered: bool,
|
|
5
|
+
clickTriggered: bool,
|
|
6
|
+
elementType: string,
|
|
7
|
+
classChange: bool,
|
|
8
|
+
newClassType: string,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let \"Elements": {
|
|
12
|
+
"children": React.element,
|
|
13
|
+
"options": Js.Json.t,
|
|
14
|
+
"stripe": Js.Promise.t<OrcaJs.switchInstance>,
|
|
15
|
+
} => React.element
|
|
16
|
+
|
|
17
|
+
let \"PaymentElement": {
|
|
18
|
+
"id": string,
|
|
19
|
+
"onBlur": option<option<Js.Json.t> => unit>,
|
|
20
|
+
"onChange": option<option<Js.Json.t> => unit>,
|
|
21
|
+
"onClick": option<option<Js.Json.t> => unit>,
|
|
22
|
+
"onFocus": option<option<Js.Json.t> => unit>,
|
|
23
|
+
"onReady": option<option<Js.Json.t> => unit>,
|
|
24
|
+
"options": Js.Json.t,
|
|
25
|
+
} => React.element
|
|
26
|
+
|
|
27
|
+
let \"CardElement": {
|
|
28
|
+
"id": string,
|
|
29
|
+
"onBlur": option<option<Js.Json.t> => unit>,
|
|
30
|
+
"onChange": option<option<Js.Json.t> => unit>,
|
|
31
|
+
"onClick": option<option<Js.Json.t> => unit>,
|
|
32
|
+
"onFocus": option<option<Js.Json.t> => unit>,
|
|
33
|
+
"onReady": option<option<Js.Json.t> => unit>,
|
|
34
|
+
"options": Js.Json.t,
|
|
35
|
+
} => React.element
|
|
36
|
+
|
|
37
|
+
let \"CardNumberElement": {
|
|
38
|
+
"id": string,
|
|
39
|
+
"onBlur": option<option<Js.Json.t> => unit>,
|
|
40
|
+
"onChange": option<option<Js.Json.t> => unit>,
|
|
41
|
+
"onClick": option<option<Js.Json.t> => unit>,
|
|
42
|
+
"onFocus": option<option<Js.Json.t> => unit>,
|
|
43
|
+
"onReady": option<option<Js.Json.t> => unit>,
|
|
44
|
+
"options": Js.Json.t,
|
|
45
|
+
} => React.element
|
|
46
|
+
|
|
47
|
+
let \"CardExpiryElement": {
|
|
48
|
+
"id": string,
|
|
49
|
+
"onBlur": option<option<Js.Json.t> => unit>,
|
|
50
|
+
"onChange": option<option<Js.Json.t> => unit>,
|
|
51
|
+
"onClick": option<option<Js.Json.t> => unit>,
|
|
52
|
+
"onFocus": option<option<Js.Json.t> => unit>,
|
|
53
|
+
"onReady": option<option<Js.Json.t> => unit>,
|
|
54
|
+
"options": Js.Json.t,
|
|
55
|
+
} => React.element
|
|
56
|
+
|
|
57
|
+
let \"CardCVCElement": {
|
|
58
|
+
"id": string,
|
|
59
|
+
"onBlur": option<option<Js.Json.t> => unit>,
|
|
60
|
+
"onChange": option<option<Js.Json.t> => unit>,
|
|
61
|
+
"onClick": option<option<Js.Json.t> => unit>,
|
|
62
|
+
"onFocus": option<option<Js.Json.t> => unit>,
|
|
63
|
+
"onReady": option<option<Js.Json.t> => unit>,
|
|
64
|
+
"options": Js.Json.t,
|
|
65
|
+
} => React.element
|
|
66
|
+
|
|
67
|
+
let useStripe: unit => Context.switchContextType
|
|
68
|
+
|
|
69
|
+
let useHyper: unit => Context.switchContextType
|
|
70
|
+
|
|
71
|
+
let useElements: unit => Context.elementsType
|
|
72
|
+
|
|
73
|
+
let useWidgets: unit => Context.elementsType
|
package/src/OrcaJs.bs.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var This = {};
|
|
5
|
+
|
|
6
|
+
function defaultPaymentElement_on(_str, _func) {
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function defaultPaymentElement_collapse(param) {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function defaultPaymentElement_blur(param) {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function defaultPaymentElement_update(_x) {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function defaultPaymentElement_destroy(param) {
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function defaultPaymentElement_unmount(param) {
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function defaultPaymentElement_mount(_string) {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function defaultPaymentElement_focus(param) {
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function defaultPaymentElement_clear(param) {
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var defaultPaymentElement = {
|
|
43
|
+
on: defaultPaymentElement_on,
|
|
44
|
+
collapse: defaultPaymentElement_collapse,
|
|
45
|
+
blur: defaultPaymentElement_blur,
|
|
46
|
+
update: defaultPaymentElement_update,
|
|
47
|
+
destroy: defaultPaymentElement_destroy,
|
|
48
|
+
unmount: defaultPaymentElement_unmount,
|
|
49
|
+
mount: defaultPaymentElement_mount,
|
|
50
|
+
focus: defaultPaymentElement_focus,
|
|
51
|
+
clear: defaultPaymentElement_clear
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
This ,
|
|
56
|
+
defaultPaymentElement ,
|
|
57
|
+
}
|
|
58
|
+
/* No side effect */
|
package/src/OrcaJs.res
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
type eventData = {
|
|
2
|
+
iframeMounted: bool,
|
|
3
|
+
focusTriggered: bool,
|
|
4
|
+
blurTriggered: bool,
|
|
5
|
+
clickTriggered: bool,
|
|
6
|
+
elementType: string,
|
|
7
|
+
classChange: bool,
|
|
8
|
+
newClassType: string,
|
|
9
|
+
}
|
|
10
|
+
type event = {key: string, data: eventData}
|
|
11
|
+
type eventParam = Event(event) | EventData(eventData) | Empty
|
|
12
|
+
type eventHandler = eventParam => unit
|
|
13
|
+
|
|
14
|
+
module This = {
|
|
15
|
+
type t
|
|
16
|
+
@get
|
|
17
|
+
external iframeElem: t => option<Js.nullable<Dom.element>> = "iframeElem"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type paymentElement = {
|
|
21
|
+
on: (string, option<option<Js.Json.t> => unit>) => unit,
|
|
22
|
+
collapse: unit => unit,
|
|
23
|
+
blur: unit => unit,
|
|
24
|
+
update: Js.Json.t => unit,
|
|
25
|
+
destroy: unit => unit,
|
|
26
|
+
unmount: unit => unit,
|
|
27
|
+
mount: string => unit,
|
|
28
|
+
focus: unit => unit,
|
|
29
|
+
clear: unit => unit,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let defaultPaymentElement = {
|
|
33
|
+
on: (_str, _func) => (),
|
|
34
|
+
collapse: () => (),
|
|
35
|
+
blur: () => (),
|
|
36
|
+
update: _x => (),
|
|
37
|
+
destroy: () => (),
|
|
38
|
+
unmount: () => (),
|
|
39
|
+
mount: _string => (),
|
|
40
|
+
focus: () => (),
|
|
41
|
+
clear: () => (),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type element = {
|
|
45
|
+
getElement: Js.Dict.key => option<paymentElement>,
|
|
46
|
+
update: Js.Json.t => unit,
|
|
47
|
+
fetchUpdates: unit => Js.Promise.t<Js.Json.t>,
|
|
48
|
+
create: (Js.Dict.key, Js.Json.t) => paymentElement,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type confirmParams = {return_url: string}
|
|
52
|
+
|
|
53
|
+
type confirmPaymentParams = {
|
|
54
|
+
elements: Js.Json.t,
|
|
55
|
+
confirmParams: Js.Nullable.t<confirmParams>,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type switchInstance = {
|
|
59
|
+
confirmPayment: Js.Json.t => Js.Promise.t<Js.Json.t>,
|
|
60
|
+
elements: Js.Json.t => element,
|
|
61
|
+
confirmCardPayment: Js_OO.Callback.arity4<
|
|
62
|
+
(This.t, string, option<Js.Json.t>, option<Js.Json.t>) => Js.Promise.t<Js.Json.t>,
|
|
63
|
+
>,
|
|
64
|
+
retrievePaymentIntent: string => Js.Promise.t<Js.Json.t>,
|
|
65
|
+
paymentRequest: Js.Json.t => Js.Json.t,
|
|
66
|
+
}
|
package/src/Window.bs.js
ADDED
package/src/Window.res
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type window
|
|
2
|
+
type parent
|
|
3
|
+
|
|
4
|
+
type event = {data: Js.Json.t}
|
|
5
|
+
@val @scope("window")
|
|
6
|
+
external addEventListener: (string, _ => unit) => unit = "addEventListener"
|
|
7
|
+
@val @scope("window")
|
|
8
|
+
external removeEventListener: (string, 'ev => unit) => unit = "removeEventListener"
|
|
9
|
+
|
|
10
|
+
@val external window: window = "window"
|
|
11
|
+
@val @scope("window") external iframeParent: parent = "parent"
|
|
12
|
+
|
|
13
|
+
external eventToJson: event => Js.Json.t = "%identity"
|
|
14
|
+
|
|
15
|
+
@val @scope(("window", "location"))
|
|
16
|
+
external replace: string => unit = "replace"
|
|
17
|
+
|
|
18
|
+
type domElement
|
|
19
|
+
@send external postMessage: (domElement, string, string) => unit = "postMessage"
|
|
20
|
+
|
|
21
|
+
@get
|
|
22
|
+
external contentWindow: Js.nullable<Dom.element> => domElement = "contentWindow"
|
|
23
|
+
|
|
24
|
+
let iframePostMessage = (iframeRef: React.ref<Js.nullable<Dom.element>>, message) => {
|
|
25
|
+
iframeRef.current->contentWindow->postMessage(message->Js.Json.stringify, "*")
|
|
26
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
3
|
+
const { library } = require("webpack");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
output: {
|
|
7
|
+
path: path.join(__dirname, "/dist"),
|
|
8
|
+
filename: "index.js",
|
|
9
|
+
library: "@juspay/react-juspay-js",
|
|
10
|
+
libraryTarget: "umd",
|
|
11
|
+
},
|
|
12
|
+
entry: "./src/Index.bs.js",
|
|
13
|
+
plugins: [],
|
|
14
|
+
devServer: {
|
|
15
|
+
port: 3030, // you can change the port
|
|
16
|
+
},
|
|
17
|
+
externals: ["react", "react-dom"],
|
|
18
|
+
|
|
19
|
+
module: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
test: /\.(js|jsx)$/,
|
|
23
|
+
exclude: /node_modules/,
|
|
24
|
+
use: {
|
|
25
|
+
loader: "babel-loader",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
test: /\.css$/i,
|
|
30
|
+
use: ["style-loader", "css-loader"],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
};
|