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