class SimplePayment::Payment
Public Instance Methods
cancel!()
click to toggle source
Cancel a payment that is approved, but not settled
# File lib/simple_payment/models/payment.rb, line 74 def cancel! return unless approved? request, response = gateway.cancel self _cancel! if response.success? persist_transaction request, response true rescue TransmissionError => e handle_error 'cancel', e end
complete!()
click to toggle source
Calls the gateway to see if an approved payment has been completed
# 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 'complete', e end
execute!(nonce)
click to toggle source
Calls the gateway to execute the payment, saving the communication details and status change to the model
# 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 'execute', e false end
refund!()
click to toggle source
Refund payment that is settled
# File lib/simple_payment/models/payment.rb, line 85 def refund! puts "refund! #{status}" return unless completed? request, response = gateway.refund self _refund! if response.success? persist_transaction request, response true rescue TransmissionError => e handle_error 'refund', e end
Private Instance Methods
gateway()
click to toggle source
# File lib/simple_payment/models/payment.rb, line 106 def gateway SimplePayment::gateway end
handle_error(request, error)
click to toggle source
# File lib/simple_payment/models/payment.rb, line 100 def handle_error(request, error) transactions.create! \ request: request, error: error.serialize end
persist_transaction(request, response)
click to toggle source
# File lib/simple_payment/models/payment.rb, line 110 def persist_transaction(request, response) transactions.create! \ request: request.serialize, response: response.serialize end