class Bitkassa::PaymentResult

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

Attributes

raw_authentication[RW]

Contains the authentication_message as posted by Bitkass

raw_payload[RW]

Contains the payload exactly as posted by Bitkassa

Public Class Methods

from_form_urlencoded(body) click to toggle source

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

# 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
new(attributes) click to toggle source

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

# 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

Public Instance Methods

meta_info() click to toggle source

Gives the extracted meta_info.

# File lib/bitkassa/payment_result.rb, line 42
def meta_info
  payload["meta_info"]
end
payment_id() click to toggle source

Gives the extracted payment_id.

# File lib/bitkassa/payment_result.rb, line 30
def payment_id
  payload["payment_id"]
end
payment_status() click to toggle source

Gives the extracted payment_status.

# File lib/bitkassa/payment_result.rb, line 36
def payment_status
  payload["payment_status"]
end
valid?() click to toggle source

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.

# 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

Private Instance Methods

json_payload() click to toggle source
# File lib/bitkassa/payment_result.rb, line 66
def json_payload
  Base64.decode64(raw_payload)
end
json_valid?() click to toggle source
# File lib/bitkassa/payment_result.rb, line 70
def json_valid?
  begin
    payload
  rescue JSON::ParserError
    return false
  end
  true
end
payload() click to toggle source
# File lib/bitkassa/payment_result.rb, line 62
def payload
  @payload ||= JSON.parse(json_payload)
end