Class: Vpago::Payway::Base
- Inherits:
-
Object
- Object
- Vpago::Payway::Base
show all
- Defined in:
- lib/vpago/payway/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(payment, options = {}) ⇒ Base
Returns a new instance of Base.
4
5
6
7
|
# File 'lib/vpago/payway/base.rb', line 4
def initialize(payment, options = {})
@options = options
@payment = payment
end
|
Instance Method Details
#action_url ⇒ Object
107
108
109
|
# File 'lib/vpago/payway/base.rb', line 107
def action_url
"#{host}#{endpoint}"
end
|
#amount ⇒ Object
13
14
15
|
# File 'lib/vpago/payway/base.rb', line 13
def amount
format('%.2f', (@payment.amount + transaction_fee))
end
|
#api_key ⇒ Object
87
88
89
|
# File 'lib/vpago/payway/base.rb', line 87
def api_key
@payment.payment_method.preferences[:api_key]
end
|
#app_checkout ⇒ Object
56
57
58
|
# File 'lib/vpago/payway/base.rb', line 56
def app_checkout
app_checkout? ? 'yes' : 'no'
end
|
#app_checkout? ⇒ Boolean
60
61
62
63
64
|
# File 'lib/vpago/payway/base.rb', line 60
def app_checkout?
return false if @options[:app_checkout].blank?
@options[:app_checkout]
end
|
#continue_success_url ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/vpago/payway/base.rb', line 66
def continue_success_url
preferred_continue_url = @payment.payment_method.preferences[:continue_success_url]
return nil if preferred_continue_url.blank?
query_string = "tran_id=#{transaction_id}&app_checkout=#{app_checkout}"
preferred_continue_url.index('?').nil? ? "#{preferred_continue_url}?#{query_string}" : "#{preferred_continue_url}&#{query_string}"
end
|
#email ⇒ Object
37
38
39
|
# File 'lib/vpago/payway/base.rb', line 37
def email
@payment.order.email.presence || ENV.fetch('DEFAULT_EMAIL_FOR_PAYMENT', nil)
end
|
#endpoint ⇒ Object
103
104
105
|
# File 'lib/vpago/payway/base.rb', line 103
def endpoint
@payment.payment_method.preferences[:endpoint]
end
|
#first_name ⇒ Object
41
42
43
|
# File 'lib/vpago/payway/base.rb', line 41
def first_name
@payment.order.billing_address.first_name
end
|
#hash_hmac ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/vpago/payway/base.rb', line 95
def hash_hmac
data = "#{merchant_id}#{transaction_id}#{amount}"
hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), api_key, data))
hash.delete("\n")
end
|
#host ⇒ Object
9
10
11
|
# File 'lib/vpago/payway/base.rb', line 9
def host
@payment.payment_method.preferences[:host]
end
|
#last_name ⇒ Object
45
46
47
|
# File 'lib/vpago/payway/base.rb', line 45
def last_name
@payment.order.billing_address.last_name
end
|
#merchant_id ⇒ Object
29
30
31
|
# File 'lib/vpago/payway/base.rb', line 29
def merchant_id
@payment.payment_method.preferences[:merchant_id]
end
|
#payment_option ⇒ Object
74
75
76
77
|
# File 'lib/vpago/payway/base.rb', line 74
def payment_option
card_option = @payment.payment_method.preferences[:payment_option]
Vpago::Payway::CARD_TYPES.index(card_option).nil? ? Vpago::Payway::CARD_TYPE_ABAPAY : card_option
end
|
#phone ⇒ Object
83
84
85
|
# File 'lib/vpago/payway/base.rb', line 83
def phone
@payment.order.billing_address.phone
end
|
#phone_country_code ⇒ Object
79
80
81
|
# File 'lib/vpago/payway/base.rb', line 79
def phone_country_code
'+855'
end
|
#return_params ⇒ Object
91
92
93
|
# File 'lib/vpago/payway/base.rb', line 91
def return_params
{ tran_id: transaction_id }.to_json
end
|
#return_url ⇒ Object
49
50
51
52
53
54
|
# File 'lib/vpago/payway/base.rb', line 49
def return_url
preferred_return_url = @payment.payment_method.preferences[:return_url]
return nil if preferred_return_url.blank?
Base64.encode64(preferred_return_url)
end
|
#transaction_fee ⇒ Object
25
26
27
|
# File 'lib/vpago/payway/base.rb', line 25
def transaction_fee
transaction_fee_fix + ((@payment.amount * transaction_fee_percentage) / 100)
end
|
#transaction_fee_fix ⇒ Object
17
18
19
|
# File 'lib/vpago/payway/base.rb', line 17
def transaction_fee_fix
@payment.payment_method.preferences[:transaction_fee_fix].to_f
end
|
#transaction_fee_percentage ⇒ Object
21
22
23
|
# File 'lib/vpago/payway/base.rb', line 21
def transaction_fee_percentage
@payment.payment_method.preferences[:transaction_fee_percentage].to_f
end
|
#transaction_id ⇒ Object
33
34
35
|
# File 'lib/vpago/payway/base.rb', line 33
def transaction_id
@payment.number
end
|