1. 1 :
  2. 2 :
  3. 3 : (function(root, factory) {
  4. 4 :
  5. 5 : if (typeof module === 'object' && module.exports) {
  6. 6 : // CommonJS-like environments that support module.exports, like Node.
  7. 7 : module.exports = factory(require('../ApiClient'), require('./InvocationContext'), require('../CommonUtil'), require('../ResponseWrapper'), require('./Base')
  8. 8 : , require('../handlers/CancelPaymentAuthorizationHandler')
  9. 9 : , require('../handlers/CreatePaymentAuthorizationHandler'), require('../OrbipayApiError'));
  10. 10 : }
  11. 11 : }(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, CancelPaymentAuthorizationHandler, CreatePaymentAuthorizationHandler, OrbipayApiError) {
  12. 12 : 'use strict';
  13. 13 :
  14. 14 : /**
  15. 15 : * The PaymentAuthorization wrapper module.
  16. 16 : * @module wrappers/PaymentAuthorization
  17. 17 : */
  18. 18 : var exports = function(id_authorization) {
  19. 19 : var _this = this;
  20. 20 : Base.call(_this);
  21. 21 : _this['ID_AUTHORIZATION'] = id_authorization;
  22. 22 : _this.id = id_authorization;
  23. 23 : };
  24. 24 :
  25. 25 : /**
  26. 26 : * Constructs a <code>PaymentAuthorization</code> from a plain JavaScript object, optionally creating a new instance.
  27. 27 : * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
  28. 28 : * @param {Object} data The plain JavaScript object bearing properties of interest.
  29. 29 : * @param {module:wrappers/PaymentAuthorization} obj Optional instance to populate.
  30. 30 : * @return {module:wrappers/PaymentAuthorization} The populated <code>PaymentAuthorization</code> instance.
  31. 31 : */
  32. 32 : exports.constructFromObject = function (data, obj) {
  33. 33 : if (data) {
  34. 34 : obj = obj || new exports();
  35. 35 : if (data.hasOwnProperty('payment_auth_reference')) {
  36. 36 : obj['payment_auth_reference'] = data['payment_auth_reference'];
  37. 37 : }
  38. 38 : if (data.hasOwnProperty('id')) {
  39. 39 : obj['id'] = data['id'];
  40. 40 : }
  41. 41 : if (data.hasOwnProperty('url')) {
  42. 42 : obj['url'] = data['url'];
  43. 43 : }
  44. 44 : if (data.hasOwnProperty('auth_amount')) {
  45. 45 : obj['auth_amount'] = data['auth_amount'];
  46. 46 : }
  47. 47 : if (data.hasOwnProperty('status')) {
  48. 48 : obj['status'] = data['status'];
  49. 49 : }
  50. 50 : if (data.hasOwnProperty('payment_method')) {
  51. 51 : obj['payment_method'] = data['payment_method'];
  52. 52 : }
  53. 53 : if (data.hasOwnProperty('currency_code3d')) {
  54. 54 : obj['currency_code3d'] = data['currency_code3d'];
  55. 55 : }
  56. 56 : if (data.hasOwnProperty('card_cvv_number')) {
  57. 57 : obj['card_cvv_number'] = data['card_cvv_number'];
  58. 58 : }
  59. 59 : if (data.hasOwnProperty('entry_time')) {
  60. 60 : obj['entry_time'] = data['entry_time'];
  61. 61 : }
  62. 62 : if (data.hasOwnProperty('captured_time')) {
  63. 63 : obj['captured_time'] = data['captured_time'];
  64. 64 : }
  65. 65 : if (data.hasOwnProperty('comments')) {
  66. 66 : obj['comments'] = data['comments'];
  67. 67 : }
  68. 68 : if (data.hasOwnProperty('custom_fields')) {
  69. 69 : obj['custom_fields'] = data['custom_fields'];
  70. 70 : }
  71. 71 : if (data.hasOwnProperty('customer')) {
  72. 72 : var Customer = require('./Customer');
  73. 73 : obj['customer'] = Customer.constructFromObject(data['customer']);
  74. 74 : }
  75. 75 : if (data.hasOwnProperty('funding_account')) {
  76. 76 : var FundingAccount = require('./FundingAccount');
  77. 77 : obj['funding_account'] = FundingAccount.constructFromObject(data['funding_account']);
  78. 78 : }
  79. 79 : if (data.hasOwnProperty('customer_account')) {
  80. 80 : var CustomerAccount = require('./CustomerAccount');
  81. 81 : obj['customer_account'] = CustomerAccount.constructFromObject(data['customer_account']);
  82. 82 : }
  83. 83 : if (data.hasOwnProperty('payment_network_response')) {
  84. 84 : var PaymentNetworkResponse = require('./PaymentNetworkResponse');
  85. 85 : obj['payment_network_response'] = PaymentNetworkResponse.constructFromObject(data['payment_network_response']);
  86. 86 : }
  87. 87 : if (data.hasOwnProperty('audit_info')) {
  88. 88 : var AuditInfo = require('./AuditInfo');
  89. 89 : obj['audit_info'] = AuditInfo.constructFromObject(data['audit_info']);
  90. 90 : }
  91. 91 : if (data.hasOwnProperty('ID_CUSTOMER')) {
  92. 92 : obj['ID_CUSTOMER'] = data['ID_CUSTOMER'];
  93. 93 : }
  94. 94 : if (data.hasOwnProperty('ID_AUTHORIZATION')) {
  95. 95 : obj['ID_AUTHORIZATION'] = data['ID_AUTHORIZATION'];
  96. 96 : }
  97. 97 : }
  98. 98 : return obj;
  99. 99 : };
  100. 100 :
  101. 101 :
  102. 102 : exports.prototype = Object.create(Base.prototype);
  103. 103 : exports.prototype.constructor = exports;
  104. 104 :
  105. 105 : /**
  106. 106 : * The unique identifier in the client system for the payment.
  107. 107 : * @member {String} payment_auth_reference
  108. 108 : */
  109. 109 : exports.prototype['payment_auth_reference'] = undefined;
  110. 110 : /**
  111. 111 : * The unique identifier assigned by EBPP to the payment authorization.
  112. 112 : * @member {String} id
  113. 113 : */
  114. 114 : exports.prototype['id'] = undefined;
  115. 115 : /**
  116. 116 : * This URL fetches the details of payment authorization.
  117. 117 : * @member {String} url
  118. 118 : */
  119. 119 : exports.prototype['url'] = undefined;
  120. 120 : /**
  121. 121 : * The amount being authorized.
  122. 122 : * @member {String} auth_amount
  123. 123 : */
  124. 124 : exports.prototype['auth_amount'] = undefined;
  125. 125 : /**
  126. 126 : * The status of the payment.
  127. 127 : * @member {String} status
  128. 128 : */
  129. 129 : exports.prototype['status'] = undefined;
  130. 130 : /**
  131. 131 : * The fulfillment method for the payment authorization.
  132. 132 : * @member {String} payment_method
  133. 133 : */
  134. 134 : exports.prototype['payment_method'] = undefined;
  135. 135 : /**
  136. 136 : * The three-letter currency code in the ISO4217 format, in uppercase, for the card account. It must be a currency supported by EBPP. This defaults to USD.
  137. 137 : * @member {String} currency_code3d
  138. 138 : */
  139. 139 : exports.prototype['currency_code3d'] = undefined;
  140. 140 : /**
  141. 141 : * This is never returned by EBPP. This needs to be passed to EBPP when making or editing a payment with a card funding account.
  142. 142 : * @member {String} card_cvv_number
  143. 143 : */
  144. 144 : exports.prototype['card_cvv_number'] = undefined;
  145. 145 : /**
  146. 146 : * The date on which the payment authorization created in UTC timestamp, with ISO8601 format. For e.g., 2019-08-13T09:21:34.359+0000.
  147. 147 : * @member {String} entry_time
  148. 148 : */
  149. 149 : exports.prototype['entry_time'] = undefined;
  150. 150 : /**
  151. 151 : * The date on which the payment authorization is captured in UTC timestamp, with ISO8601 format. For e.g., 2019-08-13T09:21:34.359+0000..
  152. 152 : * @member {String} captured_time
  153. 153 : */
  154. 154 : exports.prototype['captured_time'] = undefined;
  155. 155 : /**
  156. 156 : * Comments that can be used to recollect the operation performed on the resource object. API clients need to ensure that no sensitive information is passed in the memo. Alacriti (EBPP) is not responsible for the security of any sensitive information that may be passed as part of the memo.
  157. 157 : * @member {String} comments
  158. 158 : */
  159. 159 : exports.prototype['comments'] = undefined;
  160. 160 : /**
  161. 161 : * The additional information or meta-information that EBPP can accept, maintain and transmit back to the client. The custom fields need to be configured with EBPP before they can be accepted. EBPP would reject custom fields that are not pre-configured. Please contact <a href = \"mailto: support@billerpayments.com\">support@billerpayments.com</a> for more information on configuring and using custom fields. Only the custom fields enabled for the client, in EBPP, would be accepted in the requests.
  162. 162 : * @member {{String: String}} custom_fields
  163. 163 : */
  164. 164 : exports.prototype['custom_fields'] = undefined;
  165. 165 : /**
  166. 166 : * @member {Customer} customer
  167. 167 : */
  168. 168 : exports.prototype['customer'] = undefined;
  169. 169 : /**
  170. 170 : * @member {FundingAccount} funding_account
  171. 171 : */
  172. 172 : exports.prototype['funding_account'] = undefined;
  173. 173 : /**
  174. 174 : * @member {CustomerAccount} customer_account
  175. 175 : */
  176. 176 : exports.prototype['customer_account'] = undefined;
  177. 177 : /**
  178. 178 : * @member {PaymentNetworkResponse} payment_network_response
  179. 179 : */
  180. 180 : exports.prototype['payment_network_response'] = undefined;
  181. 181 : /**
  182. 182 : * @member {AuditInfo} audit_info
  183. 183 : */
  184. 184 : exports.prototype['audit_info'] = undefined;
  185. 185 : /**
  186. 186 : * The unique identifier assigned by EBPP to the customer.
  187. 187 : * @member {String} ID_CUSTOMER
  188. 188 : */
  189. 189 : exports.prototype['ID_CUSTOMER'] = undefined;
  190. 190 : /**
  191. 191 : * The unique identifier assigned by EBPP to the payment authorization.
  192. 192 : * @member {String} ID_AUTHORIZATION
  193. 193 : */
  194. 194 : exports.prototype['ID_AUTHORIZATION'] = undefined;
  195. 195 :
  196. 196 : /**
  197. 197 : * @param {String} client_key - The client_key of PaymentAuthorization.
  198. 198 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  199. 199 : */
  200. 200 : exports.prototype.forClient = function (client_key) {
  201. 201 : var _this = this;
  202. 202 : Base.prototype.forClient.call(_this,client_key);
  203. 203 : return _this;
  204. 204 : };
  205. 205 : /**
  206. 206 : * @param {String} channel - The channel of PaymentAuthorization.
  207. 207 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  208. 208 : */
  209. 209 : exports.prototype.videChannel = function (channel) {
  210. 210 : var _this = this;
  211. 211 : Base.prototype.videChannel.call(_this,channel);
  212. 212 : return _this;
  213. 213 : };
  214. 214 : /**
  215. 215 : * @param {String} auth_amount - The auth_amount of PaymentAuthorization.
  216. 216 : * @param {String} card_cvv_number - The card_cvv_number of PaymentAuthorization.
  217. 217 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  218. 218 : */
  219. 219 : exports.prototype.withDetails = function (auth_amount, card_cvv_number) {
  220. 220 : var _this = this;
  221. 221 :
  222. 222 : _this['auth_amount'] = auth_amount;
  223. 223 :
  224. 224 : _this['card_cvv_number'] = card_cvv_number;
  225. 225 :
  226. 226 :
  227. 227 : return _this;
  228. 228 : };
  229. 229 : /**
  230. 230 : * @param {String} ID_CUSTOMER - The ID_CUSTOMER of PaymentAuthorization.
  231. 231 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  232. 232 : */
  233. 233 : exports.prototype.forCustomer = function (id_customer) {
  234. 234 : var _this = this;
  235. 235 :
  236. 236 : _this['ID_CUSTOMER'] = id_customer;
  237. 237 : var Customer = require('./Customer');
  238. 238 : _this['customer'] = new Customer(id_customer);
  239. 239 :
  240. 240 :
  241. 241 : return _this;
  242. 242 : };
  243. 243 : /**
  244. 244 : * @param {FundingAccount} funding_account - The funding_account of PaymentAuthorization.
  245. 245 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  246. 246 : */
  247. 247 : exports.prototype.fromAccount = function (funding_account) {
  248. 248 : var _this = this;
  249. 249 :
  250. 250 : _this['funding_account'] = funding_account;
  251. 251 :
  252. 252 :
  253. 253 : return _this;
  254. 254 : };
  255. 255 : /**
  256. 256 : * @param {CustomerAccount} customer_account - The customer_account of PaymentAuthorization.
  257. 257 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  258. 258 : */
  259. 259 : exports.prototype.toAccount = function (customer_account) {
  260. 260 : var _this = this;
  261. 261 :
  262. 262 : _this['customer_account'] = customer_account;
  263. 263 :
  264. 264 :
  265. 265 : return _this;
  266. 266 : };
  267. 267 : /**
  268. 268 : * @param {String} payment_auth_reference - The payment_auth_reference of PaymentAuthorization.
  269. 269 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  270. 270 : */
  271. 271 : exports.prototype.withReference = function (payment_auth_reference) {
  272. 272 : var _this = this;
  273. 273 :
  274. 274 : _this['payment_auth_reference'] = payment_auth_reference;
  275. 275 :
  276. 276 :
  277. 277 : return _this;
  278. 278 : };
  279. 279 : /**
  280. 280 : * @param {{String: String}} custom_fields - The custom_fields of PaymentAuthorization.
  281. 281 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  282. 282 : */
  283. 283 : exports.prototype.withCustomFields = function (custom_fields) {
  284. 284 : var _this = this;
  285. 285 :
  286. 286 : _this['custom_fields'] = custom_fields;
  287. 287 :
  288. 288 :
  289. 289 : return _this;
  290. 290 : };
  291. 291 : /**
  292. 292 : * @param {String} comments - The comments of PaymentAuthorization.
  293. 293 : * @return {module:wrappers/PaymentAuthorization} The instance of <code>PaymentAuthorization</code>.
  294. 294 : */
  295. 295 : exports.prototype.withMemo = function (comments) {
  296. 296 : var _this = this;
  297. 297 :
  298. 298 : _this['comments'] = comments;
  299. 299 :
  300. 300 :
  301. 301 : return _this;
  302. 302 : };
  303. 303 :
  304. 304 : exports.prototype.cancelledBy = function (requestor, requestor_type) {
  305. 305 : var _this = this;
  306. 306 : _this.requestedBy(requestor, requestor_type);
  307. 307 : return _this;
  308. 308 : };
  309. 309 : exports.prototype.createdBy = function (requestor, requestor_type) {
  310. 310 : var _this = this;
  311. 311 : _this.requestedBy(requestor, requestor_type);
  312. 312 : return _this;
  313. 313 : };
  314. 314 :
  315. 315 : exports.prototype.cancel = function (invocation_context, callback, live_mode, api_end_point) {
  316. 316 : var _this = this;
  317. 317 : var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
  318. 318 : try {
  319. 319 : var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
  320. 320 : if (callback) {
  321. 321 : callback(response['exception'], response['data'])
  322. 322 : }
  323. 323 : } catch (e) {
  324. 324 : exception = OrbipayApiError.getDefaultException(e);
  325. 325 : if (callback) {
  326. 326 : callback(exception)
  327. 327 : }
  328. 328 : }
  329. 329 : };
  330. 330 : try {
  331. 331 : _this.withContext(invocation_context, live_mode, api_end_point);
  332. 332 : var handler = new CancelPaymentAuthorizationHandler();
  333. 333 : if (callback && CommonUtil.isFunction(callback)) {
  334. 334 : return handler.process(_this, internalCallback);
  335. 335 : } else {
  336. 336 : return handler.process(_this);
  337. 337 : }
  338. 338 : }
  339. 339 : catch (e){
  340. 340 : var error = OrbipayApiError.getDefaultException(e);
  341. 341 : if (callback) {
  342. 342 : callback(error)
  343. 343 : }
  344. 344 : }
  345. 345 : };
  346. 346 : exports.prototype.create = function (invocation_context, callback, live_mode, api_end_point) {
  347. 347 : var _this = this;
  348. 348 : var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
  349. 349 : try {
  350. 350 : var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
  351. 351 : if (callback) {
  352. 352 : callback(response['exception'], response['data'])
  353. 353 : }
  354. 354 : } catch (e) {
  355. 355 : exception = OrbipayApiError.getDefaultException(e);
  356. 356 : if (callback) {
  357. 357 : callback(exception)
  358. 358 : }
  359. 359 : }
  360. 360 : };
  361. 361 : try {
  362. 362 : _this.withContext(invocation_context, live_mode, api_end_point);
  363. 363 : var handler = new CreatePaymentAuthorizationHandler();
  364. 364 : if (callback && CommonUtil.isFunction(callback)) {
  365. 365 : return handler.process(_this, internalCallback);
  366. 366 : } else {
  367. 367 : return handler.process(_this);
  368. 368 : }
  369. 369 : }
  370. 370 : catch (e){
  371. 371 : var error = OrbipayApiError.getDefaultException(e);
  372. 372 : if (callback) {
  373. 373 : callback(error)
  374. 374 : }
  375. 375 : }
  376. 376 : };
  377. 377 :
  378. 378 : return exports;
  379. 379 :
  380. 380 : }));