Class: Paynow::PaynowClient

Inherits:
Object
  • Object
show all
Defined in:
lib/paynow/paynow_client.rb

Overview

Net::HTTP wraper for consuming the Paynow API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ PaynowClient

Returns a new instance of PaynowClient.



14
15
16
# File 'lib/paynow/paynow_client.rb', line 14

def initialize(body)
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/paynow/paynow_client.rb', line 8

def body
  @body
end

Class Method Details

.create_payment(body) ⇒ Object



10
11
12
# File 'lib/paynow/paynow_client.rb', line 10

def self.create_payment(body)
  new(body).create_payment
end

Instance Method Details

#create_paymentObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/paynow/paynow_client.rb', line 18

def create_payment
  logger.info("[PAYNOW] STARTED GET #{uri}")

  response = Net::HTTP.post(uri, json_body, headers)

  if response.code =~ /^[4-5]/
    logger.error("[PAYNOW] ERROR GET #{uri} status=#{response.code} #{JSON.parse(response.body)['errors']}")
  else
    logger.info("[PAYNOW] FINISHED GET #{uri} status=#{response.code}")
  end

  response
end