Class: Upay::Transaction

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Transaction

Returns a new instance of Transaction.



3
4
5
6
7
# File 'lib/upay/transaction.rb', line 3

def initialize(args = {})
  args.each do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

Instance Method Details

#capture_and_authorizeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/upay/transaction.rb', line 39

def capture_and_authorize
  payload = {}
  payload["transaction"] = self.to_hash
  response = Payment.new.submit_transaction(payload)["response"] || {code: "ERROR", error: "something went terribly wrong"}

  if response["code"] == "SUCCESS"
    transaction_response_hash = response["transactionResponse"] || {}
    transaction_response = TransactionResponse.new(transaction_response_hash)
  else
    raise response.to_json.inspect
  end
  transaction_response
end


33
# File 'lib/upay/transaction.rb', line 33

def cookie; @cookie end

#cookie=(cookie = nil) ⇒ Object



34
# File 'lib/upay/transaction.rb', line 34

def cookie=(cookie = nil) @cookie = cookie end

#creditCardTokenIdObject



15
# File 'lib/upay/transaction.rb', line 15

def creditCardTokenId; @creditCardTokenId end

#creditCardTokenId=(creditCardTokenId = nil) ⇒ Object



16
# File 'lib/upay/transaction.rb', line 16

def creditCardTokenId=(creditCardTokenId = nil); @creditCardTokenId = creditCardTokenId; end

#deviceSessionIdObject



27
# File 'lib/upay/transaction.rb', line 27

def deviceSessionId; @deviceSessionId end

#deviceSessionId=(deviceSessionId = nil) ⇒ Object



28
# File 'lib/upay/transaction.rb', line 28

def deviceSessionId=(deviceSessionId = nil); @deviceSessionId = deviceSessionId; end

#ipAddressObject



30
# File 'lib/upay/transaction.rb', line 30

def ipAddress; @ipAddress; end

#ipAddress=(ipAddress = nil) ⇒ Object



31
# File 'lib/upay/transaction.rb', line 31

def ipAddress=(ipAddress = nil) @ipAddress = ipAddress end

#orderObject



9
# File 'lib/upay/transaction.rb', line 9

def order; @order end

#order=(order = nil) ⇒ Object



10
# File 'lib/upay/transaction.rb', line 10

def order=(order = nil); @order = order; end

#payerObject



12
# File 'lib/upay/transaction.rb', line 12

def payer; @payer end

#payer=(payer = nil) ⇒ Object



13
# File 'lib/upay/transaction.rb', line 13

def payer=(payer = nil); @payer = payer; end

#paymentCountryObject



24
# File 'lib/upay/transaction.rb', line 24

def paymentCountry; @paymentCountry end

#paymentCountry=(paymentCountry = nil) ⇒ Object



25
# File 'lib/upay/transaction.rb', line 25

def paymentCountry=(paymentCountry = nil); @paymentCountry = paymentCountry; end

#paymentMethodObject



21
# File 'lib/upay/transaction.rb', line 21

def paymentMethod; @paymentMethod end

#paymentMethod=(paymentMethod = nil) ⇒ Object



22
# File 'lib/upay/transaction.rb', line 22

def paymentMethod=(paymentMethod = nil); @paymentMethod = paymentMethod; end

#to_hashObject



58
59
60
61
62
63
# File 'lib/upay/transaction.rb', line 58

def to_hash
  transaction_hash = self.instance_variables.each_with_object({}) { |var,hash| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var)}
  transaction_hash[:order] = self.order.to_hash if self.order
  transaction_hash[:payer] = self.payer.to_hash if self.payer
  transaction_hash
end

#typeObject



18
# File 'lib/upay/transaction.rb', line 18

def type; @type end

#type=(type = nil) ⇒ Object



19
# File 'lib/upay/transaction.rb', line 19

def type=(type = nil); @type = type; end

#userAgentObject



36
# File 'lib/upay/transaction.rb', line 36

def userAgent; @userAgent end

#userAgent=(userAgent = nil) ⇒ Object



37
# File 'lib/upay/transaction.rb', line 37

def userAgent=(userAgent = nil) @userAgent = userAgent; end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/upay/transaction.rb', line 53

def valid?
  validator = TransactionValidator.new
  validator.valid?(self)
end