-
Notifications
You must be signed in to change notification settings - Fork 3
/
myapp.rb
176 lines (133 loc) · 4.12 KB
/
myapp.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
require 'rubygems'
require 'bundler/setup'
# this will require all the gems not specified to a given group (default)
# and gems specified in your test group
Bundler.require(:default, :development)
require 'sinatra/async'
require 'sinatra/activerecord'
require './utils/entity_utils.rb'
require './utils/hash_utils.rb'
require './utils/url_utils.rb'
require './utils/pattern_matching.rb'
require './models/paypal_account.rb'
require './models/billing_agreement.rb'
require './models/paypal_payment.rb'
require './models/paypal_refund.rb'
require './models/order_permission.rb'
require './models/paypal_ipn_message.rb'
require './models/paypal_process_token.rb'
require './models/paypal_token.rb'
require './paypal_service.rb'
require './config/config_loader.rb'
require './result.rb'
APP_CONFIG = ConfigLoader.load_app_config(
[
:paypal_username,
:paypal_password,
:paypal_signature,
:paypal_app_id,
:paypal_button_source,
:paypal_endpoint,
:paypal_expiration_period,
:paypal_ipn_domain,
:paypal_ipn_protocol
])
ActiveRecord::Base.establish_connection(
adapter: "mysql2",
host: "localhost",
username: "sharetribe",
password: "secret",
database: "sharetribe_development",
encoding: "utf8"
)
class Router < Sinatra::Base
register Sinatra::Async
Api = PaypalService::API::Api
# Accounts API
post '/accounts/request/:community_id' do
res = Api.accounts.request(body: {
community_id: params[:community_id],
person_id: params[:person_id],
callback_url: params[:callback_url],
country: params[:country]
})
body { res[:data].to_json }
end
post '/accounts/request/:community_id/:person_id' do
request.body.rewind
body = HashUtils.symbolize_keys(JSON.parse(request.body.read))
res = Api.accounts.request(body: {
community_id: params[:community_id].to_i,
person_id: params[:person_id],
callback_url: body[:callback_url],
country: body[:country]
})
body { res[:data].to_json }
end
# post '/accounts/create/:community_id' do
# request.body.rewind
# body = HashUtils.symbolize_keys(JSON.parse(request.body.read))
# res = Api.accounts.create(
# community_id: community_id,
# person_id: person_id,
# order_permission_request_token: params[:order_permission_request_token],
# body: {
# order_permission_verification_code: body[:order_permission_verification_code]
# }
# )
# end
post '/accounts/create/:community_id/:person_id' do
request.body.rewind
body = HashUtils.symbolize_keys(JSON.parse(request.body.read))
puts "body #{body}"
puts "params #{params}"
res = Api.accounts.create(
community_id: params[:community_id],
person_id: params[:person_id],
order_permission_request_token: params[:order_permission_request_token],
body: {
order_permission_verification_code: body[:order_permission_verification_code]
}
)
body { res.maybe.or_else({}).to_json }
end
delete '/accounts' do
end
get '/accounts/:community_id' do
res = Api.accounts.get(
community_id: params[:community_id]
)
body { Maybe(res[:data]).or_else({}).to_json }
end
get '/accounts/:community_id/:person_id' do
res = Api.accounts.get(
community_id: params[:community_id],
person_id: params[:person_id]
)
body { Maybe(res[:data]).or_else({}).to_json }
end
post '/accounts/billing_agreement/request' do
end
post '/accounts/billing_agreement/create' do
end
delete '/accounts/billing_agreement' do
end
# Payments API
post '/payments/:community_id/request' do
end
post '/payments/:community_id/request/cancel' do
end
post '/payments/:community_id/create' do
end
post '/payments/:community_id/:transaction_id/full_capture' do
end
get '/payments/:community_id/:transaction_id' do
end
post '/payments/:community_id/:transaction_id/void' do
end
post '/payments/:community_id/:transaction_id/refund' do
end
# Billing Agreement API
post '/billing_agreement/:community_id/:person_id/charge_commission' do
end
end