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
88
89
90
|
# File 'lib/vpago/acleda_v2/base.rb', line 88
def action_url
strip_whitespace(payment_method.preferences[:payment_page_url])
end
|
#amount ⇒ Object
PDF samples quote every xpayTransaction field as a JSON string.
22
23
24
|
# File 'lib/vpago/acleda_v2/base.rb', line 22
def amount
format('%.2f', @payment.amount)
end
|
#app_scheme ⇒ Object
108
109
110
|
# File 'lib/vpago/acleda_v2/base.rb', line 108
def app_scheme
payment_method.preferences[:app_scheme]
end
|
#callback_url ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/vpago/acleda_v2/base.rb', line 98
def callback_url
if platform == 'app' && app_scheme.present?
uri = URI.parse(@payment.processing_url)
uri.scheme = app_scheme
uri.to_s
else
@payment.processing_url
end
end
|
#continue_success_url ⇒ Object
successUrlToReturn / errorUrl. The bank appends its own query string
(_paymenttokenid, _resultCode, ...) when it redirects back.
94
95
96
|
# File 'lib/vpago/acleda_v2/base.rb', line 94
def continue_success_url
@payment.processing_url
end
|
#expiry_time ⇒ Object
PDF samples quote every xpayTransaction field as a JSON string, even ones
labeled "Numeric" in the field tables (paymentCard, quantity, expiryTime).
55
56
57
|
# File 'lib/vpago/acleda_v2/base.rb', line 55
def expiry_time
payment_method.preferences[:payment_expiry_time_in_mn].to_s
end
|
#get_txn_status_url ⇒ Object
rubocop:disable Naming/AccessorMethodName
83
84
85
|
# File 'lib/vpago/acleda_v2/base.rb', line 83
def get_txn_status_url "#{xpay_service_base_url}/getTxnStatus"
end
|
#hmac512(message) ⇒ Object
132
133
134
|
# File 'lib/vpago/acleda_v2/base.rb', line 132
def hmac512(message)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), secret, message).upcase
end
|
#login_id ⇒ Object
41
42
43
|
# File 'lib/vpago/acleda_v2/base.rb', line 41
def login_id
payment_method.preferences[:login_id]
end
|
#merchant_id ⇒ Object
37
38
39
|
# File 'lib/vpago/acleda_v2/base.rb', line 37
def merchant_id
payment_method.preferences[:merchant_id]
end
|
#merchant_name ⇒ Object
33
34
35
|
# File 'lib/vpago/acleda_v2/base.rb', line 33
def merchant_name
payment_method.preferences[:merchant_name]
end
|
#open_session_hash ⇒ Object
--- HMAC-SHA512 (uppercase hex) signing ---
openSessionV2 message: merchantID + loginId + password + txid
123
124
125
|
# File 'lib/vpago/acleda_v2/base.rb', line 123
def open_session_hash
hmac512("#{merchant_id}#{login_id}#{password}#{payment_number}")
end
|
#open_session_url ⇒ Object
79
80
81
|
# File 'lib/vpago/acleda_v2/base.rb', line 79
def open_session_url
"#{xpay_service_base_url}/openSessionV2"
end
|
#opr_device ⇒ Object
android | ios (defaults to android when not supplied by the caller)
113
114
115
|
# File 'lib/vpago/acleda_v2/base.rb', line 113
def opr_device
@options[:opr_device].presence || 'android'
end
|
#order_number ⇒ Object
29
30
31
|
# File 'lib/vpago/acleda_v2/base.rb', line 29
def order_number
@payment.order.number
end
|
#parse_json(body) ⇒ Object
136
137
138
139
140
|
# File 'lib/vpago/acleda_v2/base.rb', line 136
def parse_json(body)
JSON.parse(body)
rescue JSON::ParserError
{}
end
|
#password ⇒ Object
45
46
47
|
# File 'lib/vpago/acleda_v2/base.rb', line 45
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
|
117
118
119
|
# File 'lib/vpago/acleda_v2/base.rb', line 117
def platform
@options[:platform]
end
|
#purchase_currency ⇒ Object
66
67
68
|
# File 'lib/vpago/acleda_v2/base.rb', line 66
def purchase_currency
@payment.order.currency
end
|
#purchase_date ⇒ Object
PDF: "Date of Transaction in UTC Time", sent as a YYYY-MM-DD string in the
samples. Explicit .utc so this stays correct even if config.time_zone is
ever changed away from UTC.
62
63
64
|
# File 'lib/vpago/acleda_v2/base.rb', line 62
def purchase_date
@payment.created_at.utc.strftime('%Y-%m-%d')
end
|
#secret ⇒ Object
49
50
51
|
# File 'lib/vpago/acleda_v2/base.rb', line 49
def secret
payment_method.preferences[:secret]
end
|
#txn_status_hash(token) ⇒ Object
getTxnStatus message: merchantId + loginId + password + paymentTokenid
128
129
130
|
# File 'lib/vpago/acleda_v2/base.rb', line 128
def txn_status_hash(token)
hmac512("#{merchant_id}#{login_id}#{password}#{token}")
end
|
#xpay_service_base_url ⇒ Object
--- Endpoints (each stored as a full URL preference) ---
Strip embedded whitespace: these URLs are long and wrap across lines in
the bank's PDFs, so a copy-paste into the admin preference easily carries
over a stray space/line-break where the PDF wrapped.
75
76
77
|
# File 'lib/vpago/acleda_v2/base.rb', line 75
def xpay_service_base_url
strip_whitespace(payment_method.preferences[:xpay_service_base_url])
end
|