Class: Vpago::AcledaV2::Base

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

Direct Known Subclasses

Checkout, TransactionStatus

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_urlObject

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

#amountObject

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_schemeObject



108
109
110
# File 'lib/vpago/acleda_v2/base.rb', line 108

def app_scheme
  payment_method.preferences[:app_scheme]
end

#callback_urlObject



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_urlObject

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_timeObject

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_urlObject

rubocop:disable Naming/AccessorMethodName



83
84
85
# File 'lib/vpago/acleda_v2/base.rb', line 83

def get_txn_status_url # rubocop:disable Naming/AccessorMethodName
  "#{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_idObject



41
42
43
# File 'lib/vpago/acleda_v2/base.rb', line 41

def 
  payment_method.preferences[:login_id]
end

#merchant_idObject



37
38
39
# File 'lib/vpago/acleda_v2/base.rb', line 37

def merchant_id
  payment_method.preferences[:merchant_id]
end

#merchant_nameObject



33
34
35
# File 'lib/vpago/acleda_v2/base.rb', line 33

def merchant_name
  payment_method.preferences[:merchant_name]
end

#open_session_hashObject

--- 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}#{}#{password}#{payment_number}")
end

#open_session_urlObject



79
80
81
# File 'lib/vpago/acleda_v2/base.rb', line 79

def open_session_url
  "#{xpay_service_base_url}/openSessionV2"
end

#opr_deviceObject

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_numberObject



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

#passwordObject



45
46
47
# File 'lib/vpago/acleda_v2/base.rb', line 45

def password
  payment_method.preferences[:password]
end

#payment_methodObject



13
14
15
# File 'lib/vpago/acleda_v2/base.rb', line 13

def payment_method
  @payment.payment_method
end

#payment_numberObject Also known as: transaction_id



17
18
19
# File 'lib/vpago/acleda_v2/base.rb', line 17

def payment_number
  @payment.number
end

#platformObject



117
118
119
# File 'lib/vpago/acleda_v2/base.rb', line 117

def platform
  @options[:platform]
end

#purchase_currencyObject



66
67
68
# File 'lib/vpago/acleda_v2/base.rb', line 66

def purchase_currency
  @payment.order.currency
end

#purchase_dateObject

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

#secretObject



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}#{}#{password}#{token}")
end

#xpay_service_base_urlObject

--- 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