Class: Vpago::AcledaV2::Base
- Inherits:
-
Object
- Object
- Vpago::AcledaV2::Base
show all
- Defined in:
- lib/vpago/acleda_v2/base.rb
Constant Summary
collapse
- CONTENT_TYPE_JSON =
'application/json'.freeze
- PURCHASE_DESC =
ACLEDA requires purchaseDesc to be <= 16 chars, English only.
'Purchase goods'.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(payment, options = {}) ⇒ Base
Returns a new instance of Base.
8
9
10
11
|
# File 'lib/vpago/acleda_v2/base.rb', line 8
def initialize(payment, options = {})
@options = options
@payment = payment
end
|
Instance Method Details
#action_url ⇒ Object
KHQR/Card secure web redirect target
80
81
82
|
# File 'lib/vpago/acleda_v2/base.rb', line 80
def action_url
strip_whitespace(payment_method.preferences[:payment_page_url])
end
|
#amount ⇒ Object
21
22
23
|
# File 'lib/vpago/acleda_v2/base.rb', line 21
def amount
format('%.2f', @payment.amount)
end
|
#app_scheme ⇒ Object
98
99
100
|
# File 'lib/vpago/acleda_v2/base.rb', line 98
def app_scheme
payment_method.preferences[:app_scheme]
end
|
#callback_url ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/vpago/acleda_v2/base.rb', line 90
def callback_url
return continue_success_url unless app_scheme.present? && platform == 'app'
uri = URI.parse(continue_success_url)
uri.scheme = app_scheme
uri.to_s
end
|
#continue_success_url ⇒ Object
successUrlToReturn / errorUrl. The bank appends its own query string
(_paymenttokenid, _resultCode, ...) when it redirects back.
86
87
88
|
# File 'lib/vpago/acleda_v2/base.rb', line 86
def continue_success_url
@payment.processing_url
end
|
#deeplink? ⇒ Boolean
111
112
113
|
# File 'lib/vpago/acleda_v2/base.rb', line 111
def deeplink?
payment_method.deeplink? && platform == 'app'
end
|
#expiry_time ⇒ Object
Dynamically mirrors the shopper's remaining seat/inventory hold time so the bank's
QR/session doesn't outlive the hold. Falls back to the admin-configured preference
when the order has no hold (e.g. non-inventory items) or the hold has already lapsed.
55
56
57
|
# File 'lib/vpago/acleda_v2/base.rb', line 55
def expiry_time
@expiry_time ||= (remaining_hold_minutes || payment_method.preferences[:payment_expiry_time_in_mn]).to_s
end
|
#get_txn_status_url ⇒ Object
rubocop:disable Naming/AccessorMethodName
75
76
77
|
# File 'lib/vpago/acleda_v2/base.rb', line 75
def get_txn_status_url "#{xpay_service_base_url}/getTxnStatus"
end
|
#hmac512(message) ⇒ Object
126
127
128
|
# File 'lib/vpago/acleda_v2/base.rb', line 126
def hmac512(message)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), secret, message).upcase
end
|
#login_id ⇒ Object
40
41
42
|
# File 'lib/vpago/acleda_v2/base.rb', line 40
def login_id
payment_method.preferences[:login_id]
end
|
#merchant_id ⇒ Object
36
37
38
|
# File 'lib/vpago/acleda_v2/base.rb', line 36
def merchant_id
payment_method.preferences[:merchant_id]
end
|
#merchant_name ⇒ Object
32
33
34
|
# File 'lib/vpago/acleda_v2/base.rb', line 32
def merchant_name
payment_method.preferences[:merchant_name]
end
|
#open_session_hash ⇒ Object
--- HMAC-SHA512 (uppercase hex) signing ---
openSessionV2 message: merchantID + loginId + password + txid
117
118
119
|
# File 'lib/vpago/acleda_v2/base.rb', line 117
def open_session_hash
hmac512("#{merchant_id}#{login_id}#{password}#{payment_number}")
end
|
#open_session_url ⇒ Object
71
72
73
|
# File 'lib/vpago/acleda_v2/base.rb', line 71
def open_session_url
"#{xpay_service_base_url}/openSessionV2"
end
|
#opr_device ⇒ Object
android | ios (defaults to android when not supplied by the caller)
103
104
105
|
# File 'lib/vpago/acleda_v2/base.rb', line 103
def opr_device
@options[:opr_device].presence || 'android'
end
|
#order_number ⇒ Object
28
29
30
|
# File 'lib/vpago/acleda_v2/base.rb', line 28
def order_number
@payment.order.number
end
|
#parse_json(body) ⇒ Object
130
131
132
133
134
|
# File 'lib/vpago/acleda_v2/base.rb', line 130
def parse_json(body)
JSON.parse(body)
rescue JSON::ParserError
{}
end
|
#password ⇒ Object
44
45
46
|
# File 'lib/vpago/acleda_v2/base.rb', line 44
def password
payment_method.preferences[:password]
end
|
#payment_method ⇒ Object
13
14
15
|
# File 'lib/vpago/acleda_v2/base.rb', line 13
def payment_method
@payment.payment_method
end
|
#payment_number ⇒ Object
Also known as:
transaction_id
17
18
19
|
# File 'lib/vpago/acleda_v2/base.rb', line 17
def payment_number
@payment.number
end
|
107
108
109
|
# File 'lib/vpago/acleda_v2/base.rb', line 107
def platform
@options[:platform]
end
|
#purchase_currency ⇒ Object
63
64
65
|
# File 'lib/vpago/acleda_v2/base.rb', line 63
def purchase_currency
@payment.order.currency
end
|
#purchase_date ⇒ Object
59
60
61
|
# File 'lib/vpago/acleda_v2/base.rb', line 59
def purchase_date
@payment.created_at.utc.strftime('%Y-%m-%d')
end
|
#secret ⇒ Object
48
49
50
|
# File 'lib/vpago/acleda_v2/base.rb', line 48
def secret
payment_method.preferences[:secret]
end
|
#txn_status_hash(token) ⇒ Object
getTxnStatus message: merchantId + loginId + password + paymentTokenid
122
123
124
|
# File 'lib/vpago/acleda_v2/base.rb', line 122
def txn_status_hash(token)
hmac512("#{merchant_id}#{login_id}#{password}#{token}")
end
|
#xpay_service_base_url ⇒ Object
67
68
69
|
# File 'lib/vpago/acleda_v2/base.rb', line 67
def xpay_service_base_url
strip_whitespace(payment_method.preferences[:xpay_service_base_url])
end
|