Class: CloudPayments::Client
- Inherits:
-
Object
- Object
- CloudPayments::Client
- Includes:
- Namespaces
- Defined in:
- lib/cloud_payments/client.rb,
lib/cloud_payments/client/errors.rb,
lib/cloud_payments/client/response.rb,
lib/cloud_payments/client/serializer.rb,
lib/cloud_payments/client/gateway_errors.rb,
lib/cloud_payments/client/serializer/base.rb,
lib/cloud_payments/client/serializer/multi_json.rb
Defined Under Namespace
Modules: Errors, GatewayErrors, Serializer Classes: Error, GatewayError, ReasonedGatewayError, Response, ServerError
Constant Summary collapse
- HTTP_STATUSES =
{ 300 => 'MultipleChoices', 301 => 'MovedPermanently', 302 => 'Found', 303 => 'SeeOther', 304 => 'NotModified', 305 => 'UseProxy', 307 => 'TemporaryRedirect', 308 => 'PermanentRedirect', 400 => 'BadRequest', 401 => 'Unauthorized', 402 => 'PaymentRequired', 403 => 'Forbidden', 404 => 'NotFound', 405 => 'MethodNotAllowed', 406 => 'NotAcceptable', 407 => 'ProxyAuthenticationRequired', 408 => 'RequestTimeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'LengthRequired', 412 => 'PreconditionFailed', 413 => 'RequestEntityTooLarge', 414 => 'RequestURITooLong', 415 => 'UnsupportedMediaType', 416 => 'RequestedRangeNotSatisfiable', 417 => 'ExpectationFailed', 418 => 'ImATeapot', 421 => 'TooManyConnectionsFromThisIP', 426 => 'UpgradeRequired', 450 => 'BlockedByWindowsParentalControls', 494 => 'RequestHeaderTooLarge', 497 => 'HTTPToHTTPS', 499 => 'ClientClosedRequest', 500 => 'InternalServerError', 501 => 'NotImplemented', 502 => 'BadGateway', 503 => 'ServiceUnavailable', 504 => 'GatewayTimeout', 505 => 'HTTPVersionNotSupported', 506 => 'VariantAlsoNegotiates', 510 => 'NotExtended' }
- ERRORS =
HTTP_STATUSES.inject({}) do |result, error| status, name = error result[status] = Errors.const_set(name, Class.new(ServerError)) result end
- REASON_CODES =
{ 5001 => 'ReferToCardIssuer', 5005 => 'DoNotHonor', 5006 => 'Error', 5012 => 'Invalid', 5013 => 'AmountError', 5030 => 'FormatError', 5031 => 'BankNotSupportedBySwitch', 5034 => 'SuspectedFraud', 5041 => 'LostCard', 5043 => 'StolenCard', 5051 => 'InsufficientFunds', 5054 => 'ExpiredCard', 5057 => 'TransactionNotPermitted', 5065 => 'ExceedWithdrawalFrequency', 5082 => 'IncorrectCVV', 5091 => 'Timeout', 5092 => 'CannotReachNetwork', 5096 => 'SystemError', 5204 => 'UnableToProcess', 5206 => 'AuthenticationFailed', 5207 => 'AuthenticationUnavailable', 5300 => 'AntiFraud' }
- GATEWAY_ERRORS =
REASON_CODES.inject({}) do |result, error| status, name = error result[status] = GatewayErrors.const_set(name, Class.new(ReasonedGatewayError)) result end
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ Client
constructor
A new instance of Client.
- #perform_request(path, params = nil) ⇒ Object
Methods included from Namespaces
#apple_pay, #kassa, #orders, #payments, #ping, #subscriptions
Constructor Details
#initialize(config = nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/cloud_payments/client.rb', line 13 def initialize(config = nil) @config = config || CloudPayments.config @connection = build_connection end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/cloud_payments/client.rb', line 11 def config @config end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/cloud_payments/client.rb', line 11 def connection @connection end |
Instance Method Details
#perform_request(path, params = nil) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cloud_payments/client.rb', line 18 def perform_request(path, params = nil) response = connection.post(path, (params ? convert_to_json(params) : nil), headers) Response.new(response.status, response.body, response.headers).tap do |response| raise_transport_error(response) if response.status.to_i >= 300 end end |