Permalink
Browse files

PPX and more

  • Loading branch information...
1 parent cb675ee commit 4fd47b56bd77b8935fda2359854f37c8a27ace5c @BDQ BDQ committed Feb 11, 2011
View
@@ -7,7 +7,7 @@ gem 'rails', '3.0.3'
gem 'mysql'
gem 'spree', :git => 'git://github.com/spree/spree.git'
-#gem 'spree', :path => '../spree-r3'
+#gem 'spree', :path => '../spree'
gem 'aws-s3'
gem 'jammit', '0.6.0'
@@ -20,6 +20,8 @@ gem 'spree_wishlist', :git => 'git://github.com/spree/spree_wishlist.git', :bran
gem 'spree_static_content', :git => 'git://github.com/spree/spree-static-content.git'
gem 'spree_editor', :git => 'git://github.com/divineforest/spree_editor.git'
gem 'spree_active_shipping', :git => 'git://github.com/spree/spree_active_shipping.git'
+gem 'spree_paypal_express', :git => 'git://github.com/spree/spree_paypal_express.git'
+#gem 'spree_paypal_express', :path => '../spree_paypal_express'
gem 'hoe', '2.8.0' #prevents requirement of rubygem 1.4.0 - which is not supported by heroku
View
@@ -32,7 +32,7 @@ GIT
GIT
remote: git://github.com/spree/spree.git
- revision: 314e30439ee31b79b67cceea01898c51125534eb
+ revision: bd08981d439f62734045991b7cd58101ef380be2
specs:
spree (0.50.99)
spree_api (= 0.50.99)
@@ -53,11 +53,11 @@ GIT
faker (= 0.9.4)
highline (= 1.5.1)
jquery-rails (= 0.2.6)
+ meta_search (= 1.0.1)
paperclip (= 2.3.8)
rails (= 3.0.3)
rd_awesome_nested_set (= 1.4.4)
rd_resource_controller
- rd_searchlogic (= 3.0.1)
rd_unobtrusive_date_picker (= 0.1.0)
state_machine (= 0.9.4)
stringex (= 1.0.3)
@@ -71,14 +71,21 @@ GIT
GIT
remote: git://github.com/spree/spree_active_shipping.git
- revision: 5f94a7644a5d0de2f9bd756bf496ae3d1055e1ce
+ revision: 322c61f474b7df313f9a563bf63066fd8c6198ca
specs:
spree_active_shipping (1.0.0)
active_shipping (= 0.9.3)
activemerchant (= 1.9.0)
spree_core (>= 0.30.1)
GIT
+ remote: git://github.com/spree/spree_paypal_express.git
+ revision: fbda454048067c50faebbe8f1b445d9d0563ba0e
+ specs:
+ spree_paypal_express (1.0.0)
+ spree_core (>= 0.40.3)
+
+GIT
remote: git://github.com/spree/spree_related_products.git
revision: cc13984edf5d90eaf561dfb440b6353d750c90f3
specs:
@@ -141,7 +148,7 @@ GEM
activesupport (3.0.3)
acts_as_list (0.1.2)
addressable (2.2.4)
- arel (2.0.7)
+ arel (2.0.8)
aws-s3 (0.6.2)
builder
mime-types
@@ -222,6 +229,11 @@ GEM
treetop (~> 1.4.8)
mailfactory (1.4.0)
mime-types (>= 1.13.1)
+ meta_search (1.0.1)
+ actionpack (~> 3.0.2)
+ activerecord (~> 3.0.2)
+ activesupport (~> 3.0.2)
+ arel (~> 2.0.2)
mime-types (1.16)
multi_json (0.0.5)
multipart-post (1.1.0)
@@ -269,8 +281,6 @@ GEM
rd_awesome_nested_set (1.4.4)
activerecord (>= 1.1)
rd_resource_controller (1.0.1)
- rd_searchlogic (3.0.1)
- activerecord (>= 3.0.0)
rd_unobtrusive_date_picker (0.1.0)
recaptcha (0.3.1)
rspec (2.4.0)
@@ -346,6 +356,7 @@ DEPENDENCIES
spree_active_shipping!
spree_editor!
spree_email_to_friend
+ spree_paypal_express!
spree_recently_viewed!
spree_related_products!
spree_social!
@@ -3,7 +3,7 @@
before_filter :body_id
def update_registration
- current_order.state = "address_and_payment"
+ current_order.state = "payment"
if current_order.update_attributes(params[:order])
redirect_to checkout_path
else
@@ -12,6 +12,36 @@ def update_registration
end
end
+ #overriden the handle ppx payment/redirect
+ def update
+ if @order.update_attributes(object_params)
+
+ if @order.confirm? && @order.payment.payment_method.is_a?(BillingIntegration::PaypalExpress)
+ @order.create_shipment! #in case shipping method has changed
+
+ redirect_to paypal_payment_order_checkout_url @order, :payment_method_id => @order.payment.payment_method
+ else
+ if @order.next
+ state_callback(:after)
+ else
+ flash[:error] = I18n.t(:payment_processing_failed)
+ redirect_to checkout_state_path(@order.state) and return
+ end
+
+ if @order.state == "complete" || @order.completed?
+ flash[:notice] = I18n.t(:order_processed_successfully)
+ flash[:commerce_tracking] = "nothing special"
+ redirect_to completion_route
+ else
+ redirect_to checkout_state_path(@order.state)
+ end
+ end
+
+ else
+ render :edit
+ end
+ end
+
def set_shipping
if @order.update_attributes(object_params)
@order.create_shipment!
@@ -21,19 +51,22 @@ def set_shipping
end
private
+ def redirect_to_paypal_express_form_if_needed
+ #just overrides method from ext
+ end
def object_params
# For payment step, filter order parameters to produce the expected nested attributes for a single payment and its source, discarding attributes for payment methods other than the one selected
- if @order.address_and_payment? && params.key?(:payment_source)
+ if @order.payment? && params.key?(:payment_source)
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
params[:order][:payments_attributes].first[:source_attributes] = source_params
+ params[:order][:payments_attributes].first[:source_attributes][:first_name] = params[:order][:bill_address_attributes][:firstname]
+ params[:order][:payments_attributes].first[:source_attributes][:last_name] = params[:order][:bill_address_attributes][:lastname]
end
- if (params[:order][:payments_attributes])
+
+ if params[:order][:payments_attributes]
params[:order][:payments_attributes].first[:amount] = @order.total
end
- params[:order][:payments_attributes].first[:source_attributes][:first_name] = params[:order][:bill_address_attributes][:firstname]
- params[:order][:payments_attributes].first[:source_attributes][:last_name] = params[:order][:bill_address_attributes][:lastname]
- params[:order]
end
params[:order]
end
@@ -42,13 +75,12 @@ def body_id
@body_id = "checkout"
end
- def before_address_and_payment
+ def before_payment
before_address
- before_payment
+ current_order.payments.destroy_all if request.put?
end
-
- def before_shipping_and_confirm
+ def before_confirm
before_delivery
end
@@ -1,7 +1,7 @@
module CheckoutHelper
def checkout_progress
- states = %w(address_and_payment delivery_and_confirm complete)
+ states = %w(payment confirm complete)
items = states.map do |state|
text = t("order_state.#{state}").titleize
@@ -5,9 +5,9 @@
# custom checkout steps
event :next do
- transition :from => 'cart', :to => 'address_and_payment'
- transition :from => 'address_and_payment', :to => 'shipping_and_confirm'
- transition :from => 'shipping_and_confirm', :to => 'complete'
+ transition :from => 'cart', :to => 'payment'
+ transition :from => 'payment', :to => 'confirm'
+ transition :from => 'confirm', :to => 'complete'
end
event :cancel do
@@ -36,22 +36,22 @@
end
after_transition :to => 'complete', :do => :finalize!
- after_transition :to => 'shipping_and_confirm', :do => :create_tax_charge!
- after_transition :to => 'shipping_and_confirm', :do => :create_shipment!
+ after_transition :to => 'confirm', :do => :create_tax_charge!
+ after_transition :to => 'confirm', :do => :create_shipment!
after_transition :to => 'canceled', :do => :after_cancel
end
def create_shipment!
- shipping_method ||= available_shipping_methods.first
+ self.shipping_method ||= available_shipping_methods.first
save
if shipment.present?
- shipment.update_attributes(:shipping_method => shipping_method)
+ shipment.shipping_method = shipping_method
+ shipment.save
else
self.shipments << Shipment.create(:order => self, :shipping_method => shipping_method, :address => self.ship_address)
end
end
-
end
@@ -1,7 +1,7 @@
<div id="tabs" role="tabs">
<ul>
<li <%= controller.action_name == "registration" ? "class='active'" : "" %>><span class="number">1</span><span class="title">Create an Account</span></li>
- <li <%= @order.address_and_payment? && controller.action_name != "registration" ? "class='active'" : "" %>><span class="number">2</span><span class="title">Shipping &amp; Billing</span></li>
- <li <%= @order.shipping_and_confirm? && controller.action_name != "registration" ? "class='active number'" : "class=number" %>><span class="number">3</span><span class="title">Place Order</span></li>
+ <li <%= @order.payment? && controller.action_name != "registration" ? "class='active'" : "" %>><span class="number">2</span><span class="title">Shipping &amp; Billing</span></li>
+ <li <%= @order.confirm? && controller.action_name != "registration" ? "class='active number'" : "class=number" %>><span class="number">3</span><span class="title">Place Order</span></li>
</ul>
</div>
@@ -7,7 +7,7 @@
$(this).find("option[value='" + shipping_method_id + "']").html("Updating...");
$(this).attr('disabled', 'disabled');
- $.post("/checkout/update/set_shipping", { state: "address_and_payment", "order[shipping_method_id]": shipping_method_id },
+ $.post("/checkout/update/set_shipping", { state: "payment", "order[shipping_method_id]": shipping_method_id },
function(data){
var table = $('table.total tbody');
table.html('');
@@ -71,21 +71,31 @@
<% end %>
<%= address.country.try(:name) %> <%= address.zipcode %>
</p>
- <%= link_to "edit", checkout_state_path('address_and_payment') %>
+ <%= link_to "edit", checkout_state_path('payment') %>
</div>
<% end %>
<div id="order-payment" style="padding:30px 30px 30px 0; clear:both">
<h2>Payment Details</h2>
- <h4>Credit Card </h4>
- <%= @order.payment.source.name %><br />
- <%= @order.payment.source.display_number %>
- <%= link_to "edit", checkout_state_path('address_and_payment') %>
+ <h4><%= @order.payment.payment_method.name %></h4>
+
+ <% if @order.payment.payment_method.is_a? BillingIntegration::PaypalExpress %>
+ <p>You will be redirected to PayPal to complete your order.</p>
+ <% else %>
+ <%= @order.payment.source.name %><br />
+ <%= @order.payment.source.display_number %>
+ <% end %>
+
+ <%= link_to "edit", checkout_state_path('payment') %>
</div>
<div>
</div>
<div class="submit">
- <button class="blue" type="submit">Place your order</button>
+ <% if @order.payment.payment_method.is_a? BillingIntegration::PaypalExpress %>
+ <button class="blue" type="submit">Go To PayPal</button>
+ <% else %>
+ <button class="blue" type="submit">Place your order</button>
+ <% end %>
</div>
</div>
@@ -1,19 +1,11 @@
<% content_for :javascripts do %>
<%= javascript_include_tag 'checkout', '/states' %>
- <%= javascript_tag do %>
- (function($){
- $(document).ready(function(){
- //$('#checkout_form_address').validate();
- $('span#bcountry select').change(function() { update_state('b'); });
- $('span#scountry select').change(function() { update_state('s'); });
- update_state('b');
- update_state('s');
- });
- })(jQuery);
- <% end %>
<% end %>
+<%# for now just assign the first available shipping method - can be changed on next step %>
+<%= hidden_field_tag "order[shipping_method_id]", @order.available_shipping_methods.first.try(:id) %>
+
<div id="content" role="content">
<h2>Your Billing Information</h2>
<%= form.fields_for :bill_address do |bill_form| %>
@@ -157,17 +149,33 @@
<hr />
- <ul id="payment" class="fields">
- <%# assuming single payment method %>
- <%= hidden_field_tag "order[payments_attributes][][payment_method_id]", @order.available_payment_methods.first.try(:id) %>
+ <ul id="payment" class="fields">
+ <h2>Your prefered payment option</h2>
+ <% @order.available_payment_methods.each do |method| %>
+ <li class="options">
+ <%= radio_button_tag "order[payments_attributes][][payment_method_id]", method.id, method == @order.payment_method %>
+ <label><%= t(method.name, :scope => :payment_methods, :default => method.name) %></label>
+ </li>
+ <% end %>
- <%# assuming creditcard payment method %>
- <%= render "checkout/payment/gateway", :payment_method => @order.available_payment_methods.first %>
+ <hr />
- <%# for now just assign the first available shipping method - can be changed on next step %>
- <%= hidden_field_tag "order[shipping_method_id]", @order.available_shipping_methods.first.try(:id) %>
+ <% @order.available_payment_methods.each_with_index do |method, i| %>
+ <%= render "checkout/payment/#{method.method_type}", :payment_method => method, :checked => @order.try(:payment).try(:payment_method_id) %>
+ <% end %>
+ </ul>
+
+ <hr />
+
+ <ul class="fields">
+ <h2>Coupon Code</h2>
+ <li>
+ <p>If you've got a coupon code, please enter it below.</p>
+ <%= hook :coupon_code_text_field do %>
+ <% end %>
+ </li>
+ </ul>
- </ul>
<% end %>
<br />
<div class="submit"><button type="submit" class="blue">Review your order</button></div>
@@ -1,24 +1,25 @@
-<h2>Your Credit Card Information</h2>
+
<% param_prefix = "payment_source[#{payment_method.id}]" %>
-<li>
+<li class="payment_method <%= payment_method.id %>" style="display:<%= checked == payment_method.id ? "block" : "none" %>;">
+ <h2>Your Credit Card Information</h2>
<% ['mastercard', 'visa', 'american-express', 'discover'].each do |card| %>
<%= image_tag "dogradio/icons/#{card}-curved-32px.png", :alt => card.capitalize %>
<% end %>
</li>
-<li class="three-quart">
+<li class="payment_method <%= payment_method.id %> three-quart" style="display:<%= checked == payment_method.id ? "block" : "none" %>;">
<label>Credit card number</label>
<% options_hash = Rails.env.production? ? {:autocomplete => "off"} : {} %>
<%= text_field_tag "#{param_prefix}[number]", '', options_hash.merge(:class => 'required', :size => 19, :maxlength => 19) %>
</li>
-<li class="quart last">
+<li class="payment_method <%= payment_method.id %> quart last" style="display:<%= checked == payment_method.id ? "block" : "none" %>;">
<label>Security code</label>
<%= text_field_tag "#{param_prefix}[verification_value]", '', options_hash.merge(:class => 'required', :size => 5) %>
</li>
-<li>
+<li class="payment_method <%= payment_method.id %>" style="display:<%= checked == payment_method.id ? "block" : "none" %>;">
<label>Expiration</label>
<%= select_month(Date.today, {:prefix => param_prefix, :field_name => 'month', :use_month_numbers => true}, :class => 'required half') %>
<%= select_year(Date.today, {:prefix => param_prefix, :field_name => 'year', :start_year => Date.today.year, :end_year => Date.today.year + 15}, :class => 'required half last') %>
@@ -0,0 +1,4 @@
+<li class="payment_method <%= payment_method.id %>" style="display:<%= checked == payment_method.id ? "block" : "none" %>;">
+ <h2>Your PayPal Information</h2>
+ <p>You will be redirected to PayPal's website once you've completed the rest your checkout.</p>
+</li>
Oops, something went wrong.

0 comments on commit 4fd47b5

Please sign in to comment.