Class: PayCertify::Confirmation
- Inherits:
-
Object
- Object
- PayCertify::Confirmation
- 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
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Confirmation
constructor
A new instance of Confirmation.
- #start! ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(attributes) ⇒ Confirmation
Returns a new instance of Confirmation.
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_key ⇒ Object
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
#attributes ⇒ Object
Returns the value of attribute attributes.
19 20 21 |
# File 'lib/paycertify/confirmation.rb', line 19 def attributes @attributes end |
#errors ⇒ Object
Returns the value of attribute errors.
19 20 21 |
# File 'lib/paycertify/confirmation.rb', line 19 def errors @errors end |
#response ⇒ Object
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
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
32 33 34 |
# File 'lib/paycertify/confirmation.rb', line 32 def success? response.success? end |