Created
November 8, 2012 15:00
-
-
Save v-fedorov/4039308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spree | |
class PaypalExpressCallbacksController < Spree::BaseController | |
include ActiveMerchant::Billing::Integrations | |
skip_before_filter :verify_authenticity_token | |
require 'httparty' | |
require 'json' | |
ssl_required | |
def notify | |
retrieve_details #need to retreive details first to ensure ActiveMerchant gets configured correctly. | |
@notification = Paypal::Notification.new(request.raw_post) | |
# we only care about eChecks (for now?) | |
if @notification.params["payment_type"] == "echeck" && @notification.acknowledge && @payment && @order.total >= @payment.amount | |
@payment.started_processing! | |
@payment.log_entries.create(:details => @notification.to_yaml) | |
case @notification.params["payment_status"] | |
when "Denied" | |
@payment.failure! | |
when "Completed" | |
@payment.complete! | |
end | |
end | |
render :nothing => true | |
end | |
def shipping_estimate | |
# if request.post? | |
# @method = params[:METHOD] | |
# @version = params[:CALLBACKVERSION] | |
# @token = params[:TOKEN] | |
# @currency = params[:CURRENCYCODE] | |
# @locale = params[:LOCALECODE] | |
# @street = params[:SHIPTOSTREET] | |
# @street2 = params[:SHIPTOSTREET2] | |
# @city = params[:SHIPTOCITY] | |
# @state = params[:SHIPTOSTATE] | |
# @country = params[:SHIPTOCOUNTRY] | |
# @zip = params[:SHIPTOZIP] | |
# end | |
# estimate_shipping_and_taxes | |
# payment_methods_atts = @rate_hash.map do |shipping_method| | |
# { :name => "#{shipping_method.name}", | |
# :amount => (shipping_method.cost), | |
# :default => false } | |
# end | |
# Rails.logger.debug "#{payment_methods_atts}" | |
render :text => "METHOD=CallbackResponse&OFFERINSURANCEOPTION=true&L_SHIPPINGOPTIONNAME0=UPSAir&L_SHIPPINGOPTIONAMOUNT0=20.00&L_TAXAMT0=2.20&L_INSURANCEAMOUNT0=1.51&L_SHIPPINGOPTIONISDEFAULT0=false&L_SHIPPINGOPTIONNAME1=UPS&L_SHIPPINGOPTIONAMOUNT1=10.00&L_TAXAMT1=2.00&L_INSURANCEAMOUNT1=1.35&L_SHIPPINGOPTIONISDEFAULT1=true&L_SHIPPINGOPTIONNAME2=UPSGround2&L_SHIPPINGOPTIONAMOUNT2=9.99&L_TAXAMT2=1.99&L_INSURANCEAMOUNT2=1.28&L_SHIPPINGOPTIONISDEFAULT2=false" | |
end | |
private | |
def retrieve_details | |
@order = Spree::Order.find_by_number(params["invoice"]) | |
if @order | |
@payment = @order.payments.where(:state => "pending", :source_type => "PaypalAccount").try(:first) | |
@payment.try(:payment_method).try(:provider) #configures ActiveMerchant | |
end | |
end | |
def estimate_shipping_and_taxes | |
@order = Spree::Order.find_by_number("R213772423") | |
zipcode=@zip | |
shipping_methods=Spree::ShippingMethod.all | |
#TODO remove hard coded shipping | |
#Make a deep copy of the order object then stub out the parts required to get a shipping quote | |
@shipping_order=Marshal::load(Marshal.dump(@order)) #Make a deep copy of the order object | |
@shipping_order.ship_address=Spree::Address.new(:country => Spree::Country.find_by_iso('US'), :zipcode => zipcode) | |
shipment=Spree::Shipment.new(:address => @shipping_order.ship_address) | |
@shipping_order.ship_address.shipments<<shipment | |
@shipping_order.shipments<<shipment | |
@rate_hash = @shipping_order.rate_hash | |
#TODO | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment