-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
36 lines (29 loc) · 1016 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'sinatra'
require 'httparty'
require 'openssl'
require 'pry'
class VixPayments < Sinatra::Base
post '/checkout' do
fields = params.select{|k,v| k.start_with? 'x_'}
fields.delete('x_signature')
message = fields.sort.join
key = 'vix'
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, message)
payload = {
x_account_id: params['x_account_id'],
x_reference: params['x_reference'],
x_currency: params['x_currency'],
x_test: params['x_test'],
x_amount: params['x_amount'],
x_gateway_reference: "VIX-" + "#{rand(10**15)}",
x_timestamp: Time.now.utc,
x_result: 'completed',
}
message_response = payload.sort.join
payload['x_signature'] = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, message_response)
callback_url = params['x_url_callback']
response = HTTParty.post(callback_url, body: payload)
redirect params['x_url_complete']
end
end
VixPayments.run!