solidus_culqi 0.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +25 -36
  3. data/.travis.yml +10 -17
  4. data/Gemfile +8 -2
  5. data/Rakefile +2 -0
  6. data/app/models/concerns/solidus_culqi/inject_installments_concern.rb +3 -1
  7. data/app/models/concerns/solidus_culqi/permitted_attributes_concern.rb +2 -0
  8. data/app/models/payment_decorator.rb +5 -1
  9. data/app/models/permitted_attributes_decorator.rb +5 -1
  10. data/app/models/solidus/gateway/culqi_gateway.rb +18 -11
  11. data/bin/geckodriver +28 -0
  12. data/config/routes.rb +2 -0
  13. data/db/migrate/20170919145201_add_installments_to_orders.rb +2 -0
  14. data/lib/generators/solidus_culqi/install/install_generator.rb +2 -0
  15. data/lib/solidus_culqi.rb +2 -1
  16. data/lib/solidus_culqi/engine.rb +3 -1
  17. data/lib/solidus_culqi/factories.rb +3 -1
  18. data/lib/solidus_culqi/support.rb +2 -0
  19. data/lib/solidus_culqi/version.rb +3 -1
  20. data/solidus_culqi.gemspec +7 -7
  21. data/spec/models/culqi_gateway_spec.rb +11 -0
  22. data/spec/spec_helper.rb +5 -31
  23. metadata +11 -79
  24. data/app/views/spree/checkout/existing_payment/_culqi.html.erb +0 -3
  25. data/app/views/spree/checkout/payment/_culqi.html.erb +0 -79
  26. data/lib/solidus_culqi/gateway.rb +0 -29
  27. data/spec/cassettes/Culqi_checkout/with_logged_user/store_card_in_wallet.yml +0 -206
  28. data/spec/cassettes/Culqi_checkout/with_unlogged_user/with_process_checkout/capture_payment.yml +0 -207
  29. data/spec/cassettes/Culqi_checkout/with_unlogged_user/with_process_checkout/process_order.yml +0 -156
  30. data/spec/cassettes/Culqi_checkout/with_unlogged_user/with_process_checkout/voids_a_payment.yml +0 -207
  31. data/spec/cassettes/Culqi_checkout_autocapture/with_valid_credit_card/can_process_a_valid_payment.yml +0 -156
  32. data/spec/cassettes/Culqi_checkout_autocapture/with_valid_credit_card/refunds_a_payment.yml +0 -207
  33. data/spec/features/culqi_checkout_autocapture_spec.rb +0 -77
  34. data/spec/features/culqi_checkout_spec.rb +0 -94
  35. data/spec/models/culqi_gateway.rb +0 -16
  36. data/spec/support/culqi_helper.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2ffd16d55727246157726af60755d45bd77af4ff
4
- data.tar.gz: 0eed2658dd67b31df98b22900e76fc2d216ac74a
2
+ SHA256:
3
+ metadata.gz: 80cce90c55f9d866e00d85e7243b021f569d528561a2711fbfaa7ef8fe8be170
4
+ data.tar.gz: cfc0718aaf923d29f3447c46c6e7b30fe1117e782f6a3338c97cf915f746e6c5
5
5
  SHA512:
6
- metadata.gz: 0372c44fda0f92504e10f0881f1e36e9702736a68e544071f519f9b0c377c95f25751aba199438a669536d039da85518009393749fa381f34ec623f03afad874
7
- data.tar.gz: 282edb48b247d1b4a6cd75680cc1545237dbb5d81ad6adb441673427eeba22282b6da6bbdacebf18b734d04144b6016698c631b9f7edae193c77d319ef7f67a9
6
+ metadata.gz: f50980b022b282ccc932651ee5111dccdf36e1711f18acd5f834596c2fb40611a050bf3bf6cf2b49972b13580bd83a1efb53fbe321b5e549e86d4ac0e821b5a6
7
+ data.tar.gz: 3dd82aaf6b1e7505011c58a7a714e6c68cfe1f1cd1c3340d1491028926e6839fb653ca5e54d14732661ba7facb7077344d4e1b664fd343273bf5a688caaa74ce
@@ -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.6
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
 
@@ -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
 
@@ -2,27 +2,20 @@ sudo: false
2
2
  cache: bundler
3
3
  language: ruby
4
4
  bundler_args: --quiet
5
- before_install:
6
- - gem install bundler --pre
7
5
  script:
8
6
  - bundle exec rake
9
7
  rvm:
10
- - 2.4.1
8
+ - 2.6.5
9
+ services:
10
+ - postgresql
11
+ - mysql
11
12
  env:
12
13
  matrix:
13
- - SOLIDUS_BRANCH=v1.2 DB=postgres
14
- - SOLIDUS_BRANCH=v1.3 DB=postgres
15
- - SOLIDUS_BRANCH=v1.4 DB=postgres
16
- - SOLIDUS_BRANCH=v2.0 DB=postgres
17
- - SOLIDUS_BRANCH=v2.1 DB=postgres
18
- - SOLIDUS_BRANCH=v2.2 DB=postgres
19
- - SOLIDUS_BRANCH=v2.3 DB=postgres
14
+ - SOLIDUS_BRANCH=v2.9 DB=postgres
15
+ - SOLIDUS_BRANCH=v2.10 DB=postgres
16
+ - SOLIDUS_BRANCH=v2.11 DB=postgres
20
17
  - SOLIDUS_BRANCH=master DB=postgres
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
18
+ - SOLIDUS_BRANCH=v2.9 DB=mysql
19
+ - SOLIDUS_BRANCH=v2.10 DB=mysql
20
+ - SOLIDUS_BRANCH=v2.11 DB=mysql
28
21
  - 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,10 +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'
8
11
  gem 'ffaker'
9
- gem 'mysql2'
10
- gem 'pg'
12
+ gem 'mysql2', '0.4.10'
13
+ gem 'pg', '~> 0.21'
14
+ gem 'puma'
11
15
  gem 'solidus_auth_devise'
12
16
  gem 'sqlite3'
13
17
 
14
18
  gemspec
19
+
20
+ gem 'culqi-ruby', github: 'culqi/culqi-ruby'
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,12 +1,17 @@
1
- module Solidus
2
- class Gateway::CulqiGateway < SolidusCulqi::Gateway.parent_class
3
- extend SolidusCulqi::Gateway
1
+ # frozen_string_literal: true
4
2
 
3
+ module Solidus
4
+ class Gateway::CulqiGateway < Spree::PaymentMethod::CreditCard
5
5
  preference :public_key, :string
6
6
  preference :secret_key, :string
7
7
 
8
- partial_method 'culqi'
9
- provider_method self.class
8
+ def partial_name
9
+ 'culqi'
10
+ end
11
+
12
+ def gateway_class
13
+ self.class
14
+ end
10
15
 
11
16
  def default_currency
12
17
  "PEN"
@@ -51,15 +56,16 @@ module Solidus
51
56
 
52
57
  def create_profile(payment)
53
58
  return unless payment.source.gateway_customer_profile_id.nil?
59
+
54
60
  init_culqi
55
61
  customer = get_customer(payment)
56
62
  token = payment.source.gateway_payment_profile_id
57
63
  card_token = generate_card(customer, token)
58
64
  unless customer.nil? || card_token.nil?
59
- payment.source.update({
65
+ payment.source.update(
60
66
  gateway_customer_profile_id: customer,
61
67
  gateway_payment_profile_id: card_token
62
- })
68
+ )
63
69
  end
64
70
  end
65
71
 
@@ -71,7 +77,7 @@ module Solidus
71
77
  end
72
78
 
73
79
  def commit(amount, creditcard, gateway_options, capture)
74
- installments = gateway_options[:installments]
80
+ installments = gateway_options.try(:installments)
75
81
  authorization = creditcard[:gateway_payment_profile_id]
76
82
  charge = Culqi::Charge.create(
77
83
  amount: amount,
@@ -88,8 +94,8 @@ module Solidus
88
94
  def parse_response(response)
89
95
  res = JSON.parse(response)
90
96
  ActiveMerchant::Billing::Response.new(
91
- res[:object] != "error",
92
- res[:merchant_message],
97
+ res["object"] != "error",
98
+ res["merchant_message"],
93
99
  res,
94
100
  authorization: res["id"]
95
101
  )
@@ -125,7 +131,8 @@ module Solidus
125
131
  def generate_card(customer, token)
126
132
  card = Culqi::Card.create(
127
133
  customer_id: customer,
128
- token_id: token
134
+ token_id: token,
135
+ validate: false
129
136
  )
130
137
  JSON.parse(card)["id"]
131
138
  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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddInstallmentsToOrders < SolidusSupport::Migration[4.2]
2
4
  def change
3
5
  add_column :spree_orders, :installments, :integer
@@ -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,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'solidus_core'
2
4
  require 'solidus_support'
3
5
  require 'culqi-ruby'
4
6
  require 'solidus_culqi/support'
5
- require 'solidus_culqi/gateway'
6
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:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
4
  module Support
3
5
  def self.solidus_earlier(version)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusCulqi
2
- VERSION = '0.0.2'
4
+ VERSION = '1.1.0'
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,19 +18,17 @@ 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.required_ruby_version = Gem::Requirement.new('~> 2.6')
22
+
23
+ s.add_dependency 'culqi-ruby'
19
24
  s.add_dependency 'solidus_core'
20
25
  s.add_dependency 'solidus_support'
21
- s.add_dependency 'culqi-ruby'
22
26
 
23
- s.add_development_dependency 'capybara'
24
- s.add_development_dependency 'poltergeist'
25
27
  s.add_development_dependency 'database_cleaner'
26
- s.add_development_dependency 'factory_girl'
28
+ s.add_development_dependency 'factory_bot'
27
29
  s.add_development_dependency 'pry'
28
30
  s.add_development_dependency 'rspec-rails'
29
31
  s.add_development_dependency 'rubocop'
30
32
  s.add_development_dependency 'rubocop-rspec'
31
33
  s.add_development_dependency 'simplecov'
32
- s.add_development_dependency 'vcr'
33
- s.add_development_dependency 'webmock'
34
34
  end