-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
64 lines (49 loc) · 1.66 KB
/
app.rb
File metadata and controls
64 lines (49 loc) · 1.66 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'sinatra/base'
require 'pp'
require_relative 'ruby_gestpay_starter/constants'
require_relative 'ruby_gestpay_starter/version'
require_relative 'ruby_gestpay_starter/gestpay_ws_crypt_decrypt'
class App < Sinatra::Application
# Initialization of Gestpay class
def initialize
super
@gestpay = RubyGestpayStarter::GestpayWsCryptDecrypt.new RubyGestpayStarter::SHOP_LOGIN, :test
end
get '/' do
erb :index
end
post '/pay' do
item = params['item']
amount = params['price']
logger.info "received request for item #{item} with price #{amount}..."
encrypt_request = {
shop_login: RubyGestpayStarter::SHOP_LOGIN,
amount: amount,
uic_code: '242'
}
encrypt_response = @gestpay.encrypt encrypt_request
if encrypt_response.dig(:error_code) != "0"
raise "Error during Encrypt, errorcode: "+encrypt_response.dig(:error_code)+ " errorDescription: " + encrypt_response.dig(:error_description)
end
crypted_string = encrypt_response.dig(:crypt_decrypt_string)
erb :pay, :locals => {
:item => item,
:amount => amount,
:crypted_string => crypted_string,
:shop_login => RubyGestpayStarter::SHOP_LOGIN
}
end
get '/response' do
shop_login = params['a']
crypted_string = params['b']
puts "Received message from Gestpay: #{shop_login} is here"
result = @gestpay.decrypt :shop_login => shop_login, 'CryptedString' => crypted_string
puts result.inspect
erb :response, :locals => {
:result => result,
:result_ruby => result.pretty_inspect
}
end
# start the server if ruby file executed directly
run! if app_file == $0
end