Skip to content

Commit

Permalink
Add currency service to cart page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Langlois and LDevinMacKrell committed Dec 6, 2017
1 parent 26aa9b9 commit 8cd688f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/carts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class CartsController < ApplicationController
def show
@cart = current_cart
@rainchecked = current_raincheck
@quotes = JSON.parse(Currency.get_exchange_rates)['quotes']
end
end
5 changes: 2 additions & 3 deletions app/services/currency.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Currency
def self.get_exchange_rate
response = RestClient::Request.execute(method: :get, url: "http://apilayer.net/api/live?access_key=#{ENV["CURRENCYLAYERKEY"]}&currencies=AUD,EUR,GBP,PLN")

def self.get_exchange_rates
response = RestClient::Request.execute(method: :get, url: "http://apilayer.net/api/live?access_key=#{ENV["CURRENCYLAYERKEY"]}&currencies=CAD,EUR,GBP,PLN")
end
end
6 changes: 6 additions & 0 deletions app/views/carts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<% end %>
</ul>
<p>Order Total: $<span id="cart-total"><%= @cart.price_total %></span></p>
<p>
Other Currencies:
<% @quotes.each do |currency, rate| %>
<span><strong><%= currency[3..-1] %>:</strong> <%= '%.2f' % (rate * @cart.price_total) %> </span>
<% end %>
</p>
<%= link_to new_cart_charge_path do %>
<button type="button" class="btn btn-default">Checkout</button>
<% end %>
Expand Down

0 comments on commit 8cd688f

Please sign in to comment.