solidus_culqi 0.0.1 → 1.0.1

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
- SHA1:
3
- metadata.gz: b87517498f541c5a8ad5b739f725b28921281f96
4
- data.tar.gz: 93c72f59c361757c499eb3606e793aa81b2d4573
2
+ SHA256:
3
+ metadata.gz: c623122f14e7c6ec787c93661d40fc4266fd9cefe6478d4fc30d7446496011f6
4
+ data.tar.gz: eddcf724e1dbf86a0269808c55ec84d76803ba21e7c1c16ec68f6a8d26d7e577
5
5
  SHA512:
6
- metadata.gz: c64c32c5deb830bed6db8ba903f992dfd02a01f8636254df152efebb685813494a3f3f6e775bf1b8a1914cb879a13ee9e3e1d3a62c2ac11da90c6c8554fd726d
7
- data.tar.gz: 02ea951f965722b9c7d57a2ad36f10d7d49dc945d0d36abd34e085f0ab547656b7bc256835e9062155ceb249d900b4596d5c7f9c5189a520a945687f4e250acc
6
+ metadata.gz: feb467b202a7e3ac1cad370daa66072930c1415baa3bb09a06062f2fe9443ec66fadcb84a7636efbeaa93c043394f74b9d392a6a00e556e4287aa86f128da0a8
7
+ data.tar.gz: 528d326dfe09348975b6ee4f3ec814e73cde89ddbc1fd77f19a2710ede1230adc51029b9193d752ddb350bd429eac3e8b0a9bf9287f8245783b38e4492114d1c
@@ -4,22 +4,13 @@ AllCops:
4
4
  Exclude:
5
5
  - 'spec/dummy/**/*'
6
6
  - 'vendor/bundle/**/*'
7
- TargetRubyVersion: 2.1
8
-
9
- # Sometimes I believe this reads better
10
- # This also causes spacing issues on multi-line fixes
11
- Style/BracesAroundHashParameters:
12
- Enabled: false
7
+ TargetRubyVersion: 2.5
13
8
 
14
9
  # We use class vars and will have to continue doing so for compatability
15
10
  Style/ClassVars:
16
11
  Enabled: false
17
12
 
18
- # We need these names for backwards compatability
19
- Style/PredicateName:
20
- Enabled: false
21
-
22
- Style/AccessorMethodName:
13
+ Naming/AccessorMethodName:
23
14
  Enabled: false
24
15
 
25
16
  # This has been used for customization
@@ -38,15 +29,16 @@ Style/WordArray:
38
29
  Style/ConditionalAssignment:
39
30
  Enabled: false
40
31
 
41
- Performance/Count:
42
- Enabled: false
43
-
44
32
  Style/RaiseArgs:
45
33
  Enabled: false
46
34
 
47
35
  Naming/BinaryOperatorParameterName:
48
36
  Enabled: false
49
37
 
38
+ # We need these names for backwards compatability
39
+ Naming/PredicateName:
40
+ Enabled: false
41
+
50
42
  # We can use good judgement here
51
43
  Style/RegexpLiteral:
52
44
  Enabled: false
@@ -55,31 +47,22 @@ Style/RegexpLiteral:
55
47
  Style/AsciiComments:
56
48
  Enabled: false
57
49
 
58
- Lint/EndAlignment:
50
+ Layout/EndAlignment:
59
51
  Enabled: false
60
52
 
61
- Style/ElseAlignment:
53
+ Layout/ElseAlignment:
62
54
  Enabled: false
63
55
 
64
- Style/IndentationWidth:
56
+ Layout/IndentationWidth:
65
57
  Enabled: false
66
58
 
67
- Style/AlignParameters:
59
+ Layout/ClosingParenthesisIndentation:
68
60
  Enabled: false
69
61
 
70
- Style/ClosingParenthesisIndentation:
62
+ Layout/MultilineMethodCallIndentation:
71
63
  Enabled: false
72
64
 
73
- Style/MultilineMethodCallIndentation:
74
- Enabled: false
75
-
76
- Style/IndentArray:
77
- Enabled: false
78
-
79
- Style/IndentHash:
80
- Enabled: false
81
-
82
- Style/AlignHash:
65
+ Layout/LineLength:
83
66
  Enabled: false
84
67
 
