Class: Vpago::AcledaMobile::Checkout

Inherits:
Base
  • Object
show all
Defined in:
lib/vpago/acleda_mobile/checkout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#encryption_key, #initialize, #partner_id, #payment_number, #return_to_app_url

Methods included from PaymentAmountCalculator

#amount, #amount_with_fee, #transaction_fee, #transaction_fee_fix, #transaction_fee_percentage

Constructor Details

This class inherits a constructor from Vpago::AcledaMobile::Base

Instance Attribute Details

#error_messageObject

Returns the value of attribute error_message.



4
5
6
# File 'lib/vpago/acleda_mobile/checkout.rb', line 4

def error_message
  @error_message
end

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/vpago/acleda_mobile/checkout.rb', line 4

def results
  @results
end

Instance Method Details



27
28
29
# File 'lib/vpago/acleda_mobile/checkout.rb', line 27

def acleda_android_deeplink
  "market://com.domain.acledabankqr/app?partner_id=#{partner_id}&payment_data=#{aes_encrypted_payment_data}"
end

#acleda_app_storeObject



15
16
17
# File 'lib/vpago/acleda_mobile/checkout.rb', line 15

def acleda_app_store
  'https://apps.apple.com/us/app/acleda-unity-toanchet/id1196285236'
end


23
24
25
# File 'lib/vpago/acleda_mobile/checkout.rb', line 23

def acleda_ios_deeplink
  "ACLEDAmobile://?partner_id=#{partner_id}&payment_data=#{aes_encrypted_payment_data}"
end

#acleda_play_storeObject



19
20
21
# File 'lib/vpago/acleda_mobile/checkout.rb', line 19

def acleda_play_store
  'market://details?id=com.domain.acledabankqr'
end

#aes_encrypted_payment_dataObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vpago/acleda_mobile/checkout.rb', line 42

def aes_encrypted_payment_data
  data = "#{payment_data.to_json}~#{hmac_payment_data}"
  key = encryption_key
  iv = [key].pack('H*') # #hex2bin
  cipher = OpenSSL::Cipher.new('AES-256-CBC')
  cipher.encrypt

  cipher.key = pbkdf2_key
  cipher.iv = iv

  crypt = cipher.update(data) + cipher.final
  encrypted_result = Base64.encode64(crypt).delete("\n")
  encrypted_result.gsub('/', 'acledabankSecurityTC') # #follow acleda encrypting guide
end

#callObject



6
7
8
9
10
11
12
13
# File 'lib/vpago/acleda_mobile/checkout.rb', line 6

def call
  @results = {
    play_store: acleda_play_store,
    app_store: acleda_app_store,
    acleda_ios_deeplink: acleda_ios_deeplink,
    acleda_android_deeplink: acleda_android_deeplink
  }
end

#hmac_hash(key, message) ⇒ Object



38
39
40
# File 'lib/vpago/acleda_mobile/checkout.rb', line 38

def hmac_hash(key, message)
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, message)
end

#hmac_payment_dataObject



31
32
33
34
35
36
# File 'lib/vpago/acleda_mobile/checkout.rb', line 31

def hmac_payment_data
  message = payment_data.to_json
  key = encryption_key

  hmac_hash(key, message)
end

#payment_dataObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/vpago/acleda_mobile/checkout.rb', line 57

def payment_data
  {
    app_name: 'VTENH',
    payment_amount: amount_with_fee,
    payment_amount_ccy: 'USD',
    payment_purpose: 'VTENH Transaction',
    txn_ref: payment_number,
    app_url: return_to_app_url
  }
end

#pbkdf2_keyObject



68
69
70
71
72
73
74
75
# File 'lib/vpago/acleda_mobile/checkout.rb', line 68

def pbkdf2_key
  pass = encryption_key
  salt = pass
  iter = 100
  key_len = 32

  OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: iter, length: key_len, hash: 'sha1')
end