Browse Source

Initial implementation

tags/3.0.0
Sjors Baltus 8 years ago
commit
9a3a31c047
39 changed files with 847 additions and 0 deletions
  1. 14
    0
      .gitignore
  2. 1
    0
      .rspec
  3. 7
    0
      .travis.yml
  4. 6
    0
      Gemfile
  5. 26
    0
      LICENSE
  6. 52
    0
      README.md
  7. 15
    0
      Rakefile
  8. 11
    0
      Versionfile
  9. 1
    0
      app/assets/javascripts/admin/spree_billing_sisow.js
  10. 1
    0
      app/assets/javascripts/store/spree_billing_sisow.js
  11. 3
    0
      app/assets/stylesheets/admin/spree_billing_sisow.css
  12. 3
    0
      app/assets/stylesheets/store/spree_billing_sisow.css
  13. 52
    0
      app/controllers/spree/checkout_controller_decorator.rb
  14. 11
    0
      app/controllers/spree/sisow_status_controller.rb
  15. 89
    0
      app/models/spree/billing_integration/sisow_billing.rb
  16. 59
    0
      app/models/spree/billing_integration/sisow_billing/bancontact.rb
  17. 63
    0
      app/models/spree/billing_integration/sisow_billing/ideal.rb
  18. 59
    0
      app/models/spree/billing_integration/sisow_billing/sofort.rb
  19. 10
    0
      app/models/spree/sisow_transaction.rb
  20. 8
    0
      app/views/spree/admin/payments/source_forms/_bancontact.html.erb
  21. 8
    0
      app/views/spree/admin/payments/source_forms/_ideal.html.erb
  22. 8
    0
      app/views/spree/admin/payments/source_forms/_sofort.html.erb
  23. 33
    0
      app/views/spree/admin/payments/source_views/_bancontact.html.erb
  24. 33
    0
      app/views/spree/admin/payments/source_views/_ideal.html.erb
  25. 33
    0
      app/views/spree/admin/payments/source_views/_sofort.html.erb
  26. 1
    0
      app/views/spree/checkout/payment/_bancontact.html.erb
  27. 6
    0
      app/views/spree/checkout/payment/_ideal.html.erb
  28. 1
    0
      app/views/spree/checkout/payment/_sofort.html.erb
  29. 6
    0
      config/locales/en.yml
  30. 6
    0
      config/locales/nl.yml
  31. 13
    0
      config/routes.rb
  32. 12
    0
      db/migrate/20130525124432_create_sisow_transactions.rb
  33. 38
    0
      lib/generators/spree_billing_sisow/install/install_generator.rb
  34. 2
    0
      lib/spree_billing_sisow.rb
  35. 30
    0
      lib/spree_billing_sisow/engine.rb
  36. 6
    0
      lib/spree_billing_sisow/factories.rb
  37. 7
    0
      script/rails
  38. 81
    0
      spec/spec_helper.rb
  39. 32
    0
      spree_billing_sisow.gemspec

+ 14
- 0
.gitignore View File

@@ -0,0 +1,14 @@
\#*
*~
.#*
.DS_Store
.idea
.project
.sass-cache
coverage
Gemfile.lock
tmp
nbproject
pkg
*.swp
spec/dummy

+ 1
- 0
.rspec View File

@@ -0,0 +1 @@
--color

+ 7
- 0
.travis.yml View File

@@ -0,0 +1,7 @@
language: ruby
rvm:
- 1.9.3
- 2.0
script:
- bundle exec rake test_app
- bundle exec rake spec

+ 6
- 0
Gemfile View File

@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# Provides basic authentication functionality for testing parts of your engine
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'

gemspec

+ 26
- 0
LICENSE View File

@@ -0,0 +1,26 @@
Copyright (c) 2013 [name of plugin creator]
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Spree nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 52
- 0
README.md View File