85
68
  # From http://relaxed.ruby.style/
@@ -100,7 +83,7 @@ Style/Documentation:
100
83
  Enabled: false
101
84
  StyleGuide: http://relaxed.ruby.style/#styledocumentation
102
85
 
103
- Style/DotPosition:
86
+ Layout/DotPosition:
104
87
  Enabled: false
105
88
  StyleGuide: http://relaxed.ruby.style/#styledotposition
106
89
 
@@ -168,11 +151,11 @@ Style/SingleLineMethods:
168
151
  Enabled: false
169
152
  StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
170
153
 
171
- Style/SpaceBeforeBlockBraces:
154
+ Layout/SpaceBeforeBlockBraces:
172
155
  Enabled: false
173
156
  StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
174
157
 
175
- Style/SpaceInsideParens:
158
+ Layout/SpaceInsideParens:
176
159
  Enabled: false
177
160
  StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
178
161
 
@@ -191,6 +174,15 @@ Style/WhileUntilModifier:
191
174
  Enabled: false
192
175
  StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
193
176
 
177
+ Style/HashEachMethods:
178
+ Enabled: true
179
+
180
+ Style/HashTransformKeys:
181
+ Enabled: true
182
+
183
+ Style/HashTransformValues:
184
+ Enabled: true
185
+
194
186
  Lint/AmbiguousRegexpLiteral:
195
187
  Enabled: false
196
188
  StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
@@ -199,7 +191,7 @@ Lint/AssignmentInCondition:
199
191
  Enabled: false
200
192
  StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
201
193
 
202
- Lint/HandleExceptions:
194
+ Lint/SuppressedException:
203
195
  Exclude:
204
196
  - 'Rakefile'
205
197
 
@@ -208,7 +200,7 @@ Metrics/AbcSize:
208
200
 
209
201
  Metrics/BlockLength:
210
202
  Exclude:
211
- - 'spec/*/*'
203
+ - 'spec/**/*'
212
204
 
213
205
  Metrics/BlockNesting:
214
206
  Enabled: false
@@ -222,9 +214,6 @@ Metrics/ModuleLength:
222
214
  Metrics/CyclomaticComplexity:
223
215
  Enabled: false
224
216
 
225
- Metrics/LineLength:
226
- Enabled: false
227
-
228
217
  Metrics/MethodLength:
229
218
  Enabled: false
230
219
 
@@ -5,24 +5,19 @@ bundler_args: --quiet
5
5
  script:
6
6
  - bundle exec rake
7
7
  rvm:
8
- - 2.4.1
8
+ - 2.6.5
9
+ services:
10
+ - postgresql
11
+ - mysql
9
12
  env:
10
13
  matrix:
11
- - SOLIDUS_BRANCH=v1.1 DB=postgres
12
- - SOLIDUS_BRANCH=v1.2 DB=postgres
13
- - SOLIDUS_BRANCH=v1.3 DB=postgres
14
- - SOLIDUS_BRANCH=v1.4 DB=postgres
15
- - SOLIDUS_BRANCH=v2.0 DB=postgres
16
- - SOLIDUS_BRANCH=v2.1 DB=postgres
17
- - SOLIDUS_BRANCH=v2.2 DB=postgres
18
- - SOLIDUS_BRANCH=v2.3 DB=postgres
14
+ - SOLIDUS_BRANCH=v2.7 DB=postgres
15
+ - SOLIDUS_BRANCH=v2.8 DB=postgres
16
+ - SOLIDUS_BRANCH=v2.9 DB=postgres
17
+ - SOLIDUS_BRANCH=v2.10 DB=postgres
19
18
  - SOLIDUS_BRANCH=master DB=postgres
20
- - SOLIDUS_BRANCH=v1.1 DB=mysql
21
- - SOLIDUS_BRANCH=v1.2 DB=mysql
22
- - SOLIDUS_BRANCH=v1.3 DB=mysql
23
- - SOLIDUS_BRANCH=v1.4 DB=mysql
24
- - SOLIDUS_BRANCH=v2.0 DB=mysql
25
- - SOLIDUS_BRANCH=v2.1 DB=mysql
26
- - SOLIDUS_BRANCH=v2.2 DB=mysql
27
- - SOLIDUS_BRANCH=v2.3 DB=mysql
19
+ - SOLIDUS_BRANCH=v2.7 DB=mysql
20
+ - SOLIDUS_BRANCH=v2.8 DB=mysql
21
+ - SOLIDUS_BRANCH=v2.9 DB=mysql
22
+ - SOLIDUS_BRANCH=v2.10 DB=mysql
28
23
  - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
