class PayCertify::Confirmation
Constants
- API_ENDPOINT
- MANDATORY_FIELDS
- OPTIONAL_FIELDS
Attributes
api_key[RW]
attributes[RW]
errors[RW]
response[RW]
Public Class Methods
configure() { |self| ... }
click to toggle source
# File lib/paycertify/confirmation.rb, line 55 def configure(&block) yield self if block_given? end
new(attributes)
click to toggle source
# File lib/paycertify/confirmation.rb, line 23 def initialize(attributes) raise NoCredentialsError, 'No api key provided.' unless api_key.present? self.attributes = HashWithIndifferentAccess.new(attributes) self.errors = {} validate! end
Public Instance Methods
start!()
click to toggle source
# File lib/paycertify/confirmation.rb, line 36 def start! data = attributes.slice *[MANDATORY_FIELDS + OPTIONAL_FIELDS].flatten api_response = connection.post do |request| request.url path_for('merchant/transactions') request.headers['Content-Type'] = 'application/json' request.headers['PAYCERTIFYKEY'] = api_key request.body = JSON.generate(data) end self.response = Response.new(api_response) self.errors = errors.merge(response) unless response.success? response end
success?()
click to toggle source
# File lib/paycertify/confirmation.rb, line 32 def success? response.success? end
Private Instance Methods
connection()
click to toggle source
# File lib/paycertify/confirmation.rb, line 82 def connection @connection ||= Faraday.new(url: API_ENDPOINT, ssl: {verify: false}) do |faraday| faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end end
path_for(path)
click to toggle source
# File lib/paycertify/confirmation.rb, line 90 def path_for(path) return "api/v1/" + path end
validate!()
click to toggle source
# File lib/paycertify/confirmation.rb, line 74 def validate! MANDATORY_FIELDS.each do |field| unless attributes[field].present? self.errors[field] = "Required attribute not present" end end end