Class: BankAudi::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



14
15
16
17
18
19
# File 'lib/bank_audi.rb', line 14

def initialize(options = {})
  @secret_code, @access_code, @merchant, @url =
    OPTIONS['secret_code'], OPTIONS['access_code'], OPTIONS['merchant'], OPTIONS['url']
  @merchant_txn_ref, @order_info, @amount, @return_url =
    options[:merchant_txn_ref], options[:order_info], options[:amount], options[:return_url]
end

Instance Attribute Details

#access_codeObject (readonly)

Returns the value of attribute access_code.



10
11
12
# File 'lib/bank_audi.rb', line 10

def access_code
  @access_code
end

#amountObject

Returns the value of attribute amount.



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

def amount
  @amount
end

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/bank_audi.rb', line 10

def errors
  @errors
end

#merchantObject (readonly) Also known as: merchant_id

Returns the value of attribute merchant.



10
11
12
# File 'lib/bank_audi.rb', line 10

def merchant
  @merchant
end

#merchant_txn_refObject

Returns the value of attribute merchant_txn_ref.



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

def merchant_txn_ref
  @merchant_txn_ref
end

#order_infoObject

Returns the value of attribute order_info.



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

def order_info
  @order_info
end

#return_urlObject

Returns the value of attribute return_url.



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

def return_url
  @return_url
end

#secret_codeObject (readonly)

Returns the value of attribute secret_code.



10
11
12
# File 'lib/bank_audi.rb', line 10

def secret_code
  @secret_code
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/bank_audi.rb', line 10

def url
  @url
end

Instance Method Details

#attributesObject



47
48
49
50
51
52
53
# File 'lib/bank_audi.rb', line 47

def attributes
  value = {}
  attributes_names.each do |attribute|
    value[attribute.to_sym] = self.send(attribute)
  end
  value
end

#attributes=(value = {}) ⇒ Object



55
56
57
58
59
# File 'lib/bank_audi.rb', line 55

def attributes=(value = {})
  value.each do |name, attr_value|
    self.send("#{name}=", attr_value)
  end
end

#full_urlObject



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

def full_url
  return nil if invalid?
  params = String.new
  { 'accessCode' => @access_code, 'merchTxnRef' => @merchant_txn_ref, 'merchant' => @merchant,
    'orderInfo' => @order_info, 'amount' => @amount, 'returnURL' => @return_url }.each do |name, value|
      params << '&' if params.present?
      params << (CGI::escape(name) + '=' + CGI::escape(value.to_s))
    end
  params << '&vpc_SecureHash=' + vpc_secure_hash.to_s
  @url + '?' + params
end

#invalid?Boolean

Returns:

  • (Boolean)


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

def invalid?
  !valid?
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/bank_audi.rb', line 21

def valid?
  @errors = {}
  attributes_names.each do |attribute|
    if self.send(attribute).blank?
      @errors[attribute] = "can't be blank"
      return false
    end
  end
end