@@ -0,0 +1,52 @@
Spree Billing Sisow
=================
[![Build Status](https://travis-ci.org/xtr3me/spree_billing_sisow.png)](https://travis-ci.org/xtr3me/spree_billing_sisow)

Spree Billing Integration for Sisow (Ideal / Bancontact / Sofort) payments.
This Gem is currently being build and tested, and is not yet released for use in production systems

Todo
------------
- [x] Enable Travis
- [ ] Configure Sisow correctly with Spree preferences
- [ ] Write rspec for SisowBilling
- [ ] Write rspec for Ideal
- [ ] Write rspec for Bancontact
- [ ] Write rspec for Sofort
- [ ] Release Gem

Installation
------------

Add spree_billing_sisow to your Gemfile:

```ruby
gem 'spree_billing_sisow'
```

Bundle your dependencies and run the installation generator:

```shell
bundle
bundle exec rails g spree_billing_sisow:install
```

Testing
-------

Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.

```shell
bundle
bundle exec rake test_app
bundle exec rspec spec
```

When testing your applications integration with this extension you may use it's factories.
Simply add this require statement to your spec_helper:

```ruby
require 'spree_billing_sisow/factories'
```

Copyright (c) 2013 Sjors Baltus, released under the New BSD License

+ 15
- 0
Rakefile View File

@@ -0,0 +1,15 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_billing_sisow'
Rake::Task['extension:test_app'].invoke
end

+ 11
- 0
Versionfile View File

@@ -0,0 +1,11 @@
# This file is used to designate compatibilty with different versions of Spree
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details

# Examples
#
# '1.2.x' => { :branch => 'master' }
# '1.1.x' => { :branch => '1-1-stable' }
# '1.0.x' => { :branch => '1-0-stable' }
# '0.70.x' => { :branch => '0-70-stable' }
# '0.40.x' => { :tag => 'v1.0.0', :version => '1.0.0' }


+ 1
- 0
app/assets/javascripts/admin/spree_billing_sisow.js View File

@@ -0,0 +1 @@
//= require admin/spree_backend

+ 1
- 0
app/assets/javascripts/store/spree_billing_sisow.js View File

@@ -0,0 +1 @@
//= require store/spree_frontend

+ 3
- 0
app/assets/stylesheets/admin/spree_billing_sisow.css View File

@@ -0,0 +1,3 @@
/*
*= require admin/spree_backend
*/

+ 3
- 0
app/assets/stylesheets/store/spree_billing_sisow.css View File

@@ -0,0 +1,3 @@
/*
*= require store/spree_frontend
*/

+ 52
- 0
app/controllers/spree/checkout_controller_decorator.rb View File

@@ -0,0 +1,52 @@
module Spree
CheckoutController.class_eval do
before_filter :confirm_sisow, :only => [:update]

def sisow_return
handle_sisow_response
redirect_to completion_route
end

def sisow_cancel
handle_sisow_response
redirect_to edit_order_path(@order)
end

private
def handle_sisow_response
sisow = BillingIntegration::SisowBilling.new(@order, params)
sisow.process_response

if sisow.success?
flash.notice = Spree.t(:order_processed_successfully)
elsif sisow.cancelled?
flash.warning = Spree.t(:payment_has_been_cancelled)
elsif sisow.failed?
flash.error = Spree.t(:payment_processing_failed)
end
end

def confirm_sisow
return unless (params[:state] == "payment") && params[:order][:payments_attributes]

payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
opts = {}
opts[:return_url] = sisow_return_order_checkout_url(@order)
opts[:cancel_url] = sisow_cancel_order_checkout_url(@order)
opts[:notify_url] = sisow_status_update_path

if payment_method.kind_of?(BillingIntegration::SisowBilling::Ideal)
opts[:issuer_id] = params[:issuer_id]
redirect_to payment_method.redirect_url(@order, opts)
elsif payment_method.kind_of?(BillingIntegration::SisowBilling::Sofort)
redirect_to payment_method.redirect_url(@order, opts)
elsif payment_method.kind_of?(BillingIntegration::SisowBilling::Bancontact)
redirect_to payment_method.redirect_url(@order, opts)
else
flash.error = Spree.t(:payment_processing_failed)
redirect_to completion_route
end
end

end
end

+ 11
- 0
app/controllers/spree/sisow_status_controller.rb View File

@@ -0,0 +1,11 @@
module Spree
class SisowStatusController < ApplicationController
def update
@order = Order.find_by_number!(params[:order_id])
sisow = BillingIntegration::SisowBilling.new(@order, params)
sisow.process_response
render :text => ""
end

end
end

+ 89
- 0
app/models/spree/billing_integration/sisow_billing.rb View File

@@ -0,0 +1,89 @@
module Spree
class BillingIntegration::SisowBilling < BillingIntegration

def initialize(order, sisow_return_data)
@order = order
@callback = Sisow::Api::Callback.new(
:transaction_id => sisow_return_data[:trxid],
:entrance_code => sisow_return_data[:ec],
:status => sisow_return_data[:status],
:sha1 => sisow_return_data[:sha1]
)
@sisow_transaction = SisowTransaction.where(transaction_id: sisow_return_data[:trxid], entrance_code: sisow_return_data[:ec]).first
end

def success?
@payment.completed?
end

def failed?
@payment.failed?
end

def cancelled?
@payment.void?
end

def process_response
if @order.payments.where(:source_type => 'Spree::SisowTransaction').present?
@callback.validate!

#Update the transaction with the callback details
@sisow_transaction.update_attributes(status : @callback.status, sha1 : @callback.sha1)


@payment = @order.payments.where(amount : @order.total, source_id : @sisow_transaction, payment_method_id : payment_method).first
@payment.started_processing!

if @callback.valid?
if @callback.success?
complete_payment
elsif callback.failure? OR callback.expired?
fail_payment
elsif callback.cancelled?
cancel_payment
end
end
end
end

def self.configure_sisow
Sisow.configure do |config|
config.merchant_id = Spree::Config.sisow_merchant_id
config.merchant_key = Spree::Config.sisow_merchant_key
config.test_mode = Spree::Config.sisow_test_mode
config.debug_mode = Spree::Config.sisow_debug_mode
end
end

private
def payment_method
case @sisow_transaction.transaction_type
when 'ideal'
return PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Ideal").first
when 'bancontact'
return PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Bancontact").first
when 'sofort'
return PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Sofort").first
else
raise "Unknown payment method (#{@sisow_transaction.transaction_type})"
end
end

def complete_payment
@payment.complete!

@order.update_attributes({:state => "complete", :completed_at => Time.now}, :without_protection => true)
@order.finalize!
end

def cancel_payment
@payment.pend!
@payment.void!
end

def fail_payment
@payment.failure!
end
end
end

+ 59
- 0
app/models/spree/billing_integration/sisow_billing/bancontact.rb View File

@@ -0,0 +1,59 @@
module Spree
class BillingIntegration::SisowBilling::Bancontact < BillingIntegration
include Rails.application.routes.url_helpers
preference :test_mode, :boolean, :default => false
preference :debug_mode, :boolean, :default => false
preference :merchant_id, :string
preference :merchant_key, :string
preference :language, :string, :default => 'NL'
preference :payment_options, :string, :default => 'ACC'

attr_accessible :preferred_merchant_id, :preferred_merchant_key, :preferred_language, :preferred_test_mode,
:preferred_debug_mode, :preferred_server, :preferred_payment_options

def payment_profiles_supported?
false
end

def redirect_url(order, opts = {})
sisow_transaction = SisowTransaction.create(transaction_type: 'bancontact',
transaction_id: sisow.transaction_id,
entrance_code: nil,
status: 'pending',
sha1: nil)
payment_method = PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Bancontact").first
payment = order.payments.create({:amount => order.total,
:source => sisow_transaction,
:payment_method => payment_method},
:without_protection => true)

#Update the entrance code with the payment identifier
sisow_transaction.update_attributes(entrance_code: payment.identifier)

#Update the payment state
payment.started_processing!
payment.pend!

#Set the options needed for the Sisow payment url
opts[:description] = "#{Spree::Config.site_name} - Order: #{order.number}"
opts[:purchase_id] = order.number
opts[:amount] = (order.total * 100).to_i
opts[:entrance_code] = payment.identifier
@options = opts

sisow = self.provider
sisow.payment_url
end

def provider
Spree::BillingIntegration::SisowBilling.configure_sisow
Sisow::Bancontact.new(options)
end

private
def options
@options
end

end
end

+ 63
- 0
app/models/spree/billing_integration/sisow_billing/ideal.rb View File

@@ -0,0 +1,63 @@
module Spree
class BillingIntegration::SisowBilling::Ideal < BillingIntegration
include Rails.application.routes.url_helpers
preference :test_mode, :boolean, :default => false
preference :debug_mode, :boolean, :default => false
preference :merchant_id, :string
preference :merchant_key, :string
preference :language, :string, :default => 'NL'
preference :payment_options, :string, :default => 'ACC'

attr_accessible :preferred_merchant_id, :preferred_merchant_key, :preferred_language, :preferred_test_mode,
:preferred_debug_mode, :preferred_server, :preferred_payment_options

def payment_profiles_supported?
false
end

def redirect_url(order, opts = {})
sisow_transaction = SisowTransaction.create(transaction_type: 'ideal',
transaction_id: sisow.transaction_id,
entrance_code: nil,
status: 'pending',
sha1: nil)
payment_method = PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Ideal").first
payment = order.payments.create({:amount => order.total,
:source => sisow_transaction,
:payment_method => payment_method},
:without_protection => true)

#Update the entrance code with the payment identifier
sisow_transaction.update_attributes(entrance_code: payment.identifier)

#Update the payment state
payment.started_processing!
payment.pend!

#Set the options needed for the Sisow payment url
opts[:description] = "#{Spree::Config.site_name} - Order: #{order.number}"
opts[:purchase_id] = order.number
opts[:amount] = (order.total * 100).to_i
opts[:entrance_code] = payment.identifier
@options = opts

sisow = self.provider
sisow.payment_url
end

def provider
Spree::BillingIntegration::SisowBilling.configure_sisow
Sisow::IdealPayment.new(options)
end
def self.issuer_list
Sisow::Issuer.list
end

private
def options
@options
end
end
end

+ 59
- 0
app/models/spree/billing_integration/sisow_billing/sofort.rb View File

@@ -0,0 +1,59 @@
module Spree
class BillingIntegration::SisowBilling::Sofort < BillingIntegration
include Rails.application.routes.url_helpers
preference :test_mode, :boolean, :default => false
preference :debug_mode, :boolean, :default => false
preference :merchant_id, :string
preference :merchant_key, :string
preference :language, :string, :default => 'NL'
preference :payment_options, :string, :default => 'ACC'

attr_accessible :preferred_merchant_id, :preferred_merchant_key, :preferred_language, :preferred_test_mode,
:preferred_debug_mode, :preferred_server, :preferred_payment_options

def payment_profiles_supported?
false
end

def redirect_url(order, opts = {})
sisow_transaction = SisowTransaction.create(transaction_type: 'sofort',
transaction_id: sisow.transaction_id,
entrance_code: nil,
status: 'pending',
sha1: nil)
payment_method = PaymentMethod.where(type: "Spree::BillingIntegration::SisowBilling::Sofort").first
payment = order.payments.create({:amount => order.total,
:source => sisow_transaction,
:payment_method => payment_method},
:without_protection => true)

#Update the entrance code with the payment identifier
sisow_transaction.update_attributes(entrance_code: payment.identifier)

#Update the payment state
payment.started_processing!
payment.pend!

#Set the options needed for the Sisow payment url
opts[:description] = "#{Spree::Config.site_name} - Order: #{order.number}"
opts[:purchase_id] = order.number
opts[:amount] = (order.total * 100).to_i
opts[:entrance_code] = payment.identifier
@options = opts

sisow = self.provider
sisow.payment_url
end

def provider
Spree::BillingIntegration::SisowBilling.configure_sisow
Sisow::SofortPayment.new(options)
end

private
def options
@options
end

end
end

+ 10
- 0
app/models/spree/sisow_transaction.rb View File

@@ -0,0 +1,10 @@
module Spree
class SisowTransaction < ActiveRecord::Base
has_many :payments, :as => :source
attr_accessible :transaction_id, :transaction_type, :entrance_code, :status, :sha1
def actions
[]
end
end
end

+ 8
- 0
app/views/spree/admin/payments/source_forms/_bancontact.html.erb View File

@@ -0,0 +1,8 @@
<% content_for :head do %>
<script type="text/javascript">
jQuery(document).ready(function(){
$("label:contains('<%= payment_method.name %>')").hide();
$("label:contains('<%= payment_method.name %>') input").disable();
});
</script>
<% end %>

+ 8
- 0
app/views/spree/admin/payments/source_forms/_ideal.html.erb View File

@@ -0,0 +1,8 @@
<% content_for :head do %>
<script type="text/javascript">
jQuery(document).ready(function(){
$("label:contains('<%= payment_method.name %>')").hide();
$("label:contains('<%= payment_method.name %>') input").disable();
});
</script>
<% end %>

+ 8
- 0
app/views/spree/admin/payments/source_forms/_sofort.html.erb View File

@@ -0,0 +1,8 @@
<% content_for :head do %>
<script type="text/javascript">
jQuery(document).ready(function(){
$("label:contains('<%= payment_method.name %>')").hide();
$("label:contains('<%= payment_method.name %>') input").disable();
});
</script>
<% end %>

+ 33
- 0
app/views/spree/admin/payments/source_views/_bancontact.html.erb View File

@@ -0,0 +1,33 @@
<fieldset>
<legend><%= Spree.t(:sisow_bancontact) %></legend>

<table class="index">
<tr>
<th colspan="6"><%= Spree.t(:sisow_transaction) %></th>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_transaction_id) %>:</label></td>
<td>
<%= payment.source.transaction_id %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_entrance_code) %>:</label></td>
<td>
<%= payment.source.entrance_code %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_status) %>:</label></td>
<td>
<%= payment.source.status %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_sha1) %>:</label></td>
<td>
<%= payment.source.sha1 %>
</td>
</tr>
</table>
</fieldset>

