workarea-stripe 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintrc +36 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +67 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +8 -0
- data/LICENSE +52 -0
- data/README.md +90 -0
- data/Rakefile +60 -0
- data/app/assets/javascripts/workarea/storefront/stripe/config.js.erb +29 -0
- data/app/assets/javascripts/workarea/storefront/stripe/modules/bogus_stripe_elements.js +55 -0
- data/app/assets/javascripts/workarea/storefront/stripe/modules/stripe_elements.js +113 -0
- data/app/assets/stylesheets/workarea/stripe/components/_checkout_payment_stripe.scss +19 -0
- data/app/controllers/workarea/storefront/users/credit_cards_controller.decorator +10 -0
- data/app/models/workarea/checkout/credit_card_params.decorator +30 -0
- data/app/models/workarea/checkout/steps/payment.decorator +16 -0
- data/app/models/workarea/payment.decorator +18 -0
- data/app/models/workarea/payment/authorize/credit_card.decorator +24 -0
- data/app/models/workarea/payment/credit_card.decorator +27 -0
- data/app/models/workarea/payment/purchase/credit_card.decorator +24 -0
- data/app/models/workarea/payment/store_credit_card.decorator +54 -0
- data/app/views/workarea/storefront/checkouts/_stripe_dialog.html.haml +2 -0
- data/app/views/workarea/storefront/checkouts/_stripe_form.html.haml +19 -0
- data/app/views/workarea/storefront/stripe/_stripe_js.html.haml +1 -0
- data/app/views/workarea/storefront/users/credit_cards/_stripe_form.html.haml +12 -0
- data/app/views/workarea/storefront/users/credit_cards/new.html.haml +42 -0
- data/bin/rails +20 -0
- data/config/initializers/appends.rb +33 -0
- data/config/initializers/workarea.rb +9 -0
- data/config/routes.rb +2 -0
- data/lib/active_merchant/billing/bogus_stripe_gateway.rb +29 -0
- data/lib/workarea/stripe.rb +46 -0
- data/lib/workarea/stripe/engine.rb +8 -0
- data/lib/workarea/stripe/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/bin/update +26 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +30 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +51 -0
- data/test/dummy/config/environments/production.rb +88 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/package.json +5 -0
- data/test/integration/workarea/storefront/place_order_integration_test.decorator +19 -0
- data/test/integration/workarea/storefront/users/credit_cards_integration_test.decorator +26 -0
- data/test/models/workarea/checkout/credit_card_params_test.rb +10 -0
- data/test/models/workarea/checkout/steps/payment_test.decorator +21 -0
- data/test/models/workarea/payment/authorize/credit_card_test.decorator +24 -0
- data/test/models/workarea/payment/capture_test.decorator +10 -0
- data/test/models/workarea/payment/credit_card_integration_test.decorator +26 -0
- data/test/models/workarea/payment/purchase/credit_card_test.decorator +25 -0
- data/test/models/workarea/payment/refund/credit_card_test.decorator +20 -0
- data/test/models/workarea/payment/refund_test.decorator +10 -0
- data/test/models/workarea/payment/store_credit_card_test.decorator +9 -0
- data/test/models/workarea/payment_test.decorator +20 -0
- data/test/support/stripe_public_key.rb +1 -0
- data/test/system/workarea/storefront/analytics_system_test.decorator +5 -0
- data/test/system/workarea/storefront/credit_cards_system_test.decorator +5 -0
- data/test/system/workarea/storefront/digital_products_system_test.decorator +67 -0
- data/test/system/workarea/storefront/guest_checkout_system_test.decorator +107 -0
- data/test/system/workarea/storefront/logged_in_checkout_system_test.decorator +5 -0
- data/test/system/workarea/storefront/no_js_system_test.decorator +5 -0
- data/test/system/workarea/storefront/stripe_payment_system_test.rb +97 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/test/workers/workarea/send_refund_email_test.decorator +29 -0
- data/workarea-stripe.gemspec +21 -0
- metadata +171 -0
@@ -0,0 +1 @@
|
|
1
|
+
%script{ src: 'https://js.stripe.com/v3/' }
|
@@ -0,0 +1,12 @@
|
|
1
|
+
.grid
|
2
|
+
.grid__cell
|
3
|
+
= all_payment_icons
|
4
|
+
.grid__cell.grid__cell--66-at-medium
|
5
|
+
.property
|
6
|
+
= label_tag 'credit_card[element]', nil, class: 'property__name' do
|
7
|
+
%span.property__requirement.property__requirement--required= t('workarea.storefront.forms.required')
|
8
|
+
%span.property__text= t('workarea.storefront.credit_cards.card_number')
|
9
|
+
.value
|
10
|
+
#card_element{ data: { stripe_card_input: '' } }
|
11
|
+
-# Stripe element will be inserted here
|
12
|
+
#card_errors.value__error{ role: 'alert' }
|
@@ -0,0 +1,42 @@
|
|
1
|
+
- @title = t('workarea.storefront.users.add_credit_card')
|
2
|
+
- params[:credit_card] ||= {}
|
3
|
+
|
4
|
+
- content_for :breadcrumbs do
|
5
|
+
%p.breadcrumbs__node-group
|
6
|
+
%span.breadcrumbs__node{ itemprop: 'breadcrumb' }
|
7
|
+
= link_to t('workarea.storefront.layouts.home'), root_path, rel: 'home', class: 'breadcrumbs__link'
|
8
|
+
%span.breadcrumbs__node{ itemprop: 'breadcrumb' }
|
9
|
+
= link_to t('workarea.storefront.users.account'), users_account_path, class: 'breadcrumbs__link'
|
10
|
+
%span.breadcrumbs__node{ itemprop: 'breadcrumb' }
|
11
|
+
%span.breadcrumbs__text= t('workarea.storefront.users.add_credit_card')
|
12
|
+
|
13
|
+
.view
|
14
|
+
|
15
|
+
%h1= t('workarea.storefront.users.add_credit_card')
|
16
|
+
|
17
|
+
- if @credit_card && @credit_card.errors.any?
|
18
|
+
- @credit_card.errors.full_messages.each do |message|
|
19
|
+
= render_message 'error', message, data: { analytics: validation_error_analytics_data('users').to_json }
|
20
|
+
|
21
|
+
|
22
|
+
= form_tag users_credit_cards_path, method: 'post', id: 'credit_card_form', data: { single_submit_form: '', stripe_payment_form: '' } do
|
23
|
+
.grid
|
24
|
+
.grid__cell.grid__cell--50-at-medium
|
25
|
+
.property.property--responsive
|
26
|
+
= label_tag 'credit_card[first_name]', nil, class: 'property__name' do
|
27
|
+
%span.property__text= t('workarea.storefront.users.first_name')
|
28
|
+
.value= text_field_tag 'credit_card[first_name]', params[:credit_card][:first_name], class: 'text-box', autocorrect: 'off', autocomplete: 'given-name', required: true
|
29
|
+
|
30
|
+
.grid__cell.grid__cell--50-at-medium
|
31
|
+
.property.property--responsive
|
32
|
+
= label_tag 'credit_card[last_name]', nil, class: 'property__name' do
|
33
|
+
%span.property__text= t('workarea.storefront.users.last_name')
|
34
|
+
.value= text_field_tag 'credit_card[last_name]', params[:credit_card][:last_name], class: 'text-box', autocorrect: 'off', autocomplete: 'family-name', required: true
|
35
|
+
|
36
|
+
.grid__cell
|
37
|
+
= render 'workarea/storefront/users/credit_cards/stripe_form'
|
38
|
+
|
39
|
+
.grid__cell
|
40
|
+
.grid.grid--auto
|
41
|
+
%p.grid__cell= button_tag t('workarea.storefront.forms.save'), value: 'save_credit_card', class: 'button'
|
42
|
+
%p.grid__cell= link_to t('workarea.storefront.forms.cancel'), users_account_path, class: "text-button", data: { dialog_close_button: '' }
|
data/bin/rails
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/workarea/stripe/engine', __FILE__)
|
7
|
+
APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require "action_controller/railtie"
|
14
|
+
require "action_view/railtie"
|
15
|
+
require "action_mailer/railtie"
|
16
|
+
require "rails/test_unit/railtie"
|
17
|
+
require "sprockets/railtie"
|
18
|
+
require 'teaspoon-mocha'
|
19
|
+
|
20
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Workarea
|
2
|
+
Plugin.append_partials(
|
3
|
+
'storefront.document_head',
|
4
|
+
'workarea/storefront/stripe/stripe_js'
|
5
|
+
)
|
6
|
+
|
7
|
+
Plugin.append_javascripts(
|
8
|
+
'storefront.config',
|
9
|
+
'workarea/storefront/stripe/config'
|
10
|
+
)
|
11
|
+
|
12
|
+
Plugin.append_partials(
|
13
|
+
'storefront.payment_method',
|
14
|
+
'workarea/storefront/checkouts/stripe_form'
|
15
|
+
)
|
16
|
+
|
17
|
+
Plugin.append_javascripts(
|
18
|
+
'storefront.modules',
|
19
|
+
'workarea/storefront/stripe/modules/stripe_elements'
|
20
|
+
)
|
21
|
+
|
22
|
+
if Rails.env.test?
|
23
|
+
Plugin.append_javascripts(
|
24
|
+
'storefront.modules',
|
25
|
+
'workarea/storefront/stripe/modules/bogus_stripe_elements'
|
26
|
+
)
|
27
|
+
else
|
28
|
+
Plugin.append_stylesheets(
|
29
|
+
'storefront.components',
|
30
|
+
'workarea/stripe/components/checkout_payment_stripe'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Workarea::Stripe.auto_initialize_gateway
|
2
|
+
|
3
|
+
Workarea.configure do |config|
|
4
|
+
config.stripe = ActiveSupport::Configurable::Configuration.new
|
5
|
+
|
6
|
+
if Workarea::Stripe.credentials.present?
|
7
|
+
config.stripe.public_key = Workarea::Stripe.credentials[:public_key]
|
8
|
+
end
|
9
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
module Billing
|
3
|
+
class BogusStripeGateway < BogusGateway
|
4
|
+
def initialize(options = {})
|
5
|
+
# noop
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def authorize(money, paysource, options = {})
|
10
|
+
if paysource.respond_to?(:emv?) && paysource.emv?
|
11
|
+
authorize_emv(money, paysource, options)
|
12
|
+
else
|
13
|
+
authorize_swipe(money, paysource, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def store(paysource, options = {})
|
18
|
+
case normalize(paysource)
|
19
|
+
when /1$/, /^tok/, ""
|
20
|
+
Response.new(true, SUCCESS_MESSAGE, { "id" => "cus_5678", "sources" => { "data" => [{ "id" => 'card_1111', "last4" => '1111', "exp_month" => "1", "exp_year" => "2020", "brand" => "Visa" }] } }, test: true)
|
21
|
+
when /2$/
|
22
|
+
Response.new(false, FAILURE_MESSAGE, { billingid: nil, error: FAILURE_MESSAGE }, test: true, error_code: STANDARD_ERROR_CODE[:processing_error])
|
23
|
+
else
|
24
|
+
raise Error, error_message(paysource)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'workarea'
|
2
|
+
require 'workarea/storefront'
|
3
|
+
require 'workarea/admin'
|
4
|
+
|
5
|
+
require 'workarea/stripe/engine'
|
6
|
+
require 'workarea/stripe/version'
|
7
|
+
|
8
|
+
require 'active_merchant/billing/bogus_stripe_gateway'
|
9
|
+
|
10
|
+
module Workarea
|
11
|
+
module Stripe
|
12
|
+
# Credentials for StripeGateway from Rails secrets.
|
13
|
+
#
|
14
|
+
# @return [Hash]
|
15
|
+
def self.credentials
|
16
|
+
return {} unless Rails.application.secrets.stripe.present?
|
17
|
+
Rails.application.secrets.stripe.symbolize_keys
|
18
|
+
end
|
19
|
+
|
20
|
+
# Conditionally use the real gateway when secrets are present.
|
21
|
+
# Otherwise, use the bogus gateway.
|
22
|
+
#
|
23
|
+
# @return [ActiveMerchant::Billing::Gateway]
|
24
|
+
def self.gateway
|
25
|
+
Workarea.config.gateways.credit_card
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.gateway=(gateway)
|
29
|
+
Workarea.config.gateways.credit_card = gateway
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.auto_initialize_gateway
|
33
|
+
if credentials.present?
|
34
|
+
if ENV['HTTP_PROXY'].present?
|
35
|
+
uri = URI.parse(ENV['HTTP_PROXY'])
|
36
|
+
ActiveMerchant::Billing::StripeGateway.proxy_address = uri.host
|
37
|
+
ActiveMerchant::Billing::StripeGateway.proxy_port = uri.port
|
38
|
+
end
|
39
|
+
|
40
|
+
self.gateway = ActiveMerchant::Billing::StripeGateway.new credentials
|
41
|
+
else
|
42
|
+
self.gateway = ActiveMerchant::Billing::BogusStripeGateway.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/dummy/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a starting point to setup your application.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# Install JavaScript dependencies if using Yarn
|
22
|
+
# system('bin/yarn')
|
23
|
+
|
24
|
+
|
25
|
+
puts "\n== Removing old logs and tempfiles =="
|
26
|
+
system! 'bin/rails log:clear tmp:clear'
|
27
|
+
|
28
|
+
puts "\n== Restarting application server =="
|
29
|
+
system! 'bin/rails restart'
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a way to update your development environment automatically.
|
15
|
+
# Add necessary update steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
puts "\n== Removing old logs and tempfiles =="
|
22
|
+
system! 'bin/rails log:clear tmp:clear'
|
23
|
+
|
24
|
+
puts "\n== Restarting application server =="
|
25
|
+
system! 'bin/rails restart'
|
26
|
+
end
|
data/test/dummy/bin/yarn
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
VENDOR_PATH = File.expand_path('..', __dir__)
|
3
|
+
Dir.chdir(VENDOR_PATH) do
|
4
|
+
begin
|
5
|
+
exec "yarnpkg #{ARGV.join(" ")}"
|
6
|
+
rescue Errno::ENOENT
|
7
|
+
$stderr.puts "Yarn executable was not detected in the system."
|
8
|
+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
# require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
require "action_mailer/railtie"
|
8
|
+
require "active_job/railtie"
|
9
|
+
require "action_cable/engine"
|
10
|
+
require "rails/test_unit/railtie"
|
11
|
+
require "sprockets/railtie"
|
12
|
+
|
13
|
+
# Workarea must be required before other gems to ensure control over Rails.env
|
14
|
+
# for running tests
|
15
|
+
require 'workarea/core'
|
16
|
+
require 'workarea/admin'
|
17
|
+
require 'workarea/storefront'
|
18
|
+
Bundler.require(*Rails.groups)
|
19
|
+
require "workarea/stripe"
|
20
|
+
|
21
|
+
module Dummy
|
22
|
+
class Application < Rails::Application
|
23
|
+
# Initialize configuration defaults for originally generated Rails version.
|
24
|
+
config.load_defaults 5.1
|
25
|
+
|
26
|
+
# Settings in config/environments/* take precedence over those specified here.
|
27
|
+
# Application configuration should go into files in config/initializers
|
28
|
+
# -- all .rb files in that directory are automatically loaded.
|
29
|
+
end
|
30
|
+
end
|