Class: Vpago::WingSdk::PaymentRetriever

Inherits:
Object
  • Object
show all
Defined in:
lib/vpago/wing_sdk/payment_retriever.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_api_key, wing_response) ⇒ PaymentRetriever

Returns a new instance of PaymentRetriever.



6
7
8
9
# File 'lib/vpago/wing_sdk/payment_retriever.rb', line 6

def initialize(rest_api_key, wing_response)
  @rest_api_key = rest_api_key
  @wing_response = wing_response
end

Instance Attribute Details

#paymentObject

Returns the value of attribute payment.



4
5
6
# File 'lib/vpago/wing_sdk/payment_retriever.rb', line 4

def payment
  @payment
end

Instance Method Details

#callObject



11
12
13
14
15
# File 'lib/vpago/wing_sdk/payment_retriever.rb', line 11

def call
  response = JSON.parse(prepare_decrypt)

  @payment = ::Spree::Payment.find_by(number: response['remark'])
end

#prepare_decryptObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vpago/wing_sdk/payment_retriever.rb', line 17

def prepare_decrypt
  hash = Digest::SHA256.hexdigest(@rest_api_key)
  # $key = pack('H*', $hash)
  key = [hash].pack('H*')
  iv  = 0.chr * 16
  encrypted = Base64.decode64(@wing_response)

  cipher = OpenSSL::Cipher.new('AES-256-CBC')
  cipher.decrypt
  cipher.key = key
  cipher.iv  = iv
  crypt = cipher.update(encrypted)
  crypt << cipher.final
  crypt
end