pixelpay_sdk 1.0.0.pre.beta.1

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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +40 -0
  3. data/CHANGELOG.md +10 -0
  4. data/CONTRIBUTING.md +11 -0
  5. data/Gemfile +16 -0
  6. data/Gemfile.lock +58 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +19 -0
  9. data/Rakefile +16 -0
  10. data/bitbucket-pipelines.yml +27 -0
  11. data/lib/pixelpay_sdk/assets/countries.json +247 -0
  12. data/lib/pixelpay_sdk/assets/formats.json +982 -0
  13. data/lib/pixelpay_sdk/assets/states.json +3944 -0
  14. data/lib/pixelpay_sdk/base/Helpers.rb +92 -0
  15. data/lib/pixelpay_sdk/base/RequestBehaviour.rb +31 -0
  16. data/lib/pixelpay_sdk/base/Response.rb +78 -0
  17. data/lib/pixelpay_sdk/base/ServiceBehaviour.rb +237 -0
  18. data/lib/pixelpay_sdk/entities/CardResult.rb +79 -0
  19. data/lib/pixelpay_sdk/entities/TransactionResult.rb +104 -0
  20. data/lib/pixelpay_sdk/exceptions/InvalidCredentialsException.rb +6 -0
  21. data/lib/pixelpay_sdk/exceptions/InvalidTransactionTypeException.rb +6 -0
  22. data/lib/pixelpay_sdk/models/Billing.rb +27 -0
  23. data/lib/pixelpay_sdk/models/Card.rb +36 -0
  24. data/lib/pixelpay_sdk/models/Item.rb +36 -0
  25. data/lib/pixelpay_sdk/models/Order.rb +93 -0
  26. data/lib/pixelpay_sdk/models/Settings.rb +93 -0
  27. data/lib/pixelpay_sdk/request/AuthTransaction.rb +7 -0
  28. data/lib/pixelpay_sdk/request/CaptureTransaction.rb +19 -0
  29. data/lib/pixelpay_sdk/request/CardTokenization.rb +97 -0
  30. data/lib/pixelpay_sdk/request/PaymentTransaction.rb +179 -0
  31. data/lib/pixelpay_sdk/request/SaleTransaction.rb +7 -0
  32. data/lib/pixelpay_sdk/request/StatusTransaction.rb +16 -0
  33. data/lib/pixelpay_sdk/request/VoidTransaction.rb +19 -0
  34. data/lib/pixelpay_sdk/resources/Environment.rb +9 -0
  35. data/lib/pixelpay_sdk/resources/Locations.rb +44 -0
  36. data/lib/pixelpay_sdk/responses/ErrorResponse.rb +8 -0
  37. data/lib/pixelpay_sdk/responses/FailureResponse.rb +8 -0
  38. data/lib/pixelpay_sdk/responses/InputErrorResponse.rb +8 -0
  39. data/lib/pixelpay_sdk/responses/NetworkFailureResponse.rb +8 -0
  40. data/lib/pixelpay_sdk/responses/NoAccessResponse.rb +8 -0
  41. data/lib/pixelpay_sdk/responses/NotFoundResponse.rb +8 -0
  42. data/lib/pixelpay_sdk/responses/PayloadResponse.rb +8 -0
  43. data/lib/pixelpay_sdk/responses/PaymentDeclinedResponse.rb +8 -0
  44. data/lib/pixelpay_sdk/responses/PreconditionalResponse.rb +8 -0
  45. data/lib/pixelpay_sdk/responses/SuccessResponse.rb +8 -0
  46. data/lib/pixelpay_sdk/responses/TimeoutResponse.rb +8 -0
  47. data/lib/pixelpay_sdk/services/Tokenization.rb +65 -0
  48. data/lib/pixelpay_sdk/services/Transaction.rb +108 -0
  49. data/lib/pixelpay_sdk/version.rb +5 -0
  50. data/lib/pixelpay_sdk.rb +20 -0
  51. data/pixelpay_sdk.gemspec +38 -0
  52. data/sig/pixelpay_sdk.rbs +4 -0
  53. metadata +97 -0
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+ require "json"
5
+ # Helpers
6
+ module Helpers
7
+ # Serialize object to JSON string without empties.
8
+ # Args:
9
+ # value (hash): hash to serialize.
10
+ # Returns
11
+ # string: JSON string.
12
+ def self.object_to_json(value)
13
+ verify_type(TypeError, Object, value.is_a?(Object))
14
+
15
+ hash = {}
16
+ value.instance_variables.each { |var| hash[var.to_s.delete("@")] = value.instance_variable_get(var) }
17
+
18
+ hash.each do |attr_name, attr_value|
19
+ if hash[attr_name].nil? || hash[attr_name].to_s.empty? || hash[attr_value].to_s == "[]" || hash[attr_value].to_s == "{}"
20
+ hash.delete(attr_name)
21
+ end
22
+ end
23
+
24
+ hash.to_json
25
+ rescue StandardError => e
26
+ warn("An exception occurred: #{e.message}")
27
+ end
28
+
29
+ # Hash of a given value using the specified algorithm.
30
+ # Args:
31
+ # algorithm (string): algorithm to use (e.g. "MD5", "SHA-1", "SHA-256").
32
+ # value (string): string to be hashed.
33
+ # Returns:
34
+ # hash of the value parameter using the specified algorithm.
35
+ def self.hash(algorithm, value)
36
+ case algorithm.to_s
37
+ when "MD5"
38
+ Digest::MD5.hexdigest(value.to_s)
39
+ when "SHA-1"
40
+ Digest::SHA1.hexdigest(value.to_s)
41
+ when "SHA-256"
42
+ Digest::SHA256.hexdigest(value.to_s)
43
+ else
44
+ ""
45
+ end
46
+ end
47
+
48
+ # Trim a string/null value.
49
+ # Args:
50
+ # value (string): input value.
51
+ # Returns:
52
+ # string: trimmed value or empty string.
53
+ def self.trim_value(value)
54
+ !value.to_s.empty? ? value.to_s.strip : ""
55
+ end
56
+
57
+ # Clean whitespaces from string.
58
+ # Args:
59
+ # value (string): input value.
60
+ # Returns:
61
+ # string: trimmed value or empty string.
62
+ def self.clean_string(value)
63
+ !value.to_s.empty? ? value.to_s.sub(" ", "") : ""
64
+ end
65
+
66
+ # Parse or nullify amount data.
67
+ # Args:
68
+ # amount (float): input amount.
69
+ # Returns:
70
+ # string: parsed amount or empty string.
71
+ def self.parse_amount(amount)
72
+ amount.to_s.to_f.positive? ? format("%0.2f", amount.to_s.to_f) : ""
73
+ end
74
+
75
+ # Verify type of data.
76
+ # Args:
77
+ # error_type: error type to raise.
78
+ # expected: data type expected.
79
+ # flag: condition.
80
+ # Returns:
81
+ # throw an error if the condition is met
82
+ def self.verify_type(error_type, expected, flag)
83
+ case error_type.to_s
84
+ when "TypeError"
85
+ raise TypeError, "This function only accepts parameters of type #{expected}." unless flag
86
+ when "InvalidCredentialsException"
87
+ raise InvalidCredentialsException, "This function only accepts parameters of type #{expected}." unless flag
88
+ when "InvalidTransactionTypeException"
89
+ raise InvalidTransactionTypeException, "This function only accepts parameters of type #{expected}." unless flag
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n"
4
+ require_relative "./Helpers"
5
+ require_relative "../version"
6
+
7
+ # RequestBehaviour defines the structure for the request behaviour.
8
+ class RequestBehaviour
9
+ attr_accessor :env, :lang, :from, :sdk_version
10
+
11
+ # Initialize request
12
+ def initialize
13
+ # Environment identifier (live|test|sandbox)
14
+ @env = nil
15
+ # Transaction response messages language
16
+ @lang = I18n.locale.to_s
17
+ # SDK identifier type
18
+ @from = "sdk-ruby"
19
+ # SDK version
20
+ @sdk_version = PixelpaySdk::VERSION
21
+
22
+ @lang = "es" if @lang != "es" && @lang != "en"
23
+ end
24
+
25
+ # Serialize object to JSON string.
26
+ # Returns:
27
+ # string: JSON string.
28
+ def object_to_json
29
+ Helpers.object_to_json(self)
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base/Helpers"
4
+
5
+ # Response provides a specific structure for a base response coming from a transaction.
6
+ class Response
7
+ attr_accessor :status, :action, :exception, :success, :message, :data, :errors
8
+
9
+ # Initialize base
10
+ def initialize
11
+ # HTTP response status code
12
+ @status = nil
13
+
14
+ # Response 'action to' format
15
+ @action = nil
16
+
17
+ # Exception response details
18
+ @exception = nil
19
+
20
+ # Response status success
21
+ @success = nil
22
+
23
+ # Response friendly message
24
+ @message = nil
25
+
26
+ # Response data payload
27
+ @data = nil
28
+
29
+ # Response input validation fields errors
30
+ @errors = nil
31
+ end
32
+
33
+ # Define HTTP status code response.
34
+ # Args:
35
+ # status(int): status code.
36
+ # Returns:
37
+ # Response: self.
38
+ def set_status(status)
39
+ @status = status.to_s.to_i
40
+ self
41
+ end
42
+
43
+ # Get HTTP status code.
44
+ # Returns:
45
+ # int: status code.
46
+ def get_status
47
+ status
48
+ end
49
+
50
+ # Verify input has error.
51
+ # Args:
52
+ # key (string): input key to check.
53
+ # Returns:
54
+ # boolean: input on key has errors or not.
55
+ def input_has_error(key)
56
+ return false if @errors.nil?
57
+
58
+ @errors.key?(key.to_s)
59
+ end
60
+
61
+ # Get data payload by key.
62
+ # Args:
63
+ # key (string): input key to check.
64
+ # Returns:
65
+ # Any: data or nil.
66
+ def get_data(key)
67
+ return nil if @data.nil? && @data.key?(key.to_s)
68
+
69
+ @data[key.to_s]
70
+ end
71
+
72
+ # Serialize object to JSON string.
73
+ # Returns:
74
+ # string: JSON string.
75
+ # def object_to_json
76
+ # Helpers.object_to_json(self)
77
+ # end
78
+ end
@@ -0,0 +1,237 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ require_relative "../base/Helpers"
8
+ require_relative "../exceptions/InvalidCredentialsException"
9
+ require_relative "../responses/ErrorResponse"
10
+ require_relative "../responses/FailureResponse"
11
+ require_relative "../responses/InputErrorResponse"
12
+ require_relative "../responses/NetworkFailureResponse"
13
+ require_relative "../responses/NoAccessResponse"
14
+ require_relative "../responses/NotFoundResponse"
15
+ require_relative "../responses/PayloadResponse"
16
+ require_relative "../responses/PaymentDeclinedResponse"
17
+ require_relative "../responses/PreconditionalResponse"
18
+ require_relative "../responses/SuccessResponse"
19
+ require_relative "../responses/TimeoutResponse"
20
+
21
+ # ServiceBehaviour defines the structure for the service behaviour.
22
+ class ServiceBehaviour
23
+ attr_accessor :settings
24
+
25
+ # Initialize service.
26
+ def initialize(settings)
27
+ Helpers.verify_type(TypeError, Settings, settings.instance_of?(Settings))
28
+
29
+ @settings = settings
30
+ rescue StandardError => e
31
+ warn("An exception occurred: #{e.message}")
32
+ end
33
+
34
+ # Mapping and cast HTTP response.
35
+ # Args:
36
+ # response: Response object from request.
37
+ # Returns:
38
+ # Response: parsed Reponse.
39
+ def parse_response(response)
40
+ status = response.code.to_i
41
+
42
+ bag = case status
43
+ when 200
44
+ SuccessResponse.new
45
+ when 202
46
+ PayloadResponse.new
47
+ when 400
48
+ ErrorResponse.new
49
+ when 401, 403
50
+ NoAccessResponse.new
51
+ when 402
52
+ PaymentDeclinedResponse.new
53
+ when 404, 405, 406
54
+ NotFoundResponse.new
55
+ when 408
56
+ TimeoutResponse.new
57
+ when 412, 418
58
+ PreconditionalResponse.new
59
+ when 422
60
+ InputErrorResponse.new
61
+ when 500
62
+ FailureResponse.new
63
+ else
64
+ NetworkFailureResponse.new if status > 500
65
+ end
66
+
67
+ data = JSON.parse(response.body)
68
+
69
+ bag.set_status(status)
70
+ bag.success = data.key?("success") ? data["success"] : false
71
+ bag.message = data.key?("message") ? data["message"] : nil
72
+ bag.data = data.key?("data") ? data["data"] : nil
73
+ bag.errors = data.key?("errors") ? data["errors"] : nil
74
+
75
+ bag
76
+ end
77
+
78
+ # Process the exception to Response object.
79
+ # Args:
80
+ # exception (InvalidCredentialsException): thrown exception.
81
+ # Returns:
82
+ # Response: processed response.
83
+ def exception_response(exception)
84
+ return exception if exception.instance_of?(InvalidCredentialsException)
85
+
86
+ response = FailureResponse.new
87
+ response.success = false
88
+ response.message = exception.to_s
89
+
90
+ response
91
+ end
92
+
93
+ # Build HTTP request to API.
94
+ # Args:
95
+ # uri (string): request url.
96
+ # method (string): HTTP method.
97
+ # transaction (RequestBehaviour): body object.
98
+ # Raises:
99
+ # InvalidCredentialsException: raised if no credentials found.
100
+ # Returns:
101
+ # req: prepared request.
102
+ def build_request(uri, method, transaction)
103
+ Helpers.verify_type(TypeError, RequestBehaviour, transaction.is_a?(RequestBehaviour))
104
+
105
+ if settings.auth_key.nil? || settings.auth_hash.nil?
106
+ raise InvalidCredentialsException, "The merchant credentials are not definied (key/hash)."
107
+ end
108
+
109
+ transaction.env = settings.environment if settings.environment
110
+
111
+ transaction.lang = settings.lang if settings.lang
112
+
113
+ body = transaction.object_to_json
114
+
115
+ request = case method.to_s.upcase
116
+ when "GET"
117
+ Net::HTTP::Get.new(uri)
118
+ when "POST"
119
+ Net::HTTP::Post.new(uri)
120
+ when "DELETE"
121
+ Net::HTTP::Delete.new(uri)
122
+ when "PUT"
123
+ Net::HTTP::Put.new(uri)
124
+ end
125
+
126
+ request.body = body
127
+
128
+ request["Accept"] = "application/json"
129
+ request["Content-Type"] = "application/json"
130
+ request["-Agent"] = "PixelPay HTTP/3 SDK Ruby"
131
+ request["x-auth-key"] = @settings.auth_key
132
+ request["x-auth-hash"] = @settings.auth_hash
133
+
134
+ request["x-auth-user"] = @settings.auth_user if @settings.auth_user != ""
135
+
136
+ request
137
+ rescue StandardError => e
138
+ exception_response(e)
139
+ end
140
+
141
+ # Get API route.
142
+ # Args:
143
+ # route(string): input route.
144
+ # Returns:
145
+ # (uri): Api route.
146
+ def get_route(route)
147
+ URI.parse("#{@settings.endpoint}/#{route}")
148
+ end
149
+
150
+ # API POST request.
151
+ # Args:
152
+ # url (string): input url.
153
+ # body (RequestBehaviour): input body object.
154
+ # Returns:
155
+ # response: parsed response.
156
+ def post(url, body)
157
+ unless body.is_a?(RequestBehaviour)
158
+ raise TypeError, "This function only accepts parameters of type RequestBehaviour."
159
+ end
160
+
161
+ uri = get_route(url)
162
+ req = build_request(uri, "POST", body)
163
+
164
+ raise InvalidCredentialsException, req.message if req.instance_of?(InvalidCredentialsException)
165
+
166
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
167
+ http.request(req)
168
+ end
169
+
170
+ parse_response(response)
171
+ rescue StandardError => e
172
+ exception_response(e)
173
+ end
174
+
175
+ # API PUT request.
176
+ # Args:
177
+ # url (string): input url.
178
+ # body (RequestBehaviour): input body object.
179
+ # Returns:
180
+ # response: parsed response.
181
+ def put(url, body)
182
+ Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
183
+
184
+ uri = get_route(url)
185
+ req = build_request(uri, "PUT", body)
186
+
187
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
188
+ http.request(req)
189
+ end
190
+
191
+ parse_response(response)
192
+ rescue StandardError => e
193
+ exception_response(e)
194
+ end
195
+
196
+ # API DELETE request.
197
+ # Args:
198
+ # url (string): input url.
199
+ # body (RequestBehaviour): input body object.
200
+ # Returns:
201
+ # response: parsed response.
202
+ def delete(url, body)
203
+ Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
204
+
205
+ uri = get_route(url)
206
+ req = build_request(uri, "DELETE", body)
207
+
208
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
209
+ http.request(req)
210
+ end
211
+
212
+ parse_response(response)
213
+ rescue StandardError => e
214
+ exception_response(e)
215
+ end
216
+
217
+ # API GET request.
218
+ # Args:
219
+ # url (string): input url.
220
+ # body (RequestBehaviour): input body object.
221
+ # Returns:
222
+ # response: parsed response.
223
+ def get(url, body)
224
+ Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
225
+
226
+ uri = get_route(url)
227
+ req = build_request(uri, "GET", body)
228
+
229
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
230
+ http.request(req)
231
+ end
232
+
233
+ parse_response(response)
234
+ rescue StandardError => e
235
+ exception_response(e)
236
+ end
237
+ end
@@ -0,0 +1,79 @@
1
+ require_relative "../base/Response"
2
+ require_relative "../responses/SuccessResponse"
3
+
4
+ # CardResult provides a specific structure for a response coming from a transaction with a tokenized card.
5
+ class CardResult
6
+ attr_accessor :status, :mask, :network, :type, :bin, :last, :hash, :address, :country, :state, :city,
7
+ :zip, :email, :phone
8
+
9
+ # Initialize entity.
10
+ def initialize
11
+ # Card status
12
+ @status = nil
13
+
14
+ # Card number masked
15
+ @mask = nil
16
+
17
+ # Card network brand
18
+ @network = nil
19
+
20
+ # Card type (debit/credit)
21
+ @type = nil
22
+
23
+ # Car bin number
24
+ @bin = nil
25
+
26
+ # Card last 4 numbers
27
+ @last = nil
28
+
29
+ # Card unique hash number
30
+ @hash = nil
31
+
32
+ # Billing address
33
+ @address = nil
34
+
35
+ # Billing country
36
+ @country = nil
37
+
38
+ # Billing state
39
+ @state = nil
40
+
41
+ # Billing city
42
+ @city = nil
43
+
44
+ # Billing postal code
45
+ @zip = nil
46
+
47
+ # Billing customer email
48
+ @email = nil
49
+
50
+ # Billing phone
51
+ @phone = nil
52
+ end
53
+
54
+ # Validate if response type is valid for parse.
55
+ # Args:
56
+ # response (Reponse): Response to validate.
57
+ # Returns:
58
+ # bool: is valid response.
59
+ def validate_response(response)
60
+ response.instance_of?(SuccessResponse)
61
+ end
62
+
63
+ # Convert success response to card entity.
64
+ # Args:
65
+ # response (Reponse): Input response.
66
+ # Returns:
67
+ # CardResult: mapped result.
68
+ def from_response(response)
69
+ entity = CardResult.new
70
+
71
+ entity.instance_variables.each do |var_name|
72
+ if response.data.key?(var_name.to_s.delete("@"))
73
+ entity.instance_variable_set(var_name, response.data[var_name.to_s.delete("@")])
74
+ end
75
+ end
76
+
77
+ entity
78
+ end
79
+ end
@@ -0,0 +1,104 @@
1
+ require "json"
2
+
3
+ require_relative "../base/Response"
4
+ require_relative "../responses/InputErrorResponse"
5
+ require_relative "../responses/PaymentDeclinedResponse"
6
+ require_relative "../responses/SuccessResponse"
7
+ require_relative "../responses/TimeoutResponse"
8
+
9
+ # TransactionResult provides a specific structure for a response coming from a transaction.
10
+ class TransactionResult
11
+ attr_accessor :transaction_type, :transaction_approved_amount, :transaction_amount, :transaction_auth,
12
+ :transaction_terminal, :transaction_merchant, :response_cvn, :response_avs, :response_cavv,
13
+ :transaction_id, :transaction_reference, :transaction_time, :transaction_date, :response_approved,
14
+ :response_incomplete, :response_code, :response_time, :response_reason, :payment_uuid, :payment_hash
15
+
16
+ # Initialize enitity.
17
+ def initialize
18
+ # Transaction response type
19
+ @transaction_type = nil
20
+
21
+ # Approved amount on capture/sale
22
+ @transaction_approved_amount = nil
23
+
24
+ # Initial or registered transaction amount
25
+ @transaction_amount = nil
26
+
27
+ # Transaction AUTH reference code
28
+ @transaction_auth = nil
29
+
30
+ # Transacction network terminal ID
31
+ @transaction_terminal = nil
32
+
33
+ # Transaction network merchant ID
34
+ @transaction_merchant = nil
35
+
36
+ # CVV2 result response code
37
+ @response_cvn = nil
38
+
39
+ # Address verification code response
40
+ @response_avs = nil
41
+
42
+ # CAVV network evaluation result code
43
+ @response_cavv = nil
44
+
45
+ # Transaction identifier
46
+ @transaction_id = nil
47
+
48
+ # Transaction STAN, proccesor transacction identifier or transaction reference
49
+ @transaction_reference = nil
50
+
51
+ # Transaction result time
52
+ @transaction_time = nil
53
+
54
+ # Transaction result date
55
+ @transaction_date = nil
56
+
57
+ # Response is financial approved
58
+ @response_approved = nil
59
+
60
+ # Response fatal not completed or excecution interrupted
61
+ @response_incomplete = nil
62
+
63
+ # Proccesor response code
64
+ @response_code = nil
65
+
66
+ # Network response time
67
+ @response_time = nil
68
+
69
+ # Proccesor response message
70
+ @response_reason = nil
71
+
72
+ # Payment unique identifier
73
+ @payment_uuid = nil
74
+
75
+ # Payment integrity validation hash
76
+ @payment_hash = nil
77
+ end
78
+
79
+ # Validate if response type is valid for parse.
80
+ # Args:
81
+ # response (Reponse): Response to validate.
82
+ # Returns:
83
+ # bool: is valid response.
84
+ def validate_response(response)
85
+ response.instance_of?(SuccessResponse) || response.instance_of?(PaymentDeclinedResponse) || response.instance_of?(InputErrorResponse) || response.instance_of?(TimeoutResponse)
86
+ end
87
+
88
+ # Convert success response to transaction entity.
89
+ # Args:
90
+ # response (Reponse): Input response.
91
+ # Returns:
92
+ # TransactionResult: mapped result.
93
+ def from_response(response)
94
+ entity = TransactionResult.new
95
+
96
+ entity.instance_variables.each do |var_name|
97
+ if response.data.key?(var_name.to_s.delete("@"))
98
+ entity.instance_variable_set(var_name, response.data[var_name.to_s.delete("@")])
99
+ end
100
+ end
101
+
102
+ entity
103
+ end
104
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # InvalidCredentialsException provides the possibility to create an exception of
4
+ # it's type
5
+ class InvalidCredentialsException < StandardError
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # InvalidTransactionTypeException provides the possibility to create an exception of
4
+ # it's type
5
+ class InvalidTransactionTypeException < StandardError
6
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Billing represents the billing information for a request.
4
+ class Billing
5
+ attr_accessor :address, :country, :state, :city, :zip, :phone
6
+
7
+ # Initialize model
8
+ def initialize
9
+ # Customer billing address
10
+ @address = nil
11
+
12
+ # Customer billing country alpha-2 code (ISO 3166-1)
13
+ @country = nil
14
+
15
+ # Customer billing state alpha code (ISO 3166-2)
16
+ @state = nil
17
+
18
+ # Customer billing city
19
+ @city = nil
20
+
21
+ # Customer billing postal code
22
+ @zip = nil
23
+
24
+ # Customer billing phone
25
+ @phone = nil
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base/Helpers"
4
+
5
+ # Card represents the card information for a request.
6
+ class Card
7
+ attr_accessor :number, :cvv2, :expire_month, :expire_year, :cardholder
8
+
9
+ # Initialize model
10
+ def initialize
11
+ # Card number or PAN
12
+ @number = nil
13
+
14
+ # Card security code
15
+ @cvv2 = nil
16
+
17
+ # Card expire month date (MM)
18
+ @expire_month = 00
19
+
20
+ # Card expire year date (YYYY)
21
+ @expire_year = 0000
22
+
23
+ # Cardholder name
24
+ @cardholder = nil
25
+ end
26
+
27
+ # Get expire ISO format (YYMM).
28
+ # Returns:
29
+ # string: formatted expire.
30
+ def get_expire_format
31
+ year = @expire_year != 0 ? @expire_year.to_s : " "
32
+ month = format("%02d", @expire_month)
33
+
34
+ Helpers.trim_value(year.slice(-2..) + month)
35
+ end
36
+ end