1 | let { errorHandlers, bSecurePaymentsHandler, bSecurePaymentsEventHandler } = require("../utils/listeners"); |
||
2 | |||
3 | Object.defineProperty(exports, "__esModule", { |
||
4 | value: true, |
||
5 | }); |
||
6 | |||
7 | const _api = require("../utils/api"), |
||
8 | generateOrder = _api.generateOrder; |
||
9 | const _require = require("../utils"), |
||
10 | checkEmptyHtml = _require.checkEmptyHtml, |
||
11 | isEmpty = _require.isEmpty; |
||
12 | |||
13 | function prepareFrameListener() { |
||
14 | /* |
||
15 | * CHECK TRANSACTION PARAMETERS |
||
16 | */ |
||
17 | if (isEmpty(TransactionParameters.__00trid__)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
18 | return { |
||
19 | status: false, |
||
20 | exception: errorHandlers.formatValidationError("pp_OrderId is required."), |
||
21 | }; |
||
22 | } else if (isEmpty(TransactionParameters.__01curr__)) { |
||
23 | return { |
||
24 | status: false, |
||
25 | exception: errorHandlers.formatValidationError("pp_TxnCurrency is required."), |
||
26 | }; |
||
27 | } else if (isEmpty(TransactionParameters.__02trdt__)) { |
||
28 | return { |
||
29 | status: false, |
||
30 | exception: errorHandlers.formatValidationError("pp_TxnDateTime is required."), |
||
31 | }; |
||
32 | } else if (isEmpty(TransactionParameters.__03stamt__)) { |
||
33 | return { |
||
34 | status: false, |
||
35 | exception: errorHandlers.formatValidationError("pp_TxnSubTotal is required."), |
||
36 | }; |
||
37 | } else if (isEmpty(TransactionParameters.__04damt__)) { |
||
38 | return { |
||
39 | status: false, |
||
40 | exception: errorHandlers.formatValidationError("pp_TxnDiscount is required."), |
||
41 | }; |
||
42 | } else if (isEmpty(TransactionParameters.__05tamt__)) { |
||
43 | return { |
||
44 | status: false, |
||
45 | exception: errorHandlers.formatValidationError("pp_TxnTotal is required."), |
||
46 | }; |
||
47 | } else if (isEmpty(TransactionParameters.__06cname__)) { |
||
48 | return { |
||
49 | status: false, |
||
50 | exception: errorHandlers.formatValidationError("pp_CustomerName is required."), |
||
51 | }; |
||
52 | } else if (isEmpty(TransactionParameters.__07ccc__)) { |
||
53 | return { |
||
54 | status: false, |
||
55 | exception: errorHandlers.formatValidationError("pp_CustomerCountryCode is required."), |
||
56 | }; |
||
57 | } else if (isEmpty(TransactionParameters.__08cphn__)) { |
||
58 | return { |
||
59 | status: false, |
||
60 | exception: errorHandlers.formatValidationError("pp_CustomerPhoneNumber is required."), |
||
61 | }; |
||
62 | } else if (isEmpty(TransactionParameters.__10ccc__)) { |
||
63 | return { |
||
64 | status: false, |
||
65 | exception: errorHandlers.formatValidationError("pp_CustomerCountry is required."), |
||
66 | }; |
||
67 | } else if (isEmpty(TransactionParameters.__11cstate__)) { |
||
68 | return { |
||
69 | status: false, |
||
70 | exception: errorHandlers.formatValidationError("pp_CustomerState is required."), |
||
71 | }; |
||
72 | } else if (isEmpty(TransactionParameters.__12ccity__)) { |
||
73 | return { |
||
74 | status: false, |
||
75 | exception: errorHandlers.formatValidationError("pp_CustomerCity is required."), |
||
76 | }; |
||
77 | } else if (isEmpty(TransactionParameters.__13carea__)) { |
||
78 | return { |
||
79 | status: false, |
||
80 | exception: errorHandlers.formatValidationError("pp_CustomerArea is required."), |
||
81 | }; |
||
82 | } else if (isEmpty(TransactionParameters.__14cfadd__)) { |
||
83 | return { |
||
84 | status: false, |
||
85 | exception: errorHandlers.formatValidationError("pp_CustomerFormattedAddress is required."), |
||
86 | }; |
||
87 | } else if (isEmpty(TransactionParameters.__15mid__)) { |
||
88 | return { |
||
89 | status: false, |
||
90 | exception: errorHandlers.formatValidationError("pp_MerchantID is required."), |
||
91 | }; |
||
92 | } else if (isEmpty(TransactionParameters.__16stid__)) { |
||
93 | return { |
||
94 | status: false, |
||
95 | exception: errorHandlers.formatValidationError("pp_StoreSlug is required."), |
||
96 | }; |
||
97 | } else if (isEmpty(TransactionParameters.__17seh__)) { |
||
98 | return { |
||
99 | status: false, |
||
100 | exception: errorHandlers.formatValidationError("pp_SecureId is required."), |
||
101 | }; |
||
102 | } else if (isEmpty(TransactionParameters.__18ver__)) { |
||
103 | return { |
||
104 | status: false, |
||
105 | exception: errorHandlers.formatValidationError("pp_Version is required."), |
||
106 | }; |
||
107 | } else if (isEmpty(TransactionParameters.__20red__)) { |
||
108 | return { |
||
109 | status: false, |
||
110 | exception: errorHandlers.formatValidationError("pp_RedirectURL is required."), |
||
111 | }; |
||
112 | } else if (isEmpty(TransactionParameters.__21cenv__)) { |
||
113 | return { |
||
114 | status: false, |
||
115 | exception: errorHandlers.formatValidationError("pp_ClientEnviromentId is required."), |
||
116 | }; |
||
117 | } else if (!navigator.cookieEnabled) { |
||
0 ignored issues
–
show
The variable
navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
118 | return { |
||
119 | status: false, |
||
120 | exception: errorHandlers.formatValidationError("Please Allow All Cookies from your browser settings."), |
||
121 | }; |
||
122 | } |
||
123 | /* |
||
124 | * RECEIVE MESSAGE FROM CHILD |
||
125 | */ |
||
126 | window.addEventListener("message", (e) => { |
||
127 | if (e.data.source === "embeddableShakehand") { |
||
128 | errorHandlers.handleErrors(e.data.data) |
||
129 | } |
||
130 | if (e.data.source === "embeddableShakehandSuccess") { |
||
131 | errorHandlers.handlePayments(e.data.data) |
||
132 | } |
||
133 | }); |
||
134 | return { |
||
135 | status: true, |
||
136 | exception: '', |
||
137 | }; |
||
138 | } |
||
139 | |||
140 | //Transaction Parameters |
||
141 | const TransactionParameters = { |
||
142 | __00trid__: "", // pp_OrderId |
||
143 | __01curr__: "PKR", // pp_TxnCurrency |
||
144 | __02trdt__: "", // pp_TxnDateTime |
||
145 | __03stamt__: "", // pp_TxnSubTotal |
||
146 | __04damt__: "", // pp_TxnDiscount |
||
147 | __05tamt__: "", // pp_TxnTotal |
||
148 | __06cname__: "", // pp_CustomerName |
||
149 | __07ccc__: "", // pp_CustomerCountryCode |
||
150 | __08cphn__: "", // pp_CustomerPhoneNumber |
||
151 | __09cemail__: "", // pp_CustomerEmail |
||
152 | __10ccc__: "", // pp_CustomerCountry |
||
153 | __11cstate__: "", // pp_CustomerState |
||
154 | __12ccity__: "", // pp_CustomerCity |
||
155 | __13carea__: "", // pp_CustomerArea |
||
156 | __14cfadd__: "", // pp_CustomerFormattedAddress |
||
157 | __15mid__: "", // pp_MerchantID |
||
158 | __16stid__: "", // pp_StoreSlug |
||
159 | // __17seh__: "", |
||
160 | __18ver__: "", // pp_Version |
||
161 | __19lan__: "EN", // pp_Language |
||
162 | __20red__: "", // pp_RedirectURL |
||
163 | __21cenv__: ""// pp_Environment |
||
164 | } |
||
165 | |||
166 | const bSecurePayments = { |
||
167 | initialize: function (objectId) { |
||
168 | if (typeof objectId === 'string') { |
||
169 | if (checkEmptyHtml("#bSecurePaymentPluginContainer")) { |
||
170 | errorHandlers.onException("bSecurePaymentPluginContainer is required.") |
||
171 | } else if (checkEmptyHtml("#bSecurePaymentPluginContainer")) { |
||
0 ignored issues
–
show
|
|||
172 | errorHandlers.onException("bSecurePaymentPluginContainer is required.") |
||
173 | } else { |
||
0 ignored issues
–
show
|
|||
174 | const iframeListenerPrepared = prepareFrameListener(); |
||
175 | if (iframeListenerPrepared.status) { |
||
176 | generateOrder(TransactionParameters); |
||
0 ignored issues
–
show
|
|||
177 | } else { |
||
178 | return iframeListenerPrepared.exception |
||
179 | } |
||
180 | } |
||
181 | } else { |
||
182 | errorHandlers.onException("bSecurePaymentPluginContainer is required"); |
||
0 ignored issues
–
show
|
|||
183 | } |
||
184 | }, |
||
185 | } |
||
186 | |||
187 | |||
188 | module.exports = { |
||
189 | bSecurePayments, |
||
190 | TransactionParameters, |
||
191 | bSecurePaymentsHandler: bSecurePaymentsHandler, |
||
192 | bSecurePaymentsEventHandler: bSecurePaymentsEventHandler |
||
193 | }; |
||
194 |