class Paynow::Client
Attributes
body[R]
Public Class Methods
create_payment(body)
click to toggle source
# File lib/paynow/client.rb, line 7 def self.create_payment(body) new(body).create_payment end
new(body)
click to toggle source
# File lib/paynow/client.rb, line 11 def initialize(body) @body = body end
Public Instance Methods
create_payment()
click to toggle source
# File lib/paynow/client.rb, line 15 def create_payment puts(raw_payment) logger.info("[PAYNOW] STARTED POST #{uri}") response = Net::HTTP.post(uri, payment_data,headers) decoded_response = URI.decode_www_form(response.read_body).to_h.transform_keys(&:to_sym) if response.code =~ /^[4-5]/ logger.error("[PAYNOW] ERROR GET #{uri} status=#{response.code} message=#{decoded_response.error}") else logger.info("[PAYNOW] COMPLETED GET #{uri} status=#{response.code} response=#{decoded_response}") end payment.new( raw_payment.merge( poll_url: decoded_response[:pollurl], paynow_redirect_url: decoded_response[:browserurl], status: decoded_response[:status] ) ) end
Private Instance Methods
_hash()
click to toggle source
# File lib/paynow/client.rb, line 56 def _hash Paynow::HashGenerator._hmac(raw_payment) end
headers()
click to toggle source
# File lib/paynow/client.rb, line 60 def headers {'content-type': 'application/x-www-form-urlencoded'} end
logger()
click to toggle source
# File lib/paynow/client.rb, line 72 def logger Paynow::Config.logger end
payment()
click to toggle source
# File lib/paynow/client.rb, line 64 def payment Paynow::Config.payment end
payment_builder()
click to toggle source
# File lib/paynow/client.rb, line 68 def payment_builder Paynow::Config.payment_builder end
payment_data()
click to toggle source
# File lib/paynow/client.rb, line 48 def payment_data URI.encode_www_form(raw_payment.merge({hash: _hash})) end
raw_payment()
click to toggle source
# File lib/paynow/client.rb, line 52 def raw_payment payment_builder.build(body) end
uri()
click to toggle source
# File lib/paynow/client.rb, line 40 def uri if raw_payment.has_key?(:method) URI(Paynow::Config.initiate_express_transaction_url) else URI(Paynow::Config.initiate_transaction_url) end end