Module: PaytechGem

Defined in:
lib/paytech_gem.rb,
lib/paytech_gem/version.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



25
26
27
# File 'lib/paytech_gem.rb', line 25

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



27
28
29
30
# File 'lib/paytech_gem.rb', line 27

def configure
  self.config ||= Configuration.new
  yield(config)
end

.initialize_payment(amount, item_name, ref_command) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/paytech_gem.rb', line 32

def initialize_payment(amount, item_name, ref_command)
  url = 'https://paytech.sn/api/payment/request-payment'
  headers = {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'API_KEY': config.paytech_api_key,
    'API_SECRET': config.paytech_api_secret
  }

  data = {
    item_name: item,
    item_price: amount,
    currency: config.currency,
    ref_command: ref_command,
    command_name: config.command_name,
    env: config.env,
    ipn_url: config.ipn_url,
    success_url: config.success_url,
    cancel_url: config.cancel_url
  }

  response = HTTParty.post(url, body: data.to_json, headers: headers)

  if response.code == 200
    json_response = JSON.parse(response.body)
    return json_response
  else
    return "Error: #{response.code} - #{response.body}"
  end
end