payrix 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/lib/payrix.rb +19 -0
  3. data/lib/payrix/configuration.rb +33 -0
  4. data/lib/payrix/exceptions.rb +10 -0
  5. data/lib/payrix/exceptions/api_error.rb +6 -0
  6. data/lib/payrix/exceptions/base.rb +6 -0
  7. data/lib/payrix/exceptions/connection.rb +6 -0
  8. data/lib/payrix/exceptions/invalid_request.rb +6 -0
  9. data/lib/payrix/exceptions/invalid_response.rb +6 -0
  10. data/lib/payrix/http.rb +7 -0
  11. data/lib/payrix/http/request.rb +48 -0
  12. data/lib/payrix/http/request_params.rb +67 -0
  13. data/lib/payrix/http/response.rb +45 -0
  14. data/lib/payrix/resource.rb +106 -0
  15. data/lib/payrix/resource/account_verifications.rb +21 -0
  16. data/lib/payrix/resource/accounts.rb +20 -0
  17. data/lib/payrix/resource/adjustments.rb +22 -0
  18. data/lib/payrix/resource/aggregation_result_groups.rb +21 -0
  19. data/lib/payrix/resource/aggregation_results.rb +21 -0
  20. data/lib/payrix/resource/aggregations.rb +22 -0
  21. data/lib/payrix/resource/alert_actions.rb +19 -0
  22. data/lib/payrix/resource/alert_triggers.rb +19 -0
  23. data/lib/payrix/resource/alerts.rb +19 -0
  24. data/lib/payrix/resource/apikeys.rb +19 -0
  25. data/lib/payrix/resource/assessments.rb +24 -0
  26. data/lib/payrix/resource/auth_tokens.rb +19 -0
  27. data/lib/payrix/resource/base.rb +220 -0
  28. data/lib/payrix/resource/batches.rb +20 -0
  29. data/lib/payrix/resource/billing_events.rb +19 -0
  30. data/lib/payrix/resource/billing_modifiers.rb +19 -0
  31. data/lib/payrix/resource/billings.rb +21 -0
  32. data/lib/payrix/resource/chargeback_documents.rb +19 -0
  33. data/lib/payrix/resource/chargeback_message_results.rb +21 -0
  34. data/lib/payrix/resource/chargeback_messages.rb +22 -0
  35. data/lib/payrix/resource/chargeback_statuses.rb +21 -0
  36. data/lib/payrix/resource/chargebacks.rb +24 -0
  37. data/lib/payrix/resource/confirm_codes.rb +19 -0
  38. data/lib/payrix/resource/contacts.rb +21 -0
  39. data/lib/payrix/resource/credentials.rb +20 -0
  40. data/lib/payrix/resource/customers.rb +24 -0
  41. data/lib/payrix/resource/decision_actions.rb +20 -0
  42. data/lib/payrix/resource/decision_rules.rb +19 -0
  43. data/lib/payrix/resource/decisions.rb +23 -0
  44. data/lib/payrix/resource/disbursement_entries.rb +22 -0
  45. data/lib/payrix/resource/disbursement_results.rb +22 -0
  46. data/lib/payrix/resource/disbursements.rb +25 -0
  47. data/lib/payrix/resource/divisions.rb +19 -0
  48. data/lib/payrix/resource/entities.rb +25 -0
  49. data/lib/payrix/resource/entity_datas.rb +20 -0
  50. data/lib/payrix/resource/entity_debts.rb +21 -0
  51. data/lib/payrix/resource/entity_reserves.rb +20 -0
  52. data/lib/payrix/resource/entity_returns.rb +22 -0
  53. data/lib/payrix/resource/entries.rb +25 -0
  54. data/lib/payrix/resource/entry_origins.rb +21 -0
  55. data/lib/payrix/resource/fee_modifiers.rb +19 -0
  56. data/lib/payrix/resource/fee_rules.rb +19 -0
  57. data/lib/payrix/resource/fees.rb +22 -0
  58. data/lib/payrix/resource/fund_origins.rb +21 -0
  59. data/lib/payrix/resource/funds.rb +22 -0
  60. data/lib/payrix/resource/holds.rb +21 -0
  61. data/lib/payrix/resource/invoice_items.rb +19 -0
  62. data/lib/payrix/resource/invoice_line_items.rb +19 -0
  63. data/lib/payrix/resource/invoice_parameters.rb +19 -0
  64. data/lib/payrix/resource/invoice_results.rb +23 -0
  65. data/lib/payrix/resource/invoices.rb +21 -0
  66. data/lib/payrix/resource/iplists.rb +19 -0
  67. data/lib/payrix/resource/items.rb +20 -0
  68. data/lib/payrix/resource/logins.rb +23 -0
  69. data/lib/payrix/resource/mappings.rb +19 -0
  70. data/lib/payrix/resource/members.rb +22 -0
  71. data/lib/payrix/resource/merchant_results.rb +21 -0
  72. data/lib/payrix/resource/merchants.rb +21 -0
  73. data/lib/payrix/resource/message_threads.rb +21 -0
  74. data/lib/payrix/resource/messages.rb +20 -0
  75. data/lib/payrix/resource/mixin.rb +9 -0
  76. data/lib/payrix/resource/mixin/create_disabled.rb +11 -0
  77. data/lib/payrix/resource/mixin/delete_disabled.rb +11 -0
  78. data/lib/payrix/resource/mixin/update_disabled.rb +11 -0
  79. data/lib/payrix/resource/note_documents.rb +19 -0
  80. data/lib/payrix/resource/notes.rb +19 -0
  81. data/lib/payrix/resource/org_entities.rb +18 -0
  82. data/lib/payrix/resource/org_flow_actions.rb +18 -0
  83. data/lib/payrix/resource/org_flows.rb +18 -0
  84. data/lib/payrix/resource/orgs.rb +18 -0
  85. data/lib/payrix/resource/payment_update_groups.rb +21 -0
  86. data/lib/payrix/resource/payment_updates.rb +22 -0
  87. data/lib/payrix/resource/payout_flows.rb +20 -0
  88. data/lib/payrix/resource/payouts.rb +21 -0
  89. data/lib/payrix/resource/pending_entries.rb +25 -0
  90. data/lib/payrix/resource/plans.rb +20 -0
  91. data/lib/payrix/resource/profit_share_results.rb +21 -0
  92. data/lib/payrix/resource/profit_share_rules.rb +19 -0
  93. data/lib/payrix/resource/profit_shares.rb +20 -0
  94. data/lib/payrix/resource/refunds.rb +20 -0
  95. data/lib/payrix/resource/report_items.rb +19 -0
  96. data/lib/payrix/resource/report_results.rb +21 -0
  97. data/lib/payrix/resource/reports.rb +19 -0
  98. data/lib/payrix/resource/reserve_entries.rb +23 -0
  99. data/lib/payrix/resource/reserves.rb +21 -0
  100. data/lib/payrix/resource/secrets.rb +20 -0
  101. data/lib/payrix/resource/sessions.rb +20 -0
  102. data/lib/payrix/resource/statement_entries.rb +23 -0
  103. data/lib/payrix/resource/statements.rb +22 -0
  104. data/lib/payrix/resource/subscription_tokens.rb +18 -0
  105. data/lib/payrix/resource/subscriptions.rb +21 -0
  106. data/lib/payrix/resource/team_logins.rb +19 -0
  107. data/lib/payrix/resource/teams.rb +19 -0
  108. data/lib/payrix/resource/terminal_txn_datas.rb +20 -0
  109. data/lib/payrix/resource/terminal_txn_results.rb +22 -0
  110. data/lib/payrix/resource/terminal_txns.rb +29 -0
  111. data/lib/payrix/resource/terminals.rb +21 -0
  112. data/lib/payrix/resource/tokens.rb +20 -0
  113. data/lib/payrix/resource/txn_datas.rb +20 -0
  114. data/lib/payrix/resource/txn_metadatas.rb +21 -0
  115. data/lib/payrix/resource/txn_results.rb +22 -0
  116. data/lib/payrix/resource/txns.rb +34 -0
  117. data/lib/payrix/resource/vendors.rb +19 -0
  118. data/lib/payrix/version.rb +3 -0
  119. metadata +215 -0
