app/models/gateway_notification.rb in supercharged-2.0.4 vs app/models/gateway_notification.rb in supercharged-2.1.0
- old
+ new
@@ -10,11 +10,17 @@
before_create :set_charge_id
attr_accessor :raw_post, :logger
def acknowledge
- adapter.acknowledge
+ res = adapter.acknowledge
+
+ if charge_id.nil? && adapter.item_id
+ update_column(:charge_id, adapter.item_id)
+ end
+
+ res
end
def complete?
adapter.complete?
end
@@ -26,30 +32,29 @@
def success_response
adapter.respond_to?(:success_response) ? adapter.success_response : "OK"
end
def approve
+ raise EmptyChargeIdError unless charge_id
+
logger.info "real amount = #{real_amount}"
charge.approve(real_amount) unless charge.ok?
end
def real_amount
- params[service.mappings[:amount]]
+ adapter.gross
end
private
def adapter
@adapter ||= "ActiveMerchant::Billing::Integrations::#{gateway.classify}::Notification".classify.constantize.new(raw_post)
rescue NameError
raise "Unknown integration '#{gateway}'"
end
- def service
- "ActiveMerchant::Billing::Integrations::#{gateway.classify}::Helper".classify.constantize
- end
-
def set_charge_id
- self.charge_id = adapter.item_id || raise(EmptyChargeIdError)
+ self.charge_id ||= adapter.item_id
+ true
end
end