@@ -5,9 +7,14 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
5
7
  branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
8
  gem 'solidus', github: 'solidusio/solidus', branch: branch
7
9
 
10
+ gem 'deface'
11
+ gem 'ffaker'
12
+ gem 'mysql2', '0.4.10'
13
+ gem 'pg', '~> 0.21'
14
+ gem 'puma'
15
+ gem 'solidus_auth_devise'
16
+ gem 'sqlite3'
17
+
8
18
  gemspec
9
19
 
10
- group :test do
11
- gem 'ffaker'
12
- gem 'sqlite3'
13
- end
20
+ gem 'culqi-ruby', github: 'culqi/culqi-ruby'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  Solidus Culqi
2
2
  =============
3
+ [![Gem Version][rubygems-image]][rubygems-url]
4
+ [![Build Status][travis-image]][travis-url]
3
5
 
4
6
  Add [Culqi](https://www.culqi.com/) support for [solidus](https://solidus.io/) e-commerce.
5
7
 
@@ -28,3 +30,8 @@ First bundle your dependencies, then run `rake`. `rake` will default to building
28
30
  bundle
29
31
  bundle exec rake
30
32
  ```
33
+
34
+ [rubygems-image]: https://badge.fury.io/rb/solidus_culqi.svg
35
+ [rubygems-url]: https://badge.fury.io/rb/solidus_culqi
36
+ [travis-image]: https://travis-ci.org/ccarruitero/solidus_culqi.svg?branch=master
37
+ [travis-url]: https://travis-ci.org/ccarruitero/solidus_culqi
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
 
3
5
  Bundler::GemHelper.install_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
4
  module InjectInstallmentsConcern
3
5
  extend ActiveSupport::Concern
@@ -8,7 +10,7 @@ module SolidusCulqi
8
10
  module InstanceMethods
9
11
  def gateway_options
10
12
  options = super
11
- installments = order.installments
13
+ installments = order.try(:installments)
12
14
  options[:installments] = installments if installments
13
15
  options
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
4
  module PermittedAttributesConcern
3
5
  def checkout_attributes
@@ -1 +1,5 @@
1
- Spree::Payment.include SolidusCulqi::InjectInstallmentsConcern
1
+ # frozen_string_literal: true
2
+
3
+ module PaymentDecorator
4
+ Spree::Payment.include SolidusCulqi::InjectInstallmentsConcern
5
+ end
@@ -1 +1,5 @@
1
- Spree::PermittedAttributes.singleton_class.prepend SolidusCulqi::PermittedAttributesConcern
1
+ # frozen_string_literal: true
2
+
3
+ module PermittedAttributesDecorator
4
+ Spree::PermittedAttributes.singleton_class.prepend SolidusCulqi::PermittedAttributesConcern
5
+ end
@@ -1,24 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solidus
2
- class Gateway::CulqiGateway < ::Spree::Gateway
4
+ class Gateway::CulqiGateway < Spree::PaymentMethod::CreditCard
3
5
  preference :public_key, :string
4
6
  preference :secret_key, :string
5
7
 
6
- def default_currency
7
- "PEN"
8
+ def partial_name
9
+ 'culqi'
8
10
  end
9
11
 
10
- if SolidusSupport.solidus_gem_version < Gem::Version.new('2.3.x')
11
- def method_type
12
- 'culqi'
13
- end
14
- else
15
- def partial_name
16
- 'culqi'
17
- end
12
+ def gateway_class
13
+ self.class
18
14
  end
19
15
 
20
- def provider_class
21
- self.class
16
+ def default_currency
17
+ "PEN"
22
18
  end
23
19
 
24
20
  def authorize(amount, creditcard, gateway_options)
@@ -37,21 +33,40 @@ module Solidus
37
33
  parse_response(charge)
38
34
  end
39
35
 
40
- def credit(amount, creditcard, _gateway_options)
36
+ def credit(amount, _creditcard, response_code, _gateway_options)
41
37
  init_culqi
42
38
  # Culqi only accepts 'duplicado','fraudulento' o 'solicitud_comprador'
43
39
  # like reason's value
44
40
  refund = Culqi::Refund.create(
45
41
  amount: amount,
46
- charge_id: creditcard,
42
+ charge_id: response_code,
47
43
  reason: "solicitud_comprador"
48
44
  )
49
45
  parse_response(refund)
50
46
  end
51
47
 
52
- def void(creditcard, gateway_options)
48
+ def void(response_code, creditcard, gateway_options)
53
49
  amount = gateway_options[:subtotal].to_i
54
- credit(amount, creditcard, gateway_options)
50
+ credit(amount, creditcard, response_code, gateway_options)
51
+ end
52
+
53
+ def payment_profiles_supported?
54
+ true
55
+ end
56
+
57
+ def create_profile(payment)
58
+ return unless payment.source.gateway_customer_profile_id.nil?
59
+
60
+ init_culqi
61
+ customer = get_customer(payment)
62
+ token = payment.source.gateway_payment_profile_id
63
+ card_token = generate_card(customer, token)
64
+ unless customer.nil? || card_token.nil?
65
+ payment.source.update(
66
+ gateway_customer_profile_id: customer,
67
+ gateway_payment_profile_id: card_token
68
+ )
69
+ end
55
70
  end
56
71
 
57
72
  private
@@ -62,7 +77,7 @@ module Solidus
62
77
  end
63
78
 
64
79
  def commit(amount, creditcard, gateway_options, capture)
65
- installments = gateway_options[:installments]
80
+ installments = gateway_options.try(:installments)
66
81
  authorization = creditcard[:gateway_payment_profile_id]
67
82
  charge = Culqi::Charge.create(
68
83
  amount: amount,
@@ -79,11 +94,47 @@ module Solidus
79
94
  def parse_response(response)
80
95
  res = JSON.parse(response)
81
96
  ActiveMerchant::Billing::Response.new(
82
- res[:object] != "error",
83
- res[:merchant_message],
97
+ res["object"] != "error",
98
+ res["merchant_message"],
84
99
  res,
85
100
  authorization: res["id"]
86
101
  )
87
102
  end
103
+
104
+ def find_customer(email)
105
+ res = Culqi::Customer.list
106
+ customers = JSON.parse(res)["data"]
107
+ customers.select { |customer| customer["email"] == email }.first
108
+ end
109
+
110
+ def get_customer(payment)
111
+ address = payment.order.bill_address
112
+ email = payment.order.email
113
+ customer = find_customer(email)
114
+ customer = generate_customer(address, email) if customer.nil?
115
+ customer["id"]
116
+ end
117
+
118
+ def generate_customer(address, email)
119
+ culqi_customer = Culqi::Customer.create(
120
+ address: address.address1,
121
+ address_city: address.state.name,
122
+ country_code: address.country.iso,
123
+ email: email,
124
+ first_name: address.first_name,
125
+ last_name: address.last_name,
126
+ phone_number: address.phone.tr("/() -/", "")
127
+ )
128
+ JSON.parse(culqi_customer)
129
+ end
130
+
131
+ def generate_card(customer, token)
132
+ card = Culqi::Card.create(
133
+ customer_id: customer,
134
+ token_id: token,
135
+ validate: false
136
+ )
137
+ JSON.parse(card)["id"]
138
+ end
88
139
  end
89
140
  end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'fileutils'
4
+ require 'open-uri'
5
+ require 'archive/zip'
6
+
7
+ path = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest'
8
+
9
+ res = Net::HTTP.get_response(URI(path))
10
+ json = JSON.parse(res.body)
11
+ download_url = json['url']
12
+
13
+ filename = 'geckodriver'
14
+
15
+ Dir.chdir platform_install_dir do
16
+ FileUtils.rm_f filename
17
+ File.open(filename, "wb") do |saved_file|
18
+ URI.parse(download_url).open("rb") do |read_file|
19
+ saved_file.write(read_file.read)
20
+ end
21
+ end
22
+
23
+ raise "Could not download #{download_url}" unless File.exists? filename
24
+ Archive::Zip.extract(filename, '.', :overwrite => :all)
25
+ end
26
+ raise "Could not unzip #{filename} to get #{binary_path}" unless File.exists? binary_path
27
+ FileUtils.chmod "ugo+rx", binary_path
28
+ File.open(version_path, 'w') { |file| file.write(download_version) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Spree::Core::Engine.routes.draw do
2
4
  # Add your extension routes here
3
5
  end
@@ -1,4 +1,6 @@
1
- class AddInstallmentsToOrders < ActiveRecord::Migration[5.1]
1
+ # frozen_string_literal: true
2
+
3
+ class AddInstallmentsToOrders < SolidusSupport::Migration[4.2]
2
4
  def change
3
5
  add_column :spree_orders, :installments, :integer
4
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'solidus_core'
2
4
  require 'solidus_support'
3
5
  require 'culqi-ruby'
6
+ require 'solidus_culqi/support'
4
7
  require 'solidus_culqi/engine'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
4
  class Engine < Rails::Engine
3
5
  engine_name 'solidus_culqi'
@@ -12,7 +14,7 @@ module SolidusCulqi
12
14
  end
13
15
 
14
16
  def self.activate
15
- Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
17
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')).sort.map do |c|
16
18
  Rails.configuration.cache_classes ? require(c) : load(c)
17
19
  end
18
20
  end
@@ -1,4 +1,6 @@
1
- FactoryGirl.define do
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
2
4
  # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
5
  #
4
6
  # Example adding this to your spec_helper will load these Factories for use:
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusCulqi
4
+ module Support
5
+ def self.solidus_earlier(version)
6
+ SolidusSupport.solidus_gem_version < Gem::Version.new(version)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
- VERSION = '0.0.1'
4
+ VERSION = '1.0.1'
3
5
  end
@@ -1,4 +1,6 @@
1
- $:.push File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $:.push File.expand_path('lib', __dir__)
2
4
 
3
5
  require 'solidus_culqi/version'
4
6
 
@@ -16,14 +18,12 @@ Gem::Specification.new do |s|
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
20
 
21
+ s.add_dependency 'culqi-ruby'
19
22
  s.add_dependency 'solidus_core'
20
23
  s.add_dependency 'solidus_support'
21
- s.add_dependency 'culqi-ruby'
22
24
 
23
- s.add_development_dependency 'capybara'
24
- s.add_development_dependency 'poltergeist'
25
25
  s.add_development_dependency 'database_cleaner'
26
- s.add_development_dependency 'factory_girl'
26
+ s.add_development_dependency 'factory_bot'
27
27
  s.add_development_dependency 'pry'
28
28
  s.add_development_dependency 'rspec-rails'
29
29
  s.add_development_dependency 'rubocop'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Solidus::Gateway::CulqiGateway, type: :model do
6
+ let!(:gateway) { described_class.new }
7
+
8
+ it { gateway.respond_to?(:partial_name) }
9
+ it { expect(gateway.partial_name).to eq('culqi') }
10
+ it { expect(gateway.gateway_class).to eq(Solidus::Gateway::CulqiGateway) }
11
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Run Coverage report
2
4
  require 'simplecov'
3
5
  SimpleCov.start do
@@ -13,29 +15,19 @@ end
13
15
  # Configure Rails Environment
14
16
  ENV['RAILS_ENV'] = 'test'
15
17
 
16
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
18
+ require File.expand_path('dummy/config/environment.rb', __dir__)
17
19
 
18
20
  require 'rspec/rails'
19
21
  require 'database_cleaner'
20
22
  require 'ffaker'
21
- require 'capybara/rspec'
22
- require 'capybara/poltergeist'
23
23
  require 'pry'
24
24
 
25
- Capybara.register_driver(:poltergeist) do |app|
26
- Capybara::Poltergeist::Driver.new app, timeout: 90
27
- end
28
- Capybara.javascript_driver = :poltergeist
29
- Capybara.default_max_wait_time = 10
30
-
31
25
  # Requires supporting ruby files with custom matchers and macros, etc,
32
26
  # in spec/support/ and its subdirectories.
33
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
27
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
34
28
 
35
29
  # Requires factories and other useful helpers defined in spree_core.
36
30
  require 'spree/testing_support/authorization_helpers'
37
- require 'spree/testing_support/capybara_ext'
38
- require 'spree/testing_support/controller_requests'
39
31
  require 'spree/testing_support/factories'
40
32
  require 'spree/testing_support/url_helpers'
41
33
  require 'spree/testing_support/preferences'
@@ -44,9 +36,7 @@ require 'spree/testing_support/preferences'
44
36
  require 'solidus_culqi/factories'
45
37
 
46
38
  RSpec.configure do |config|
47
- config.include FactoryGirl::Syntax::Methods
48
- config.include CulqiHelper
49
- config.include Spree::TestingSupport::UrlHelpers
39
+ config.include FactoryBot::Syntax::Methods
50
40
  config.include Spree::TestingSupport::Preferences
51
41
 
52
42
  # Infer an example group's spec type from the file location.
@@ -80,7 +70,6 @@ RSpec.configure do |config|
80
70
  config.before :each do
81
71
  DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
82
72
  DatabaseCleaner.start
83
- reset_spree_preferences
84
73
  end
85
74
 
86
75
  # After each spec clean the database.
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_culqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - César Carruitero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-19 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: solidus_core
14
+ name: culqi-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: solidus_support
28
+ name: solidus_core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: culqi-ruby
42
+ name: solidus_support
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -52,34 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: capybara
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: poltergeist
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: database_cleaner
85
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: factory_girl
70
+ name: factory_bot
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -197,7 +169,7 @@ files:
197
169
  - app/models/payment_decorator.rb
198
170
  - app/models/permitted_attributes_decorator.rb
199
171
  - app/models/solidus/gateway/culqi_gateway.rb
200
- - app/views/spree/checkout/payment/_culqi.html.erb
172
+ - bin/geckodriver
201
173
  - bin/rails
202
174
  - config/locales/en.yml
203
175
  - config/routes.rb
@@ -206,12 +178,11 @@ files:
206
178
  - lib/solidus_culqi.rb
207
179
  - lib/solidus_culqi/engine.rb
208
180
  - lib/solidus_culqi/factories.rb
181
+ - lib/solidus_culqi/support.rb
209
182
  - lib/solidus_culqi/version.rb
210
183
  - solidus_culqi.gemspec
211
- - spec/features/culqi_checkout_autocapture_spec.rb
212
- - spec/features/culqi_checkout_spec.rb
184
+ - spec/models/culqi_gateway_spec.rb
213
185
  - spec/spec_helper.rb
214
- - spec/support/culqi_helper.rb
215
186
  homepage: https://github.com/ccarruitero/solidus_culqi
216
187
  licenses:
217
188
  - MIT
@@ -231,8 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
202
  - !ruby/object:Gem::Version
232
203
  version: '0'
233
204
  requirements: []
234
- rubyforge_project:
235
- rubygems_version: 2.6.13
205
+ rubygems_version: 3.1.4
236
206
  signing_key:
237
207
  specification_version: 4
238
208
  summary: Adds solidus support for Culqi Gateway
@@ -1,79 +0,0 @@
1
- <%= render "spree/checkout/payment/gateway", payment_method: payment_method %>
2
- <% param_prefix = "payment_source[#{payment_method.id}]" %>
3
-
4
- <p class="field installmentField">
5
- <%= label_tag "installments", Spree.t(:installments) %><span class="required">*</span><br />
6
- <%= select_tag "[order][installments]", [], class: "culqiInstallments" %>
7
- </p>
8
-
9
- <script type="text/javascript" src="https://checkout.culqi.com/v2"></script>
10
- <script type="text/javascript">
11
- Culqi.publicKey = "<%= payment_method.preferred_public_key %>";
12
- Culqi.useClasses = true;
13
- Culqi.init();
14
-
15
- var paymentMethodId = "<%= payment_method.id %>";
16
- Spree.culqiPaymentMethod = $('#payment_method_' + paymentMethodId);
17
- $('.installmentField').toggle();
18
-
19
- function addCulqiField(className, value) {
20
- Spree.culqiPaymentMethod.append("<input type='hidden' value='" + value + "' class='"+ className +"'/>");
21
- }
22
-
23
- function addCulqiSelectOptions(className, options) {
24
- var select = Spree.culqiPaymentMethod.find(className);
25
- for(var i=0; i < options.length; i++) {
26
- select.append("<option value='" + options[i] + "'>" + options[i] + "</option");
27
- }
28
- $('.installmentField').toggle();
29
- }
30
-
31
- function goToNextStep() {
32
- Spree.culqiPaymentMethod.parents("form").get(0).submit();
33
- }
34
-
35
- function allowedInstallments(token) {
36
- var installments = token['iin']['installments_allowed'];
37
- var submitBtn = $('#checkout_form_payment [data-hook=buttons]');
38
- if (installments.length > 0) {
39
- (installments.indexOf(0) !== -1) ? null : installments.unshift(0);
40
- Spree.culqiPaymentMethod.find('#card_number, #card_expiry, #card_code').prop("disabled", true);
41
- addCulqiSelectOptions('.culqiInstallments', installments);
42
- submitBtn.off('click');
43
- submitBtn.click(function(e) {
44
- e.preventDefault();
45
- goToNextStep();
46
- });
47
- } else {
48
- goToNextStep();
49
- }
50
- }
51
-
52
- function culqi() {
53
- if (Culqi.token) {
54
- Spree.culqiPaymentMethod.append("<input type='hidden' name='<%= param_prefix %>[gateway_payment_profile_id]' value='" + Culqi.token['id'] + "'/>");
55
- allowedInstallments(Culqi.token)
56
- } else if (Culqi.error) {
57
- $('#culqiError').html(Culqi.error['user_message']);
58
- return $('#culqiError').show();
59
- }
60
- }
61
-
62
- Spree.culqiPaymentMethod.find('.cardCode').addClass('culqi-cvv');
63
-
64
- $(document).ready(function() {
65
- Spree.culqiPaymentMethod.prepend("<div id='culqiError' class='errorExplanation' style='display:none'></div>");
66
- $('#checkout_form_payment [data-hook=buttons]').click(function(e) {
67
- if (Spree.culqiPaymentMethod.is(':visible')) {
68
- e.preventDefault();
69
- var expiration = $('.cardExpiry:visible').payment('cardExpiryVal');
70
- var cardNumber = Spree.culqiPaymentMethod.find('.cardNumber').val().replace(/ /g,'')
71
- addCulqiField('culqi-email', '<%= @order.email %>');
72
- addCulqiField('culqi-expm', expiration['month']);
73
- addCulqiField('culqi-expy', expiration['year']);
74
- addCulqiField('culqi-card', cardNumber);
75
- Culqi.createToken();
76
- }
77
- });
78
- });
79
- </script>
@@ -1,77 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe "Culqi checkout autocapture", type: :feature do
4
- let(:zone) { create(:zone) }
5
- let(:country) { create(:country) }
6
- let(:product) { create(:product) }
7
-
8
- before do
9
- zone.members << Spree::ZoneMember.create!(zoneable: country)
10
- create(:store)
11
- create(:free_shipping_method)
12
- Spree::Config.set(auto_capture: true)
13
- setup_culqi_gateway
14
- checkout_until_payment
15
- end
16
-
17
- context "with valid credit card" do
18
- stub_authorization!
19
-
20
- before do
21
- fill_in "Card Number", with: "4111 1111 1111 1111"
22
- page.execute_script("$('.cardNumber').trigger('change')")
23
- fill_in "Card Code", with: "123"
24
- fill_in "Expiration", with: "09 / 20"
25
- click_button "Save and Continue"
26
- sleep(5) # Wait for API to return + form to submit
27
- click_button "Save and Continue"
28
- end
29
-
30
- it "can process a valid payment", js: true do
31
- expect(page.current_url).to include("/checkout/confirm")
32
- click_button "Place Order"
33
- expect(page).to have_content("Your order has been processed successfully")
34
- end
35
-
36
- it "refunds a payment", js: true do
37
- reason = FactoryGirl.create(:refund_reason)
38
-
39
- click_button "Place Order"
40
- visit spree.admin_order_payments_path(Spree::Order.last)
41
- sleep(3)
42
- click_icon(:reply)
43
- fill_in "Amount", with: Spree::Order.last.amount.to_f
44
- select reason.name, from: "Reason", visible: false
45
- click_on "Refund"
46
- expect(Spree::Refund.count).to be(1)
47
- end
48
- end
49
-
50
- context "when missing credit card number" do
51
- it "shows an error", js: true do
52
- fill_in "Expiration", with: "01 / #{Time.now.year + 1}"
53
- fill_in "Card Code", with: "123"
54
- click_button "Save and Continue"
55
- expect(page).to have_content("El numero de tarjeta de crédito o débito brindado no es válido.")
56
- end
57
- end
58
-
59
- context "when missing expiration date" do
60
- it "shows an error", js: true do
61
- fill_in "Card Number", with: "4242 4242 4242 4242"
62
- fill_in "Card Code", with: "123"
63
- click_button "Save and Continue"
64
- expect(page).to have_content("de expiración de tu tarjeta es inválido.")
65
- end
66
- end
67
-
68
- context "with an invalid credit card number" do
69
- it "shows an error", js: true do
70
- fill_in "Card Number", with: "1111 1111 1111"
71
- fill_in "Expiration", with: "02 / #{Time.now.year + 1}"
72
- fill_in "Card Code", with: "123"
73
- click_button "Save and Continue"
74
- expect(page).to have_content("El numero de tarjeta de crédito o débito brindado no es válido.")
75
- end
76
- end
77
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe "Culqi checkout", type: :feature do
4
- let(:zone) { create(:zone) }
5
- let(:country) { create(:country) }
6
- let(:product) { create(:product) }
7
- stub_authorization!
8
-
9
- before do
10
- zone.members << Spree::ZoneMember.create!(zoneable: country)
11
- create(:store)
12
- create(:free_shipping_method)
13
- setup_culqi_gateway
14
- checkout_until_payment
15
-
16
- fill_in "Card Number", with: "4111 1111 1111 1111"
17
- page.execute_script("$('.cardNumber').trigger('change')")
18
- fill_in "Card Code", with: "123"
19
- fill_in "Expiration", with: "09 / 20"
20
- click_button "Save and Continue"
21
- sleep(5) # Wait for API to return + form to submit
22
- find(".culqiInstallments").select("2")
23
- click_button "Save and Continue"
24
- end
25
-
26
- context "with process checkout" do
27
- before do
28
- expect(page.current_url).to include("/checkout/confirm")
29
- click_button "Place Order"
30
- end
31
-
32
- it "process order", js: true do
33
- expect(page).to have_content("Your order has been processed successfully")
34
- end
35
-
36
- it "capture payment", js: true do
37
- visit spree.admin_order_payments_path(Spree::Order.last)
38
- sleep(3)
39
- click_icon(:capture)
40
- expect(page).to have_content("Payment Updated")
41
- end
42
-
43
- it "voids a payment", js: true do
44
- visit spree.admin_order_payments_path(Spree::Order.last)
45
- sleep(3)
46
- click_icon(:void)
47
- expect(page).to have_content("Payment Updated")
48
- end
49
- end
50
- end
@@ -1,43 +0,0 @@
1
- require "spec_helper"
2
-
3
- module CulqiHelper
4
- def setup_culqi_gateway
5
- Solidus::Gateway::CulqiGateway.create!(
6
- name: "Culqi",
7
- preferred_secret_key: "sk_test_SpwICNI4YT0OSLHY",
8
- preferred_public_key: "pk_test_CaY0noGVG8ohIj4P"
9
- )
10
- end
11
-
12
- def checkout_until_payment
13
- visit spree.product_path(product)
14
- click_button "Add To Cart"
15
-
16
- # expect(page).to have_current_path("/cart")
17
- click_button "Checkout"
18
-
19
- # Address
20
- # expect(page).to have_current_path("/checkout/address")
21
- fill_in "Customer E-Mail", with: "han@example.com"
22
-
23
- country = Spree::Country.first
24
- within("#billing") do
25
- fill_in "First Name", with: "Han"
26
- fill_in "Last Name", with: "Solo"
27
- fill_in "Street Address", with: "YT-1300"
28
- fill_in "City", with: "Mos Eisley"
29
- select "United States of America", from: "Country"
30
- select country.states.first, from: "order_bill_address_attributes_state_id"
31
- fill_in "Zip", with: "12010"
32
- fill_in "Phone", with: "(555) 555-5555"
33
- end
34
- click_on "Save and Continue"
35
-
36
- # Delivery
37
- # expect(page).to have_current_path("/checkout/delivery")
38
- # expect(page).to have_content("UPS Ground")
39
- click_on "Save and Continue"
40
-
41
- # expect(page).to have_current_path("/checkout/payment")
42
- end
43
- end