Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

checking out with skrill during payment step

  • Loading branch information...
commit 0b0de91b657c8d3e875614c7d6634a6da41d2ce8 1 parent 5742c8e
Chris Mar cmar authored
37 app/controllers/spree/checkout_controller_decorator.rb
View
@@ -1,17 +1,9 @@
module Spree
CheckoutController.class_eval do
- def skrill_cancel
- flash[:error] = t(:payment_has_been_cancelled)
- redirect_to edit_order_checkout_url(@order, :state => 'payment')
- end
-
- def skrill_success
- @order = Order.where(:number => params[:order_id]).first
-
- if @order.token == params[:token]
-
- if @order.payments.where(:source_type => 'SkrillAccount').present?
+ before_filter :confirm_skrill, :only => [:update]
+ def skrill_return
+ if @order.payments.where(:source_type => 'Spree::SkrillTransaction').present?
#need to force checkout to complete state
until @order.state == "complete"
if @order.next!
@@ -19,14 +11,29 @@ def skrill_success
state_callback(:after)
end
end
- end
-
- flash.notice = t(:order_processed_successfully)
- redirect_to completion_route
+ flash.notice = t(:order_processed_successfully)
+ redirect_to completion_route
else
redirect_to root_url
end
+ end
+ def skrill_cancel
+ flash[:error] = t(:payment_has_been_cancelled)
+ redirect_to edit_order_path(@order)
end
+
+ private
+ def confirm_skrill
+ return unless (params[:state] == "payment") && params[:order][:payments_attributes]
+
+ payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
+ if payment_method.kind_of?(BillingIntegration::Skrill::QuickCheckout)
+ #TODO confirming payment method
+ redirect_to edit_order_checkout_url(@order, :state => 'payment'),
+ :notice => t(:complete_skrill_checkout)
+ end
+ end
+
end
end
14 app/controllers/spree/skrill_status_controller.rb
View
@@ -1,12 +1,16 @@
module Spree
class SkrillStatusController < ApplicationController
def update
- payment_id = params[:transaction_id].split('-').last
+ @order = Order.find_by_number!(params[:order_id])
+ payment_method = PaymentMethod.find(params[:payment_method_id])
+ skrill_transaction = SkrillTransaction.create_from_postback params
- payment = Payment.find(payment_id)
-
- unless payment.completed?
+ payment = @order.payments.create(:amount => @order.total,
+ :source => skrill_transaction,
+ :payment_method => payment_method)
+ payment.started_processing!
+ unless payment.completed?
case params[:status]
when "0"
payment.pend #may already be pending
@@ -17,10 +21,10 @@ def update
else
raise "Unexpected payment status"
end
-
end
render :text => ""
end
+
end
end
31 app/helpers/spree/checkout_helper_decorator.rb
View
@@ -1,31 +0,0 @@
-module Spree
- CheckoutHelper.module_eval do
- def checkout_progress
- states = checkout_states
- items = states.map do |state|
- text = t("order_state.#{state}").titleize
-
- css_classes = []
- if @order.skrill?
- current_index = states.index('payment')
- else
- current_index = states.index(@order.state)
- end
- state_index = states.index(state)
-
- if state_index < current_index
- css_classes << 'completed'
- text = link_to text, checkout_state_path(state)
- end
-
- css_classes << 'next' if state_index == current_index + 1
- css_classes << 'current' if state == @order.state
- css_classes << 'first' if state_index == 0
- css_classes << 'last' if state_index == states.length - 1
- # It'd be nice to have separate classes but combining them with a dash helps out for IE6 which only sees the last class
- content_tag('li', content_tag('span', text), :class => css_classes.join('-'))
- end
- content_tag('ol', raw(items.join("\n")), :class => 'progress-steps', :id => "checkout-step-#{@order.state}")
- end
- end
-end
7 app/models/spree/billing_integration/skrill/quick_checkout.rb
View
@@ -15,22 +15,23 @@ def redirect_url(order, opts = {})
set_global_options(opts)
opts[:detail1_text] = order.number
- opts[:detail1_description] = 'Order Number:'
+ opts[:detail1_description] = "#{rand(999)} Order Number:"
opts[:pay_from_email] = order.email
opts[:firstname] = order.bill_address.firstname
opts[:lastname] = order.bill_address.lastname
opts[:address] = order.bill_address.address1
opts[:address2] = order.bill_address.address2
- opts[:phone_number] = order.bill_address.phone
+ opts[:phone_number] = order.bill_address.phone.gsub(/\D/,'') if order.bill_address.phone
opts[:city] = order.bill_address.city
opts[:postal_code] = order.bill_address.zipcode
opts[:state] = order.bill_address.state.nil? ? order.bill_address.state_name.to_s : order.bill_address.state.abbr
opts[:country] = order.bill_address.country.name
opts[:hide_login] = 1
- opts[:merchant_fields] = 'platform'
+ opts[:merchant_fields] = 'platform,order_id,payment_method_id'
opts[:platform] = 'Spree'
+ opts[:order_id] = order.number
skrill = self.provider
skrill.payment_url(opts)
9 app/models/spree/skrill_account.rb
View
@@ -1,9 +0,0 @@
-module Spree
- class SkrillAccount < ActiveRecord::Base
- has_many :payments, :as => :source
-
- def actions
- []
- end
- end
-end
19 app/models/spree/skrill_transaction.rb
View
@@ -0,0 +1,19 @@
+module Spree
+ class SkrillTransaction < ActiveRecord::Base
+ has_many :payments, :as => :source
+
+ def actions
+ []
+ end
+
+ def self.create_from_postback(params)
+ SkrillTransaction.create(:email => params[:pay_from_email],
+ :amount => params[:mb_amount],
+ :currency => params[:mb_currency],
+ :transaction_id => params[:mb_transaction_id],
+ :customer_id => params[:customer_id],
+ :payment_type => params[:payment_type])
+ end
+
+ end
+end
4 app/overrides/add_skrill_status_to_order_show.rb
View
@@ -1,4 +1,4 @@
-Deface::Override.new(:virtual_path => 'orders/show',
+Deface::Override.new(:virtual_path => 'spree/orders/show',
:name => 'add_skrill_status_to_order_show',
:insert_before => "code[erb-loud]:contains('shared/order_details')",
- :partial => 'shared/skrill_status')
+ :partial => 'spree/shared/skrill_status')
26 app/views/spree/checkout/_skrill.html.erb
View
@@ -1,26 +0,0 @@
-<%
-opts = {}
-opts[:transaction_id] = "#{@order.number}-#{@order.payment.id}"
-opts[:amount] = @order.payment.amount
-opts[:return_url] = skrill_success_order_checkout_url(@order, :token => @order.token)
-opts[:cancel_url] = skrill_cancel_order_checkout_url(@order, :token => @order.token)
-opts[:status_url] = skrill_status_update_url
-%>
-
-<fieldset id="skrill_payment" data-hook>
- <legend><%= t(:payment_information) %></legend>
- <iframe id="skrill_frame" src="<%= @order.payment_method.redirect_url @order, opts %>"></iframe>
-</fieldset>
-
-<p data-hook="change_payment_method">
- <%= link_to t(:change_payment_method), edit_order_checkout_url(@order, :state => 'payment') %>
-</p>
-
-<style>
- iframe#skrill_frame{
- border: 0px;
- width: 500px;
- height: 500px;
- }
-</style>
-
27 app/views/spree/checkout/payment/_quickcheckout.html.erb
View
@@ -1 +1,28 @@
<p data-hook="skrill_quick_checkout"></p>
+
+<%
+opts = {}
+opts[:transaction_id] = "#{@order.number}"
+opts[:amount] = @order.total
+opts[:return_url] = skrill_return_order_checkout_url(@order, :token => @order.token)
+opts[:cancel_url] = skrill_cancel_order_checkout_url(@order, :token => @order.token)
+opts[:status_url] = skrill_status_update_url
+opts[:payment_method_id] = payment_method.id
+%>
+
+<%= opts.inspect %>
+
+<style>
+ iframe.skrill_frame{
+ border: 0px;
+ width: 500px;
+ height: 500px;
+ }
+</style>
+
+<fieldset id="skrill_payment__<%= payment_method.id %>" data-hook>
+ <legend><%= t(:payment_information) %></legend>
+ <iframe id="skrill_frame_<%= payment_method.id %>"
+ class="skrill_frame" src="<%= payment_method.redirect_url @order, opts %>"></iframe>
+</fieldset>
+
1  config/locales/en.yml
View
@@ -1,3 +1,4 @@
en:
payment_has_been_cancelled: The payment has been cancelled.
change_payment_method: Change Payment Method
+ complete_skrill_checkout: Please complete Skrill checkout before continuing
2  config/routes.rb
View
@@ -4,7 +4,7 @@
resource :checkout, :controller => 'checkout' do
member do
get :skrill_cancel
- get :skrill_success
+ get :skrill_return
end
end
end
8 db/migrate/20111118164630_create_skrill_accounts.rb
View
@@ -1,8 +0,0 @@
-class CreateSkrillAccounts < ActiveRecord::Migration
- def change
- create_table :skrill_accounts do |t|
- t.string :email
- t.timestamps
- end
- end
-end
14 db/migrate/20111118164631_create_skrill_transactions.rb
View
@@ -0,0 +1,14 @@
+class CreateSkrillTransactions < ActiveRecord::Migration
+ def change
+ create_table :spree_skrill_transactions do |t|
+ t.string :email
+ t.float :amount
+ t.string :currency
+ t.integer :transaction_id
+ t.integer :customer_id
+ t.string :payment_type
+ t.timestamps
+ end
+ end
+end
+
21 lib/spree_skrill/engine.rb
View
@@ -10,27 +10,6 @@ class Engine < Rails::Engine
end
def self.activate
- Spree::Order.state_machine.states << skrill_state = StateMachine::State.new(Spree::Order.state_machine, 'skrill')
-
- Spree::Order.state_machine.events << next_event = StateMachine::Event.new(Spree::Order.state_machine, :next)
- next_event.transition :from => 'cart', :to => 'address'
- next_event.transition :from => 'address', :to => 'delivery'
- next_event.transition :from => 'delivery', :to => 'payment', :if => :payment_required?
- next_event.transition :from => 'payment', :to => 'skrill', :if => lambda {true}
- next_event.transition :from => 'skrill', :to => 'complete'
- next_event.transition :from => 'payment', :to => 'confirm', :if => Proc.new { Spree::Gateway.current && Spree::Gateway.current.payment_profiles_supported? }
- next_event.transition :from => 'payment', :to => 'complete'
-
- Spree::Order.state_machine.before_transition :to => 'skrill', :do => Proc.new{ |order|
- skrill_account = Spree::SkrillAccount.find_or_create_by_email(order.email)
-
- payment = order.payment
- payment.update_attribute(:source, skrill_account)
- payment.started_processing!
- payment.pend!
-
- }
-
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
Please sign in to comment.
Something went wrong with that request. Please try again.