Class: Vpago::Payway::TransactionStatus

Inherits:
Base
  • Object
show all
Defined in:
lib/vpago/payway/transaction_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#action_url, #amount, #api_key, #app_checkout, #app_checkout?, #continue_success_url, #email, #endpoint, #first_name, #hash_hmac, #host, #initialize, #last_name, #merchant_id, #payment_option, #phone, #phone_country_code, #return_params, #return_url, #transaction_fee, #transaction_fee_fix, #transaction_fee_percentage, #transaction_id

Constructor Details

This class inherits a constructor from Vpago::Payway::Base

Instance Attribute Details

#error_messageObject

Returns the value of attribute error_message.



6
7
8
# File 'lib/vpago/payway/transaction_status.rb', line 6

def error_message
  @error_message
end

#resultObject

Returns the value of attribute result.



6
7
8
# File 'lib/vpago/payway/transaction_status.rb', line 6

def result
  @result
end

Instance Method Details

#callObject



8
9
10
11
# File 'lib/vpago/payway/transaction_status.rb', line 8

def call
  prepare
  process
end

#check_remote_statusObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vpago/payway/transaction_status.rb', line 26

def check_remote_status
  conn = Faraday::Connection.new do |faraday|
    faraday.request :url_encoded
  end

  data = {
    tran_id: transaction_id,
    hash: checker_hmac
  }

  conn.post(check_transaction_url, data)
end

#check_transaction_urlObject



65
66
67
68
69
70
71
# File 'lib/vpago/payway/transaction_status.rb', line 65

def check_transaction_url
  if endpoint[-1] == '/'
    "#{host}#{endpoint}check/transaction/"
  else
    "#{host}#{endpoint}/check/transaction/"
  end
end

#checker_hmacObject



18
19
20
21
22
23
24
# File 'lib/vpago/payway/transaction_status.rb', line 18

def checker_hmac
  data = "#{merchant_id}#{transaction_id}"
  hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), api_key, data))

  # somehow php counter part are not able to decode if the \n present.
  hash.delete("\n")
end

#fail!(message) ⇒ Object



57
58
59
# File 'lib/vpago/payway/transaction_status.rb', line 57

def fail!(message)
  @error_message = message
end

#json_responseObject



53
54
55
# File 'lib/vpago/payway/transaction_status.rb', line 53

def json_response
  @json_response ||= JSON.parse(@response.body)
end

#prepareObject



13
14
15
16
# File 'lib/vpago/payway/transaction_status.rb', line 13

def prepare
  @error_message = nil
  @result = nil
end

#processObject



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

def process
  @response = check_remote_status

  if @response.status == 200
    if json_response['status'].zero?
      @result = json_response
    else
      fail!(json_response['description'])
    end
  else
    fail!(@response.body)
  end
end

#success?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/vpago/payway/transaction_status.rb', line 61

def success?
  @error_message.nil?
end