-
Notifications
You must be signed in to change notification settings - Fork 0
/
copypasta.txt
117 lines (95 loc) · 3.59 KB
/
copypasta.txt
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
get '/' do
@payment_request = Apruve::PaymentRequest.new api_key: api_key, merchant_id: merchant_id, amount_cents: 1150, currency: 'USD'
@payment_request.line_items << Apruve::LineItem.new(description: 'Description "for" a widget', title: 'A Widget', sku: "SKU-ABCD", amount_cents: 1000, quantity: 1)
@payment_request.line_items << Apruve::LineItem.new(title: 'Another Widget', description: 'Description for another widget', sku: "SKU-EFGH", amount_cents: 150, quantity: 1)
erb :index
end
<script src="https://test.apruve.com/js/apruve.js" type="text/javascript"></script>
<script type="text/javascript">
apruve.logoSrc = 'http://localhost:4567/img/generic-logo.png';
apruve.secureHash = '<%= @payment_request.token %>';
apruve.paymentRequest = <%= @payment_request.to_json %>;
apruve.registerApruveCallback(apruve.APRUVE_COMPLETE_EVENT, function () {
$('#paymentRequestStatus').html(apruve.status)
$('#paymentRequestToken').html(apruve.paymentRequestId)
$('#tokenField').val(apruve.paymentRequestId)
$('#shoppingCart').hide()
$('#thankYou').show()
});
</script>
<div id="apruveDiv"/>
post '/finish_order' do
token = params[:token]
amount_cents = 1150
uri = URI.parse(Apruve::ApruveClient::APRUVE_PAYMENTS_URL % token)
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
req['Apruve-Api-Key'] = api_key
req.body = "{\"amount_cents\":#{amount_cents}}"
res = http.request(req)
puts "Response #{res.code} #{res.message}: #{res.body}"
result_data = JSON.parse(res.body)
case res
when Net::HTTPSuccess
@paymentStatus = result_data['status']
@paymentId = result_data['id']
@paymentUrl = result_data['view_url']
erb :finished
else
res.value
end
end
<div id="thankYou">
<div class="row">
<div class="span8 offset2">
<% if @paymentStatus == "captured" %>
<h1>Thank you for your order!</h1>
<h3>Payment has been made. We'll ship that right out.</h3>
<% elsif @paymentStatus == "pending" %>
<h1>Thank you for your order!</h1>
<h3>Your order will be shipped as soon as final payment is approved.</h3>
<% elsif @paymentStatus == "rejected" %>
<h1>Payment for your order has been rejected.</h1>
<h3>Please select another payment method.</h3>
<% else %>
<h1>An unexpected response was received.</h1>
<% end %>
</div>
</div>
<div class="row">
<div class="span6 offset3">
<div class="well-large" style="text-align: center">
<table class="table">
<tr>
<td><strong>Order</strong></td>
<td><strong>Complete</strong></td>
</tr>
<tr>
<td><strong>Payment Status</strong></td>
<td><strong>
<div id="paymentStatus"><%= @paymentStatus %></div>
</strong></td>
</tr>
<tr>
<td><strong>Payment ID</strong></td>
<td><strong>
<div id="paymentId"><%= @paymentId %></div>
</strong></td>
</tr>
<tr>
<td><strong>Payment URL</strong></td>
<td><strong>
<div id="paymentUrl"><%= @paymentUrl %></div>
</strong></td>
</tr>
</table>
</div>
</div>
</div>
</div>
post '/webhook_notify' do
request.body.rewind
@webhook_data = JSON.parse request.body.read
puts "GOT WEBHOOK DATA FOR PAYMENT #{@webhook_data['payment_id']} : #{@webhook_data['status']}"
end