@@ -0,0 +1,21 @@
1
+ module Payrix
2
+ module Resource
3
+ class AggregationResultGroups < Base
4
+
5
+ include Mixin::UpdateDisabled
6
+ include Mixin::CreateDisabled
7
+ def initialize(params)
8
+ super(params, ATTRS)
9
+
10
+ @resource_name = 'aggregationResultGroups'
11
+ end
12
+
13
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
14
+ :aggregation, :resource, :search, :totals, :lastModified,
15
+ :effective, :default, :type, :level, :degrouping]
16
+
17
+ attr_accessor *ATTRS
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Payrix
2
+ module Resource
3
+ class AggregationResults < Base
4
+
5
+ include Mixin::UpdateDisabled
6
+ include Mixin::CreateDisabled
7
+ def initialize(params)
8
+ super(params, ATTRS)
9
+
10
+ @resource_name = 'aggregationResults'
11
+ end
12
+
13
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
14
+ :aggregationResultGroup, :field, :count, :sum, :min,
15
+ :max, :grouping]
16
+
17
+ attr_accessor *ATTRS
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Payrix
2
+ module Resource
3
+ class Aggregations < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'aggregations'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :login, :name, :description, :resource, :search,
13
+ :totals, :status, :schedule, :scheduleFactor, :start,
14
+ :inactive, :frozen, :entity, :forlogin, :org,
15
+ :team, :division, :partition, :type, :level,
16
+ :default, :degrouping]
17
+
18
+ attr_accessor *ATTRS
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class AlertActions < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'alertActions'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :type, :options, :value, :alert, :retries,
13
+ :headerName, :headerValue]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class AlertTriggers < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'alertTriggers'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :alert, :event, :resource, :name, :description,
13
+ :inactive, :frozen]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class Alerts < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'alerts'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :login, :forlogin, :team, :name, :description,
13
+ :inactive, :frozen, :division]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class Apikeys < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'apikeys'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :login, :key, :name, :description, :public,
13
+ :inactive, :frozen, :token, :effectiveRoles]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Payrix
2
+ module Resource
3
+ class Assessments < Base
4
+
5
+ include Mixin::UpdateDisabled
6
+ include Mixin::DeleteDisabled
7
+ include Mixin::CreateDisabled
8
+ def initialize(params)
9
+ super(params, ATTRS)
10
+
11
+ @resource_name = 'assessments'
12
+ end
13
+
14
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
15
+ :entity, :onentity, :forentity, :partition, :opposingAssessment,
16
+ :fee, :disbursement, :txn, :chargeback, :merchant,
17
+ :event, :eventId, :description, :amount, :platform,
18
+ :currency]
19
+
20
+ attr_accessor *ATTRS
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class AuthTokens < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'authTokens'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :login, :token, :customer, :used, :inactive,
13
+ :frozen]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,220 @@
1
+ module Payrix
2
+ module Resource
3
+ class Base
4
+ attr_reader :resource_name
5
+
6
+ def initialize(params, attrs)
7
+ @attrs = attrs
8
+ @request_options = Payrix::Http::RequestParams.new
9
+
10
+ set(params)
11
+ end
12
+
13
+ def request_options
14
+ @request_options
15
+ end
16
+
17
+ def request_options=(params = {})
18
+ @request_options.sort = params['sort'] unless params['sort'].nil?
19
+ @request_options.expand = params['expand'] unless params['expand'].nil?
20
+ @request_options.totals = params['totals'] unless params['totals'].nil?
21
+ @request_options.page = params['page'] unless params['page'].nil?
22
+ end
23
+
24
+ def set(params)
25
+ if params.is_a?(Hash) && !params.empty?
26
+ params.each do |k, v|
27
+ if @attrs.include? k
28
+ public_send("#{k}=", v) if respond_to? "#{k}="
29
+ else
30
+ self.class.send(:attr_accessor, k)
31
+ self.instance_variable_set("@#{k}", v);
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def to_json(nested = false)
38
+ excludes = ['request_options', 'resource_name', 'response', 'attrs']
39
+
40
+ instance_variables.inject({}) do |hash, var|
41
+ key = var.to_s.delete('@')
42
+ val = instance_variable_get(var)
43
+
44
+ if !excludes.include? key
45
+ if val.is_a? Base
46
+ hash[key] = val.to_json(true) if nested
47
+ else
48
+ hash[key] = val
49
+ end
50
+ end
51
+
52
+ hash
53
+ end
54
+ end
55
+
56
+ def status
57
+ @response.nil? ? false : @response.status
58
+ end
59
+
60
+ def has_errors?
61
+ @response.nil? ? false : @response.has_errors?
62
+ end
63
+
64
+ def response
65
+ @response.nil? ? [] : @response.response
66
+ end
67
+
68
+ def details
69
+ @response.nil? ? [] : @response.details
70
+ end
71
+
72
+ def totals
73
+ @response.nil? ? [] : @response.totals
74
+ end
75
+
76
+ def has_more?
77
+ @response.nil? ? true : @response.has_more?
78
+ end
79
+
80
+ def retrieve(params = {})
81
+ set(params)
82
+
83
+ headers = build_headers
84
+
85
+ search = build_search(to_json)
86
+ search += "&#{request_options.sort}" if request_options
87
+ headers['SEARCH'] = search
88
+
89
+ headers['Content-Type'] = "application/json"
90
+ query_params = []
91
+ if request_options
92
+ query_params << request_options.expand if request_options.expand
93
+ query_params << request_options.page if request_options.page
94
+ if request_options.totals
95
+ headers['TOTALS'] = request_options.totals
96
+ end
97
+ end
98
+
99
+ method = 'get'
100
+ url = Payrix.configuration.url
101
+ endpoint = "#{@resource_name}?#{query_params.join('&')}"
102
+ data = {}
103
+
104
+ body, status = Payrix::Http::Request.instance.send_http(method, url, endpoint, data, headers)
105
+ @response = Payrix::Http::Response.new(body, status, self.class)
106
+
107
+ success = validate_response
108
+ request_options.go_next_page if success
109
+
110
+ success
111
+ end
112
+
113
+ def create(params = {})
114
+ set(params)
115
+
116
+ headers = build_headers
117
+ headers['Content-Type'] = "application/json"
118
+ method = 'post'
119
+ url = Payrix.configuration.url
120
+ endpoint = "#{@resource_name}"
121
+ data = to_json
122
+
123
+ body, status = Payrix::Http::Request.instance.send_http(method, url, endpoint, data, headers)
124
+ @response = Payrix::Http::Response.new(body, status, self.class)
125
+
126
+ validate_response
127
+ end
128
+
129
+ def update(params = {})
130
+ set(params)
131
+
132
+ if !id
133
+ if Payrix.configuration.exception_enabled
134
+ raise Payrix::Exceptions::InvalidRequest.new('ID is required for this action')
135
+ else
136
+ return false
137
+ end
138
+ end
139
+
140
+ headers = build_headers
141
+ headers['Content-Type'] = "application/json"
142
+ method = 'put'
143
+ url = Payrix.configuration.url
144
+ endpoint = "#{@resource_name}/#{id}"
145
+ data = to_json
146
+
147
+ body, status = Payrix::Http::Request.instance.send_http(method, url, endpoint, data, headers)
148
+ @response = Payrix::Http::Response.new(body, status, self.class)
149
+
150
+ validate_response
151
+ end
152
+
153
+ def delete(params = {})
154
+ set(params)
155
+
156
+ if !id
157
+ if Payrix.configuration.exception_enabled
158
+ raise Payrix::Exceptions::InvalidRequest.new('ID is required for this delete')
159
+ else
160
+ return false
161
+ end
162
+ end
163
+
164
+ headers = build_headers
165
+ headers['Content-Type'] = "application/json"
166
+ method = 'delete'
167
+ url = Payrix.configuration.url
168
+ endpoint = "#{@resource_name}/#{id}"
169
+ data = {}
170
+
171
+ body, status = Payrix::Http::Request.instance.send_http(method, url, endpoint, data, headers)
172
+ @response = Payrix::Http::Response.new(body, status, self.class)
173
+
174
+ validate_response
175
+ end
176
+
177
+ protected
178
+ def build_headers()
179
+ config = Payrix.configuration
180
+
181
+ if !config.url
182
+ raise Payrix::Exceptions::InvalidRequest.new('Invalid URL')
183
+ end
184
+
185
+ headers = {}
186
+
187
+ if config.api_key
188
+ headers['APIKEY'] = config.api_key
189
+ elsif config.session_key
190
+ headers['SESSIONKEY'] = config.session_key
191
+ end
192
+
193
+ headers
194
+ end
195
+
196
+ def build_search(values = {})
197
+ values
198
+ .delete_if { |k, v| v.nil? || v.empty? }
199
+ .map { |k, v| "#{k}[equals]=#{v}" }
200
+ .join('&')
201
+ end
202
+
203
+ def validate_response
204
+ if @response.has_errors?
205
+ if Payrix.configuration.exception_enabled
206
+ raise Payrix::Exceptions::ApiError.new('There are errors in the response')
207
+ end
208
+
209
+ false
210
+ else
211
+ true
212
+ end
213
+ end
214
+
215
+ def errors
216
+ @response.nil? ? [] : @response.errors
217
+ end
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,20 @@
1
+ module Payrix
2
+ module Resource
3
+ class Batches < Base
4
+
5
+ include Mixin::DeleteDisabled
6
+ def initialize(params)
7
+ super(params, ATTRS)
8
+
9
+ @resource_name = 'batches'
10
+ end
11
+
12
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
13
+ :merchant, :date, :status, :clientRef, :inactive,
14
+ :frozen, :processingDate, :processingId]
15
+
16
+ attr_accessor *ATTRS
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Payrix
2
+ module Resource
3
+ class BillingEvents < Base
4
+
5
+ def initialize(params)
6
+ super(params, ATTRS)
7
+
8
+ @resource_name = 'billingEvents'
9
+ end
10
+
11
+ ATTRS = [:id, :created, :modified, :creator, :modifier,
12
+ :billing, :event, :eventSchedule, :deductFromBalance, :inactive,
13
+ :frozen]
14
+
15
+ attr_accessor *ATTRS
16
+
17
+ end
18
+ end
19
+ end