Method: SlidePay::Payment#process

Defined in:
lib/slidepay/resources/payment.rb

#process(options_hash = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slidepay/resources/payment.rb', line 38

def process(options_hash={})
  token = @token || options_hash[:token]
  api_key = @api_key || options_hash[:api_key]
  endpoint = @endpoint || options_hash[:endpoint]

  response = SlidePay.post(path: "payment/simple", api_key: api_key, token: token, endpoint: endpoint, data: self.to_json)

  if response.was_successful?
    self["payment_id"] = response.data["payment_id"]
    self["order_master_id"] = response.data["order_master_id"]
    true
  elsif response.error_text
    raise Exception.new(response.error_text)
  elsif response.data["status_message"]
    raise Exception.new(response.data["status_message"])
  else
    raise Exception.new("Payment could not be processed.")
  end
end