Class: Liqpay::Response

Inherits:
SignedPayload show all
Defined in:
lib/liqpay/response.rb

Overview

Represents a response from the LiqPay API.

Constant Summary collapse

SUCCESS_STATUSES =
%w[success wait_secure sandbox].freeze
ATTRIBUTES =
%w[public_key order_id amount currency description type status transaction_id sender_phone].freeze

Instance Attribute Summary collapse

Attributes inherited from SignedPayload

#private_key, #public_key

Instance Method Summary collapse

Methods inherited from SignedPayload

#signature

Constructor Details

#initialize(params = {}, options = {}) ⇒ Response

Returns a new instance of Response.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/liqpay/response.rb', line 33

def initialize(params = {}, options = {})
  super(options)

  @data = params['data']
  parsed_data = JSON.parse(Base64.strict_decode64(data))

  ATTRIBUTES.each do |attribute|
    instance_variable_set "@#{attribute}", parsed_data[attribute]
  end
  @request_signature = params['signature']

  decode!
end

Instance Attribute Details

#amountObject (readonly)

Amount of payment. MUST match the requested amount



19
20
21
# File 'lib/liqpay/response.rb', line 19

def amount
  @amount
end

#currencyObject (readonly)

Currency of payment. MUST match the requested currency



21
22
23
# File 'lib/liqpay/response.rb', line 21

def currency
  @currency
end

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/liqpay/response.rb', line 16

def data
  @data
end

#sender_phoneObject (readonly)

Payer’s phone



31
32
33
# File 'lib/liqpay/response.rb', line 31

def sender_phone
  @sender_phone
end

#statusObject (readonly)

Status of payment. One of ‘

failure
success
wait_secure - success, but the card wasn't known to the system
sandbox


27
28
29
# File 'lib/liqpay/response.rb', line 27

def status
  @status
end

#transaction_idObject (readonly)

LiqPAY’s internal transaction ID



29
30
31
# File 'lib/liqpay/response.rb', line 29

def transaction_id
  @transaction_id
end

Instance Method Details

#success?Boolean

Returns true, if the transaction was successful

Returns:

  • (Boolean)


48
49
50
# File 'lib/liqpay/response.rb', line 48

def success?
  SUCCESS_STATUSES.include? status
end