spree_gateway 3.3.7 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd974d5699eb1d952f981435c81405d4cff0ac19f4bbbe1d9e6fa14cdeaf51f8
4
- data.tar.gz: 7ba5f9c55f4467ed8c2846a38ff186606ed919a50bdf3835a052a95cc515472a
3
+ metadata.gz: aad9aebb297d8d3075838334fa28add9b8d814ff823221b9c45dde589e8ef854
4
+ data.tar.gz: f31ea14dab0e47a5d046b7890c351c257e5eecdd779300efc1251b63527cf6ef
5
5
  SHA512:
6
- metadata.gz: 6b2aeb0c49744cbe445461485577ca9ab6088e6edcd5d921c46e3610273d01aec8a4c6a56253b57fb56d338c7c034cad5119ec765de251e2130c1306c82f9d28
7
- data.tar.gz: eafb26b67ee4052ca4f51b923aa3a1c786a98b78a049956b090a6b52fd627b374c97b5317db9faae93c4c67d4bf1d105ea9ae1492e921f86499ae60c2de6bd8a
6
+ metadata.gz: d88b3801880261fb8ad09ca80549f436c2dd71a6c47319dd4a6f22b5bf6b0dd88300028b4c5f859018fa0f9c221ddaf49e22091da5208d8054b48d10ce05d149
7
+ data.tar.gz: 2be4ce4186492ad74826a4d58b1f5415078457aa380373e592cbd80dc2116443a9d1de04fec68c0d51abe47af5e2486ea1240524fd3e79cea7a2fd9bb1a9182e
@@ -11,8 +11,9 @@ env:
11
11
  - DB=mysql
12
12
 
13
13
  gemfile:
14
- - gemfiles/spree_3_1.gemfile
15
14
  - gemfiles/spree_3_2.gemfile
15
+ - gemfiles/spree_3_5.gemfile
16
+ - gemfiles/spree_3_6.gemfile
16
17
  - gemfiles/spree_master.gemfile
17
18
 
18
19
  script:
@@ -20,8 +21,9 @@ script:
20
21
  - bundle exec rake spec
21
22
 
22
23
  rvm:
23
- - 2.3.1
24
- - 2.2.7
24
+ - 2.5.1
25
+ - 2.4.4
26
+ - 2.3.7
25
27
 
26
28
  matrix:
27
29
  allow_failures:
data/Appraisals CHANGED
@@ -1,12 +1,18 @@
1
- appraise 'spree-3-1' do
2
- gem 'spree', '~> 3.1.0'
3
- end
4
-
5
1
  appraise 'spree-3-2' do
6
2
  gem 'spree', '~> 3.2.0'
7
3
  gem 'rails-controller-testing'
8
4
  end
9
5
 
6
+ appraise 'spree-3-5' do
7
+ gem 'spree', '~> 3.5.0'
8
+ gem 'rails-controller-testing'
9
+ end
10
+
11
+ appraise 'spree-3-6' do
12
+ gem 'spree', '~> 3.6.0'
13
+ gem 'rails-controller-testing'
14
+ end
15
+
10
16
  appraise 'spree-master' do
11
17
  gem 'spree', github: 'spree/spree', branch: 'master'
12
18
  gem 'rails-controller-testing'
