1. 1 :
  2. 2 : (function(root, factory) {
  3. 3 :
  4. 4 : if (typeof module === 'object' && module.exports) {
  5. 5 : // CommonJS-like environments that support module.exports, like Node.
  6. 6 : module.exports = factory(require('logtown').getLogger('orbipay-paymentsapi-client/src/wrappers/Base'), require('./InvocationContext'), require('../CommonUtil'));
  7. 7 : }
  8. 8 : }(this, function(logger, InvocationContext, CommonUtil) {
  9. 9 : 'use strict';
  10. 10 :
  11. 11 : var exports = function() {
  12. 12 : };
  13. 13 :
  14. 14 : exports.constructFromObject = function (data, obj) {
  15. 15 : if (data) {
  16. 16 : obj = obj || new exports();
  17. 17 : if (data.hasOwnProperty('invocation_context')) {
  18. 18 : obj['invocation_context'] = InvocationContext.constructFromObject(data['invocation_context']);
  19. 19 : }
  20. 20 : if (data.hasOwnProperty('api_end_point')) {
  21. 21 : obj['api_end_point'] = data['api_end_point'];
  22. 22 : }
  23. 23 : }
  24. 24 : return obj;
  25. 25 : };
  26. 26 :
  27. 27 : /**
  28. 28 : * @member {String} invocation_context
  29. 29 : */
  30. 30 : exports.prototype['invocation_context'] = undefined;
  31. 31 : /**
  32. 32 : * @member {String} api_end_point
  33. 33 : */
  34. 34 : exports.prototype['api_end_point'] = undefined;
  35. 35 : /**
  36. 36 : * @member {String} http_status_code
  37. 37 : */
  38. 38 : exports.prototype['http_status_code'] = undefined;
  39. 39 :
  40. 40 : /**
  41. 41 : * @private
  42. 42 : * @param {String} requestor
  43. 43 : * @param {String} requestor_type
  44. 44 : * @return module:model/customer/Customer
  45. 45 : */
  46. 46 : exports.prototype.requestedBy = function (requestor, requestor_type) {
  47. 47 : var _this = this;
  48. 48 : if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
  49. 49 : _this['invocation_context'] = new InvocationContext();
  50. 50 :
  51. 51 : }
  52. 52 : _this['invocation_context']['requestor'] = requestor;
  53. 53 : _this['invocation_context']['requestor_type'] = requestor_type;
  54. 54 : };
  55. 55 :
  56. 56 :
  57. 57 : /**
  58. 58 : * @param {String} channel
  59. 59 : * @return module:model/customer/Customer
  60. 60 : */
  61. 61 : exports.prototype.videChannel = function (channel) {
  62. 62 : var _this = this;
  63. 63 : if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
  64. 64 : _this['invocation_context'] = new InvocationContext();
  65. 65 :
  66. 66 : }
  67. 67 : _this['invocation_context']['channel'] = channel;
  68. 68 : };
  69. 69 :
  70. 70 : /**
  71. 71 : * @param {String} client_key
  72. 72 : * @return module:model/customer/Customer
  73. 73 : */
  74. 74 : exports.prototype.forClient = function (client_key) {
  75. 75 : var _this = this;
  76. 76 : if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
  77. 77 : _this['invocation_context'] = new InvocationContext();
  78. 78 : }
  79. 79 : _this['invocation_context']['client_key'] = client_key;
  80. 80 : };
  81. 81 :
  82. 82 : /**
  83. 83 : * @private
  84. 84 : * @param {String} live_mode.
  85. 85 : * @param {String} api_end_point. For example http://localhost:8080/payments/v1
  86. 86 : */
  87. 87 : exports.prototype.setAPIEndPoint = function (live_mode, api_end_point) {
  88. 88 : var _this = this;
  89. 89 : if (live_mode === 'true') {
  90. 90 : _this['api_end_point'] = 'https://api.orbipay.com/payments/v1';
  91. 91 : }
  92. 92 : else if (live_mode === 'false' && !api_end_point) {
  93. 93 : _this['api_end_point'] = 'https://sbapi.orbipay.com/payments/v1';
  94. 94 : }
  95. 95 : else if(live_mode === 'false' && api_end_point){
  96. 96 : _this['api_end_point'] = api_end_point;
  97. 97 : }
  98. 98 : else{
  99. 99 : logger.error('Invalid value for live_mode, value Received in request :'+ live_mode +', valid values for live_mode: true, false');
  100. 100 : throw new Error('Invalid value for live_mode, value Received in request :'+ live_mode +', valid values for live_mode: true, false');
  101. 101 : }
  102. 102 : };
  103. 103 :
  104. 104 : /**
  105. 105 : * @private
  106. 106 : * @param {module:model/base/InvocationContext} invocation_context
  107. 107 : * @param {String} live_mode.
  108. 108 : * @param {String} api_end_point. For example http://localhost:8080/payments/v1
  109. 109 : * @return module:model/customer/Customer
  110. 110 : */
  111. 111 : exports.prototype.withContext = function (invocation_context, live_mode, api_end_point) {
  112. 112 : var _this = this;
  113. 113 : _this.setAPIEndPoint(live_mode, api_end_point);
  114. 114 : if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
  115. 115 : _this['invocation_context'] = new InvocationContext();
  116. 116 : }
  117. 117 :
  118. 118 : if (invocation_context) {
  119. 119 : logger.info('idempotent_request_key :', invocation_context['idempotent_request_key']);
  120. 120 : _this['invocation_context']['X-OPAY-Headers'] = invocation_context['X-OPAY-Headers'];
  121. 121 : _this['invocation_context']['idempotent_request_key'] = invocation_context['idempotent_request_key'];
  122. 122 : _this['invocation_context']['product'] = invocation_context['product'];
  123. 123 : _this['invocation_context']['api_key'] = invocation_context['api_key'];
  124. 124 : _this['invocation_context']['auth_scheme'] = invocation_context['auth_scheme'];
  125. 125 : if(invocation_context['secret']){
  126. 126 : _this['invocation_context']['secret'] = invocation_context['secret'];
  127. 127 : }
  128. 128 : else{
  129. 129 : throw new Error('Invalid value for secret');
  130. 130 : }
  131. 131 : }
  132. 132 : };
  133. 133 :
  134. 134 : return exports;
  135. 135 :
  136. 136 : }));