Class: PayCertify::Confirmation

Inherits:
Object
  • Object
show all
Defined in:
lib/paycertify/confirmation.rb

Defined Under Namespace

Classes: NoCredentialsError, Response

Constant Summary collapse

API_ENDPOINT =
'https://www.paycertify.com/'
MANDATORY_FIELDS =
[
  :transaction_id, :cc_last_four_digits, :name, :email, 
  :phone, :amount, :currency, :payment_gateway
]
OPTIONAL_FIELDS =
[
  :status, :transaction_date, :order_description, :card_type, :name_on_card, 
  :address, :city, :zip, :state, :country, :confirmation_type, :fraud_score_processing, :scheduled_messages, 
  :thank_you_page_url, :metadata
]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Confirmation

Returns a new instance of Confirmation.

Raises:



23
24
25
26
27
28
29
30
# 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

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



53
54
55
# File 'lib/paycertify/confirmation.rb', line 53

def api_key
  @api_key
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



19
20
21
# File 'lib/paycertify/confirmation.rb', line 19

def attributes
  @attributes
end

#errorsObject

Returns the value of attribute errors.



19
20
21
# File 'lib/paycertify/confirmation.rb', line 19

def errors
  @errors
end

#responseObject

Returns the value of attribute response.



19
20
21
# File 'lib/paycertify/confirmation.rb', line 19

def response
  @response
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



55
56
57
# File 'lib/paycertify/confirmation.rb', line 55

def configure(&block)
  yield self if block_given?
end

Instance Method Details

#start!Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/paycertify/confirmation.rb', line 32

def success?
  response.success?
end