Class: BankAudi::Request
- Inherits:
-
Object
- Object
- BankAudi::Request
- Defined in:
- lib/bank_audi.rb
Instance Attribute Summary collapse
-
#access_code ⇒ Object
readonly
Returns the value of attribute access_code.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#merchant ⇒ Object
(also: #merchant_id)
readonly
Returns the value of attribute merchant.
-
#merchant_txn_ref ⇒ Object
Returns the value of attribute merchant_txn_ref.
-
#order_info ⇒ Object
Returns the value of attribute order_info.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#secret_code ⇒ Object
readonly
Returns the value of attribute secret_code.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(value = {}) ⇒ Object
- #full_url ⇒ Object
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
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( = {}) @secret_code, @access_code, @merchant, @url = OPTIONS['secret_code'], OPTIONS['access_code'], OPTIONS['merchant'], OPTIONS['url'] @merchant_txn_ref, @order_info, @amount, @return_url = [:merchant_txn_ref], [:order_info], [:amount], [:return_url] end |
Instance Attribute Details
#access_code ⇒ Object (readonly)
Returns the value of attribute access_code.
10 11 12 |
# File 'lib/bank_audi.rb', line 10 def access_code @access_code end |
#amount ⇒ Object
Returns the value of attribute amount.
11 12 13 |
# File 'lib/bank_audi.rb', line 11 def amount @amount end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/bank_audi.rb', line 10 def errors @errors end |
#merchant ⇒ Object (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_ref ⇒ Object
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_info ⇒ Object
Returns the value of attribute order_info.
11 12 13 |
# File 'lib/bank_audi.rb', line 11 def order_info @order_info end |
#return_url ⇒ Object
Returns the value of attribute return_url.
11 12 13 |
# File 'lib/bank_audi.rb', line 11 def return_url @return_url end |
#secret_code ⇒ Object (readonly)
Returns the value of attribute secret_code.
10 11 12 |
# File 'lib/bank_audi.rb', line 10 def secret_code @secret_code end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/bank_audi.rb', line 10 def url @url end |
Instance Method Details
#attributes ⇒ Object
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_url ⇒ Object
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
31 32 33 |
# File 'lib/bank_audi.rb', line 31 def invalid? !valid? end |
#valid? ⇒ 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 |