Class: JuspayCheckout::ExpressCheckout

Inherits:
Object
  • Object
show all
Defined in:
lib/juspay_checkout/express_checkout.rb

Direct Known Subclasses

Card, Customer, Order, Payment, Wallet

Class Method Summary collapse

Class Method Details

.credential_configObject



30
31
32
# File 'lib/juspay_checkout/express_checkout.rb', line 30

def credential_config
	$juspay_config = ::Rails.application.config_for(:juspay)
end

.request(partial_url, http_method, params = {}) ⇒ Object



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
# File 'lib/juspay_checkout/express_checkout.rb', line 4

def request(partial_url, http_method, params = {})
	begin
		# base url for juspay
		if ::Rails.env == 'production'
      		base_url = 'https://api.juspay.in'
    	else
      		base_url = 'https://sandbox.juspay.in'
		end
		$juspay_config or credential_config
		# basic auth info
		auth = {username: $juspay_config['api_key'], password: ''}

		# header
		header = {'Accept': 'application/json'}	
		
		if http_method == 'get'
			response =  HTTParty.get(base_url+partial_url, basic_auth: auth, headers: header).to_hash rescue nil
		elsif http_method == 'post'
			response = HTTParty.post(base_url+partial_url, body: params, basic_auth: auth, headers: header).to_hash rescue nil
		end
		response
	rescue
		nil
	end
end