15 lines
		
	
	
		
			364 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			15 lines
		
	
	
		
			364 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| module BtcpayManager
 | |
|   class FetchExchangeRate < BtcpayManagerService
 | |
|     def initialize(fiat_currency:)
 | |
|       @fiat_currency = fiat_currency
 | |
|     end
 | |
| 
 | |
|     def call
 | |
|       pair_str = "BTC_#{@fiat_currency}"
 | |
|       res = get "rates", { currencyPair: pair_str }
 | |
|       pair = res.find{|p| p["currencyPair"] == pair_str }
 | |
|       rate = pair["rate"].to_f
 | |
|     end
 | |
|   end
 | |
| end
 |