Class: Vpago::Acleda::DeeplinkCheckout

Inherits:
Base
  • Object
show all
Defined in:
lib/vpago/acleda/deeplink_checkout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#acleda_company_name, #acleda_payment_card, #action_url, #app_checkout, #app_checkout?, #error_url, #expiry_time, #host, #initialize, #login_id, #merchant_id, #merchant_name, #order_number, #other_url, #password, #payment_number, #purchase_date, #signature, #success_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::Acleda::Base

Instance Attribute Details

#error_messageObject

Returns the value of attribute error_message.



4
5
6
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 4

def error_message
  @error_message
end

#resultsObject

Returns the value of attribute results.



4
5
6
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 4

def results
  @results
end

Instance Method Details



27
28
29
# File 'lib/vpago/acleda/deeplink_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/deeplink_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/deeplink_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/deeplink_checkout.rb', line 19

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

#aes_encrypted_payment_dataObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 40

def aes_encrypted_payment_data
  data = "#{payment_data.to_json}~#{hmac_encrypted_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/deeplink_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_encrypted_payment_dataObject



31
32
33
34
35
36
37
38
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 31

def hmac_encrypted_payment_data
  json_data = payment_data.to_json
  key = encryption_key

  encrypted_result = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, json_data))
  encrypted_result.delete!("\n")
  encrypted_result
end

#payment_dataObject



55
56
57
58
59
60
61
62
63
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 55

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

#pbkdf2_keyObject



65
66
67
68
69
70
71
# File 'lib/vpago/acleda/deeplink_checkout.rb', line 65

def pbkdf2_key
  pass = encryption_key
  salt = pass
  iter = 100
  key_len = 32
  OpenSSL::KDF.pbkdf2_hmac(pass, salt:, iterations: iter, length: key_len, hash: 'sha1')
end