solidus_culqi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b87517498f541c5a8ad5b739f725b28921281f96
4
+ data.tar.gz: 93c72f59c361757c499eb3606e793aa81b2d4573
5
+ SHA512:
6
+ metadata.gz: c64c32c5deb830bed6db8ba903f992dfd02a01f8636254df152efebb685813494a3f3f6e775bf1b8a1914cb879a13ee9e3e1d3a62c2ac11da90c6c8554fd726d
7
+ data.tar.gz: 02ea951f965722b9c7d57a2ad36f10d7d49dc945d0d36abd34e085f0ab547656b7bc256835e9062155ceb249d900b4596d5c7f9c5189a520a945687f4e250acc
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ .rvmrc
3
+ \#*
4
+ *~
5
+ .#*
6
+ .DS_Store
7
+ .idea
8
+ .project
9
+ .sass-cache
10
+ coverage
11
+ Gemfile.lock
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.swp
16
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,235 @@
1
+ # Relaxed.Ruby.Style
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - 'spec/dummy/**/*'
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
13
+
14
+ # We use class vars and will have to continue doing so for compatability
15
+ Style/ClassVars:
16
+ Enabled: false
17
+
18
+ # We need these names for backwards compatability
19
+ Style/PredicateName:
20
+ Enabled: false
21
+
22
+ Style/AccessorMethodName:
23
+ Enabled: false
24
+
25
+ # This has been used for customization
26
+ Style/MutableConstant:
27
+ Enabled: false
28
+
29
+ Style/ClassAndModuleChildren:
30
+ Enabled: false
31
+
32
+ Style/GuardClause:
33
+ Enabled: false
34
+
35
+ Style/WordArray:
36
+ Enabled: false
37
+
38
+ Style/ConditionalAssignment:
39
+ Enabled: false
40
+
41
+ Performance/Count:
42
+ Enabled: false
43
+
44
+ Style/RaiseArgs:
45
+ Enabled: false
46
+
47
+ Naming/BinaryOperatorParameterName:
48
+ Enabled: false
49
+
50
+ # We can use good judgement here
51
+ Style/RegexpLiteral:
52
+ Enabled: false
53
+
54
+ # Unicode comments are useful
55
+ Style/AsciiComments:
56
+ Enabled: false
57
+
58
+ Lint/EndAlignment:
59
+ Enabled: false
60
+
61
+ Style/ElseAlignment:
62
+ Enabled: false
63
+
64
+ Style/IndentationWidth:
65
+ Enabled: false
66
+
67
+ Style/AlignParameters:
68
+ Enabled: false
69
+
70
+ Style/ClosingParenthesisIndentation:
71
+ Enabled: false
72
+
73
+ Style/MultilineMethodCallIndentation:
74
+ Enabled: false
75
+
76
+ Style/IndentArray:
77
+ Enabled: false
78
+
79
+ Style/IndentHash:
80
+ Enabled: false
81
+
82
+ Style/AlignHash:
83
+ Enabled: false
84
+
85
+ # From http://relaxed.ruby.style/
86
+
87
+ Style/Alias:
88
+ Enabled: false
89
+ StyleGuide: http://relaxed.ruby.style/#stylealias
90
+
91
+ Style/BeginBlock:
92
+ Enabled: false
93
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
94
+
95
+ Style/BlockDelimiters:
96
+ Enabled: false
97
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
98
+
99
+ Style/Documentation:
100
+ Enabled: false
101
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
102
+
103
+ Style/DotPosition:
104
+ Enabled: false
105
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
106
+
107
+ Style/DoubleNegation:
108
+ Enabled: false
109
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
110
+
111
+ Style/EndBlock:
112
+ Enabled: false
113
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
114
+
115
+ Style/FormatString:
116
+ Enabled: false
117
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
118
+
119
+ Style/IfUnlessModifier:
120
+ Enabled: false
121
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
122
+
123
+ Style/Lambda:
124
+ Enabled: false
125
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
126
+
127
+ Style/ModuleFunction:
128
+ Enabled: false
129
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
130
+
131
+ Style/MultilineBlockChain:
132
+ Enabled: false
133
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
134
+
135
+ Style/NegatedIf:
136
+ Enabled: false
137
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
138
+
139
+ Style/NegatedWhile:
140
+ Enabled: false
141
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
142
+
143
+ Style/ParallelAssignment:
144
+ Enabled: false
145
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
146
+
147
+ Style/PercentLiteralDelimiters:
148
+ Enabled: false
149
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
150
+
151
+ Style/PerlBackrefs:
152
+ Enabled: false
153
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
154
+
155
+ Style/Semicolon:
156
+ Enabled: false
157
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
158
+
159
+ Style/SignalException:
160
+ Enabled: false
161
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
162
+
163
+ Style/SingleLineBlockParams:
164
+ Enabled: false
165
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
166
+
167
+ Style/SingleLineMethods:
168
+ Enabled: false
169
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
170
+
171
+ Style/SpaceBeforeBlockBraces:
172
+ Enabled: false
173
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
174
+
175
+ Style/SpaceInsideParens:
176
+ Enabled: false
177
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
178
+
179
+ Style/SpecialGlobalVars:
180
+ Enabled: false
181
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
182
+
183
+ Style/StringLiterals:
184
+ Enabled: false
185
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
186
+
187
+ Style/SymbolProc:
188
+ Enabled: false
189
+
190
+ Style/WhileUntilModifier:
191
+ Enabled: false
192
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
193
+
194
+ Lint/AmbiguousRegexpLiteral:
195
+ Enabled: false
196
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
197
+
198
+ Lint/AssignmentInCondition:
199
+ Enabled: false
200
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
201
+
202
+ Lint/HandleExceptions:
203
+ Exclude:
204
+ - 'Rakefile'
205
+
206
+ Metrics/AbcSize:
207
+ Enabled: false
208
+
209
+ Metrics/BlockLength:
210
+ Exclude:
211
+ - 'spec/*/*'
212
+
213
+ Metrics/BlockNesting:
214
+ Enabled: false
215
+
216
+ Metrics/ClassLength:
217
+ Enabled: false
218
+
219
+ Metrics/ModuleLength:
220
+ Enabled: false
221
+
222
+ Metrics/CyclomaticComplexity:
223
+ Enabled: false
224
+
225
+ Metrics/LineLength:
226
+ Enabled: false
227
+
228
+ Metrics/MethodLength:
229
+ Enabled: false
230
+
231
+ Metrics/ParameterLists:
232
+ Enabled: false
233
+
234
+ Metrics/PerceivedComplexity:
235
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ bundler_args: --quiet
5
+ script:
6
+ - bundle exec rake
7
+ rvm:
8
+ - 2.4.1
9
+ env:
10
+ 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
19
+ - 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
28
+ - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
4
+
5
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
7
+
8
+ gemspec
9
+
10
+ group :test do
11
+ gem 'ffaker'
12
+ gem 'sqlite3'
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2017 César Carruitero
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ Solidus Culqi
2
+ =============
3
+
4
+ Add [Culqi](https://www.culqi.com/) support for [solidus](https://solidus.io/) e-commerce.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add solidus_culqi to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'solidus_culqi'
13
+ ```
14
+
15
+ Bundle your dependencies and run the installation generator:
16
+
17
+ ```shell
18
+ bundle
19
+ bundle exec rails g solidus_culqi:install
20
+ ```
21
+
22
+ Testing
23
+ -------
24
+
25
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
26
+
27
+ ```shell
28
+ bundle
29
+ bundle exec rake
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ begin
6
+ require 'spree/testing_support/extension_rake'
7
+ require 'rubocop/rake_task'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i(first_run rubocop spec)
15
+ rescue LoadError
16
+ # no rspec available
17
+ end
18
+
19
+ task :first_run do
20
+ if Dir['spec/dummy'].empty?
21
+ Rake::Task[:test_app].invoke
22
+ Dir.chdir('../../')
23
+ end
24
+ end
25
+
26
+ desc 'Generates a dummy app for testing'
27
+ task :test_app do
28
+ ENV['LIB_NAME'] = 'solidus_culqi'
29
+ Rake::Task['extension:test_app'].invoke
30
+ end
@@ -0,0 +1,17 @@
1
+ module SolidusCulqi
2
+ module InjectInstallmentsConcern
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ prepend(InstanceMethods)
6
+ end
7
+
8
+ module InstanceMethods
9
+ def gateway_options
10
+ options = super
11
+ installments = order.installments
12
+ options[:installments] = installments if installments
13
+ options
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusCulqi
2
+ module PermittedAttributesConcern
3
+ def checkout_attributes
4
+ super | [:installments]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ Spree::Payment.include SolidusCulqi::InjectInstallmentsConcern
@@ -0,0 +1 @@
1
+ Spree::PermittedAttributes.singleton_class.prepend SolidusCulqi::PermittedAttributesConcern
@@ -0,0 +1,89 @@
1
+ module Solidus
2
+ class Gateway::CulqiGateway < ::Spree::Gateway
3
+ preference :public_key, :string
4
+ preference :secret_key, :string
5
+
6
+ def default_currency
7
+ "PEN"
8
+ end
9
+
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
18
+ end
19
+
20
+ def provider_class
21
+ self.class
22
+ end
23
+
24
+ def authorize(amount, creditcard, gateway_options)
25
+ init_culqi
26
+ commit(amount, creditcard, gateway_options, false)
27
+ end
28
+
29
+ def purchase(amount, creditcard, gateway_options)
30
+ init_culqi
31
+ commit(amount, creditcard, gateway_options, true)
32
+ end
33
+
34
+ def capture(_amount, response_code, _gateway_options)
35
+ init_culqi
36
+ charge = Culqi::Charge.capture(response_code)
37
+ parse_response(charge)
38
+ end
39
+
40
+ def credit(amount, creditcard, _gateway_options)
41
+ init_culqi
42
+ # Culqi only accepts 'duplicado','fraudulento' o 'solicitud_comprador'
43
+ # like reason's value
44
+ refund = Culqi::Refund.create(
45
+ amount: amount,
46
+ charge_id: creditcard,
47
+ reason: "solicitud_comprador"
48
+ )
49
+ parse_response(refund)
50
+ end
51
+
52
+ def void(creditcard, gateway_options)
53
+ amount = gateway_options[:subtotal].to_i
54
+ credit(amount, creditcard, gateway_options)
55
+ end
56
+
57
+ private
58
+
59
+ def init_culqi
60
+ Culqi.public_key = preferred_public_key
61
+ Culqi.secret_key = preferred_secret_key
62
+ end
63
+
64
+ def commit(amount, creditcard, gateway_options, capture)
65
+ installments = gateway_options[:installments]
66
+ authorization = creditcard[:gateway_payment_profile_id]
67
+ charge = Culqi::Charge.create(
68
+ amount: amount,
69
+ capture: capture,
70
+ currency_code: default_currency,
71
+ description: gateway_options[:description],
72
+ email: gateway_options[:email],
73
+ installments: installments || 0,
74
+ source_id: authorization
75
+ )
76
+ parse_response(charge)
77
+ end
78
+
79
+ def parse_response(response)
80
+ res = JSON.parse(response)
81
+ ActiveMerchant::Billing::Response.new(
82
+ res[:object] != "error",
83
+ res[:merchant_message],
84
+ res,
85
+ authorization: res["id"]
86
+ )
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,79 @@
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>
data/bin/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/solidus_culqi/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: Hello world
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,5 @@
1
+ class AddInstallmentsToOrders < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :spree_orders, :installments, :integer
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module SolidusCulqi
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :auto_run_migrations, type: :boolean, default: false
5
+
6
+ def add_migrations
7
+ run 'bundle exec rake railties:install:migrations FROM=solidus_culqi'
8
+ end
9
+
10
+ def run_migrations
11
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
12
+ if run_migrations
13
+ run 'bundle exec rake db:migrate'
14
+ else
15
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ require 'solidus_core'
2
+ require 'solidus_support'
3
+ require 'culqi-ruby'
4
+ require 'solidus_culqi/engine'
@@ -0,0 +1,22 @@
1
+ module SolidusCulqi
2
+ class Engine < Rails::Engine
3
+ engine_name 'solidus_culqi'
4
+
5
+ # use rspec for tests
6
+ config.generators do |g|
7
+ g.test_framework :rspec
8
+ end
9
+
10
+ initializer 'spree.gateway.payment_methods', after: 'spree.register.payment_methods' do |app|
11
+ app.config.spree.payment_methods << Solidus::Gateway::CulqiGateway
12
+ end
13
+
14
+ def self.activate
15
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
16
+ Rails.configuration.cache_classes ? require(c) : load(c)
17
+ end
18
+ end
19
+
20
+ config.to_prepare(&method(:activate).to_proc)
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
+ #
4
+ # Example adding this to your spec_helper will load these Factories for use:
5
+ # require 'solidus_culqi/factories'
6
+ end
@@ -0,0 +1,3 @@
1
+ module SolidusCulqi
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,32 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'solidus_culqi/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'solidus_culqi'
7
+ s.version = SolidusCulqi::VERSION
8
+ s.summary = 'Adds solidus support for Culqi Gateway'
9
+ s.description = s.summary
10
+ s.license = 'MIT'
11
+
12
+ s.author = 'César Carruitero'
13
+ s.email = 'ccarruitero@protonmail.com'
14
+ s.homepage = 'https://github.com/ccarruitero/solidus_culqi'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+
19
+ s.add_dependency 'solidus_core'
20
+ s.add_dependency 'solidus_support'
21
+ s.add_dependency 'culqi-ruby'
22
+
23
+ s.add_development_dependency 'capybara'
24
+ s.add_development_dependency 'poltergeist'
25
+ s.add_development_dependency 'database_cleaner'
26
+ s.add_development_dependency 'factory_girl'
27
+ s.add_development_dependency 'pry'
28
+ s.add_development_dependency 'rspec-rails'
29
+ s.add_development_dependency 'rubocop'
30
+ s.add_development_dependency 'rubocop-rspec'
31
+ s.add_development_dependency 'simplecov'
32
+ end
@@ -0,0 +1,77 @@
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
@@ -0,0 +1,50 @@
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
@@ -0,0 +1,93 @@
1
+ # Run Coverage report
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec/dummy'
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Views', 'app/views'
10
+ add_group 'Libraries', 'lib'
11
+ end
12
+
13
+ # Configure Rails Environment
14
+ ENV['RAILS_ENV'] = 'test'
15
+
16
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
17
+
18
+ require 'rspec/rails'
19
+ require 'database_cleaner'
20
+ require 'ffaker'
21
+ require 'capybara/rspec'
22
+ require 'capybara/poltergeist'
23
+ require 'pry'
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
+ # Requires supporting ruby files with custom matchers and macros, etc,
32
+ # in spec/support/ and its subdirectories.
33
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
34
+
35
+ # Requires factories and other useful helpers defined in spree_core.
36
+ require 'spree/testing_support/authorization_helpers'
37
+ require 'spree/testing_support/capybara_ext'
38
+ require 'spree/testing_support/controller_requests'
39
+ require 'spree/testing_support/factories'
40
+ require 'spree/testing_support/url_helpers'
41
+ require 'spree/testing_support/preferences'
42
+
43
+ # Requires factories defined in lib/solidus_culqi/factories.rb
44
+ require 'solidus_culqi/factories'
45
+
46
+ RSpec.configure do |config|
47
+ config.include FactoryGirl::Syntax::Methods
48
+ config.include CulqiHelper
49
+ config.include Spree::TestingSupport::UrlHelpers
50
+ config.include Spree::TestingSupport::Preferences
51
+
52
+ # Infer an example group's spec type from the file location.
53
+ config.infer_spec_type_from_file_location!
54
+
55
+ # == Mock Framework
56
+ #
57
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
58
+ #
59
+ # config.mock_with :mocha
60
+ # config.mock_with :flexmock
61
+ # config.mock_with :rr
62
+ config.mock_with :rspec
63
+ config.color = true
64
+
65
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
66
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
67
+
68
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
69
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
70
+ # to setup a test will be unavailable to the browser, which runs under a separate server instance.
71
+ config.use_transactional_fixtures = false
72
+
73
+ # Ensure Suite is set to use transactions for speed.
74
+ config.before :suite do
75
+ DatabaseCleaner.strategy = :transaction
76
+ DatabaseCleaner.clean_with :truncation
77
+ end
78
+
79
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
80
+ config.before :each do
81
+ DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
82
+ DatabaseCleaner.start
83
+ reset_spree_preferences
84
+ end
85
+
86
+ # After each spec clean the database.
87
+ config.after :each do
88
+ DatabaseCleaner.clean
89
+ end
90
+
91
+ config.fail_fast = ENV['FAIL_FAST'] || false
92
+ config.order = 'random'
93
+ end
@@ -0,0 +1,43 @@
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
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solidus_culqi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - César Carruitero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: solidus_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: solidus_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: culqi-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Adds solidus support for Culqi Gateway
182
+ email: ccarruitero@protonmail.com
183
+ executables: []
184
+ extensions: []
185
+ extra_rdoc_files: []
186
+ files:
187
+ - ".gitignore"
188
+ - ".rspec"
189
+ - ".rubocop.yml"
190
+ - ".travis.yml"
191
+ - Gemfile
192
+ - LICENSE
193
+ - README.md
194
+ - Rakefile
195
+ - app/models/concerns/solidus_culqi/inject_installments_concern.rb
196
+ - app/models/concerns/solidus_culqi/permitted_attributes_concern.rb
197
+ - app/models/payment_decorator.rb
198
+ - app/models/permitted_attributes_decorator.rb
199
+ - app/models/solidus/gateway/culqi_gateway.rb
200
+ - app/views/spree/checkout/payment/_culqi.html.erb
201
+ - bin/rails
202
+ - config/locales/en.yml
203
+ - config/routes.rb
204
+ - db/migrate/20170919145201_add_installments_to_orders.rb
205
+ - lib/generators/solidus_culqi/install/install_generator.rb
206
+ - lib/solidus_culqi.rb
207
+ - lib/solidus_culqi/engine.rb
208
+ - lib/solidus_culqi/factories.rb
209
+ - lib/solidus_culqi/version.rb
210
+ - solidus_culqi.gemspec
211
+ - spec/features/culqi_checkout_autocapture_spec.rb
212
+ - spec/features/culqi_checkout_spec.rb
213
+ - spec/spec_helper.rb
214
+ - spec/support/culqi_helper.rb
215
+ homepage: https://github.com/ccarruitero/solidus_culqi
216
+ licenses:
217
+ - MIT
218
+ metadata: {}
219
+ post_install_message:
220
+ rdoc_options: []
221
+ require_paths:
222
+ - lib
223
+ required_ruby_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ requirements: []
234
+ rubyforge_project:
235
+ rubygems_version: 2.6.13
236
+ signing_key:
237
+ specification_version: 4
238
+ summary: Adds solidus support for Culqi Gateway
239
+ test_files: []