stripe_clerk 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b8f9e27d91d265d4eb9aef205c22742a7a4e7bc5
4
+ data.tar.gz: 68ec8b7821d56c94a79bbb91f64bbf3804fbd97f
5
+ SHA512:
6
+ metadata.gz: 90579060163c05f9cbc82f191dbad01712683d32496443f277526bc9dc193e5facfaf5e6c6af5459e47ff3f29f4243aaf5808d370c1605ae54bd6c5a6c4fd8e9
7
+ data.tar.gz: e2c9a3f2f839f6e7aafef44d250552f9310d4012b5c2fa0561cb3e9407a78c0435be60c7e11ee4cfbc8c43cec0ae6849be8dcb0bb7449a5430756f1bf4d3503f
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Basia Klosowska
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'StripeClerk'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,8 @@
1
+ // show transfer data after click "money transfer" button on order page:
2
+
3
+ $(document).ready(function() {
4
+ $('.custom-button').click(function() {
5
+ var detailsDiv = $('#payment-data');
6
+ detailsDiv.css("display", "block");
7
+ });
8
+ });
@@ -0,0 +1,4 @@
1
+ module StripeClerk
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ require_dependency "stripe_clerk/application_controller"
2
+
3
+ module StripeClerk
4
+ class ChargesController < ApplicationController
5
+
6
+ include ChargesHelper
7
+
8
+ def new
9
+ end
10
+
11
+ def show
12
+ @order = Order.find( session[:order] )
13
+ end
14
+
15
+ def create
16
+ order = Order.find( session[:order] )
17
+
18
+ customer = Stripe::Customer.create(
19
+ :email => order.email ,
20
+ :card => params[:stripeToken]
21
+ )
22
+
23
+ charge_customer customer.id , order
24
+
25
+ redirect_to main_app.shop_order_path
26
+
27
+ rescue Stripe::StripeError => e # nothing must escape, CardError is just a subset
28
+ flash[:error] = e.message
29
+ redirect_to charges_path
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module StripeClerk
2
+ module ChargesHelper
3
+
4
+ # determine if the given user has ordered by card and if so return the charge
5
+ # given user may be nil, in which case nil is returned (save caller checking)
6
+ # nil is also returned if no stripe order was placed
7
+ # from the returned charge one may get the card (to display last4) or
8
+ # the customer to create a new charge (with the charge_customer method)
9
+ def has_charge user
10
+ return nil unless user
11
+ order = Order.where(email: user.email).where(payment_type: :stripe).order(:ordered_on).last
12
+ return nil unless order
13
+ Stripe::Charge.retrieve(order.payment_info)
14
+ end
15
+
16
+ # reusable helper to charge given customer_id for given order
17
+ # orders save the charge_id, so customers may be re-charged using that
18
+ # (has_charge helper will return the latest charge for a user and .customer will give it's id)
19
+ # Throws any StripeError , specifically CardError
20
+ #
21
+ def charge_customer customer_id , order
22
+ charge = Stripe::Charge.create(
23
+ :customer => customer_id,
24
+ :amount => (order.total_price*100).to_i,
25
+ :description => t(:order) + " : " + order.number ,
26
+ :currency => 'eur'
27
+ )
28
+
29
+ order.pay_now
30
+ order.payment_info = charge.id
31
+ order.payment_type = "stripe"
32
+ order.save
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ = form_tag stripe_clerk.charges_path do
2
+ %article
3
+ %label.amount
4
+ %span= t("stripe_clerk.amount") + ":"
5
+ = euros order.total_price
6
+ %script.stripe-button{"data-amount" => "#{order.total_price*100}",
7
+ "data-currency" => "eur",
8
+ "data-description" => "#{t(:order_number)} #{order.number}",
9
+ "data-key" => Rails.configuration.stripe[:publishable_key],
10
+ "data-locale" => "auto",
11
+ "data-image" => "#{image_url('your_stripe_logo.png')}",
12
+ "data-name" => t("stripe_clerk.company"),
13
+ "data-panel-label" => t("stripe_clerk.pay_with_card"),
14
+ "data-label" => t("stripe_clerk.pay_with_card"),
15
+ "data-allow-remember-me" => "false" ,
16
+ "data-email" => "#{@order.email}",
17
+ :src => "https://checkout.stripe.com/checkout.js"}
18
+ %a.custom-button
19
+ %span= t("stripe_clerk.transfer")
@@ -0,0 +1,5 @@
1
+ %h4
2
+ = t("stripe_clerk.paid")
3
+ = succeed "!" do
4
+ %strong
5
+ = euros order.total_price
@@ -0,0 +1,6 @@
1
+ Rails.configuration.stripe = {
2
+ :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
3
+ :secret_key => ENV['STRIPE_SECRET_KEY']
4
+ }
5
+
6
+ Stripe.api_key = Rails.configuration.stripe[:secret_key]
@@ -0,0 +1,7 @@
1
+ en:
2
+ stripe_clerk:
3
+ amount: Amount
4
+ paid: Paid
5
+ transfer: Money Transfer
6
+ pay_with_card: Pay with card
7
+ company: "stripe_clerk.company key"
@@ -0,0 +1,7 @@
1
+ fi:
2
+ stripe_clerk:
3
+ paid: Maksettu
4
+ transfer: Maksa pankilla
5
+ amount: Määrä
6
+ pay_with_card: Maksa kortilla
7
+ company: Auringosta Itään, Kuusta Länteen
@@ -0,0 +1,3 @@
1
+ StripeClerk::Engine.routes.draw do
2
+ resources :charges
3
+ end
@@ -0,0 +1,2 @@
1
+ require "stripe_clerk/engine"
2
+
@@ -0,0 +1,11 @@
1
+ require "stripe"
2
+
3
+ module StripeClerk
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace StripeClerk
6
+
7
+ config.assets.precompile += %w( your_stripe_logo.png )
8
+
9
+ config.active_record.raise_in_transactional_callbacks = true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module StripeClerk
2
+ VERSION = "0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :stripe_clerk do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stripe_clerk
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Basia Klosowska, Anna Góra
8
+ - Torsten Ruger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-01-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: office_clerk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: stripe
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Stripe Payment method for office_clerk ecommerce system.
43
+ email:
44
+ - barbaraklosowska@gmail.com
45
+ - torsten@villtaika.fi
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - MIT-LICENSE
51
+ - Rakefile
52
+ - app/assets/images/stripe.png
53
+ - app/assets/images/your_stripe_logo.png
54
+ - app/assets/javascripts/stripe_clerk/charges.js
55
+ - app/controllers/stripe_clerk/application_controller.rb
56
+ - app/controllers/stripe_clerk/charges_controller.rb
57
+ - app/helpers/stripe_clerk/charges_helper.rb
58
+ - app/views/stripe_clerk/charges/_new.html.haml
59
+ - app/views/stripe_clerk/charges/_show.html.haml
60
+ - config/initializers/stripe.rb
61
+ - config/locales/stripe_clerk_en.yml
62
+ - config/locales/stripe_clerk_fi.yml
63
+ - config/routes.rb
64
+ - lib/stripe_clerk.rb
65
+ - lib/stripe_clerk/engine.rb
66
+ - lib/stripe_clerk/version.rb
67
+ - lib/tasks/stripe_clerk_tasks.rake
68
+ homepage: https://github.com/rubyclerks/stripe_clerk
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.5.1
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Stripe Payment method for office_clerk ecommerce system.
92
+ test_files: []