app/models/subscription_fu/transaction.rb in subscription_fu-0.2.1 vs app/models/subscription_fu/transaction.rb in subscription_fu-0.3.0

- old
+ new

@@ -52,12 +52,15 @@ begin send("complete_#{action}_#{gateway}", opts) update_attributes!(:status => "complete") rescue Exception => err if defined? ::ExceptionNotifier - data = (err.respond_to?(:data) ? err.data : {}).merge(:subscription => subscription.inspect, :transaction => self.inspect) + data = {:api_response => err.respond_to?(:response) ? err.response : nil, :subscription => subscription.inspect, :transaction => self.inspect} ::ExceptionNotifier::Notifier.background_exception_notification(err, :data => data).deliver + elsif defined? ::HoptoadNotifier + data = {:subscription => subscription.inspect, :transaction => self.inspect} + ::HoptoadNotifier.notify(err, :parameters => data) else logger.warn(err) logger.debug(err.backtrace.join("\n")) end update_attributes!(:status => "failed") @@ -123,13 +126,20 @@ t.complete(:effective => sub_starts_at, :reason => :update) end end def complete_cancellation_paypal(opts) - # update the record beforehand, because paypal raises an error if - # the profile is already cancelled + begin + SubscriptionFu::Paypal.express_request.renew!(sub_paypal_profile_id, :Cancel, :note => sub_cancel_reason) + rescue Paypal::Exception::APIError => err + if err.response.details.all?{|d| d.error_code == "11556"} + # 11556 - Invalid profile status for cancel action; profile should be active or suspended + logger.info("Got '#{err.response.details.inspect}' from paypal which indicates profile wasn't active (any more)...") + else + raise err + end + end complete_cancellation(opts) - SubscriptionFu::Paypal.express_request.renew!(sub_paypal_profile_id, :Cancel, :note => sub_cancel_reason) end def complete_cancellation_nogw(opts) complete_cancellation(opts) end