@@ -12,27 +12,27 @@ def index
12
12
end
13
13
14
14
def new
15
- # todo : use "base currency"
15
+ # TODO : use "base currency"
16
16
session [ :selected_currency ] = params [ :currency ] if params [ :currency ] . present?
17
17
selected_currency = session [ :selected_currency ] || 'USD'
18
- from_currency = " USD"
18
+ from_currency = ' USD'
19
19
20
20
@total_amount_to_pay = convert_currency ( Ticket . total_price ( @conference , current_user , paid : false ) . amount , from_currency , selected_currency )
21
21
raise CanCan ::AccessDenied . new ( 'Nothing to pay for!' , :new , Payment ) if @total_amount_to_pay . zero?
22
22
23
23
@has_registration_ticket = params [ :has_registration_ticket ]
24
24
@unpaid_ticket_purchases = current_user . ticket_purchases . unpaid . by_conference ( @conference )
25
- #a way to display the currency values in the view, but there might be a better way to do this.
25
+ # a way to display the currency values in the view, but there might be a better way to do this.
26
26
@converted_prices = { }
27
27
@unpaid_ticket_purchases . each do |ticket_purchase |
28
- #hardcoded
28
+ # hardcoded
29
29
@converted_prices [ ticket_purchase . id ] = convert_currency ( ticket_purchase . price . amount , 'USD' , selected_currency )
30
30
end
31
31
@currency = selected_currency
32
32
end
33
33
34
34
def create
35
- @payment = Payment . new ( payment_params )
35
+ @payment = Payment . new ( payment_params )
36
36
37
37
if @payment . purchase && @payment . save
38
38
update_purchased_ticket_purchases
@@ -80,20 +80,18 @@ def load_currency_conversions
80
80
81
81
def convert_currency ( amount , from_currency , to_currency )
82
82
update_rate ( from_currency , to_currency )
83
-
83
+
84
84
money_amount = Money . from_amount ( amount , from_currency )
85
- converted_amount = money_amount . exchange_to ( to_currency )
86
- converted_amount
85
+ money_amount . exchange_to ( to_currency )
87
86
end
88
-
87
+
89
88
def update_rate ( from_currency , to_currency )
90
89
conversion = @currency_conversions . find_by ( from_currency : from_currency , to_currency : to_currency )
91
90
if conversion
92
91
Money . add_rate ( from_currency , to_currency , conversion . rate )
93
92
else
94
- #If no conversion is found. Typically only possible if base to base. Maybe make this error out.
93
+ # If no conversion is found. Typically only possible if base to base. Maybe make this error out.
95
94
Money . add_rate ( from_currency , to_currency , 1 ) unless from_currency == to_currency
96
95
end
97
96
end
98
-
99
97
end
0 commit comments