class MidtransApi::Client

Attributes

config[R]

Public Class Methods

new(options = {}) { |config| ... } click to toggle source
# File lib/midtrans_api/client.rb, line 24
def initialize(options = {})
  @config = MidtransApi::Configure.new(options)

  yield @config if block_given?

  @connection = Faraday.new(url: "#{@config.api_url}/#{@config.api_version}/") do |connection|
    connection.basic_auth(@config.server_key, '')

    unless @config.notification_url.nil?
      connection.headers['X-Override-Notification'] = @config.notification_url
    end

    connection.request :json
    connection.response :json

    connection.use MidtransApi::Middleware::HandleResponseException
    connection.adapter Faraday.default_adapter
  end
end

Public Instance Methods

credit_card_charge() click to toggle source
# File lib/midtrans_api/client.rb, line 52
def credit_card_charge
  @credit_card_charge ||= MidtransApi::Api::CreditCard::Charge.new(self)
end
credit_card_token() click to toggle source
# File lib/midtrans_api/client.rb, line 48
def credit_card_token
  @credit_card_token ||= MidtransApi::Api::CreditCard::Token.new(self)
end
get(url, params) click to toggle source
# File lib/midtrans_api/client.rb, line 60
def get(url, params)
  response = @connection.get(url, params)
  response.body
end
gopay_charge() click to toggle source
# File lib/midtrans_api/client.rb, line 44
def gopay_charge
  @charge ||= MidtransApi::Api::Gopay::Charge.new(self)
end
post(url, params) click to toggle source
# File lib/midtrans_api/client.rb, line 65
def post(url, params)
  response = @connection.post(url, params)
  response.body
end
status() click to toggle source
# File lib/midtrans_api/client.rb, line 56
def status
  @status ||= MidtransApi::Api::Check::Status.new(self)
end