Skip to content

Commit

Permalink
Merge pull request #328 from spark-solutions/add_stripe_info
Browse files Browse the repository at this point in the history
Set stripe app info & add Spree 4 support
  • Loading branch information
damianlegawiec authored Sep 24, 2019
2 parents 9a103b8 + 541f741 commit 41b46aa
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gemfile:
# - gemfiles/spree_3_2.gemfile
- gemfiles/spree_3_5.gemfile
- gemfiles/spree_3_7.gemfile
- gemfiles/spree_4_0.gemfile
- gemfiles/spree_master.gemfile

script:
Expand All @@ -34,10 +35,16 @@ matrix:
gemfile: gemfiles/spree_master.gemfile
- rvm: 2.4.4
gemfile: gemfiles/spree_master.gemfile
- rvm: 2.3.7
gemfile: gemfiles/spree_4_0.gemfile
- rvm: 2.4.4
gemfile: gemfiles/spree_4_0.gemfile
- rvm: 2.5.1
gemfile: gemfiles/spree_3_2.gemfile
- rvm: 2.4.4
gemfile: gemfiles/spree_3_2.gemfile
- rvm: 2.5.1
gemfile: gemfiles/spree_3_5.gemfile

before_install:
- mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
Expand Down
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ appraise 'spree-3-7' do
gem 'rails-controller-testing'
end

appraise 'spree-4-0' do
gem 'spree', '~> 4.0.0.rc2'
gem 'rails-controller-testing'
end

appraise 'spree-master' do
gem 'spree', github: 'spree/spree', branch: 'master'
gem 'rails-controller-testing'
Expand Down
21 changes: 15 additions & 6 deletions app/models/spree/gateway/stripe_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def capture(money, response_code, gateway_options)
provider.capture(money, response_code, gateway_options)
end

def credit(money, creditcard, response_code, gateway_options)
provider.refund(money, response_code, {})
def credit(money, creditcard, response_code, gateway_options)tes
provider.refund(money, response_code, {}, gateway_options)
end

def void(response_code, creditcard, gateway_options)
provider.void(response_code, {})
provider.void(response_code, {}, gateway_options)
end

def cancel(response_code)
provider.void(response_code, {})
provider.void(response_code, {}, gateway_options)
end

def create_profile(payment)
Expand Down Expand Up @@ -87,14 +87,17 @@ def create_profile(payment)

# In this gateway, what we call 'secret_key' is the 'login'
def options
options = super
options.merge(:login => preferred_secret_key)
super.merge(
login: preferred_secret_key,
application: app_info
)
end

def options_for_purchase_or_auth(money, creditcard, gateway_options)
options = {}
options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
options[:currency] = gateway_options[:currency]
options[:application] = app_info

if customer = creditcard.gateway_customer_profile_id
options[:customer] = customer
Expand Down Expand Up @@ -133,5 +136,11 @@ def update_source!(source)
source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
source
end

def app_info
name_with_version = "SpreeGateway/#{SpreeGateway.version}"
url = 'https://spreecommerce.org'
"#{name_with_version} #{url}"
end
end
end
8 changes: 8 additions & 0 deletions gemfiles/spree_4_0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails-controller-testing"
gem "spree", "~> 4.0.0.rc2"

gemspec path: "../"
27 changes: 27 additions & 0 deletions lib/active_merchant/billing/stripe_gateway_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module ActiveMerchant
module Billing
module StripeGatewayDecorator
def self.prepended(base)
base.class_eval do
alias_method :original_headers, :headers
alias_method :original_add_customer_data, :add_customer_data

private

def headers(options = {})
headers = original_headers(options)
headers['User-Agent'] = headers['X-Stripe-Client-User-Agent']
headers
end

def add_customer_data(post, options)
original_add_customer_data(post, options)
post[:payment_user_agent] = "SpreeGateway/#{SpreeGateway.version}"
end
end
end
end
end
end

ActiveMerchant::Billing::StripeGateway.prepend(ActiveMerchant::Billing::StripeGatewayDecorator)
3 changes: 3 additions & 0 deletions lib/spree_gateway/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def self.activate
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/spree/*_decorator*.rb')) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
Dir.glob(File.join(File.dirname(__FILE__), '../../lib/active_merchant/**/*_decorator*.rb')) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end

def self.backend_available?
Expand Down
5 changes: 5 additions & 0 deletions lib/spree_gateway/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module SpreeGateway
def self.version
'3.6.3'
end
end
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'capybara/rails'
require 'capybara-screenshot/rspec'
require "selenium-webdriver"
require 'webdrivers'
require 'database_cleaner'
require 'ffaker'
require 'rspec/active_model/mocks'
Expand Down Expand Up @@ -56,8 +57,10 @@
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new app,
browser: :chrome,
options: Selenium::WebDriver::Chrome::Options.new(args: %w[disable-popup-blocking headless disable-gpu window-size=1920,1080])
options: Selenium::WebDriver::Chrome::Options.new(
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],
log_level: :error
)
end

Capybara.javascript_driver = :chrome
end
14 changes: 9 additions & 5 deletions spree_gateway.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# coding: utf-8

require_relative 'lib/spree_gateway/version.rb'

Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_gateway'
s.version = '3.6.1'
s.version = SpreeGateway.version
s.summary = 'Additional Payment Gateways for Spree Commerce'
s.description = s.summary

Expand All @@ -21,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency 'spree_extension'

s.add_development_dependency 'appraisal'
s.add_development_dependency 'bootstrap-sass', '>= 3.3.5.1'
s.add_development_dependency 'bootstrap-sass'
s.add_development_dependency 'braintree'
s.add_development_dependency 'capybara'
s.add_development_dependency 'capybara-screenshot'
Expand All @@ -31,14 +34,15 @@ Gem::Specification.new do |s|
s.add_development_dependency 'ffaker'
s.add_development_dependency 'guard-rspec'
s.add_development_dependency 'launchy'
s.add_development_dependency 'mysql2', '~> 0.5.1'
s.add_development_dependency 'pg', '~> 0.18'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'pg'
s.add_development_dependency 'pry'
s.add_development_dependency 'puma'
s.add_development_dependency 'rspec-activemodel-mocks'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'webdrivers'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'sqlite3', '~> 1.4.1'
s.add_development_dependency 'sqlite3'
end

0 comments on commit 41b46aa

Please sign in to comment.