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



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

def action_url
  strip_whitespace(payment_method.preferences[:payment_page_url])
end

#amountObject



21
22
23
# File 'lib/vpago/acleda_v2/base.rb', line 21

def amount
  format('%.2f', @payment.amount)
end

#app_schemeObject



94
95
96
# File 'lib/vpago/acleda_v2/base.rb', line 94

def app_scheme
  payment_method.preferences[:app_scheme]
end

#callback_urlObject



90
91
92
# File 'lib/vpago/acleda_v2/base.rb', line 90

def callback_url
  @payment.processing_url
end

#continue_success_urlObject

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

Returns:

  • (Boolean)


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

def deeplink?
  payment_method.deeplink? && platform == 'app'
end

#expiry_timeObject

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_urlObject

rubocop:disable Naming/AccessorMethodName



75
76
77
# File 'lib/vpago/acleda_v2/base.rb', line 75

def get_txn_status_url # rubocop:disable Naming/AccessorMethodName
  "#{xpay_service_base_url}/getTxnStatus"
end

#hmac512(message) ⇒ Object



122
123
124
# File 'lib/vpago/acleda_v2/base.rb', line 122

def hmac512(message)
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), secret, message).upcase
end

#login_idObject



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

def 
  payment_method.preferences[:login_id]
end

#merchant_idObject



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

def merchant_id
  payment_method.preferences[:merchant_id]
end

#merchant_nameObject



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

def merchant_name
  payment_method.preferences[:merchant_name]
end

#open_session_hashObject

--- HMAC-SHA512 (uppercase hex) signing --- openSessionV2 message: merchantID + loginId + password + txid



113
114
115
# File 'lib/vpago/acleda_v2/base.rb', line 113

def open_session_hash
  hmac512("#{merchant_id}#{}#{password}#{payment_number}")
end

#open_session_urlObject



71
72
73
# File 'lib/vpago/acleda_v2/base.rb', line 71

def open_session_url
  "#{xpay_service_base_url}/openSessionV2"
end

#opr_deviceObject

android | ios (defaults to android when not supplied by the caller)



99
100
101
# File 'lib/vpago/acleda_v2/base.rb', line 99

def opr_device
  @options[:opr_device].presence || 'android'
end

#order_numberObject



28
29
30
# File 'lib/vpago/acleda_v2/base.rb', line 28

def order_number
  @payment.order.number
end

#parse_json(body) ⇒ Object



126
127
128
129
130
# File 'lib/vpago/acleda_v2/base.rb', line 126

def parse_json(body)
  JSON.parse(body)
rescue JSON::ParserError
  {}
end

#passwordObject



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

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



103
104
105
# File 'lib/vpago/acleda_v2/base.rb', line 103

def platform
  @options[:platform]
end

#purchase_currencyObject



63
64
65
# File 'lib/vpago/acleda_v2/base.rb', line 63

def purchase_currency
  @payment.order.currency
end

#purchase_dateObject



59
60
61
# File 'lib/vpago/acleda_v2/base.rb', line 59

def purchase_date
  @payment.created_at.utc.strftime('%Y-%m-%d')
end

#secretObject



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



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

def txn_status_hash(token)
  hmac512("#{merchant_id}#{}#{password}#{token}")
end

#xpay_service_base_urlObject



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