Class: Vpago::Vattanac::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vpago/vattanac/base.rb

Direct Known Subclasses

Checkout, TransactionStatus

Constant Summary collapse

CONTENT_TYPE_JSON =
'application/json'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(payment) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/vpago/vattanac/base.rb', line 8

def initialize(payment)
  @payment = payment
end

Instance Method Details

#access_tokenObject



32
33
34
# File 'lib/vpago/vattanac/base.rb', line 32

def access_token
  @access_token ||= fetch_access_token
end

#access_token_urlObject



20
21
22
# File 'lib/vpago/vattanac/base.rb', line 20

def access_token_url
  payment_method.preferred_access_token_url
end

#amountObject



52
53
54
# File 'lib/vpago/vattanac/base.rb', line 52

def amount
  @payment.amount
end

#check_transaction_urlObject



28
29
30
# File 'lib/vpago/vattanac/base.rb', line 28

def check_transaction_url
  payment_method.preferred_check_transaction_url
end

#currencyObject



56
57
58
# File 'lib/vpago/vattanac/base.rb', line 56

def currency
  'USD'
end

#default_headersObject



60
61
62
# File 'lib/vpago/vattanac/base.rb', line 60

def default_headers
  { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => CONTENT_TYPE_JSON }
end

#generate_payment_urlObject



24
25
26
# File 'lib/vpago/vattanac/base.rb', line 24

def generate_payment_url
  payment_method.preferred_generate_payment_url
end

#merchant_idObject



48
49
50
# File 'lib/vpago/vattanac/base.rb', line 48

def merchant_id
  payment_method.preferred_merchant_id
end

#parse_json(body) ⇒ Object



64
65
66
67
68
# File 'lib/vpago/vattanac/base.rb', line 64

def parse_json(body)
  JSON.parse(body)
rescue JSON::ParserError
  {}
end

#passwordObject



16
17
18
# File 'lib/vpago/vattanac/base.rb', line 16

def password
  payment_method.preferred_password
end

#payment_methodObject



36
37
38
# File 'lib/vpago/vattanac/base.rb', line 36

def payment_method
  @payment.payment_method
end

#payment_numberObject



40
41
42
# File 'lib/vpago/vattanac/base.rb', line 40

def payment_number
  @payment.number
end

#payment_typeObject



44
45
46
# File 'lib/vpago/vattanac/base.rb', line 44

def payment_type
  payment_method.preferred_payment_type
end

#usernameObject



12
13
14
# File 'lib/vpago/vattanac/base.rb', line 12

def username
  payment_method.preferred_username
end