Class: Bitkassa::PaymentResult

Inherits:
Object
  • Object
show all
Defined in:
lib/bitkassa/payment_result.rb

Overview

A PaymentResult represents the result which is posted to return_url. This callback contains the status of the payment.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ PaymentResult

Attributes: raw_payload the original, unencoded string containing the payload. raw_authentication the original string containing the signed message.



21
22
23
24
25
26
# File 'lib/bitkassa/payment_result.rb', line 21

def initialize(attributes)
  attributes.each do |key, value|
    setter_method = "#{key}=".to_sym
    send(setter_method, value)
  end
end

Instance Attribute Details

#raw_authenticationObject

Contains the authentication_message as posted by Bitkass



8
9
10
# File 'lib/bitkassa/payment_result.rb', line 8

def raw_authentication
  @raw_authentication
end

#raw_payloadObject

Contains the payload exactly as posted by Bitkassa



6
7
8
# File 'lib/bitkassa/payment_result.rb', line 6

def raw_payload
  @raw_payload
end

Class Method Details

.from_form_urlencoded(body) ⇒ Object

Initialize a PaymentResult from a www-url-encoded body.



12
13
14
15
# File 'lib/bitkassa/payment_result.rb', line 12

def self.from_form_urlencoded(body)
  params = Hash[URI.decode_www_form(body)]
  new(raw_payload: params["p"], raw_authentication: params["a"])
end

Instance Method Details

#meta_infoObject

Gives the extracted meta_info.



42
43
44
# File 'lib/bitkassa/payment_result.rb', line 42

def meta_info
  payload["meta_info"]
end

#payment_idObject

Gives the extracted payment_id.



30
31
32
# File 'lib/bitkassa/payment_result.rb', line 30

def payment_id
  payload["payment_id"]
end

#payment_statusObject

Gives the extracted payment_status.



36
37
38
# File 'lib/bitkassa/payment_result.rb', line 36

def payment_status
  payload["payment_status"]
end

#valid?Boolean

Wether or not this payment result can be considered valid. Authentication is checked, payload and authentication should be available and the decoded JSON should be valid JSON. When the result is valid, it is safe to assume no-one tampered with it and that it was sent by Bitkassa.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/bitkassa/payment_result.rb', line 52

def valid?
  return false if raw_payload.nil? || raw_payload.empty?
  return false if raw_authentication.nil? || raw_authentication.empty?
  return false unless json_valid?

  Authentication.valid?(raw_authentication, json_payload)
end