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/SimplePaymentHandler'), require('../OrbipayApiError'));
  9. 9 : }
  10. 10 : }(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, SimplePaymentHandler, OrbipayApiError) {
  11. 11 : 'use strict';
  12. 12 :
  13. 13 : /**
  14. 14 : * The SimplePayment wrapper module.
  15. 15 : * @module wrappers/SimplePayment
  16. 16 : */
  17. 17 : var exports = function() {
  18. 18 :
  19. 19 : };
  20. 20 : exports.constructFromObject = function (data, obj) {
  21. 21 : if (data) {
  22. 22 : obj = obj || new exports();
  23. 23 : if (data.hasOwnProperty('id')) {
  24. 24 : obj['id'] = data['id'];
  25. 25 : }
  26. 26 : if (data.hasOwnProperty('url')) {
  27. 27 : obj['url'] = data['url'];
  28. 28 : }
  29. 29 : if (data.hasOwnProperty('fee')) {
  30. 30 : var Fee = require('./Fee');
  31. 31 : obj['fee'] = Fee.constructFromObject(data['fee']);
  32. 32 : }
  33. 33 : if (data.hasOwnProperty('status')) {
  34. 34 : obj['status'] = data['status'];
  35. 35 : }
  36. 36 : if (data.hasOwnProperty('payment_method')) {
  37. 37 : obj['payment_method'] = data['payment_method'];
  38. 38 : }
  39. 39 : if (data.hasOwnProperty('confirmation_number')) {
  40. 40 : obj['confirmation_number'] = data['confirmation_number'];
  41. 41 : }
  42. 42 : if (data.hasOwnProperty('custom_fields')) {
  43. 43 : obj['custom_fields'] = data['custom_fields'];
  44. 44 : }
  45. 45 : if (data.hasOwnProperty('currency_code3d')) {
  46. 46 : obj['currency_code3d'] = data['currency_code3d'];
  47. 47 : }
  48. 48 : if (data.hasOwnProperty('amount')) {
  49. 49 : obj['amount'] = data['amount'];
  50. 50 : }
  51. 51 : if (data.hasOwnProperty('card_cvv_number')) {
  52. 52 : obj['card_cvv_number'] = data['card_cvv_number'];
  53. 53 : }
  54. 54 : if (data.hasOwnProperty('payment_date')) {
  55. 55 : obj['payment_date'] = data['payment_date'];
  56. 56 : }
  57. 57 : if (data.hasOwnProperty('payment_schedule_type')) {
  58. 58 : obj['payment_schedule_type'] = data['payment_schedule_type'];
  59. 59 : }
  60. 60 : if (data.hasOwnProperty('payment_request_date')) {
  61. 61 : obj['payment_request_date'] = data['payment_request_date'];
  62. 62 : }
  63. 63 : if (data.hasOwnProperty('payment_amount_type')) {
  64. 64 : obj['payment_amount_type'] = data['payment_amount_type'];
  65. 65 : }
  66. 66 : if (data.hasOwnProperty('payment_reference')) {
  67. 67 : obj['payment_reference'] = data['payment_reference'];
  68. 68 : }
  69. 69 : if (data.hasOwnProperty('expected_payment_settlement_date')) {
  70. 70 : obj['expected_payment_settlement_date'] = data['expected_payment_settlement_date'];
  71. 71 : }
  72. 72 : if (data.hasOwnProperty('payment_entry_date')) {
  73. 73 : obj['payment_entry_date'] = data['payment_entry_date'];
  74. 74 : }
  75. 75 : if (data.hasOwnProperty('payment_return_date')) {
  76. 76 : obj['payment_return_date'] = data['payment_return_date'];
  77. 77 : }
  78. 78 : if (data.hasOwnProperty('return_code')) {
  79. 79 : obj['return_code'] = data['return_code'];
  80. 80 : }
  81. 81 : if (data.hasOwnProperty('payment_notification_email')) {
  82. 82 : obj['payment_notification_email'] = data['payment_notification_email'];
  83. 83 : }
  84. 84 : if (data.hasOwnProperty('cryptogram')) {
  85. 85 : obj['cryptogram'] = data['cryptogram'];
  86. 86 : }
  87. 87 : if (data.hasOwnProperty('eci')) {
  88. 88 : obj['eci'] = data['eci'];
  89. 89 : }
  90. 90 : if (data.hasOwnProperty('comments')) {
  91. 91 : obj['comments'] = data['comments'];
  92. 92 : }
  93. 93 : if (data.hasOwnProperty('customer')) {
  94. 94 : var Customer = require('./Customer');
  95. 95 : obj['customer'] = Customer.constructFromObject(data['customer']);
  96. 96 : }
  97. 97 : if (data.hasOwnProperty('funding_account')) {
  98. 98 : var FundingAccount = require('./FundingAccount');
  99. 99 : obj['funding_account'] = FundingAccount.constructFromObject(data['funding_account']);
  100. 100 : }
  101. 101 : if (data.hasOwnProperty('customer_account')) {
  102. 102 : var CustomerAccount = require('./CustomerAccount');
  103. 103 : obj['customer_account'] = CustomerAccount.constructFromObject(data['customer_account']);
  104. 104 : }
  105. 105 : if (data.hasOwnProperty('payment_network_response')) {
  106. 106 : var PaymentNetworkResponse = require('./PaymentNetworkResponse');
  107. 107 : obj['payment_network_response'] = PaymentNetworkResponse.constructFromObject(data['payment_network_response']);
  108. 108 : }
  109. 109 : if (data.hasOwnProperty('audit_info')) {
  110. 110 : var AuditInfo = require('./AuditInfo');
  111. 111 : obj['audit_info'] = AuditInfo.constructFromObject(data['audit_info']);
  112. 112 : }
  113. 113 : if (data.hasOwnProperty('save_funding_account')) {
  114. 114 : obj['save_funding_account'] = data['save_funding_account'];
  115. 115 : }
  116. 116 : }
  117. 117 : return obj;
  118. 118 : };
  119. 119 :
  120. 120 :
  121. 121 : exports.prototype = Object.create(Base.prototype);
  122. 122 : exports.prototype.constructor = exports;
  123. 123 :
  124. 124 : /**
  125. 125 : * The unique identifier assigned by EBPP to the payment.
  126. 126 : * @member {String} id
  127. 127 : */
  128. 128 : exports.prototype['id'] = undefined;
  129. 129 : /**
  130. 130 : * This URL fetches the details of payment.
  131. 131 : * @member {String} url
  132. 132 : */
  133. 133 : exports.prototype['url'] = undefined;
  134. 134 : /**
  135. 135 : * @member {Fee} fee
  136. 136 : */
  137. 137 : exports.prototype['fee'] = undefined;
  138. 138 : /**
  139. 139 : * The status of the payment.
  140. 140 : * @member {String} status
  141. 141 : */
  142. 142 : exports.prototype['status'] = undefined;
  143. 143 : /**
  144. 144 : * The fulfillment method for the payment.
  145. 145 : * @member {String} payment_method
  146. 146 : */
  147. 147 : exports.prototype['payment_method'] = undefined;
  148. 148 : /**
  149. 149 : * The confirmation number or reference provided to the customer for the payment.
  150. 150 : * @member {String} confirmation_number
  151. 151 : */
  152. 152 : exports.prototype['confirmation_number'] = undefined;
  153. 153 : /**
  154. 154 : * 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.
  155. 155 : * @member {{String: String}} custom_fields
  156. 156 : */
  157. 157 : exports.prototype['custom_fields'] = undefined;
  158. 158 : /**
  159. 159 : * 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.
  160. 160 : * @member {String} currency_code3d
  161. 161 : */
  162. 162 : exports.prototype['currency_code3d'] = undefined;
  163. 163 : /**
  164. 164 : * The amount being paid. In case the payment_amount_type is 'discounted_amount', 'penalty_amount' or 'other', the amount needs to be specified. In other cases, this is derived from the payment_amount_type.
  165. 165 : * @member {String} amount
  166. 166 : */
  167. 167 : exports.prototype['amount'] = undefined;
  168. 168 : /**
  169. 169 : * This is never returned by EBPP. This needs to be passed to EBPP when making or editing a payment with a card funding account.
  170. 170 : * @member {String} card_cvv_number
  171. 171 : */
  172. 172 : exports.prototype['card_cvv_number'] = undefined;
  173. 173 : /**
  174. 174 : * The date on which the payment is scheduled to be made. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
  175. 175 : * @member {String} payment_date
  176. 176 : */
  177. 177 : exports.prototype['payment_date'] = undefined;
  178. 178 : /**
  179. 179 : * The schedule type for the payment. This defaults to one_time_payment.
  180. 180 : * @member {String} payment_schedule_type
  181. 181 : */
  182. 182 : exports.prototype['payment_schedule_type'] = undefined;
  183. 183 : /**
  184. 184 : * The date on which the biller wants the payment to be settled. It must be in ISO8601 full-date format, namely, YYYY-MM-DD. This is applicable only if the client has opted for it.
  185. 185 : * @member {String} payment_request_date
  186. 186 : */
  187. 187 : exports.prototype['payment_request_date'] = undefined;
  188. 188 : /**
  189. 189 : * The type of amount, as per the bill/statement, that is being paid. The payment amount is derived from the amount type selected for the payment. This defaults to other.
  190. 190 : * @member {String} payment_amount_type
  191. 191 : */
  192. 192 : exports.prototype['payment_amount_type'] = undefined;
  193. 193 : /**
  194. 194 : * The unique identifier in the client system for the payment.
  195. 195 : * @member {String} payment_reference
  196. 196 : */
  197. 197 : exports.prototype['payment_reference'] = undefined;
  198. 198 : /**
  199. 199 : * The date on which the payment is expected to be settled with the biller. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
  200. 200 : * @member {String} expected_payment_settlement_date
  201. 201 : */
  202. 202 : exports.prototype['expected_payment_settlement_date'] = undefined;
  203. 203 : /**
  204. 204 : * The date on which the payment is captured in EBPP. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
  205. 205 : * @member {String} payment_entry_date
  206. 206 : */
  207. 207 : exports.prototype['payment_entry_date'] = undefined;
  208. 208 : /**
  209. 209 : * The date on which the ACH returns is received by EBPP.
  210. 210 : * @member {String} payment_return_date
  211. 211 : */
  212. 212 : exports.prototype['payment_return_date'] = undefined;
  213. 213 : /**
  214. 214 : * The ACH return code or the chargeback code received from Visa/Mastercard, in the event of returned payments.
  215. 215 : * @member {String} return_code
  216. 216 : */
  217. 217 : exports.prototype['return_code'] = undefined;
  218. 218 : /**
  219. 219 : * The email address to which notifications for the payment will be sent. The notifications will be sent to the customer's email in case this is not provided.
  220. 220 : * @member {String} payment_notification_email
  221. 221 : */
  222. 222 : exports.prototype['payment_notification_email'] = undefined;
  223. 223 : /**
  224. 224 : * This is applicable only for Apple Pay transactions. Online Payment Cryptogram, as defined by 3-D secure.
  225. 225 : * @member {String} cryptogram
  226. 226 : */
  227. 227 : exports.prototype['cryptogram'] = undefined;
  228. 228 : /**
  229. 229 : * This is applicable only for Apple Pay transactions. ECI Indicator, as defined by 3-D secure. The card network may add an ECI indicator to the card data. This indicator is then included in the payment token. if you receive an ECI indicator, you must pass it on to your payment processor, otherwise, the transaction fails.
  230. 230 : * @member {String} eci
  231. 231 : */
  232. 232 : exports.prototype['eci'] = undefined;
  233. 233 : /**
  234. 234 : * 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.
  235. 235 : * @member {String} comments
  236. 236 : */
  237. 237 : exports.prototype['comments'] = undefined;
  238. 238 : /**
  239. 239 : * @member {Customer} customer
  240. 240 : */
  241. 241 : exports.prototype['customer'] = undefined;
  242. 242 : /**
  243. 243 : * @member {FundingAccount} funding_account
  244. 244 : */
  245. 245 : exports.prototype['funding_account'] = undefined;
  246. 246 : /**
  247. 247 : * @member {CustomerAccount} customer_account
  248. 248 : */
  249. 249 : exports.prototype['customer_account'] = undefined;
  250. 250 : /**
  251. 251 : * @member {PaymentNetworkResponse} payment_network_response
  252. 252 : */
  253. 253 : exports.prototype['payment_network_response'] = undefined;
  254. 254 : /**
  255. 255 : * @member {AuditInfo} audit_info
  256. 256 : */
  257. 257 : exports.prototype['audit_info'] = undefined;
  258. 258 : /**
  259. 259 : * query param
  260. 260 : * @member {String} save_funding_account
  261. 261 : */
  262. 262 : exports.prototype['save_funding_account'] = undefined;
  263. 263 :
  264. 264 : /**
  265. 265 : * @param {String} client_key - The client_key of SimplePayment.
  266. 266 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  267. 267 : */
  268. 268 : exports.prototype.forClient = function (client_key) {
  269. 269 : var _this = this;
  270. 270 : Base.prototype.forClient.call(_this,client_key);
  271. 271 : return _this;
  272. 272 : };
  273. 273 : /**
  274. 274 : * @param {String} channel - The channel of SimplePayment.
  275. 275 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  276. 276 : */
  277. 277 : exports.prototype.videChannel = function (channel) {
  278. 278 : var _this = this;
  279. 279 : Base.prototype.videChannel.call(_this,channel);
  280. 280 : return _this;
  281. 281 : };
  282. 282 : /**
  283. 283 : * @param {String} payment_amount_type - The payment_amount_type of SimplePayment.
  284. 284 : * @param {String} amount - The amount of SimplePayment.
  285. 285 : * @param {String} payment_date - The payment_date of SimplePayment.
  286. 286 : * @param {String} payment_request_date - The payment_request_date of SimplePayment.
  287. 287 : * @param {String} card_cvv_number - The card_cvv_number of SimplePayment.
  288. 288 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  289. 289 : */
  290. 290 : exports.prototype.withDetails = function (payment_amount_type, amount, payment_date, payment_request_date, card_cvv_number) {
  291. 291 : var _this = this;
  292. 292 :
  293. 293 : _this['payment_amount_type'] = payment_amount_type;
  294. 294 :
  295. 295 : _this['amount'] = amount;
  296. 296 :
  297. 297 : _this['payment_date'] = payment_date;
  298. 298 :
  299. 299 : _this['payment_request_date'] = payment_request_date;
  300. 300 :
  301. 301 : _this['card_cvv_number'] = card_cvv_number;
  302. 302 :
  303. 303 :
  304. 304 : return _this;
  305. 305 : };
  306. 306 : /**
  307. 307 : * @param {FundingAccount} funding_account - The funding_account of SimplePayment.
  308. 308 : * @param {String} save_funding_account - The save_funding_account of SimplePayment.
  309. 309 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  310. 310 : */
  311. 311 : exports.prototype.fromAccount = function (funding_account, save_funding_account) {
  312. 312 : var _this = this;
  313. 313 :
  314. 314 : _this['funding_account'] = funding_account;
  315. 315 :
  316. 316 : _this['save_funding_account'] = save_funding_account;
  317. 317 :
  318. 318 :
  319. 319 : return _this;
  320. 320 : };
  321. 321 : /**
  322. 322 : * @param {CustomerAccount} customer_account - The customer_account of SimplePayment.
  323. 323 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  324. 324 : */
  325. 325 : exports.prototype.toAccount = function (customer_account) {
  326. 326 : var _this = this;
  327. 327 :
  328. 328 : _this['customer_account'] = customer_account;
  329. 329 :
  330. 330 :
  331. 331 : return _this;
  332. 332 : };
  333. 333 : /**
  334. 334 : * @param {String} payment_reference - The payment_reference of SimplePayment.
  335. 335 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  336. 336 : */
  337. 337 : exports.prototype.withReference = function (payment_reference) {
  338. 338 : var _this = this;
  339. 339 :
  340. 340 : _this['payment_reference'] = payment_reference;
  341. 341 :
  342. 342 :
  343. 343 : return _this;
  344. 344 : };
  345. 345 : /**
  346. 346 : * @param {String} payment_notification_email - The payment_notification_email of SimplePayment.
  347. 347 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  348. 348 : */
  349. 349 : exports.prototype.withPaymentNotificationEmail = function (payment_notification_email) {
  350. 350 : var _this = this;
  351. 351 :
  352. 352 : _this['payment_notification_email'] = payment_notification_email;
  353. 353 :
  354. 354 :
  355. 355 : return _this;
  356. 356 : };
  357. 357 : /**
  358. 358 : * @param {{String: String}} custom_fields - The custom_fields of SimplePayment.
  359. 359 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  360. 360 : */
  361. 361 : exports.prototype.withCustomFields = function (custom_fields) {
  362. 362 : var _this = this;
  363. 363 :
  364. 364 : _this['custom_fields'] = custom_fields;
  365. 365 :
  366. 366 :
  367. 367 : return _this;
  368. 368 : };
  369. 369 : /**
  370. 370 : * @param {String} comments - The comments of SimplePayment.
  371. 371 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  372. 372 : */
  373. 373 : exports.prototype.withMemo = function (comments) {
  374. 374 : var _this = this;
  375. 375 :
  376. 376 : _this['comments'] = comments;
  377. 377 :
  378. 378 :
  379. 379 : return _this;
  380. 380 : };
  381. 381 : /**
  382. 382 : * @param {Fee} fee - The fee of SimplePayment.
  383. 383 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  384. 384 : */
  385. 385 : exports.prototype.withFee = function (fee) {
  386. 386 : var _this = this;
  387. 387 :
  388. 388 : _this['fee'] = fee;
  389. 389 :
  390. 390 :
  391. 391 : return _this;
  392. 392 : };
  393. 393 : /**
  394. 394 : * @param {Customer} customer - The customer of SimplePayment.
  395. 395 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  396. 396 : */
  397. 397 : exports.prototype.forCustomer = function (customer) {
  398. 398 : var _this = this;
  399. 399 :
  400. 400 : _this['customer'] = customer;
  401. 401 :
  402. 402 :
  403. 403 : return _this;
  404. 404 : };
  405. 405 : /**
  406. 406 : * @param {String} cryptogram - The cryptogram of SimplePayment.
  407. 407 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  408. 408 : */
  409. 409 : exports.prototype.withCryptogram = function (cryptogram) {
  410. 410 : var _this = this;
  411. 411 :
  412. 412 : _this['cryptogram'] = cryptogram;
  413. 413 :
  414. 414 :
  415. 415 : return _this;
  416. 416 : };
  417. 417 : /**
  418. 418 : * @param {String} eci - The eci of SimplePayment.
  419. 419 : * @return {module:wrappers/SimplePayment} The instance of <code>SimplePayment</code>.
  420. 420 : */
  421. 421 : exports.prototype.withEci = function (eci) {
  422. 422 : var _this = this;
  423. 423 :
  424. 424 : _this['eci'] = eci;
  425. 425 :
  426. 426 :
  427. 427 : return _this;
  428. 428 : };
  429. 429 :
  430. 430 : exports.prototype.createdBy = function (requestor, requestor_type) {
  431. 431 : var _this = this;
  432. 432 : _this.requestedBy(requestor, requestor_type);
  433. 433 : return _this;
  434. 434 : };
  435. 435 :
  436. 436 : exports.prototype.create = function (invocation_context, callback, live_mode, api_end_point) {
  437. 437 : var _this = this;
  438. 438 : var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
  439. 439 : try {
  440. 440 : var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
  441. 441 : if (callback) {
  442. 442 : callback(response['exception'], response['data'])
  443. 443 : }
  444. 444 : } catch (e) {
  445. 445 : exception = OrbipayApiError.getDefaultException(e);
  446. 446 : if (callback) {
  447. 447 : callback(exception)
  448. 448 : }
  449. 449 : }
  450. 450 : };
  451. 451 : try {
  452. 452 : _this.withContext(invocation_context, live_mode, api_end_point);
  453. 453 : var handler = new SimplePaymentHandler();
  454. 454 : if (callback && CommonUtil.isFunction(callback)) {
  455. 455 : return handler.process(_this, internalCallback);
  456. 456 : } else {
  457. 457 : return handler.process(_this);
  458. 458 : }
  459. 459 : }
  460. 460 : catch (e){
  461. 461 : var error = OrbipayApiError.getDefaultException(e);
  462. 462 : if (callback) {
  463. 463 : callback(error)
  464. 464 : }
  465. 465 : }
  466. 466 : };
  467. 467 :
  468. 468 : return exports;
  469. 469 :
  470. 470 : }));