Class: Vpago::WingSdk::PaymentRetriever
- Inherits:
-
Object
- Object
- Vpago::WingSdk::PaymentRetriever
- Defined in:
- lib/vpago/wing_sdk/payment_retriever.rb
Instance Attribute Summary collapse
-
#payment ⇒ Object
Returns the value of attribute payment.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(rest_api_key, wing_response) ⇒ PaymentRetriever
constructor
A new instance of PaymentRetriever.
- #prepare_decrypt ⇒ Object
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
#payment ⇒ Object
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
#call ⇒ Object
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_decrypt ⇒ Object
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 |