Class: PaypalAdaptivePaymentAccount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PaypalAdaptivePaymentAccount
- Defined in:
- app/models/paypal_adaptive_payment_account.rb
Overview
Instance Method Summary collapse
- #actions ⇒ Object
- #can_capture?(payment) ⇒ Boolean
- #can_credit?(payment) ⇒ Boolean
- #capture(payment) ⇒ Object
- #credit(payment, amount = nil) ⇒ Object
- #echeck?(payment) ⇒ Boolean
-
#payment_gateway ⇒ Object
fix for Payment#payment_profiles_supported?.
- #record_log(payment, response) ⇒ Object
Instance Method Details
#actions ⇒ Object
5 6 7 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 5 def actions %w{capture credit} end |
#can_capture?(payment) ⇒ Boolean
22 23 24 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 22 def can_capture?(payment) !echeck?(payment) && payment.state == "PENDING" end |
#can_credit?(payment) ⇒ Boolean
43 44 45 46 47 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 43 def can_credit?(payment) return false unless payment.state == "COMPLETED" payment.credit_allowed > 0 !find_capture(payment).nil? end |
#capture(payment) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 9 def capture(payment) = (payment) ap_response = payment.payment_method.provider.capture((100 * payment.amount).to_i, .params["transaction"]["0"][".id"]) if ap_response.success? record_log payment, ap_response payment.complete else gateway_error(ap_response.) end end |
#credit(payment, amount = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 26 def credit(payment, amount=nil) = find_capture(payment) amount = payment.credit_allowed >= payment.order.outstanding_balance.abs ? payment.order.outstanding_balance : payment.credit_allowed ap_response = payment.payment_method.provider.credit(amount.nil? ? (100 * amount).to_i : (100 * amount).to_i, .params["transaction"]["0"][".id"]) if ap_response.success? record_log payment, ap_response payment.update_attribute(:amount, payment.amount - amount) payment.complete payment.order.update! else gateway_error(ap_response.) end end |
#echeck?(payment) ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 54 def echeck?(payment) logs = payment.log_entries.all(:order => 'created_at DESC') logs.each do |log| details = YAML.load(log.details) # return the transaction details if details.params['type'] == 'echeck' return true end end return false end |
#payment_gateway ⇒ Object
fix for Payment#payment_profiles_supported?
50 51 52 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 50 def payment_gateway false end |
#record_log(payment, response) ⇒ Object
65 66 67 |
# File 'app/models/paypal_adaptive_payment_account.rb', line 65 def record_log(payment, response) payment.log_entries.create(:details => response.to_yaml) end |