Class: Vpago::PaywayV2::Base
- Inherits:
-
Object
- Object
- Vpago::PaywayV2::Base
show all
- Defined in:
- lib/vpago/payway_v2/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_v2/base.rb', line 4
def initialize(payment, options = {})
@options = options
@payment = payment
end
|
Instance Method Details
#amount ⇒ Object
25
26
27
|
# File 'lib/vpago/payway_v2/base.rb', line 25
def amount
format('%.2f', (@payment.amount + transaction_fee))
end
|
#api_key ⇒ Object
88
89
90
|
# File 'lib/vpago/payway_v2/base.rb', line 88
def api_key
@payment.payment_method.preferences[:api_key]
end
|
#continue_success_url ⇒ Object
69
70
71
|
# File 'lib/vpago/payway_v2/base.rb', line 69
def continue_success_url
@payment.processing_url
end
|
#email ⇒ Object
50
51
52
|
# File 'lib/vpago/payway_v2/base.rb', line 50
def email
@payment.order.email.presence || ENV.fetch('DEFAULT_EMAIL_FOR_PAYMENT', nil)
end
|
#first_name ⇒ Object
54
55
56
|
# File 'lib/vpago/payway_v2/base.rb', line 54
def first_name
@payment.order.billing_address&.first_name&.strip
end
|
#hash_data ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/vpago/payway_v2/base.rb', line 134
def hash_data
result = "#{req_time}#{merchant_id}#{transaction_id}#{amount}#{first_name}#{last_name}"
result += email if email.present?
result += phone if phone.present?
result += type if type.present?
result += payment_option if payment_option.present?
result += return_url if return_url.present?
result += continue_success_url if continue_success_url.present?
result += return_deeplink if return_deeplink.present?
result += return_params if return_params.present?
result += payout if payout.present?
log_hash_data = "Hash data: #{result}"
Rails.logger.info(log_hash_data)
result
end
|
#hash_hmac ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/vpago/payway_v2/base.rb', line 125
def hash_hmac
hash = Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), api_key, hash_data))
log_hash_data = "Hash hmac: #{hash}"
Rails.logger.info(log_hash_data)
hash
end
|
#host ⇒ Object
17
18
19
|
# File 'lib/vpago/payway_v2/base.rb', line 17
def host
@payment.payment_method.preferences[:host]
end
|
#last_name ⇒ Object
58
59
60
|
# File 'lib/vpago/payway_v2/base.rb', line 58
def last_name
@payment.order.billing_address&.last_name&.strip
end
|
#merchant_id ⇒ Object
41
42
43
|
# File 'lib/vpago/payway_v2/base.rb', line 41
def merchant_id
@payment.payment_method.preferences[:merchant_id]
end
|
#order_jwt_token ⇒ Object
153
154
155
156
|
# File 'lib/vpago/payway_v2/base.rb', line 153
def order_jwt_token
payload = { order_number: @payment.order.number, order_id: @payment.order.id }
JWT.encode(payload, @payment.order.token, 'HS256')
end
|
#payment_option ⇒ Object
78
79
80
81
|
# File 'lib/vpago/payway_v2/base.rb', line 78
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
|
#payout ⇒ Object
98
99
100
101
102
103
|
# File 'lib/vpago/payway_v2/base.rb', line 98
def payout
@payout ||= begin
payouts = Vpago::PaywayV2::PayoutsParamsConstructor.new(@payment).call
payouts.empty? ? nil : Base64.strict_encode64(payouts.to_json)
end
end
|
#phone ⇒ Object
84
85
86
|
# File 'lib/vpago/payway_v2/base.rb', line 84
def phone
@payment.order.billing_address&.phone
end
|
#public_key ⇒ Object
21
22
23
|
# File 'lib/vpago/payway_v2/base.rb', line 21
def public_key
@payment.payment_method.preferences[:public_key]
end
|
#req_time ⇒ Object
9
10
11
|
# File 'lib/vpago/payway_v2/base.rb', line 9
def req_time
@payment.created_at.strftime('%Y%m%d%H%M%S')
end
|
#return_deeplink ⇒ Object
119
120
121
122
123
|
# File 'lib/vpago/payway_v2/base.rb', line 119
def return_deeplink
return nil unless return_deeplink_url.present?
Base64.strict_encode64({ android_scheme: return_deeplink_url, ios_scheme: return_deeplink_url }.to_json)
end
|
#return_deeplink_url ⇒ Object
redirect to continue URL, let it handle redirecting to app. allowed override to specific app eg. from tg://t.me
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/vpago/payway_v2/base.rb', line 107
def return_deeplink_url
app_scheme = @payment.payment_method.preferences[:app_scheme]
if app_scheme.present?
uri = URI.parse(continue_success_url)
uri.scheme = app_scheme
uri.to_s
else
continue_success_url
end
end
|
#return_params ⇒ Object
92
93
94
95
96
|
# File 'lib/vpago/payway_v2/base.rb', line 92
def return_params
uri = URI.parse(@payment.process_payment_url)
query_params = Rack::Utils.parse_nested_query(uri.query)
query_params.to_json
end
|
#return_url ⇒ Object
62
63
64
65
66
67
|
# File 'lib/vpago/payway_v2/base.rb', line 62
def return_url
uri = URI.parse(@payment.process_payment_url)
uri.query = nil
Base64.encode64(uri.to_s).delete("\n")
end
|
#transaction_fee ⇒ Object
37
38
39
|
# File 'lib/vpago/payway_v2/base.rb', line 37
def transaction_fee
transaction_fee_fix + ((@payment.amount * transaction_fee_percentage) / 100)
end
|
#transaction_fee_fix ⇒ Object
29
30
31
|
# File 'lib/vpago/payway_v2/base.rb', line 29
def transaction_fee_fix
@payment.payment_method.preferences[:transaction_fee_fix].to_f
end
|
#transaction_fee_percentage ⇒ Object
33
34
35
|
# File 'lib/vpago/payway_v2/base.rb', line 33
def transaction_fee_percentage
@payment.payment_method.preferences[:transaction_fee_percentage].to_f
end
|
#transaction_id ⇒ Object
45
46
47
|
# File 'lib/vpago/payway_v2/base.rb', line 45
def transaction_id
@payment.number
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/vpago/payway_v2/base.rb', line 13
def type
@payment.payment_method.enable_pre_auth ? 'pre-auth' : 'purchase'
end
|
#view_type ⇒ Object
null, hosted_view, checkout, qr
74
75
76
|
# File 'lib/vpago/payway_v2/base.rb', line 74
def view_type
'hosted_view'
end
|