+ 33
- 0
app/views/spree/admin/payments/source_views/_ideal.html.erb View File

@@ -0,0 +1,33 @@
<fieldset>
<legend><%= Spree.t(:sisow_ideal) %></legend>

<table class="index">
<tr>
<th colspan="6"><%= Spree.t(:sisow_transaction) %></th>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_transaction_id) %>:</label></td>
<td>
<%= payment.source.transaction_id %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_entrance_code) %>:</label></td>
<td>
<%= payment.source.entrance_code %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_status) %>:</label></td>
<td>
<%= payment.source.status %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_sha1) %>:</label></td>
<td>
<%= payment.source.sha1 %>
</td>
</tr>
</table>
</fieldset>

+ 33
- 0
app/views/spree/admin/payments/source_views/_sofort.html.erb View File

@@ -0,0 +1,33 @@
<fieldset>
<legend><%= Spree.t(:sisow_sofort) %></legend>

<table class="index">
<tr>
<th colspan="6"><%= Spree.t(:sisow_transaction) %></th>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_transaction_id) %>:</label></td>
<td>
<%= payment.source.transaction_id %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_entrance_code) %>:</label></td>
<td>
<%= payment.source.entrance_code %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_status) %>:</label></td>
<td>
<%= payment.source.status %>
</td>
</tr>
<tr>
<td><label><%= Spree.t(:sisow_sha1) %>:</label></td>
<td>
<%= payment.source.sha1 %>
</td>
</tr>
</table>
</fieldset>

