Module: Yaka::ClassMethods

Included in:
Yaka
Defined in:
lib/yaka/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#publish_payment(data, token = nil) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yaka/class_methods.rb', line 5

def publish_payment(data, token = nil)
  conn = Faraday.new(url: Yaka::HOST_URL) # create a new Connection with base URL
  conn.basic_auth(Yaka.config.shop_id, Yaka.config.private_key) # set the Authentication header

  @result = conn.post do |req|
    req.url Yaka::PAYMENTS_URL
    req.headers['Content-Type'] = 'application/json'
    req.headers['Idempotence-Key'] = token
    req.body = data.to_json
  end

  body = JSON.parse(@result.body)
  raise Yaka::Error, body['description'] if body.dig('code').to_s.include?('error')

  body
end

#yandex_ip?(ip) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yaka/class_methods.rb', line 22

def yandex_ip?(ip)
  addr = IPAddr.new(ip)

  if addr.ipv4?
    Yaka::ALLOWED_YANDEX_V4_MASKS.any? { |mask, length| addr.mask(length) == mask }
  elsif addr.ipv6?
    Yaka::ALLOWED_YANDEX_V6_MASKS.any? { |mask, length| addr.mask(length) == mask }
  else
    raise Yaka::Error, 'Invalid request ip address'
  end
end