/
pay_offer_angular.html
309 lines (280 loc) · 13.4 KB
/
pay_offer_angular.html
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
{% extends "core/base.html" %}
{% load l10n %}
{% block topright %}
{% endblock %}
{% block mainContent%}
<script src="/static/bootstrap/js/jquery.numeric.js"></script>
<script src="/static/js/angular.min.js"></script>
<script type="text/javascript">
var mod = angular.module('pay_offer', [])
mod.config(
function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
}
);
function PayCtrl($scope) {
var CURRENCY_SYMBOLS = {
'USD': 'US$',
'BTC': 'BTC'
};
var CURRENCY_NAMES = {
'USD': 'US dollars',
'BTC': 'Bitcoins'
};
var DECIMAL_PLACES = {
'USD': 2,
'BTC': 4
};
var CONVERSION_RATES = {
'USD': 1,
'BTC': 0.00815661
};
var CURRENCY_METHODS = {
USD: 'Paypal',
BTC: 'Bitcoin'
}
var FEE_RATE = 0.03;
var BITCOIN_FEE = 0.0005;
$scope.USD_2_BTC_RATE = 122.60001;
$scope.getCurrencySymbol = function(currency){
return CURRENCY_SYMBOLS[currency]
}
$scope.getCurrencyName = function(currency){
return CURRENCY_NAMES[currency]
}
$scope.currentCurrencyMethod = function(){
return CURRENCY_METHODS[$scope.selectedCurrency];
}
$scope.offer = {
id: {{ offer.id }},
title: '{{ offer.issue.title }}',
price: '20.00',
currency: 'USD'
}
$scope.solutions = [
{
id: 1,
programmerScreenName: 'John Doe',
acceptsPaypal: true,
acceptsBitcoin: true,
imglink: 'http://www.gravatar.com/avatar/0a8eb9426eb59a7d8481118403aee8ef?d=identicon&s=23'
},
{
id: 2,
programmerScreenName: 'Mike Eod',
acceptsPaypal: false,
acceptsBitcoin: true,
imglink: 'http://www.gravatar.com/avatar/4dbc40e7a6fa89a3568a926378c22ace?d=identicon&s=23'
}
]
var prefillForm = function(){
var enabledSolutions = []
for(var i=0; i < $scope.solutions.length; i++){
var solution = $scope.solutions[i];
var enabled = $scope.isEnabled(solution);
if(enabled){
enabledSolutions.push(solution);
} else {
solution.price = '';
}
}
var count = enabledSolutions.length;
var convRate = CONVERSION_RATES[$scope.selectedCurrency];
var totalPrice = parseFloat($scope.offer.price) * convRate;
var sharedPrice = totalPrice / count;
var decimalPlaces = DECIMAL_PLACES[$scope.selectedCurrency];
sharedPrice = sharedPrice.toFixed(decimalPlaces);
for(var i=0; i < enabledSolutions.length; i++){
var solution = enabledSolutions[i];
solution.price = sharedPrice;
}
}
var initialize = function(){
$scope.selectedCurrency = $scope.offer.currency;
$scope.showCurrencyAlert = false;
$scope.showConfirm = false;
$scope.fsFee = '0'
$scope.totalPayment = '0'
prefillForm();
}
$scope.isEnabled = function(solution){
if($scope.selectedCurrency == 'USD'){
return solution.acceptsPaypal;
} else if ($scope.selectedCurrency == 'BTC'){
return solution.acceptsBitcoin;
}
}
$scope.getFormattedPrice = function(solution){
var decimalPlaces = DECIMAL_PLACES[$scope.selectedCurrency];
var price = parseFloat(solution.price);
if(!isNaN(price)){
return price.toFixed(decimalPlaces);
} else {
return '';
}
}
$scope.onCurrencyChange = function(){
var showCurrencyAlert = $scope.selectedCurrency != $scope.offer.currency
if(showCurrencyAlert){
$('#divCurrencyAlert').slideDown();
$('#alert_modal_currency').modal()
} else {
$('#divCurrencyAlert').slideUp();
}
prefillForm();
}
$scope.getSelectedSolutions = function(){
var selectedSolutions = [];
var totalPrice = 0;
for(var i=0; i < $scope.solutions.length; i++){
var solution = $scope.solutions[i];
var enabled = $scope.isEnabled(solution);
if(enabled){
var price = parseFloat(solution.price);
var selected = !isNaN(price);
if(selected){
selectedSolutions.push(solution);
totalPrice += price;
}
}
}
var fee = totalPrice * FEE_RATE;
var decimalPlaces = DECIMAL_PLACES[$scope.selectedCurrency];
$scope.fsFee = fee.toFixed(decimalPlaces)
var isBitcoin = $scope.selectedCurrency == 'BTC'
if(isBitcoin){
var count = selectedSolutions.length;
$scope.f_bitcoinFee = BITCOIN_FEE * count
} else {
$scope.f_bitcoinFee = 0;
}
$scope.bitcoinFee = $scope.f_bitcoinFee.toFixed(decimalPlaces)
var totalPayment = totalPrice + fee + $scope.f_bitcoinFee;
$scope.totalPayment = totalPayment.toFixed(decimalPlaces)
return selectedSolutions;
}
$scope.next = function(){
$scope.showConfirm = true;
}
initialize();
}
</script>
<form>
<div class="span12" ng-app="pay_offer" ng-controller="PayCtrl">
<div class="modal hide fade in" id="alert_modal_currency">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Heads up: different currency</h3>
</div>
<div class="modal-body">
<div class="alert alert-info">
<p>
You've made an offer in {[{ getCurrencyName(offer.currency) }]},
and now you're choosing to pay with {[{ getCurrencyName(selectedCurrency) }]}.<br>
FreedomSponsors simply forwards payments using the same currency that you pay.
This means you can only pay in a currency that's accepted by the developer on the receiving side.<br>
</p>
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>
</div>
</div>
<h3>
Pay up offer: {[{ getCurrencySymbol(offer.currency) }]} {[{ offer.price }]} - {[{ offer.title }]}
</h3>
<div class="row-fluid" style="margin-top: 10px;">
<div class="span6" >
<div style="border-width: 1px; border-style: solid; border-radius: 5px; padding: 10px; border-color: #ccc;">
<div class="row-fluid">
<div class="span6" style="text-align: right; font-weight: bold; margin-top: 5px">
Select currency to pay
</div>
<div class="span6">
<select ng-model="selectedCurrency" ng-change="onCurrencyChange()">
<option value="USD">US$, using Paypal</option>
<option value="BTC">Bitcoin</option>
</select>
</div>
</div>
<div id="divCurrencyAlert" class="alert alert-info hide">
<p>Suggested conversion rate: <span style="font-weight: bold">BTC 1.0 = US$ {[{ USD_2_BTC_RATE }]}</span> <br>(fetched from <a href="http://blockchain.info">blockchain)</a></p>
</div>
<hr>
<table class="table">
<thead>
<tr>
<th>Programmer</th>
<th>Accepted methods</th>
<th>Amount (US$)</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="solution in solutions">
<td>
<img ng-src="{[{ solution.imglink }]}">
{[{ solution.programmerScreenName }]}
</td>
<td>
<img ng-show="{[{ solution.acceptsPaypal }]}" src="/static/img/paypal_icon_32.png" class="popopo" rel="popover" data-content="FreedomSponsors has verified that this user is able to receive payments via Paypal" data-original-title="Paypal verified">
<img ng-show="{[{ solution.acceptsBitcoin }]}" src="/static/img/bitcoin_icon_32.png" class="popopo" rel="popover" data-content="This user may receive payments in Bitcoin" data-original-title="Accepts Bitcoin">
</td>
<td>
<input type="text" style="width: 100px;" ng-disabled="!isEnabled(solution)" ng-model="solution.price">
</td>
</tr>
</tbody>
</table>
</div>
<div style="text-align:right; margin: 10px 0px;">
<button class="btn btn-primary" type="button" ng-click="next()">Next ></button>
</div>
</div>
<div class="span6" data-ng-animate="'fade'" ng-show="showConfirm">
<div style="border-width: 1px; border-style: solid; border-radius: 5px; padding: 10px; ; border-color: #ccc;">
<span style="font-weight:bold;">Confirm payment details</span>
<hr>
<table class="table">
<thead>
<tr>
<th>Description</th>
<th style="text-align: right">Amount ({[{ getCurrencySymbol(selectedCurrency) }]})</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="solution in getSelectedSolutions()">
<td>
<img ng-src="{[{ solution.imglink }]}">
{[{ solution.programmerScreenName }]}
</td>
<td style="text-align:right">{[{ getFormattedPrice(solution) }]}</td>
</tr>
<tr>
<td style="vertical-align: middle;">
<img src="/static/img/FS_logo_32x32.png">
FreedomSponsors
</td>
<td style="text-align:right">{[{ fsFee }]}</td>
</tr>
<tr ng-show="f_bitcoinFee > 0">
<td style="vertical-align: middle;">
<img src="/static/img/bitcoin_icon_32.png">
Bitcoin miners' fee
</td>
<td style="text-align:right">{[{ bitcoinFee }]}</td>
</tr>
<tr style="font-weight: bold;">
<td>Total</td>
<td style="text-align:right">{[{ totalPayment }]}</td>
</tr>
</tbody>
</table>
</div>
<div style="text-align:right; margin: 10px 0px;">
<button class="btn btn-primary" type="button">Proceed to payment with {[{ currentCurrencyMethod() }]}</button>
</div>
</div>
</div>
</div>
</form>
{% endblock mainContent%}