+ 1
- 0
app/views/spree/checkout/payment/_bancontact.html.erb View File

@@ -0,0 +1 @@
<p data-hook="sisow_bancontact"></p>

+ 6
- 0
app/views/spree/checkout/payment/_ideal.html.erb View File

@@ -0,0 +1,6 @@
<p data-hook="sisow_ideal"></p>

<fieldset id="sisow_payment__<%= payment_method.id %>" data-hook>
<legend><%= Spree.t(:bank_selection) %></legend>
<%= select_tag "issuer_id", options_from_collection_for_select(Spree::BillingIntegration::SisowBilling::Ideal.issuer_list, "id", "name") %>
</fieldset>

+ 1
- 0
app/views/spree/checkout/payment/_sofort.html.erb View File

@@ -0,0 +1 @@
<p data-hook="sisow_sofort"></p>

+ 6
- 0
config/locales/en.yml View File

@@ -0,0 +1,6 @@
en:
spree:
sisow_ideal: "Sisow Ideal"
sisow_bancontact: "Sisow Bancontact"
sisow_sofort: "Sisow Sofort"
bank_selection: "Select your bank"

+ 6
- 0
config/locales/nl.yml View File

@@ -0,0 +1,6 @@
nl:
spree:
sisow_ideal: "Sisow Ideal"
sisow_bancontact: "Sisow Bancontact"
sisow_sofort: "Sisow Sofort"
bank_selection: "Selecteer uw bank"

