spree_midtrans_gateway 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd66d67c60709aa161dfd2bb71b4b6699ec300be
4
+ data.tar.gz: 7d5b9dfb2aa0c86d1168c488e63027ef2a4a0b5b
5
+ SHA512:
6
+ metadata.gz: 9637938378940f80e752bcb9615b17fb1136c7f8327f79557c232ff5dd58d9cfc9c44cae217ebda9f9a0702530dc40ef7386155377ffad27d9556d8e530b2027
7
+ data.tar.gz: d153c71902448b29621503c9611b6587730befc72acaad68b467a46ca19e0bc3f66031b52e337e3b6f873d6df89b97427ea427f70adf6cfa8f735498b076cb5a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+ SupportedStyles:
4
+ - double_quotes
5
+ # If `true`, strings which span multiple lines using `\` for continuation must
6
+ # use the same type of quotes on each line.
7
+ ConsistentQuotesInMultiline: false
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ EnforcedStyle: double_quotes
11
+ SupportedStyles:
12
+ - double_quotes
13
+
14
+ Style/ClassAndModuleChildren:
15
+ EnforcedStyle: compact
16
+
17
+ Style/DocumentationMethod:
18
+ RequireForNonPublicMethods: false
19
+
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
22
+
23
+ Documentation:
24
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.0
5
+ before_install: gem install bundler
6
+ install:
7
+ - ./bin/setup
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dimazniawan@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in spree_midtrans_gateway.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,263 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ spree_midtrans_gateway (0.1.0)
5
+ spree_core (~> 3.1, < 4.0)
6
+ veritrans (~> 2.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.9)
12
+ actionpack (= 4.2.9)
13
+ actionview (= 4.2.9)
14
+ activejob (= 4.2.9)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.9)
18
+ actionview (= 4.2.9)
19
+ activesupport (= 4.2.9)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.9)
25
+ activesupport (= 4.2.9)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
30
+ activejob (4.2.9)
31
+ activesupport (= 4.2.9)
32
+ globalid (>= 0.3.0)
33
+ activemerchant (1.72.0)
34
+ activesupport (>= 3.2.14, < 6.x)
35
+ builder (>= 2.1.2, < 4.0.0)
36
+ i18n (>= 0.6.9)
37
+ nokogiri (~> 1.4)
38
+ activemodel (4.2.9)
39
+ activesupport (= 4.2.9)
40
+ builder (~> 3.1)
41
+ activerecord (4.2.9)
42
+ activemodel (= 4.2.9)
43
+ activesupport (= 4.2.9)
44
+ arel (~> 6.0)
45
+ activesupport (4.2.9)
46
+ i18n (~> 0.7)
47
+ minitest (~> 5.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
49
+ tzinfo (~> 1.1)
50
+ acts_as_list (0.9.7)
51
+ activerecord (>= 3.0)
52
+ addressable (2.5.2)
53
+ public_suffix (>= 2.0.2, < 4.0)
54
+ arel (6.0.4)
55
+ ast (2.3.0)
56
+ awesome_nested_set (3.0.3)
57
+ activerecord (>= 4.0.0, < 5)
58
+ builder (3.2.3)
59
+ camertron-eprun (1.1.1)
60
+ cancancan (1.10.1)
61
+ carmen (1.0.2)
62
+ activesupport (>= 3.0.0)
63
+ cldr-plurals-runtime-rb (1.0.1)
64
+ climate_control (0.2.0)
65
+ cocaine (0.5.8)
66
+ climate_control (>= 0.0.3, < 1.0)
67
+ concurrent-ruby (1.0.5)
68
+ css_parser (1.6.0)
69
+ addressable
70
+ deface (1.2.0)
71
+ nokogiri (~> 1.6)
72
+ polyglot
73
+ rails (>= 4.1)
74
+ rainbow (>= 2.1.0)
75
+ diff-lcs (1.3)
76
+ erubis (2.7.0)
77
+ excon (0.59.0)
78
+ ffaker (2.7.0)
79
+ font-awesome-rails (4.7.0.2)
80
+ railties (>= 3.2, < 5.2)
81
+ friendly_id (5.1.0)
82
+ activerecord (>= 4.0.0)
83
+ globalid (0.4.0)
84
+ activesupport (>= 4.2.0)
85
+ highline (1.6.21)
86
+ htmlentities (4.3.4)
87
+ i18n (0.8.6)
88
+ kaminari (1.0.1)
89
+ activesupport (>= 4.1.0)
90
+ kaminari-actionview (= 1.0.1)
91
+ kaminari-activerecord (= 1.0.1)
92
+ kaminari-core (= 1.0.1)
93
+ kaminari-actionview (1.0.1)
94
+ actionview
95
+ kaminari-core (= 1.0.1)
96
+ kaminari-activerecord (1.0.1)
97
+ activerecord
98
+ kaminari-core (= 1.0.1)
99
+ kaminari-core (1.0.1)
100
+ loofah (2.0.3)
101
+ nokogiri (>= 1.5.9)
102
+ mail (2.6.6)
103
+ mime-types (>= 1.16, < 4)
104
+ mime-types (3.1)
105
+ mime-types-data (~> 3.2015)
106
+ mime-types-data (3.2016.0521)
107
+ mimemagic (0.3.0)
108
+ mini_portile2 (2.3.0)
109
+ minitest (5.10.3)
110
+ monetize (1.7.0)
111
+ money (~> 6.9)
112
+ money (6.9.0)
113
+ i18n (>= 0.6.4, < 0.9)
114
+ nokogiri (1.8.1)
115
+ mini_portile2 (~> 2.3.0)
116
+ paperclip (4.3.7)
117
+ activemodel (>= 3.2.0)
118
+ activesupport (>= 3.2.0)
119
+ cocaine (~> 0.5.5)
120
+ mime-types
121
+ mimemagic (= 0.3.0)
122
+ parallel (1.12.0)
123
+ paranoia (2.1.5)
124
+ activerecord (~> 4.0)
125
+ parser (2.4.0.0)
126
+ ast (~> 2.2)
127
+ polyamorous (1.3.1)
128
+ activerecord (>= 3.0)
129
+ polyglot (0.3.5)
130
+ powerpack (0.1.1)
131
+ premailer (1.10.4)
132
+ addressable
133
+ css_parser (>= 1.4.10)
134
+ htmlentities (>= 4.0.0)
135
+ premailer-rails (1.9.7)
136
+ actionmailer (>= 3, < 6)
137
+ premailer (~> 1.7, >= 1.7.9)
138
+ public_suffix (3.0.0)
139
+ rack (1.6.8)
140
+ rack-test (0.6.3)
141
+ rack (>= 1.0)
142
+ rails (4.2.9)
143
+ actionmailer (= 4.2.9)
144
+ actionpack (= 4.2.9)
145
+ actionview (= 4.2.9)
146
+ activejob (= 4.2.9)
147
+ activemodel (= 4.2.9)
148
+ activerecord (= 4.2.9)
149
+ activesupport (= 4.2.9)
150
+ bundler (>= 1.3.0, < 2.0)
151
+ railties (= 4.2.9)
152
+ sprockets-rails
153
+ rails-deprecated_sanitizer (1.0.3)
154
+ activesupport (>= 4.2.0.alpha)
155
+ rails-dom-testing (1.0.8)
156
+ activesupport (>= 4.2.0.beta, < 5.0)
157
+ nokogiri (~> 1.6)
158
+ rails-deprecated_sanitizer (>= 1.0.1)
159
+ rails-html-sanitizer (1.0.3)
160
+ loofah (~> 2.0)
161
+ railties (4.2.9)
162
+ actionpack (= 4.2.9)
163
+ activesupport (= 4.2.9)
164
+ rake (>= 0.8.7)
165
+ thor (>= 0.18.1, < 2.0)
166
+ rainbow (2.2.2)
167
+ rake
168
+ rake (10.5.0)
169
+ ransack (1.4.1)
170
+ actionpack (>= 3.0)
171
+ activerecord (>= 3.0)
172
+ activesupport (>= 3.0)
173
+ i18n
174
+ polyamorous (~> 1.1)
175
+ responders (2.4.0)
176
+ actionpack (>= 4.2.0, < 5.3)
177
+ railties (>= 4.2.0, < 5.3)
178
+ rspec (3.6.0)
179
+ rspec-core (~> 3.6.0)
180
+ rspec-expectations (~> 3.6.0)
181
+ rspec-mocks (~> 3.6.0)
182
+ rspec-core (3.6.0)
183
+ rspec-support (~> 3.6.0)
184
+ rspec-expectations (3.6.0)
185
+ diff-lcs (>= 1.2.0, < 2.0)
186
+ rspec-support (~> 3.6.0)
187
+ rspec-mocks (3.6.0)
188
+ diff-lcs (>= 1.2.0, < 2.0)
189
+ rspec-support (~> 3.6.0)
190
+ rspec-support (3.6.0)
191
+ rubocop (0.50.0)
192
+ parallel (~> 1.10)
193
+ parser (>= 2.3.3.1, < 3.0)
194
+ powerpack (~> 0.1)
195
+ rainbow (>= 2.2.2, < 3.0)
196
+ ruby-progressbar (~> 1.7)
197
+ unicode-display_width (~> 1.0, >= 1.0.1)
198
+ ruby-progressbar (1.8.3)
199
+ spree_core (3.1.9)
200
+ activemerchant (~> 1.59)
201
+ acts_as_list (~> 0.7, >= 0.7.2)
202
+ awesome_nested_set (~> 3.0.1)
203
+ cancancan (~> 1.10.1)
204
+ carmen (~> 1.0.0)
205
+ deface (~> 1.0)
206
+ ffaker (~> 2.2)
207
+ font-awesome-rails (~> 4.0)
208
+ friendly_id (~> 5.1.0)
209
+ highline (~> 1.6.18)
210
+ kaminari (~> 1.0.1)
211
+ monetize (~> 1.1)
212
+ paperclip (~> 4.3.0)
213
+ paranoia (~> 2.1.0)
214
+ premailer-rails
215
+ rails (~> 4.2.5)
216
+ ransack (~> 1.4.1)
217
+ responders
218
+ sprockets-rails
219
+ state_machines-activerecord (~> 0.2)
220
+ stringex
221
+ truncate_html (~> 0.9.3)
222
+ twitter_cldr (~> 3.0)
223
+ sprockets (3.7.1)
224
+ concurrent-ruby (~> 1.0)
225
+ rack (> 1, < 3)
226
+ sprockets-rails (3.2.1)
227
+ actionpack (>= 4.0)
228
+ activesupport (>= 4.0)
229
+ sprockets (>= 3.0.0)
230
+ state_machines (0.5.0)
231
+ state_machines-activemodel (0.5.0)
232
+ activemodel (>= 4.1, < 5.2)
233
+ state_machines (>= 0.5.0)
234
+ state_machines-activerecord (0.5.0)
235
+ activerecord (>= 4.1, < 5.2)
236
+ state_machines-activemodel (>= 0.5.0)
237
+ stringex (2.7.1)
238
+ thor (0.20.0)
239
+ thread_safe (0.3.6)
240
+ truncate_html (0.9.3)
241
+ twitter_cldr (3.6.0)
242
+ camertron-eprun
243
+ cldr-plurals-runtime-rb (~> 1.0)
244
+ tzinfo
245
+ tzinfo (1.2.3)
246
+ thread_safe (~> 0.1)
247
+ unicode-display_width (1.3.0)
248
+ veritrans (2.2.0)
249
+ excon (~> 0.20)
250
+
251
+ PLATFORMS
252
+ ruby
253
+
254
+ DEPENDENCIES
255
+ bundler (~> 1.15)
256
+ rails (~> 4, < 5)
257
+ rake (~> 10.0)
258
+ rspec (~> 3)
259
+ rubocop (~> 0.50)
260
+ spree_midtrans_gateway!
261
+
262
+ BUNDLED WITH
263
+ 1.16.0.pre.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dimas J. Taniawan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Spree::Midtrans::Gateway
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/spree/midtrans/gateway`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'spree_midtrans_gateway'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install spree_midtrans_gateway
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dimasjt/spree-midtrans-gateway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Spree::Midtrans::Gateway project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dimasjt/spree-midtrans-gateway/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,52 @@
1
+ module Spree
2
+ class MidtransController < StoreController
3
+ skip_before_action :verify_authenticity_token, only: :notifications
4
+
5
+ # this action redirected from /checkout/payment
6
+ # will redirect to midtrans page
7
+ def charge
8
+ order = current_order || raise(ActiveRecord::RecordNotFound)
9
+ payment_method = Spree::PaymentMethod.where(type: "Spree::Gateway::MidtransGateway").find(params[:payment_method_id])
10
+ charge = payment_method.charge(order)
11
+
12
+ order.next
13
+
14
+ if charge.success? && order.complete?
15
+ redirect_to charge.redirect_url
16
+ else
17
+ flash[:error] = charge.data[:message]
18
+ redirect_to checkout_state_path(:payment)
19
+ end
20
+ end
21
+
22
+ # action to process after success in midtrans page
23
+ # have params :order_id as Spree::Order#number
24
+ def success
25
+ order = Spree::Order.find_by!(number: params[:order_id])
26
+
27
+ if order.complete?
28
+ order.payment_state = 'paid'
29
+ order.save
30
+ flash.notice = Spree.t(:order_processed_successfully)
31
+ end
32
+
33
+ redirect_to order_path(order)
34
+ end
35
+
36
+ # this action will run when Midtrans send notification by webhook
37
+ # https://dashboard.sandbox.midtrans.com/settings/vtweb_configuration
38
+ def notifications
39
+ order = Spree::Order.find_by_number(params[:order_id])
40
+
41
+ order.payment_state =
42
+ if params[:status_code] == "200" && params[:fraud_status] == "accept"
43
+ 'paid'
44
+ else
45
+ 'failed'
46
+ end
47
+
48
+ order.save
49
+ head 200
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,92 @@
1
+ require "veritrans"
2
+
3
+ module Spree
4
+ class Gateway::MidtransGateway < Gateway
5
+ preference :client_key, :string
6
+ preference :server_key, :string
7
+
8
+ def provider_class
9
+ ::Midtrans
10
+ end
11
+
12
+ def provider
13
+ ::Midtrans.new(
14
+ client_key: preferred_client_key,
15
+ server_key: preferred_server_key,
16
+ api_host: preferred_test_mode ? "https://api.sandbox.midtrans.com" : "https://api.midtrans.com"
17
+ )
18
+ end
19
+
20
+ def method_type
21
+ 'midtrans'
22
+ end
23
+
24
+ def auto_capture?
25
+ true
26
+ end
27
+
28
+ def supports?(source)
29
+ true
30
+ end
31
+
32
+ def source_required?
33
+ false
34
+ end
35
+
36
+ def charge(order)
37
+ result = provider.charge(
38
+ payment_type: "VTWEB",
39
+ transaction_details: {
40
+ order_id: order.number,
41
+ gross_amount: order.total
42
+ },
43
+ # NOTE: items disabled because shipping and tax not provided by Midtrans
44
+ # item_details: line_items(order),
45
+ customer_details: customer(order)
46
+ )
47
+
48
+ order.payments.create!(
49
+ amount: order.total,
50
+ payment_method: self,
51
+ )
52
+ result
53
+ end
54
+
55
+ private
56
+
57
+ def customer(order)
58
+ billing = order.bill_address
59
+ {
60
+ first_name: billing.firstname,
61
+ last_name: billing.lastname,
62
+ email: order.email,
63
+ phone: billing.phone,
64
+ shipping_address: address(order.ship_address),
65
+ billing_address: address(billing)
66
+ }
67
+ end
68
+
69
+ def address(addrs)
70
+ {
71
+ first_name: addrs.try(:firstname),
72
+ last_name: addrs.try(:lastname),
73
+ phone: addrs.phone,
74
+ address1: addrs.address1,
75
+ city: addrs.city,
76
+ postal_code: addrs.zipcode
77
+ }
78
+ end
79
+
80
+ # def line_items(order)
81
+ # order.line_items.map do |li|
82
+ # {
83
+ # id: li.id,
84
+ # price: li.price,
85
+ # quantity: li.quantity,
86
+ # name: li.product.name
87
+ # }
88
+ # end
89
+ # end
90
+ #
91
+ end
92
+ end
@@ -0,0 +1,2 @@
1
+ <%= link_to Spree.t("pay_with_midtrans", scope: :midtrans), midtrans_charge_url(payment_method_id: payment_method.id), method: :post, id: "payment-midtrans" %>
2
+ <span><%= Spree.t("info", scope: :midtrans) %></span>
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "spree_core"
5
+ require "spree_midtrans_gateway"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ en:
2
+ spree:
3
+ midtrans:
4
+ pay_with_midtrans: Pay through Midtrans
5
+ info: You will redirect to Midtrans page
@@ -0,0 +1,5 @@
1
+ en:
2
+ spree:
3
+ midtrans:
4
+ pay_with_midtrans: Bayar melalui Midtrans
5
+ info: Kamu akan dialihkan ke halaman pembayaran Midtrans
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Spree::Core::Engine.add_routes do
2
+ get "/payment/midtrans/success", to: "midtrans#success", as: :midtrans_success
3
+ post "/payment/midtrans/notifications", to: "midtrans#notifications", as: :midtrans_notifications
4
+ post "/payment/midtrans/charge", to: "midtrans#charge", as: :midtrans_charge
5
+ end
@@ -0,0 +1,21 @@
1
+ module SpreeMidtransGateway
2
+ class Engine < Rails::Engine
3
+ require "spree/core"
4
+ isolate_namespace Spree
5
+ engine_name "spree_midtrans_gateway"
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ def self.activate
10
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
11
+ Rails.configuration.cache_classes ? require(c) : load(c)
12
+ end
13
+ end
14
+
15
+ config.to_prepare &method(:activate).to_proc
16
+
17
+ initializer "spree.midtrans_gateway.payment_methods", after: "spree.register.payment_methods" do |app|
18
+ app.config.spree.payment_methods << Spree::Gateway::MidtransGateway
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SpreeMidtransGateway
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "spree_core"
2
+ require "spree_midtrans_gateway/version"
3
+ require "spree_midtrans_gateway/engine"
@@ -0,0 +1,104 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
18
+ require "spree_midtrans_gateway"
19
+
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
45
+ # have no way to turn it off -- the option exists only for backwards
46
+ # compatibility in RSpec 3). It causes shared context metadata to be
47
+ # inherited by the metadata hash of host groups and examples, rather than
48
+ # triggering implicit auto-inclusion in groups with matching metadata.
49
+ config.shared_context_metadata_behavior = :apply_to_host_groups
50
+
51
+ # The settings below are suggested to provide a good initial experience
52
+ # with RSpec, but feel free to customize to your heart's content.
53
+ =begin
54
+ # This allows you to limit a spec run to individual examples or groups
55
+ # you care about by tagging them with `:focus` metadata. When nothing
56
+ # is tagged with `:focus`, all examples get run. RSpec also provides
57
+ # aliases for `it`, `describe`, and `context` that include `:focus`
58
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
59
+ config.filter_run_when_matching :focus
60
+
61
+ # Allows RSpec to persist some state between runs in order to support
62
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
63
+ # you configure your source control system to ignore this file.
64
+ config.example_status_persistence_file_path = "spec/examples.txt"
65
+
66
+ # Limits the available syntax to the non-monkey patched syntax that is
67
+ # recommended. For more details, see:
68
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
69
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
71
+ config.disable_monkey_patching!
72
+
73
+ # This setting enables warnings. It's recommended, but in some cases may
74
+ # be too noisy due to issues in dependencies.
75
+ config.warnings = true
76
+
77
+ # Many RSpec users commonly either run the entire suite or an individual
78
+ # file, and it's useful to allow more verbose output when running an
79
+ # individual spec file.
80
+ if config.files_to_run.one?
81
+ # Use the documentation formatter for detailed output,
82
+ # unless a formatter has already been configured
83
+ # (e.g. via a command-line flag).
84
+ config.default_formatter = "doc"
85
+ end
86
+
87
+ # Print the 10 slowest examples and example groups at the
88
+ # end of the spec run, to help surface which specs are running
89
+ # particularly slow.
90
+ config.profile_examples = 10
91
+
92
+ # Run specs in random order to surface order dependencies. If you find an
93
+ # order dependency and want to debug it, you can fix the order by providing
94
+ # the seed, which is printed after each run.
95
+ # --seed 1234
96
+ config.order = :random
97
+
98
+ # Seed global randomization in this process using the `--seed` CLI option.
99
+ # Setting this allows you to use `--seed` to deterministically reproduce
100
+ # test failures related to randomization by passing the same `--seed` value
101
+ # as the one that triggered the failure.
102
+ Kernel.srand config.seed
103
+ =end
104
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe SpreeMidtransGateway do
4
+ it "should have version" do
5
+ expect(SpreeMidtransGateway::VERSION).to eq("0.1.0")
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "spree_midtrans_gateway/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spree_midtrans_gateway"
8
+ spec.version = SpreeMidtransGateway::VERSION
9
+ spec.authors = ["Dimas J. Taniawan"]
10
+ spec.email = ["dimazniawan@gmail.com"]
11
+
12
+ spec.summary = "Midtrans gateway for Spree"
13
+ spec.description = "Midtrans payment gateway for Spree framework"
14
+ spec.homepage = "https://github.com/dimasjt/spree_midtrans_gateway"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.test_files = `git ls-files -- spec/*`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 2.1.0"
22
+
23
+ spec.add_dependency "spree_core", "~> 3.1", "< 4.0"
24
+ spec.add_dependency "veritrans", "~> 2.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3"
29
+ spec.add_development_dependency "rubocop", "~> 0.50"
30
+ spec.add_development_dependency "rails", "~> 4", "< 5"
31
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_midtrans_gateway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dimas J. Taniawan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: veritrans
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.15'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.15'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.50'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.50'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '4'
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: '5'
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '4'
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '5'
123
+ description: Midtrans payment gateway for Spree framework
124
+ email:
125
+ - dimazniawan@gmail.com
126
+ executables: []
127
+ extensions: []
128
+ extra_rdoc_files: []
129
+ files:
130
+ - ".gitignore"
131
+ - ".rspec"
132
+ - ".rubocop.yml"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - app/controllers/spree/midtrans_controller.rb
141
+ - app/models/spree/gateway/midtrans_gateway.rb
142
+ - app/views/spree/checkout/payment/_midtrans.html.erb
143
+ - bin/console
144
+ - bin/setup
145
+ - config/locales/en.yml
146
+ - config/locales/id.yml
147
+ - config/routes.rb
148
+ - lib/spree_midtrans_gateway.rb
149
+ - lib/spree_midtrans_gateway/engine.rb
150
+ - lib/spree_midtrans_gateway/version.rb
151
+ - spec/spec_helper.rb
152
+ - spec/spree_midtrans_gateway/spree_midtrans_gateway_spec.rb
153
+ - spree_midtrans_gateway.gemspec
154
+ homepage: https://github.com/dimasjt/spree_midtrans_gateway
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 2.1.0
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.6.11
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Midtrans gateway for Spree
178
+ test_files:
179
+ - spec/spec_helper.rb
180
+ - spec/spree_midtrans_gateway/spree_midtrans_gateway_spec.rb