Class: SubscriptionFu::Transaction
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SubscriptionFu::Transaction
- Defined in:
- app/models/subscription_fu/transaction.rb
Class Method Summary collapse
- .create_activation(gateway, initiator) ⇒ Object
- .create_cancellation(initiator, related_transaction, subscription) ⇒ Object
Instance Method Summary collapse
- #abort ⇒ Object
- #complete(opts = {}) ⇒ Object
- #initiator_email ⇒ Object
-
#needs_authorization? ⇒ Boolean
billing API.
- #start_checkout(return_url, cancel_url) ⇒ Object
Class Method Details
.create_activation(gateway, initiator) ⇒ Object
20 21 22 |
# File 'app/models/subscription_fu/transaction.rb', line 20 def self.create_activation(gateway, initiator) create!(:initiator => initiator, :gateway => gateway, :status => 'initiated', :action => "activation") end |
.create_cancellation(initiator, related_transaction, subscription) ⇒ Object
24 25 26 27 |
# File 'app/models/subscription_fu/transaction.rb', line 24 def self.create_cancellation(initiator, , subscription) gateway = subscription.paypal_profile_id.blank? ? 'nogw' : 'paypal' create!(:initiator => initiator, :gateway => gateway, :status => 'initiated', :action => "cancellation", :related_transaction => ) end |
Instance Method Details
#abort ⇒ Object
84 85 86 87 88 89 |
# File 'app/models/subscription_fu/transaction.rb', line 84 def abort raise "abort only available in initiated state, but: #{status}" unless status == "initiated" update_attributes(:status => "aborted") .each { |t| t.abort } true end |
#complete(opts = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/subscription_fu/transaction.rb', line 48 def complete(opts = {}) raise "complete only available in initiated state, but: #{status}" unless status == "initiated" success = true begin send("complete_#{action}_#{gateway}", opts) update_attributes!(:status => "complete") rescue Exception => err data = { :subscription => subscription.inspect, :transaction => self.inspect } if err.instance_of?(Paypal::Exception::APIError) data[:paypal_response] = err.response.inspect data[:paypal_error_message] = err. elsif err.instance_of?(Paypal::Exception::HttpError) data[:http_error_code] = err.code data[:http_error_message] = err. end if defined? ::ExceptionNotifier ::ExceptionNotifier::Notifier.background_exception_notification(err, :data => data).deliver elsif defined? ::HoptoadNotifier ::HoptoadNotifier.notify(err, :parameters => data) else logger.info("could not complete #{action} on #{gateway}") logger.info("details: #{data.inspect}") logger.warn(err) logger.debug(err.backtrace.join("\n")) end update_attributes!(:status => "failed") .each { |t| t.abort } success = false end success end |
#initiator_email ⇒ Object
29 30 31 |
# File 'app/models/subscription_fu/transaction.rb', line 29 def initiator_email initiator.email if initiator.respond_to?(:email) end |
#needs_authorization? ⇒ Boolean
billing API
35 36 37 |
# File 'app/models/subscription_fu/transaction.rb', line 35 def gateway == "paypal" && action == "activation" end |
#start_checkout(return_url, cancel_url) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/models/subscription_fu/transaction.rb', line 39 def start_checkout(return_url, cancel_url) raise "start_checkout is only for activation" unless action == "activation" raise "start_checkout is only for non-activated subscriptions" if sub_activated? raise "start_checkout already called once, have a token" unless identifier.blank? raise "start_checkout only available in initiated state, but: #{status}" unless status == "initiated" send("start_checkout_#{gateway}", return_url, cancel_url) end |