module DistributionApi
Constants
- VERSION
Attributes
api_endpoint[RW]
api_key[RW]
api_secret[RW]
Public Class Methods
cancel_card(reference)
click to toggle source
# File lib/distribution-api-client.rb, line 29 def self.cancel_card(reference) req_params = { url: ("#{api_endpoint}/cards/#{URI::encode_www_form_component reference}/cancel"), method: :post, headers: { accept: :json }, payload: {} } req = RestClient::Request.new(req_params) req.sign!(api_key, api_secret) req.execute end
card_url(reference)
click to toggle source
# File lib/distribution-api-client.rb, line 36 def self.card_url(reference) timestamp = Time.now.utc.httpdate security = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', api_secret, "#{reference}\n#{timestamp}")) query_string = { key: api_key, timestamp: timestamp, reference: reference, security: security }.map { |k, v| "#{k}=#{URI::encode_www_form_component(v)}" }.join('&') "#{api_endpoint}/widget?#{query_string}" end
create_card(reference, amount, currency, merchant_id, user)
click to toggle source
# File lib/distribution-api-client.rb, line 20 def self.create_card(reference, amount, currency, merchant_id, user) user = user.to_json if user.is_a?(Hash) payload = { amount: amount, currency: currency, merchant_id: merchant_id, reference: reference, user: user } req_params = { url: "#{api_endpoint}/cards", method: :post, headers: { accept: :json }, payload: payload } req = RestClient::Request.new(req_params) req.sign!(api_key, api_secret) parse_response req.execute end
setup(api_key, api_secret, api_endpoint='https://distribution.api.wizypay.com/v1')
click to toggle source
# File lib/distribution-api-client.rb, line 14 def self.setup(api_key, api_secret, api_endpoint='https://distribution.api.wizypay.com/v1') self.api_endpoint = api_endpoint self.api_key = api_key self.api_secret = api_secret end
Private Class Methods
parse_response(response)
click to toggle source
# File lib/distribution-api-client.rb, line 50 def self.parse_response(response) Hash[JSON::parse(response).map { |k,v| [k.to_sym, v] }] end