Method: PaytechGem.initialize_payment

Defined in:
lib/paytech_gem.rb

.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