+ 13
- 0
config/routes.rb View File

@@ -0,0 +1,13 @@
Spree::Core::Engine.routes.draw do

resources :orders do
resource :checkout, :controller => 'checkout' do
member do
get :sisow_cancel
get :sisow_return
end
end
end
match '/sisow' => 'sisow_status#update', :via => :post, :as => :sisow_status_update
end

+ 12
- 0
db/migrate/20130525124432_create_sisow_transactions.rb View File

@@ -0,0 +1,12 @@
class CreateSisowTransactions < ActiveRecord::Migration
def change
create_table :spree_sisow_transactions do |t|
t.string :transaction_id
t.string :entrance_code
t.string :status
t.string :sha1

t.timestamps
end
end
end

+ 38
- 0
lib/generators/spree_billing_sisow/install/install_generator.rb View File

@@ -0,0 +1,38 @@
module SpreeBillingSisow
module Generators
class InstallGenerator < Rails::Generators::Base

class_option :auto_run_migrations, :type => :boolean, :default => false

def add_javascripts
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_billing_sisow\n"
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_billing_sisow\n"
end

def add_stylesheets
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_billing_sisow\n", :before => /\*\//, :verbose => true
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_billing_sisow\n", :before => /\*\//, :verbose => true
end

def add_sisow_configuration
initializer("sisow.rb") do
"Sisow.configure do |config|\n config.merchant_key = 'your-merchant-key'\n config.merchant_id = 'your-merchant-id'\n config.test_mode = false # default: false\n config.debug_mode = false # default: false\nend"
end
puts "Don't forget to configure Sisow in config/initializers/sisow.rb"
end

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=spree_billing_sisow'
end

