Class: SwipeHQ::Transaction
- Inherits:
-
Object
- Object
- SwipeHQ::Transaction
- Defined in:
- lib/swipehq/transaction.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#approved ⇒ Object
readonly
Returns the value of attribute approved.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#default_quantity ⇒ Object
Returns the value of attribute default_quantity.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#item ⇒ Object
Returns the value of attribute item.
-
#status ⇒ Object
Returns the value of attribute status.
-
#user_data ⇒ Object
Returns the value of attribute user_data.
Instance Method Summary collapse
- #attributes ⇒ Object
- #create ⇒ Object
-
#initialize(params = nil) ⇒ Transaction
constructor
A new instance of Transaction.
- #payment_url ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(params = nil) ⇒ Transaction
Returns a new instance of Transaction.
9 10 11 12 13 14 15 |
# File 'lib/swipehq/transaction.rb', line 9 def initialize(params = nil) if params params.each do |k,v| self.send("#{k}=",v) end end end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def amount @amount end |
#approved ⇒ Object (readonly)
Returns the value of attribute approved.
7 8 9 |
# File 'lib/swipehq/transaction.rb', line 7 def approved @approved end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def currency @currency end |
#default_quantity ⇒ Object
Returns the value of attribute default_quantity.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def default_quantity @default_quantity end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/swipehq/transaction.rb', line 7 def id @id end |
#identifier ⇒ Object
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def identifier @identifier end |
#item ⇒ Object
Returns the value of attribute item.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def item @item end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def status @status end |
#user_data ⇒ Object
Returns the value of attribute user_data.
4 5 6 |
# File 'lib/swipehq/transaction.rb', line 4 def user_data @user_data end |
Instance Method Details
#attributes ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/swipehq/transaction.rb', line 17 def attributes a = {} %w{ identifier id item description amount default_quantity user_data currency }.each do |att| a[att.to_sym] = self.send(att) end return a end |
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/swipehq/transaction.rb', line 25 def create params = { api_key: SwipeHQ.api_key, merchant_id: SwipeHQ.merchant_id } attributes.each do |k,v| params["td_#{k}".to_sym] = v end res = SwipeHQ.request( :get, 'https://api.swipehq.com/createTransactionIdentifier.php', params ) if res['response_code'] and res['response_code'] == 200 @identifier = res['data']['identifier'] else @identifier = nil end end |
#payment_url ⇒ Object
66 67 68 69 |
# File 'lib/swipehq/transaction.rb', line 66 def payment_url return nil unless @identifier "https://payment.swipehq.com/?identifier_id=#{@identifier}" end |
#verify ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/swipehq/transaction.rb', line 45 def verify return nil unless @identifier params = { api_key: SwipeHQ.api_key, merchant_id: SwipeHQ.merchant_id, transaction_id: @identifier } res = SwipeHQ.request( :get, 'https://api.swipehq.com/verifyTransaction.php', params ) if res['response_code'] and res['response_code'] == 200 @id = res['data']['transaction_id'] @status = res['data']['status'] || 'pending' @approved = res['data']['transaction_approved'] == 'yes' else @status = nil end end |