Class: SimplePayment::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SimplePayment::Payment
- Includes:
- AASM
- Defined in:
- lib/simple_payment/models/payment.rb
Instance Method Summary collapse
-
#cancel! ⇒ Object
Calls the gateway to cancel an approved payment or to refund a completed payment.
-
#complete! ⇒ Object
Calls the gateway to see if an approved payment has been completed.
-
#execute!(nonce) ⇒ Object
Calls the gateway to execute the payment, saving the communication details and status change to the model.
- #refund! ⇒ Object
Instance Method Details
#cancel! ⇒ Object
Calls the gateway to cancel an approved payment or to refund a completed payment.
75 76 77 78 79 80 81 82 |
# File 'lib/simple_payment/models/payment.rb', line 75 def cancel! return unless approved? request, response = gateway.cancel self _cancel! if response.success? persist_transaction request, response rescue TransmissionError => e handle_error e end |
#complete! ⇒ Object
Calls the gateway to see if an approved payment has been completed
65 66 67 68 69 70 71 |
# File 'lib/simple_payment/models/payment.rb', line 65 def complete! return unless may__complete? _complete! if gateway.completed?(self) rescue TransmissionError => e handle_error e end |
#execute!(nonce) ⇒ Object
Calls the gateway to execute the payment, saving the communication details and status change to the model
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/simple_payment/models/payment.rb', line 45 def execute!(nonce) return unless may__approve? request, response = gateway.execute(self, nonce) if response.success? _approve else _fail end self.external_id ||= response.external_id self.external_fee = gateway.calculate_fee(self) save! persist_transaction request, response response.success? rescue TransmissionError => e handle_error e false end |
#refund! ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/simple_payment/models/payment.rb', line 84 def refund! return unless completed? request, response = gateway.refund self _refund! if response.success? persist_transaction request, response rescue TransmissionError => e handle_error e end |