data/README.md CHANGED
@@ -4,10 +4,33 @@
4
4
  [![Code Climate](https://codeclimate.com/github/spree/spree_gateway.svg)](https://codeclimate.com/github/spree/spree_gateway)
5
5
 
6
6
  Community supported Spree Payment Method Gateways. It works as a wrapper for
7
- active_merchant gateway. Note that for some gateways you might still need to
8
- add another gem to your Gemfile to make it work. For example active_merchant
9
- require `braintree` but it doesn't include that gem on its gemspec. So you
10
- need to manually add it to your rails app Gemfile.
7
+ [active_merchant](https://github.com/activemerchant/active_merchant) gateway.
8
+
9
+ Supported payment gateways:
10
+ * Authorize.net (with CIM support)
11
+ * Apple Pay (via Stripe)
12
+ * BanWire
13
+ * Bambora (previously Beanstream)
14
+ * Braintree
15
+ * CyberSource
16
+ * ePay
17
+ * eWay
18
+ * maxipago
19
+ * MasterCard Payment Gateway Service (formerly MiGS)
20
+ * Moneris
21
+ * PayJunction
22
+ * Payflow
23
+ * Paymill
24
+ * Pin Payments
25
+ * QuickPay
26
+ * sage Pay
27
+ * SecurePay
28
+ * Spreadly
29
+ * Stripe (with Stripe Elements)
30
+ * USAePay
31
+ * Worldpay (previously Cardsave)
32
+
33
+ For`PayPal` support head over to [braintree_vzero](https://github.com/spree-contrib/spree_braintree_vzero) extension.
11
34
 
12
35
  ## Installation
13
36
 
@@ -70,7 +93,21 @@ Starting point:
70
93
  * Submit your pull request
71
94
 
72
95
 
73
- Copyright (c) 2014 [Spree Commerce][4] and other [contributors][5], released under the [New BSD License][3]
96
+ License
97
+ ----------------------
98
+
99
+ Spree is released under the [New BSD License][3].
100
+
101
+ About Spark Solutions
102
+ ----------------------
103
+ [![Spark Solutions](http://sparksolutions.co/wp-content/uploads/2015/01/logo-ss-tr-221x100.png)][spark]
104
+
105
+ Spree Gateway is maintained by [Spark Solutions Sp. z o.o.][spark].
106
+
107
+ We are passionate about open source software.
108
+ We are [available for hire][spark].
109
+
110
+ [spark]:http://sparksolutions.co?utm_source=github
74
111
 
75
112
  [1]: http://www.fsf.org/licensing/essays/free-sw.html
76
113
  [2]: https://github.com/spree/spree_gateway/issues
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ class Gateway::StripeApplePayGateway < Gateway::StripeGateway
3
+ preference :country_code, :string, default: 'US'
4
+ preference :domain_verification_certificate, :text
5
+
6
+ def method_type
7
+ 'stripe_apple_pay'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Spree
2
+ class Gateway::StripeElementsGateway < Gateway::StripeGateway
3
+ def method_type
4
+ 'stripe_elements'
5
+ end
6
+ end
7
+ end
@@ -87,17 +87,14 @@ module Spree
87
87
 
88
88
  # In this gateway, what we call 'secret_key' is the 'login'
89
89
  def options
90
- super.merge(
91
- login: preferred_secret_key,
92
- application: app_info
93
- )
90
+ options = super
91
+ options.merge(:login => preferred_secret_key)
94
92
  end
95
93
 
96
94
  def options_for_purchase_or_auth(money, creditcard, gateway_options)
97
95
  options = {}
98
96
  options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
99
97
  options[:currency] = gateway_options[:currency]
100
- options[:application] = app_info
101
98
 
102
99
  if customer = creditcard.gateway_customer_profile_id
103
100
  options[:customer] = customer
@@ -136,11 +133,5 @@ module Spree
136
133
  source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
137
134
  source
138
135
  end
139
-
140
- def app_info
141
- name_with_version = "SpreeGateway/#{SpreeGateway.version}"
142
- url = 'https://spreecommerce.org'
143
- "#{name_with_version} #{url}"
144
- end
145
136
  end
146
137
  end
@@ -0,0 +1,15 @@
1
+ module SpreeGateway
2
+ module ApplePayOrderDecorator
3
+ def confirmation_required?
4
+ return false if paid_with_apple_pay?
5
+
6
+ super
7
+ end
8
+
9
+ def paid_with_apple_pay?
10
+ payments.valid.any?(&:apple_pay?)
11
+ end
12
+ end
13
+ end
14
+
15
+ Spree::Order.prepend SpreeGateway::ApplePayOrderDecorator
@@ -0,0 +1,9 @@
1
+ module SpreeGateway
2
+ module ApplePayPaymentDecorator
3
+ def apple_pay?
4
+ payment_method.is_a? Spree::Gateway::StripeApplePayGateway
5
+ end
6
+ end
7
+ end
8
+
9
+ Spree::Payment.prepend SpreeGateway::ApplePayPaymentDecorator
@@ -0,0 +1,6 @@
1
+ # we need to add this route to the root Rails application because Spree can
2
+ # be mounted to some path eg. /shop and Apple Pay expects to access this file
3
+ # via https://example.com/.well-known/apple-developer-merchantid-domain-association
4
+ Rails.application.routes.draw do
5
+ get '/.well-known/apple-developer-merchantid-domain-association' => 'spree/apple_pay_domain_verification#show'
6
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "spree", "~> 3.2.0"
6
5
  gem "rails-controller-testing"
6
+ gem "spree", "~> 3.2.0"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails-controller-testing"
6
+ gem "spree", "~> 3.5.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails-controller-testing"
6
+ gem "spree", "~> 3.6.0"
7
+
8
+ gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "spree", :github => "spree/spree", :branch => "master"
6
5
  gem "rails-controller-testing"
6
+ gem "spree", github: "spree/spree", branch: "master"
7
7
 
8
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ module Spree
2
+ class ApplePayDomainVerificationController < Spree::BaseController
3
+ def show
4
+ gateway = Spree::Gateway::StripeApplePayGateway.active.last
5
+
6
+ raise ActiveRecord::RecordNotFound unless gateway
7
+
8
+ render plain: gateway.preferred_domain_verification_certificate
9
+ end
10
+ end
11
+ end
@@ -1,27 +1,18 @@
1
1
  module SpreeGateway
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
- class_option :auto_run_migrations, type: :boolean, default: false
4
+ class_option :migrate, type: :boolean, default: true, banner: 'Migrate the database'
5
5
 
6
6
  def add_migrations
7
7
  run 'bundle exec rake railties:install:migrations FROM=spree_gateway'
8
8
  end
9
9
 
10
10
  def run_migrations
11
- if running_migrations?
12
- run 'bundle exec rake db:migrate'
13
- else
14
- puts "Skiping rake db:migrate, don't forget to run it!"
15
- end
16
- end
17
-
18
- private
19
-
20
- def running_migrations?
21
- options.auto_run_migrations? || begin
22
- response = ask 'Would you like to run the migrations now? [Y/n]'
23
- ['', 'y'].include? response.downcase
24
- end
11
+ if options[:migrate]
12
+ run 'bundle exec rake db:migrate VERBOSE=false'
13
+ else
14
+ puts "Skiping rake db:migrate, don't forget to run it!"
15
+ end
25
16
  end
26
17
  end
27
18
  end
@@ -1,5 +1,4 @@
1
1
  require 'spree_core'
2
2
  require 'spree_gateway/engine'
3
- require 'spree_gateway/version'
4
3
  require 'sass/rails'
5
4
  require 'spree_extension'
@@ -30,6 +30,8 @@ module SpreeGateway
30
30
  app.config.spree.payment_methods << Spree::Gateway::SecurePayAU
31
31
  app.config.spree.payment_methods << Spree::Gateway::SpreedlyCoreGateway
32
32
  app.config.spree.payment_methods << Spree::Gateway::StripeGateway
33
+ app.config.spree.payment_methods << Spree::Gateway::StripeElementsGateway
34
+ app.config.spree.payment_methods << Spree::Gateway::StripeApplePayGateway
33
35
  app.config.spree.payment_methods << Spree::Gateway::UsaEpayTransaction
34
36
  app.config.spree.payment_methods << Spree::Gateway::Worldpay
35
37
  end
@@ -40,11 +42,8 @@ module SpreeGateway
40
42
  'lib/assets/javascripts/spree/frontend/spree_gateway.js',
41
43
  'lib/assets/stylesheets/spree/frontend/spree_gateway.css',
42
44
  ]
43
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
44
- Rails.configuration.cache_classes ? require(c) : load(c)
45
- end
46
45
  end
47
- Dir.glob(File.join(File.dirname(__FILE__), '../../lib/active_merchant/**/*_decorator*.rb')) do |c|
46
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/spree/*_decorator*.rb')) do |c|
48
47
  Rails.application.config.cache_classes ? require(c) : load(c)
49
48
  end
50
49
  end
@@ -61,8 +60,9 @@ module SpreeGateway
61
60
  paths["app/views"] << "lib/views/backend"
62
61
  end
63
62
 
63
+ paths['app/controllers'] << 'lib/controllers'
64
+
64
65
  if self.frontend_available?
65
- paths["app/controllers"] << "lib/controllers/frontend"
66
66
  paths["app/views"] << "lib/views/frontend"
67
67
  end
68
68
 
@@ -57,7 +57,7 @@
57
57
  }
58
58
  };
59
59
 
60
- $(document).ready(function() {
60
+ Spree.ready(function() {
61
61
  Spree.stripePaymentMethod.prepend("<div id='stripeError' class='errorExplanation alert alert-danger' style='display:none'></div>");
62
62
  return $('#checkout_form_payment [data-hook=buttons]').click(function() {
63
63
  var expiration, params;
@@ -78,16 +78,4 @@
78
78
  });
79
79
  </script>
80
80
 
81
- <%- if @order.has_checkout_step?('address') -%>
82
- <script>
83
- Spree.stripeAdditionalInfo = {
84
- name: "<%= @order.bill_address.full_name %>",
85
- address_line1: "<%= @order.bill_address.address1 %>",
86
- address_line2: "<%= @order.bill_address.address2 %>",
87
- address_city: "<%= @order.bill_address.city %>",
88
- address_state: "<%= @order.bill_address.state_text %>",
89
- address_zip: "<%= @order.bill_address.zipcode %>",
90
- address_country: "<%= @order.bill_address.country %>"
91
- }
92
- </script>
93
- <%- end -%>
81
+ <%= render 'spree/checkout/payment/stripe_additional_info', bill_address: @order.bill_address %>
@@ -0,0 +1,14 @@
1
+ <% bill_address ||= @order.bill_address %>
2
+ <%- if @order.has_checkout_step?('address') -%>
3
+ <script>
4
+ Spree.stripeAdditionalInfo = {
5
+ name: "<%= bill_address.full_name %>",
6
+ address_line1: "<%= bill_address.address1 %>",
7
+ address_line2: "<%= bill_address.address2 %>",
8
+ address_city: "<%= bill_address.city %>",
9
+ address_state: "<%= bill_address.state_text %>",
10
+ address_zip: "<%= bill_address.zipcode %>",
11
+ address_country: "<%= bill_address.country %>"
12
+ }
13
+ </script>
14
+ <%- end -%>
@@ -0,0 +1,97 @@
1
+ <% param_prefix = "payment_source[#{payment_method.id}]" %>
2
+
3
+ <div id="payment-request-button">
4
+ <!-- A Stripe Element will be inserted here. -->
5
+ </div>
6
+
7
+ <script type="text/javascript" src="https://js.stripe.com/v3/"></script>
8
+
9
+ <script>
10
+ Spree.stripeApplePayPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
11
+ var stripeApplePay = Stripe("<%= payment_method.preferred_publishable_key %>");
12
+ var elements = stripeApplePay.elements();
13
+
14
+ var paymentRequest = stripeApplePay.paymentRequest({
15
+ country: '<%= payment_method.preferred_country_code.try(:upcase) %>',
16
+ currency: '<%= @order.currency.downcase %>',
17
+ displayItems: [
18
+ <% @order.line_items.each do |line_item| %>
19
+ {
20
+ label: '<%= line_item.name %> x <%= line_item.quantity %>',
21
+ amount: <%= Spree::Money.new(line_item.total, currency: line_item.currency).amount_in_cents %>
22
+ },
23
+ <% end %>
24
+ <% if @order.tax_total != 0 %>
25
+ {
26
+ label: '<%= Spree.t(:tax) %>',
27
+ amount: <%= Spree::Money.new(@order.tax_total, currency: @order.currency).amount_in_cents %>
28
+ },
29
+ <% end %>
30
+ <% if @order.shipment_total != 0 %>
31
+ {
32
+ label: '<%= Spree.t(:shipment) %>',
33
+ amount: <%= Spree::Money.new(@order.shipment_total, currency: @order.currency).amount_in_cents %>
34
+ }
35
+ <% end %>
36
+ ],
37
+ total: {
38
+ label: '<%= Spree.t(:total) %>',
39
+ amount: <%= Spree::Money.new(@order.total, currency: @order.currency).amount_in_cents %>
40
+ },
41
+ requestPayerName: false,
42
+ requestPayerEmail: false,
43
+ requestPayerPhone: false
44
+ });
45
+
46
+ var prButton = elements.create('paymentRequestButton', {
47
+ paymentRequest: paymentRequest,
48
+ });
49
+
50
+ // Check the availability of the Payment Request API first.
51
+ paymentRequest.canMakePayment().then(function(result) {
52
+ if (result) {
53
+ prButton.mount('#payment-request-button');
54
+ } else {
55
+ document.getElementById('payment-request-button').style.display = 'none';
56
+ }
57
+ });
58
+
59
+ function addCreditCardFieldToForm(form, name, value) {
60
+ var hiddenInput = document.createElement('input');
61
+
62
+ hiddenInput.setAttribute('type', 'hidden');
63
+ hiddenInput.setAttribute('name', name);
64
+ hiddenInput.setAttribute('value', value);
65
+ form.appendChild(hiddenInput);
66
+ };
67
+
68
+ paymentRequest.on('token', function(ev) {
69
+ var form = document.getElementById('checkout_form_payment');
70
+ var token = ev.token;
71
+ if (ev.payerName) {
72
+ var payerName = ev.payerName
73
+ } else if (Spree.stripeAdditionalInfo) {
74
+ var payerName = Spree.stripeAdditionalInfo.name
75
+ }
76
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[gateway_payment_profile_id]', token.id);
77
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[number]', token.card.last4);
78
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[month]', token.card.exp_month);
79
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[year]', token.card.exp_year);
80
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[name]', payerName);
81
+ ev.complete('success');
82
+ form.submit();
83
+ });
84
+
85
+ Spree.ready(function() {
86
+ Spree.stripeApplePayPaymentMethod.prepend("<div id='stripeApplePayError' class='errorExplanation alert alert-danger' style='display:none'></div>");
87
+ var form = document.getElementById('checkout_form_payment');
88
+ form.addEventListener('submit', function(e) {
89
+ if (Spree.stripeApplePayPaymentMethod.is(':visible')) {
90
+ $('#stripeApplePayError').hide();
91
+ e.preventDefault();
92
+ }
93
+ });
94
+ });
95
+ </script>
96
+
97
+ <%= render 'spree/checkout/payment/stripe_additional_info' %>
@@ -0,0 +1,104 @@
1
+ <% param_prefix = "payment_source[#{payment_method.id}]" %>
2
+ <div class="well clearfix">
3
+ <p class="field">
4
+ <%= label_tag "name_on_card_#{payment_method.id}" do %>
5
+ <%= Spree.t(:name_on_card) %><abbr class="required" title="required">*</abbr>
6
+ <% end %>
7
+ <%= text_field_tag "#{param_prefix}[name]", "#{@order.bill_address_firstname} #{@order.bill_address_lastname}", { id: "name_on_card_#{payment_method.id}", class: 'form-control required'} %>
8
+ </p>
9
+ <div class="form-row">
10
+ <%= label_tag "card_number" do %>
11
+ <%= Spree.t(:card_number) %><abbr class="required" title="required">*</abbr>
12
+ <% end %>
13
+ <div class="form-control required cardNumber">
14
+ <div id="card-element">
15
+ <!-- a Stripe Element will be inserted here. -->
16
+ </div>
17
+ </div>
18
+ <!-- Used to display form errors -->
19
+ <div id="card-errors" role="alert"></div>
20
+ </div>
21
+ </p>
22
+ </div>
23
+
24
+ <script type="text/javascript" src="https://js.stripe.com/v3/"></script>
25
+
26
+ <script>
27
+ Spree.stripeElementsPaymentMethod = $('#payment_method_' + <%= payment_method.id %>);
28
+ var stripeElements = Stripe("<%= payment_method.preferred_publishable_key %>");
29
+ var elements = stripeElements.elements();
30
+
31
+ var card = elements.create('card', {
32
+ iconStyle: 'solid',
33
+ hidePostalCode: true,
34
+ style: {
35
+ base: {
36
+ iconColor: '#555555',
37
+ lineHeight: '24px',
38
+ fontWeight: 300,
39
+ fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
40
+ fontSize: '14px',
41
+
42
+ '::placeholder': {
43
+ color: '#555555',
44
+ },
45
+ },
46
+ invalid: {
47
+ iconColor: '#e85746',
48
+ color: '#e85746',
49
+ }
50
+ },
51
+ classes: {
52
+ focus: 'is-focused',
53
+ empty: 'is-empty',
54
+ },
55
+ });
56
+ card.mount('#card-element');
57
+
58
+ function addCreditCardFieldToForm(form, name, value) {
59
+ var hiddenInput = document.createElement('input');
60
+
61
+ hiddenInput.setAttribute('type', 'hidden');
62
+ hiddenInput.setAttribute('name', name);
63
+ hiddenInput.setAttribute('value', value);
64
+ form.appendChild(hiddenInput);
65
+ };
66
+
67
+ function stripeElementsTokenHandler(token) {
68
+ var form = document.getElementById('checkout_form_payment');
69
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[gateway_payment_profile_id]', token.id)
70
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[number]', token.card.last4)
71
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[month]', token.card.exp_month)
72
+ addCreditCardFieldToForm(form, '<%= param_prefix %>[year]', token.card.exp_year)
73
+ form.submit();
74
+ };
75
+
76
+ function createStripeElementsToken() {
77
+ stripeElements.createToken(card, Spree.stripeAdditionalInfo).then(function (result) {
78
+ if (result.error) {
79
+ // Inform the user if there was an error
80
+ var errorElement = document.getElementById('card-errors');
81
+
82
+ $('#stripeElementsError').html(result.error.message);
83
+ $('#stripeElementsError').show()
84
+ Spree.enableSave();
85
+ } else {
86
+ stripeElementsTokenHandler(result.token);
87
+ }
88
+ });
89
+ };
90
+
91
+ Spree.ready(function() {
92
+ Spree.stripeElementsPaymentMethod.prepend("<div id='stripeElementsError' class='errorExplanation alert alert-danger' style='display:none'></div>");
93
+ var form = document.getElementById('checkout_form_payment');
94
+ form.addEventListener('submit', function(e) {
95
+ if (Spree.stripeElementsPaymentMethod.is(':visible')) {
96
+ $('#stripeElementsError').hide();
97
+ e.preventDefault();
98
+ createStripeElementsToken();
99
+ }
100
+ });
101
+ });
102
+ </script>
103
+
104
+ <%= render 'spree/checkout/payment/stripe_additional_info' %>
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Order do
4
+ let(:order_one) { OrderWalkthrough.up_to(:payment) }
5
+ let(:order_two) { OrderWalkthrough.up_to(:payment) }
6
+ let(:stripe_apple_pay_payment_method) do
7
+ Spree::Gateway::StripeApplePayGateway.create!(
8
+ name: 'ApplePay',
9
+ preferred_domain_verification_certificate: FFaker::Lorem.characters(20)
10
+ )
11
+ end
12
+ let(:stripe_credit_card_payment_method) do
13
+ Spree::Gateway::StripeGateway.create!(
14
+ name: 'CreditCard',
15
+ preferred_secret_key: FFaker::Lorem.characters(20),
16
+ preferred_publishable_key: FFaker::Lorem.characters(20)
17
+ )
18
+ end
19
+
20
+ before do
21
+ Spree::Config[:always_include_confirm_step] = true
22
+ allow_any_instance_of(Spree::PaymentMethod).to receive(:source_required?).and_return(false)
23
+
24
+ order_one.payments.create(payment_method_id: stripe_apple_pay_payment_method.id,
25
+ amount: 29.99,
26
+ state: 'completed')
27
+ order_two.payments.create(payment_method_id: stripe_credit_card_payment_method.id,
28
+ amount: 29.99,
29
+ state: 'completed')
30
+ order_one.update_totals
31
+ order_two.update_totals
32
+ end
33
+
34
+ describe '#paid_with_apple_pay?' do
35
+ context 'when an order was paid with Apply Pay' do
36
+ it 'returns true' do
37
+ expect(order_one.paid_with_apple_pay?).to eq true
38
+ end
39
+ end
40
+
41
+ context 'when an order was paid with Credit Card' do
42
+ it 'returns false' do
43
+ expect(order_two.paid_with_apple_pay?).to eq false
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#confirmation_required?' do
49
+ context 'when an order was paid with Apply Pay' do
50
+ it 'returns false' do
51
+ expect(order_one.confirmation_required?).to eq false
52
+ end
53
+ end
54
+
55
+ context 'when an order was paid with Credit Card' do
56
+ it 'returns true' do
57
+ expect(order_two.confirmation_required?).to eq true
58
+ end
59
+ end
60
+ end
61
+
62
+ context 'when an order was paid with Apply Pay' do
63
+ it 'proceeds to Complete order state' do
64
+ order_one.next
65
+
66
+ expect(order_one.state).to eq 'complete'
67
+ end
68
+ end
69
+
70
+ context 'when an order was paid with Credit Card' do
71
+ it 'proceeds to Confirm order state' do
72
+ order_two.next
73
+
74
+ expect(order_two.state).to eq 'confirm'
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Apple Pay Domain Verification', type: :request do
4
+ let(:domain_verification_certificate) { FFaker::Lorem.characters(20) }
5
+ let(:stripe_apple_pay_payment_method) do
6
+ Spree::Gateway::StripeApplePayGateway.create!(
7
+ name: 'ApplePay',
8
+ preferred_domain_verification_certificate: domain_verification_certificate
9
+ )
10
+ end
11
+ let(:execute) { get '/.well-known/apple-developer-merchantid-domain-association' }
12
+
13
+ shared_examples 'returns 404' do
14
+ it 'returns RecordNotFound exception' do
15
+ expect { execute }.to raise_exception(ActiveRecord::RecordNotFound)
16
+ end
17
+ end
18
+
19
+ context 'apple pay gateway exists' do
20
+ before do
21
+ stripe_apple_pay_payment_method
22
+ execute
23
+ end
24
+
25
+ it 'returns 200 HTTP status' do
26
+ expect(response.status).to eq(200)
27
+ end
28
+
29
+ it 'renders domain verification certificate' do
30
+ expect(response.body).to eq domain_verification_certificate
31
+ end
32
+ end
33
+
34
+ context 'apple pay gateway doesnt exist' do
35
+ it_behaves_like 'returns 404'
36
+ end
37
+
38
+ context 'apple pay gateway not active' do
39
+ before do
40
+ stripe_apple_pay_payment_method.update_column(:active, false)
41
+ end
42
+
43
+ it_behaves_like 'returns 404'
44
+ end
45
+ end
@@ -11,10 +11,10 @@ require 'capybara/rspec'
11
11
  require 'capybara/rails'
12
12
  require 'capybara-screenshot/rspec'
13
13
  require "selenium-webdriver"
14
- require 'webdrivers'
15
14
  require 'database_cleaner'
16
15
  require 'ffaker'
17
16
  require 'rspec/active_model/mocks'
17
+ require 'pry'
18
18
 
19
19
  Dir[File.join(File.dirname(__FILE__), "support", "**", "*.rb")].each { |f| require f }
20
20
 
@@ -23,7 +23,7 @@ require 'spree/testing_support/order_walkthrough'
23
23
  require 'spree/testing_support/preferences'
24
24
  require 'spree/testing_support/capybara_ext'
25
25
 
26
- FactoryGirl.find_definitions
26
+ FactoryBot.find_definitions
27
27
 
28
28
  RSpec.configure do |config|
29
29
  config.infer_spec_type_from_file_location!
@@ -35,7 +35,7 @@ RSpec.configure do |config|
35
35
  #config.filter_run focus: true
36
36
  #config.filter_run_excluding slow: true
37
37
 
38
- config.include FactoryGirl::Syntax::Methods
38
+ config.include FactoryBot::Syntax::Methods
39
39
  config.include Spree::TestingSupport::Preferences
40
40
 
41
41
  config.before :suite do
@@ -56,10 +56,8 @@ RSpec.configure do |config|
56
56
  Capybara.register_driver :chrome do |app|
57
57
  Capybara::Selenium::Driver.new app,
58
58
  browser: :chrome,
59
- options: Selenium::WebDriver::Chrome::Options.new(
60
- args: %w[no-sandbox disable-dev-shm-usage disable-popup-blocking headless disable-gpu window-size=1920,1080 --enable-features=NetworkService,NetworkServiceInProcess --disable-features=VizDisplayCompositor],
61
- log_level: :error
62
- )
59
+ options: Selenium::WebDriver::Chrome::Options.new(args: %w[disable-popup-blocking headless disable-gpu window-size=1920,1080])
63
60
  end
61
+
64
62
  Capybara.javascript_driver = :chrome
65
63
  end
@@ -1,13 +1,8 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib/', __FILE__)
3
- $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
-
5
- require 'spree_gateway/version'
6
-
7
2
  Gem::Specification.new do |s|
8
3
  s.platform = Gem::Platform::RUBY
9
4
  s.name = 'spree_gateway'
10
- s.version = SpreeGateway.version
5
+ s.version = '3.4.0'
11
6
  s.summary = 'Additional Payment Gateways for Spree Commerce'
12
7
  s.description = s.summary
13
8
 
@@ -25,27 +20,25 @@ Gem::Specification.new do |s|
25
20
  s.add_dependency 'spree_core', spree_version
26
21
  s.add_dependency 'spree_extension'
27
22
 
23
+ s.add_development_dependency 'appraisal'
24
+ s.add_development_dependency 'bootstrap-sass', '>= 3.3.5.1'
28
25
  s.add_development_dependency 'braintree'
29
26
  s.add_development_dependency 'capybara'
30
27
  s.add_development_dependency 'capybara-screenshot'
31
28
  s.add_development_dependency 'coffee-rails'
32
29
  s.add_development_dependency 'database_cleaner'
33
- s.add_development_dependency 'factory_girl'
34
- s.add_development_dependency 'factory_bot', '~> 4.7'
30
+ s.add_development_dependency 'factory_bot'
35
31
  s.add_development_dependency 'ffaker'
36
32
  s.add_development_dependency 'guard-rspec'
37
33
  s.add_development_dependency 'launchy'
38
- s.add_development_dependency 'mysql2'
34
+ s.add_development_dependency 'mysql2', '~> 0.5.1'
39
35
  s.add_development_dependency 'pg', '~> 0.18'
40
36
  s.add_development_dependency 'pry'
41
37
  s.add_development_dependency 'puma'
42
38
  s.add_development_dependency 'rspec-activemodel-mocks'
43
39
  s.add_development_dependency 'rspec-rails'
44
- s.add_development_dependency 'bootstrap-sass', '>= 3.3.5.1'
45
40
  s.add_development_dependency 'sass-rails', '>= 3.2'
46
41
  s.add_development_dependency 'selenium-webdriver'
47
- s.add_development_dependency 'webdrivers', '~> 3.9.0'
48
42
  s.add_development_dependency 'simplecov'
49
- s.add_development_dependency 'sqlite3', '~> 1.3.6'
50
- s.add_development_dependency 'appraisal'
43
+ s.add_development_dependency 'sqlite3'
51
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.7
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spree Commerce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: braintree
48
+ name: appraisal
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
@@ -59,7 +59,21 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: capybara
62
+ name: bootstrap-sass
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.3.5.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.3.5.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: braintree
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - ">="
@@ -73,7 +87,7 @@ dependencies:
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
- name: capybara-screenshot
90
+ name: capybara
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - ">="
@@ -87,7 +101,7 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: coffee-rails
104
+ name: capybara-screenshot
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - ">="
@@ -101,7 +115,7 @@ dependencies:
101
115
  - !ruby/object:Gem::Version
102
116
  version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
- name: database_cleaner
118
+ name: coffee-rails
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - ">="
@@ -115,7 +129,7 @@ dependencies:
115
129
  - !ruby/object:Gem::Version
116
130
  version: '0'
117
131
  - !ruby/object:Gem::Dependency
118
- name: factory_girl
132
+ name: database_cleaner
119
133
  requirement: !ruby/object:Gem::Requirement
120
134
  requirements:
121
135
  - - ">="
@@ -132,16 +146,16 @@ dependencies:
132
146
  name: factory_bot
133
147
  requirement: !ruby/object:Gem::Requirement
134
148
  requirements:
135
- - - "~>"
149
+ - - ">="
136
150
  - !ruby/object:Gem::Version
137
- version: '4.7'
151
+ version: '0'
138
152
  type: :development
139
153
  prerelease: false
140
154
  version_requirements: !ruby/object:Gem::Requirement
141
155
  requirements:
142
- - - "~>"
156
+ - - ">="
143
157
  - !ruby/object:Gem::Version
144
- version: '4.7'
158
+ version: '0'
145
159
  - !ruby/object:Gem::Dependency
146
160
  name: ffaker
147
161
  requirement: !ruby/object:Gem::Requirement
@@ -188,16 +202,16 @@ dependencies:
188
202
  name: mysql2
189
203
  requirement: !ruby/object:Gem::Requirement
190
204
  requirements:
191
- - - ">="
205
+ - - "~>"
192
206
  - !ruby/object:Gem::Version
193
- version: '0'
207
+ version: 0.5.1
194
208
  type: :development
195
209
  prerelease: false
196
210
  version_requirements: !ruby/object:Gem::Requirement
197
211
  requirements:
198
- - - ">="
212
+ - - "~>"
199
213
  - !ruby/object:Gem::Version
200
- version: '0'
214
+ version: 0.5.1
201
215
  - !ruby/object:Gem::Dependency
202
216
  name: pg
203
217
  requirement: !ruby/object:Gem::Requirement
@@ -268,20 +282,6 @@ dependencies:
268
282
  - - ">="
269
283
  - !ruby/object:Gem::Version
270
284
  version: '0'
271
- - !ruby/object:Gem::Dependency
272
- name: bootstrap-sass
273
- requirement: !ruby/object:Gem::Requirement
274
- requirements:
275
- - - ">="
276
- - !ruby/object:Gem::Version
277
- version: 3.3.5.1
278
- type: :development
279
- prerelease: false
280
- version_requirements: !ruby/object:Gem::Requirement
281
- requirements:
282
- - - ">="
283
- - !ruby/object:Gem::Version
284
- version: 3.3.5.1
285
285
  - !ruby/object:Gem::Dependency
286
286
  name: sass-rails
287
287
  requirement: !ruby/object:Gem::Requirement
@@ -310,20 +310,6 @@ dependencies:
310
310
  - - ">="
311
311
  - !ruby/object:Gem::Version
312
312
  version: '0'
313
- - !ruby/object:Gem::Dependency
314
- name: webdrivers
315
- requirement: !ruby/object:Gem::Requirement
316
- requirements:
317
- - - "~>"
318
- - !ruby/object:Gem::Version
319
- version: 3.9.0
320
- type: :development
321
- prerelease: false
322
- version_requirements: !ruby/object:Gem::Requirement
323
- requirements:
324
- - - "~>"
325
- - !ruby/object:Gem::Version
326
- version: 3.9.0
327
313
  - !ruby/object:Gem::Dependency
328
314
  name: simplecov
329
315
  requirement: !ruby/object:Gem::Requirement
@@ -340,20 +326,6 @@ dependencies:
340
326
  version: '0'
341
327
  - !ruby/object:Gem::Dependency
342
328
  name: sqlite3
343
- requirement: !ruby/object:Gem::Requirement
344
- requirements:
345
- - - "~>"
346
- - !ruby/object:Gem::Version
347
- version: 1.3.6
348
- type: :development
349
- prerelease: false
350
- version_requirements: !ruby/object:Gem::Requirement
351
- requirements:
352
- - - "~>"
353
- - !ruby/object:Gem::Version
354
- version: 1.3.6
355
- - !ruby/object:Gem::Dependency
356
- name: appraisal
357
329
  requirement: !ruby/object:Gem::Requirement
358
330
  requirements:
359
331
  - - ">="
@@ -406,34 +378,42 @@ files:
406
378
  - app/models/spree/gateway/sage_pay.rb
407
379
  - app/models/spree/gateway/secure_pay_au.rb
408
380
  - app/models/spree/gateway/spreedly_core_gateway.rb
381
+ - app/models/spree/gateway/stripe_apple_pay_gateway.rb
382
+ - app/models/spree/gateway/stripe_elements_gateway.rb
409
383
  - app/models/spree/gateway/stripe_gateway.rb
410
384
  - app/models/spree/gateway/usa_epay_transaction.rb
411
385
  - app/models/spree/gateway/worldpay.rb
386
+ - app/models/spree/order_decorator.rb
387
+ - app/models/spree/payment_decorator.rb
412
388
  - config/locales/bg.yml
413
389
  - config/locales/de.yml
414
390
  - config/locales/en.yml
415
391
  - config/locales/sv.yml
392
+ - config/routes.rb
416
393
  - db/migrate/20121017004102_update_braintree_payment_method_type.rb
417
394
  - db/migrate/20130213222555_update_stripe_payment_method_type.rb
418
395
  - db/migrate/20130415222802_update_balanced_payment_method_type.rb
419
396
  - db/migrate/20131008221012_update_paypal_payment_method_type.rb
420
397
  - db/migrate/20131112133401_migrate_stripe_preferences.rb
421
- - gemfiles/spree_3_1.gemfile
422
398
  - gemfiles/spree_3_2.gemfile
399
+ - gemfiles/spree_3_5.gemfile
400
+ - gemfiles/spree_3_6.gemfile
423
401
  - gemfiles/spree_master.gemfile
424
- - lib/active_merchant/billing/gateways/stripe_decorator.rb
425
402
  - lib/assets/javascripts/spree/frontend/spree_gateway.js
426
403
  - lib/assets/stylesheets/spree/frontend/spree_gateway.css
404
+ - lib/controllers/spree/apple_pay_domain_verification_controller.rb
427
405
  - lib/generators/spree_gateway/install/install_generator.rb
428
406
  - lib/spree_gateway.rb
429
407
  - lib/spree_gateway/engine.rb
430
- - lib/spree_gateway/version.rb
431
408
  - lib/views/backend/spree/admin/log_entries/_braintree.html.erb
432
409
  - lib/views/backend/spree/admin/log_entries/_stripe.html.erb
433
410
  - lib/views/backend/spree/admin/payments/source_forms/_quickcheckout.html.erb
434
411
  - lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb
435
412
  - lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb
436
413
  - lib/views/frontend/spree/checkout/payment/_stripe.html.erb
414
+ - lib/views/frontend/spree/checkout/payment/_stripe_additional_info.html.erb
415
+ - lib/views/frontend/spree/checkout/payment/_stripe_apple_pay.html.erb
416
+ - lib/views/frontend/spree/checkout/payment/_stripe_elements.html.erb
437
417
  - script/rails
438
418
  - spec/features/stripe_checkout_spec.rb
439
419
  - spec/models/gateway/authorize_net_cim_spec.rb
@@ -461,6 +441,8 @@ files:
461
441
  - spec/models/gateway/stripe_gateway_spec.rb
462
442
  - spec/models/gateway/usa_epay_transaction_spec.rb
463
443
  - spec/models/gateway/worldpay_spec.rb
444
+ - spec/models/spree/order_spec.rb
445
+ - spec/requests/apple_pay_domain_verification.rb
464
446
  - spec/spec_helper.rb
465
447
  - spec/support/wait_for_stripe.rb
466
448
  - spree_gateway.gemspec
@@ -484,7 +466,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
466
  version: '0'
485
467
  requirements:
486
468
  - none
487
- rubygems_version: 3.0.2
469
+ rubyforge_project:
470
+ rubygems_version: 2.7.6
488
471
  signing_key:
489
472
  specification_version: 4
490
473
  summary: Additional Payment Gateways for Spree Commerce
@@ -515,5 +498,7 @@ test_files:
515
498
  - spec/models/gateway/stripe_gateway_spec.rb
516
499
  - spec/models/gateway/usa_epay_transaction_spec.rb
517
500
  - spec/models/gateway/worldpay_spec.rb
501
+ - spec/models/spree/order_spec.rb
502
+ - spec/requests/apple_pay_domain_verification.rb
518
503
  - spec/spec_helper.rb
519
504
  - spec/support/wait_for_stripe.rb
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "spree", "~> 3.1.0"
6
-
7
- gemspec :path => "../"
@@ -1,17 +0,0 @@
1
- ActiveMerchant::Billing::StripeGateway.class_eval do
2
- private
3
-
4
- alias_method :original_headers, :headers
5
- alias_method :original_add_customer_data, :add_customer_data
6
-
7
- def headers(options = {})
8
- headers = original_headers(options)
9
- headers['User-Agent'] = headers['X-Stripe-Client-User-Agent']
10
- headers
11
- end
12
-
13
- def add_customer_data(post, options)
14
- original_add_customer_data(post, options)
15
- post[:payment_user_agent] = "SpreeGateway/#{SpreeGateway.version}"
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- module SpreeGateway
2
- def self.version
3
- '3.3.7'
4
- end
5
- end