Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring: models. order has_many payment_notifications and that's …

…all we need
  • Loading branch information...
commit 2ef5cbe249a8f3541271136f7f0af2fdc7293ded 1 parent 743b482
@tomash tomash authored
View
36 app/controllers/paypal_payment_notifications_controller.rb
@@ -0,0 +1,36 @@
+class PaypalPaymentNotificationsController < CheckoutController
+ protect_from_forgery :except => [:create]
+ skip_before_filter :restriction_access
+
+ def create
+ @order = Order.find_by_number(params[:invoice])
+ PaymentNotification.create!(:params => params,
+ :order_id => Order.number_eq(params[:invoice]).first,
+ :status => params[:payment_status],
+ :transaction_id => params[:txn_id])
+
+ # this logging stuff won't live here for long...
+
+ logger.info("created PP Notification for order #{@order.number} (#{@order.id}). thread #{Thread.current.to_s}")
+
+ Order.transaction do
+ # main part of hacks
+ order = @order
+ order.payment.complete
+ logger.info("order #{order.number} (#{order.id}) -- completed payment")
+ while order.state != "complete"
+ logger.info("advancing state of Order #{order.number} (#{order.id}). current state #{order.state}. thread #{Thread.current.to_s}")
+ order.next
+ logger.info("advanced state of Order #{order.number} (#{order.id}). current state #{order.state}. thread #{Thread.current.to_s}. issuing callback")
+ state_callback(:after) # that line will run all _not run before_ callbacks
+ logger.info("Order #{order.number} (#{order.id}) -- callback complete")
+ end
+ order.update_totals
+ order.update!
+ logger.info("Order #{order.number} (#{order.id}) updated successfully, IPN complete")
+ end
+
+ render :nothing => true
+ end
+
+end
View
4 app/models/order_decorator.rb
@@ -1,5 +1,5 @@
-Order.class_eval do
- has_many :paypal_payments
+Order.class_eval do
+ has_many :payment_notifications
def shipment_cost
adjustment_total - credit_total
View
14 app/models/payment_notification.rb
@@ -0,0 +1,14 @@
+class PaymentNotification < ActiveRecord::Base
+ belongs_to :order
+ serialize :params
+ after_create :mark_order_as_paid
+
+ private
+
+ def mark_order_as_paid
+ if(status == "Completed")
+ logger.info "Order #{self.order.number} should be marked as paid now -- IPN status 'Completed'"
+ #order.update_attributes({:paid_on => Date.today, :status_id => Status.PAID.id})
+ end
+ end
+end
View
4 app/models/paypal_payment.rb
@@ -1,4 +0,0 @@
-class PaypalPayment < Payment
- has_many :paypal_txns
- alias :txns :paypal_txns
-end
View
4 app/models/paypal_txn.rb
@@ -1,4 +0,0 @@
-class PaypalTxn < ActiveRecord::Base
- belongs_to :paypal_payment
- validates_numericality_of :amount
-end
Please sign in to comment.
Something went wrong with that request. Please try again.