Class: Bitkassa::Request

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

Overview

Generic HTTP Request

Direct Known Subclasses

PaymentRequest, StatusRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Request

Initalize a request

  • attributes Hash



15
16
17
18
# File 'lib/bitkassa/request.rb', line 15

def initialize(attributes = {})
  @initialized_at = Time.now.to_i
  assign_attributes(attributes)
end

Instance Attribute Details

#authenticator=(value) ⇒ Object

Overrides the default Bitkassa::Authentication to sign the authentication



11
12
13
# File 'lib/bitkassa/request.rb', line 11

def authenticator=(value)
  @authenticator = value
end

#responder=(value) ⇒ Object

Override the class that is initialized to capture the perform response. Defaults to Bitkassa::PaymentResponse.



7
8
9
# File 'lib/bitkassa/request.rb', line 7

def responder=(value)
  @responder = value
end

Instance Method Details

#attributesObject

Defines the attributes to be serialised in the payload merchant_id and action will be merged by default.



41
42
43
# File 'lib/bitkassa/request.rb', line 41

def attributes
  {}
end

#can_perform?Boolean

Returns:

  • (Boolean)


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

def can_perform?
  return false if Bitkassa.config.merchant_id.nil?
  return false if Bitkassa.config.merchant_id.empty?
  return false if Bitkassa.config.secret_api_key.nil?
  return false if Bitkassa.config.secret_api_key.empty?
  true
end

#payload_actionObject

Defines the action to insert into the payload.



47
48
49
# File 'lib/bitkassa/request.rb', line 47

def payload_action
  ""
end

#performObject

Make the request.

returns Bitkassa::PaymentResponse Regardless of the response, this this PaymentResponse is initialized.

When a payment cannot be made because of incorrect or missing data, a Bitkassa::Exception is raised.



28
29
30
31
32
33
34
35
36
# File 'lib/bitkassa/request.rb', line 28

def perform
  if can_perform?
    response = HTTPI.post(uri, params_string)
    responder.from_json(response.body)
  else
    fail Bitkassa::Exception,
         "Your merchant_id or merchant_key are not set"
  end
end