Class: Rma::Payment::Gateway::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/rma/payment/gateway/authorization.rb

Overview

Authorization class for RMA Payment Gateway. Handles authentication and authorization for the RMA Payment Gateway client.

Examples:

auth = Rma::Payment::Gateway::Authorization.new(client)
auth.authorize

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Authorization

Returns a new instance of Authorization.



20
21
22
# File 'lib/rma/payment/gateway/authorization.rb', line 20

def initialize(client)
  @client = client
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



18
19
20
# File 'lib/rma/payment/gateway/authorization.rb', line 18

def amount
  @amount
end

#clientObject (readonly)

Returns the value of attribute client.



18
19
20
# File 'lib/rma/payment/gateway/authorization.rb', line 18

def client
  @client
end

#emailObject (readonly)

Returns the value of attribute email.



18
19
20
# File 'lib/rma/payment/gateway/authorization.rb', line 18

def email
  @email
end

#order_noObject (readonly)

Returns the value of attribute order_no.



18
19
20
# File 'lib/rma/payment/gateway/authorization.rb', line 18

def order_no
  @order_no
end

Instance Method Details

#call(order_no, amount, email) ⇒ Object

Fetch authorization token Returns the authorization response



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rma/payment/gateway/authorization.rb', line 26

def call(order_no, amount, email)
  @order_no = order_no
  @amount = amount
  @email = email
  validate_authorization_request!
  response = client.post(body: authorization_request_body)

  validate_authorization_response!(response)

  response["result"]
rescue StandardError => e
  raise AuthenticationError, "Failed to authorize: #{e.message}"
end