def run_migrations
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
if run_migrations
run 'bundle exec rake db:migrate'
else
puts 'Skipping rake db:migrate, don\'t forget to run it!'
end
end
end
end
end

+ 2
- 0
lib/spree_billing_sisow.rb View File

@@ -0,0 +1,2 @@
require 'spree_core'
require 'spree_billing_sisow/engine'

+ 30
- 0
lib/spree_billing_sisow/engine.rb View File

@@ -0,0 +1,30 @@
module SpreeBillingSisow
class Engine < Rails::Engine
require 'spree/core'
isolate_namespace Spree
engine_name 'spree_billing_sisow'

config.autoload_paths += %W(#{config.root}/lib)

# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

config.to_prepare &method(:activate).to_proc

initializer "spree_billing_sisow.register.payment_methods", :after => 'spree.register.payment_methods' do |app|
app.config.spree.payment_methods += [
Spree::BillingIntegration::SisowBilling::Ideal,
Spree::BillingIntegration::SisowBilling::Bancontact,
Spree::BillingIntegration::SisowBilling::Sofort
]
end
end
end

+ 6
- 0
lib/spree_billing_sisow/factories.rb View File

@@ -0,0 +1,6 @@
FactoryGirl.define do
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
# Example adding this to your spec_helper will load these Factories for use:
# require 'spree_billing_sisow/factories'
end

+ 7
- 0
script/rails View File

@@ -0,0 +1,7 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/spree_billing_sisow/engine', __FILE__)

require 'rails/all'
require 'rails/engine/commands'

+ 81
- 0
spec/spec_helper.rb View File

@@ -0,0 +1,81 @@
# Run Coverage report
require 'simplecov'
SimpleCov.start do
add_group 'Controllers', 'app/controllers'
add_group 'Helpers', 'app/helpers'
add_group 'Mailers', 'app/mailers'
add_group 'Models', 'app/models'
add_group 'Views', 'app/views'
add_group 'Libraries', 'lib'
end

# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'

require File.expand_path('../dummy/config/environment.rb', __FILE__)

require 'rspec/rails'
require 'database_cleaner'
require 'ffaker'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }

# Requires factories defined in spree_core
require 'spree/testing_support/factories'
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/url_helpers'

# Requires factories defined in lib/spree_billing_sisow/factories.rb
require 'spree_billing_sisow/factories'

RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods

# == URL Helpers
#
# Allows access to Spree's routes in specs:
#
# visit spree.admin_path
# current_path.should eql(spree.products_path)
config.include Spree::TestingSupport::UrlHelpers

# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
config.color = true

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
# to cleanup after each test instead. Without transactional fixtures set to false the records created
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
config.use_transactional_fixtures = false

# Ensure Suite is set to use transactions for speed.
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end

# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
config.before :each do
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end

# After each spec clean the database.
config.after :each do
DatabaseCleaner.clean
end

config.fail_fast = ENV['FAIL_FAST'] || false
end

+ 32
- 0
spree_billing_sisow.gemspec View File

@@ -0,0 +1,32 @@
# encoding: UTF-8
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_billing_sisow'
s.version = '0.0.1'
s.summary = 'Spree billing integration for Sisow payment provider'
s.description = 'Spree billing integration for Sisow iDeal /Bancontact / Sofort payments'
s.required_ruby_version = '>= 1.9.3'

s.author = 'Sjors Baltus'
s.email = 'spree_gems@sjorsbaltus.nl'
s.homepage = 'http://github.com/xtr3me/spree_billing_sisow'

#s.files = `git ls-files`.split("\n")
#s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '~> 2.0.0'
s.add_dependency 'sisow', '~> 1.5'

s.add_development_dependency 'capybara', '~> 2.1'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_girl', '~> 4.2'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.13'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'sqlite3'
end

Loading…
Cancel
Save