Class: PayRb::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pay_rb/client.rb

Constant Summary collapse

BASE_URLS =
{
  dsk: {
    uat: 'https://uat.dskbank.bg',
    production: 'https://epg.dskbank.bg'
  },
  jcc: {
    uat: 'https://gateway-test.jcc.com.cy',
    production: 'https://gateway.jcc.com.cy'
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, environment:, bank:) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pay_rb/client.rb', line 14

def initialize(username:, password:, environment:, bank:)
  @username = username
  @password = password
  @environment = environment.to_sym
  @bank = bank.to_sym

  validate_environment
  validate_bank

  @base_url = BASE_URLS[@bank][@environment]
end

Instance Method Details

#get_extended_order_status(order_id) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/pay_rb/client.rb', line 48

def get_extended_order_status(order_id)
  params = { orderId: order_id }

  response = connection.post('/payment/rest/getOrderStatusExtended.do') do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.body = URI.encode_www_form(default_params.merge(params))
  end

  JSON.parse(response.body)
end

#get_order_status(order_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/pay_rb/client.rb', line 37

def get_order_status(order_id)
  params = { orderId: order_id }

  response = connection.post('/payment/rest/getOrderStatus.do') do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.body = URI.encode_www_form(default_params.merge(params))
  end

  JSON.parse(response.body)
end

#payment_registration(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/pay_rb/client.rb', line 26

def payment_registration(params)
  camelized_params = params.transform_keys { |key| key.to_s.camelize(:lower) }

  response = connection.post('/payment/rest/register.do') do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.body = URI.encode_www_form(default_params.merge(camelized_params))
  end

  JSON.parse(response.body)
end

#refund_payment(params) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/pay_rb/client.rb', line 59

def refund_payment(params)
  camelized_params = params.transform_keys { |key| key.to_s.camelize(:lower) }

  response = connection.post('/payment/rest/refund.do') do |req|
    req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req.body = URI.encode_www_form(default_params.merge(camelized_params))
  end

  JSON.parse(response.body)
end