Class: Bitkassa::PaymentResult
- Inherits:
-
Object
- Object
- Bitkassa::PaymentResult
- 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
-
#raw_authentication ⇒ Object
Contains the authentication_message as posted by Bitkass.
-
#raw_payload ⇒ Object
Contains the payload exactly as posted by Bitkassa.
Class Method Summary collapse
-
.from_form_urlencoded(body) ⇒ Object
Initialize a
PaymentResult
from a www-url-encoded body.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ PaymentResult
constructor
Attributes:
raw_payload
the original, unencoded string containing the payload. -
#meta_info ⇒ Object
Gives the extracted meta_info.
-
#payment_id ⇒ Object
Gives the extracted payment_id.
-
#payment_status ⇒ Object
Gives the extracted payment_status.
-
#valid? ⇒ Boolean
Wether or not this payment result can be considered valid.
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_authentication ⇒ Object
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_payload ⇒ Object
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_info ⇒ Object
Gives the extracted meta_info.
42 43 44 |
# File 'lib/bitkassa/payment_result.rb', line 42 def payload["meta_info"] end |
#payment_id ⇒ Object
Gives the extracted payment_id.
30 31 32 |
# File 'lib/bitkassa/payment_result.rb', line 30 def payment_id payload["payment_id"] end |
#payment_status ⇒ Object
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.
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 |