spree_instamojo 0.0.1.alpha → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.travis.yml +26 -0
- data/Appraisals +29 -0
- data/Gemfile +9 -0
- data/LICENSE +30 -0
- data/README.md +50 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_instamojo.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_instamojo.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_instamojo.css +4 -0
- data/app/assets/stylesheets/spree/frontend/spree_instamojo.css +4 -0
- data/app/controllers/spree/instamojo_controller.rb +106 -0
- data/app/controllers/spree/paytm_controller.rb +71 -0
- data/app/models/spree/gateway/instamojo.rb +45 -0
- data/app/models/spree/gateway/paytm.rb +259 -0
- data/app/models/spree/payment_checkout.rb +4 -0
- data/app/views/spree/admin/payments/source_views/_instamojo.html.erb +0 -0
- data/app/views/spree/admin/payments/source_views/_paytm.html.erb +0 -0
- data/app/views/spree/checkout/payment/_instamojo.html.erb +4 -0
- data/app/views/spree/checkout/payment/_paytm.html.erb +4 -0
- data/app/views/spree/instamojo/confirm.html.erb +17 -0
- data/app/views/spree/instamojo/index.html.erb +11 -0
- data/app/views/spree/paytm/confirm.html.erb +17 -0
- data/app/views/spree/paytm/index.html.erb +13 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +7 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20180308104631_create_spree_instamojo_checkout.rb +13 -0
- data/lib/generators/spree_instamojo/install/install_generator.rb +31 -0
- data/lib/spree_instamojo.rb +5 -0
- data/lib/spree_instamojo/engine.rb +27 -0
- data/lib/spree_instamojo/factories.rb +6 -0
- data/lib/spree_instamojo/version.rb +17 -0
- data/spec/spec_helper.rb +99 -0
- data/spree_instamojo.gemspec +28 -0
- metadata +43 -217
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f4962e51ee7822e36169843efcdb6d8257736d7f6a88cac40c30dda78421e0d
|
4
|
+
data.tar.gz: fb9be552b425a8e457dca9898e86746d9f044063a0199e25a91cc989438aa542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4241ca253847bb08adc33766d3263779d3ea12aaff984297cfe4182ad8f45019cf2d75d525cf957ab18364b58e8ebb91c464fba252d81e2879f357523f9771a5
|
7
|
+
data.tar.gz: 7417d30b8ddc394b042e2691b3a5142e1c66b6202f44e7d5e2a28aae0b63197390ca9ed5e8830aaaa69a397bab90aff01d08cc1c67ff7e8cab0291c9dd4ab9be
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
\#*
|
2
|
+
*~
|
3
|
+
.#*
|
4
|
+
.DS_Store
|
5
|
+
.idea
|
6
|
+
.localeapp/locales
|
7
|
+
.project
|
8
|
+
coverage
|
9
|
+
default
|
10
|
+
Gemfile.lock
|
11
|
+
tmp
|
12
|
+
nbproject
|
13
|
+
pkg
|
14
|
+
*.sw?
|
15
|
+
spec/dummy
|
16
|
+
.rvmrc
|
17
|
+
.sass-cache
|
18
|
+
public/spree
|
19
|
+
.ruby-version
|
20
|
+
.ruby-gemset
|
21
|
+
gemfiles/*.gemfile.lock
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
sudo: required
|
2
|
+
dist: trusty
|
3
|
+
|
4
|
+
language: ruby
|
5
|
+
|
6
|
+
env:
|
7
|
+
- DB=postgres
|
8
|
+
- DB=mysql
|
9
|
+
|
10
|
+
gemfile:
|
11
|
+
- gemfiles/spree_3_1.gemfile
|
12
|
+
- gemfiles/spree_3_2.gemfile
|
13
|
+
- gemfiles/spree_3_3.gemfile
|
14
|
+
- gemfiles/spree_3_4.gemfile
|
15
|
+
- gemfiles/spree_master.gemfile
|
16
|
+
|
17
|
+
script:
|
18
|
+
- bundle exec rake test_app
|
19
|
+
- bundle exec rake spec
|
20
|
+
|
21
|
+
rvm:
|
22
|
+
- 2.3.1
|
23
|
+
- 2.2.7
|
24
|
+
|
25
|
+
before_install:
|
26
|
+
- mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
appraise 'spree-3-1' do
|
2
|
+
gem 'spree', '~> 3.1.0'
|
3
|
+
gem 'spree_auth_devise', '~> 3.1.0'
|
4
|
+
gem 'rails_test_params_backport', group: :test
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'spree-3-2' do
|
8
|
+
gem 'spree', '~> 3.2.0'
|
9
|
+
gem 'spree_auth_devise', '~> 3.2.0'
|
10
|
+
gem 'rails-controller-testing'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'spree-3-3' do
|
14
|
+
gem 'spree', '~> 3.3.0'
|
15
|
+
gem 'spree_auth_devise', '~> 3.3.0'
|
16
|
+
gem 'rails-controller-testing'
|
17
|
+
end
|
18
|
+
|
19
|
+
appraise 'spree-3-4' do
|
20
|
+
gem 'spree', '~> 3.4.0'
|
21
|
+
gem 'spree_auth_devise', '~> 3.3.0'
|
22
|
+
gem 'rails-controller-testing'
|
23
|
+
end
|
24
|
+
|
25
|
+
appraise 'spree-master' do
|
26
|
+
gem 'spree', github: 'spree/spree', branch: 'master'
|
27
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
|
28
|
+
gem 'rails-controller-testing'
|
29
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'spree', github: 'spree/spree', branch: 'master'
|
4
|
+
# Provides basic authentication functionality for testing parts of your engine
|
5
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
|
6
|
+
gem 'rails-controller-testing'
|
7
|
+
gem "typhoeus"
|
8
|
+
|
9
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2018, guptalakshya92
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
SpreeInstamojo
|
2
|
+
==============
|
3
|
+
|
4
|
+
Introduction goes here.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
1. Add this extension to your Gemfile with this line:
|
9
|
+
```ruby
|
10
|
+
gem 'spree_instamojo', github: 'guptalakshya92/spree_instamojo'
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Install the gem using Bundler:
|
14
|
+
```ruby
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
3. Copy & run migrations
|
19
|
+
```ruby
|
20
|
+
bundle exec rails g spree_instamojo:install
|
21
|
+
```
|
22
|
+
|
23
|
+
4. Restart your server
|
24
|
+
|
25
|
+
If your server was running, restart it so that it can find the assets properly.
|
26
|
+
|
27
|
+
## Testing
|
28
|
+
|
29
|
+
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. The dummy app can be regenerated by using `rake test_app`.
|
30
|
+
|
31
|
+
```shell
|
32
|
+
bundle
|
33
|
+
bundle exec rake
|
34
|
+
```
|
35
|
+
|
36
|
+
When testing your applications integration with this extension you may use it's factories.
|
37
|
+
Simply add this require statement to your spec_helper:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'spree_instamojo/factories'
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
If you'd like to contribute, please take a look at the
|
47
|
+
[instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
|
48
|
+
pull request.
|
49
|
+
|
50
|
+
Copyright (c) 2018 [name of extension creator], released under the New BSD License
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
if Dir["spec/dummy"].empty?
|
11
|
+
Rake::Task[:test_app].invoke
|
12
|
+
Dir.chdir("../../")
|
13
|
+
end
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generates a dummy app for testing'
|
18
|
+
task :test_app do
|
19
|
+
ENV['LIB_NAME'] = 'spree_instamojo'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Spree
|
2
|
+
class InstamojoController < StoreController
|
3
|
+
protect_from_forgery only: :index
|
4
|
+
|
5
|
+
def index
|
6
|
+
payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
|
7
|
+
order = current_order
|
8
|
+
@param_list = Hash.new
|
9
|
+
if(address = current_order.bill_address || current_order.ship_address)
|
10
|
+
phone = address.phone
|
11
|
+
end
|
12
|
+
@param_list[:buyer_name] = address.firstname
|
13
|
+
@param_list[:purpose] = order.number
|
14
|
+
@param_list[:amount] = order.total.to_s
|
15
|
+
@param_list[:email] = order.email
|
16
|
+
@param_list[:phone] = phone
|
17
|
+
@param_list[:redirect_url] = payment_method.redirect_url
|
18
|
+
@param_list[:allow_repeated_payments] = false
|
19
|
+
@param_list[:send_email] = false
|
20
|
+
@param_list[:send_sms] = false
|
21
|
+
request = Typhoeus.post(payment_method.get_instamojo_url,
|
22
|
+
body: @param_list,
|
23
|
+
headers: {'X-Api-Key' => payment_method.preferred_api_key,
|
24
|
+
'X-Auth-Token'=> payment_method.preferred_auth_token})
|
25
|
+
response = JSON.parse(request.response_body)
|
26
|
+
if response.present? && response["success"] && response["payment_request"]["longurl"].present?
|
27
|
+
@instamj_txn_url = response["payment_request"]["longurl"]+"?embed=form"
|
28
|
+
else
|
29
|
+
flash[:error] = "Payment failed"
|
30
|
+
redirect_to checkout_state_path(order.state) and return
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def confirm
|
35
|
+
@payment_method = Spree::PaymentMethod.find_by(type: Spree::Gateway::Instamojo.to_s)
|
36
|
+
payment_request_id = params[:payment_request_id]
|
37
|
+
@order = current_order
|
38
|
+
if payment_request_id.present?
|
39
|
+
payment_details_request = Typhoeus.get("https://test.instamojo.com/api/1.1/payment-requests/"+payment_request_id+"/",
|
40
|
+
headers: {'X-Api-Key' => @payment_method.preferred_api_key,
|
41
|
+
'X-Auth-Token'=> @payment_method.preferred_auth_token})
|
42
|
+
payment_details_response = JSON.parse(payment_details_request.response_body)
|
43
|
+
@order = @order || Spree::Order.find_by(number: payment_details_response["payment_request"]["purpose"])
|
44
|
+
payment = payment_details_response["payment_request"]["payments"].select { |payment| payment["status"] === 'Credit' && payment["amount"].to_f === @order.total.to_f}.last
|
45
|
+
if payment.present? && payment["status"] === "Credit"
|
46
|
+
success_payment payment_request_id, payment
|
47
|
+
else
|
48
|
+
failed_payment payment_request_id
|
49
|
+
end
|
50
|
+
else
|
51
|
+
@error = true
|
52
|
+
@message = "There was an error processing your payment"
|
53
|
+
@redirect_path = checkout_state_path(@order.state)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def failed_payment payment_request_id
|
59
|
+
payment_request_id = payment_request_id
|
60
|
+
res_code = "301"
|
61
|
+
update_payment(payment_request_id, nil, nil, 'Failed', res_code)
|
62
|
+
@payment.state = "failed"
|
63
|
+
@payment.save
|
64
|
+
@order.update_attributes(payment_state: "failed")
|
65
|
+
@error = true
|
66
|
+
@message = "There was an error processing your payment"
|
67
|
+
@redirect_path = checkout_state_path(@order.state)
|
68
|
+
end
|
69
|
+
|
70
|
+
def success_payment payment_request_id , payment
|
71
|
+
payment_request_id = payment_request_id
|
72
|
+
payment_id = payment["payment_id"]
|
73
|
+
status = payment["status"]
|
74
|
+
amount = payment["amount"]
|
75
|
+
res_code = "201"
|
76
|
+
update_payment(payment_request_id, payment_id, amount, status, res_code)
|
77
|
+
@order.next!
|
78
|
+
@message = Spree.t(:order_processed_successfully)
|
79
|
+
@current_order = nil
|
80
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
81
|
+
flash['order_completed'] = true
|
82
|
+
@error = false
|
83
|
+
@redirect_path = order_path(@order)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def update_payment payment_request_id , payment_id, amount, status, res_code
|
90
|
+
@payment = @order.payments.create!(
|
91
|
+
payment_method: @payment_method,
|
92
|
+
source: Spree::PaymentCheckout.create(
|
93
|
+
payment_request_id: payment_request_id,
|
94
|
+
payment_id: payment_id,
|
95
|
+
order_id: @order.id,
|
96
|
+
status: status,
|
97
|
+
amount: amount
|
98
|
+
),
|
99
|
+
amount: @order.total,
|
100
|
+
response_code: res_code
|
101
|
+
)
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Spree
|
2
|
+
class PaytmController < StoreController
|
3
|
+
protect_from_forgery only: :index
|
4
|
+
|
5
|
+
def index
|
6
|
+
payment_method = Spree::PaymentMethod.find(params[:payment_method_id])
|
7
|
+
order = current_order
|
8
|
+
@param_list = Hash.new
|
9
|
+
@param_list['CALLBACK_URL'] = "#{request.base_url}/paytm/confirm"
|
10
|
+
@param_list['MID'] = payment_method.preferred_merchant_id
|
11
|
+
@param_list['INDUSTRY_TYPE_ID'] = payment_method.preferred_industry_type_id
|
12
|
+
@param_list['CHANNEL_ID'] = payment_method.preferred_channel_id
|
13
|
+
@param_list['WEBSITE'] = payment_method.preferred_website
|
14
|
+
if @param_list.values.select{ |value| value unless value.present? }.present?
|
15
|
+
flash[:error] = Spree.t('paytm.paytm_payment_failed')
|
16
|
+
redirect_to checkout_state_path(order.state) and return
|
17
|
+
else
|
18
|
+
@param_list['REQUEST_TYPE'] = payment_method.request_type
|
19
|
+
@param_list['ORDER_ID'] = payment_method.txnid(order)
|
20
|
+
@param_list['TXN_AMOUNT'] = order.total.to_s
|
21
|
+
if(address = current_order.bill_address || current_order.ship_address)
|
22
|
+
phone = address.phone
|
23
|
+
end
|
24
|
+
#if user is not loggedin, Passing phone as customer id
|
25
|
+
cust_id = spree_current_user.nil? ? phone : spree_current_user.id
|
26
|
+
@param_list['CUST_ID'] = "CUST-#{cust_id}-ORDER-#{payment_method.txnid(order)}"
|
27
|
+
@param_list['MOBILE_NO'] = phone
|
28
|
+
@param_list['EMAIL'] = order.email
|
29
|
+
|
30
|
+
checksum = payment_method.new_pg_checksum(@param_list)
|
31
|
+
@param_list['CHECKSUMHASH'] = checksum
|
32
|
+
@paytm_txn_url = payment_method.txn_url
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def confirm
|
37
|
+
payment_method = Spree::PaymentMethod.find_by(type: Spree::Gateway::Paytm.to_s)
|
38
|
+
checksum_hash = params["CHECKSUMHASH"]
|
39
|
+
params.delete("CHECKSUMHASH")
|
40
|
+
@status = params["STATUS"]
|
41
|
+
@orderid = params["ORDERID"]
|
42
|
+
@order = current_order || Spree::Order.find_by(number: @orderid.split("-").last)
|
43
|
+
@payment = @order.payments.create!(
|
44
|
+
source: Spree::PaymentCheckout.create(
|
45
|
+
payment_request_id: params['TXNID'],
|
46
|
+
checksum: checksum_hash,
|
47
|
+
order_id: @order.id
|
48
|
+
),
|
49
|
+
payment_method: payment_method,
|
50
|
+
amount: @order.total,
|
51
|
+
response_code: params['RESPCODE']
|
52
|
+
)
|
53
|
+
if @status == "TXN_SUCCESS"
|
54
|
+
@order.next
|
55
|
+
@message = Spree.t(:order_processed_successfully)
|
56
|
+
@current_order = nil
|
57
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
58
|
+
flash['order_completed'] = true
|
59
|
+
@error = false
|
60
|
+
@redirect_path = order_path(@order)
|
61
|
+
else
|
62
|
+
@payment.state = "failed"
|
63
|
+
@payment.save
|
64
|
+
@order.update_attributes(payment_state: "failed")
|
65
|
+
@error = true
|
66
|
+
@message = "There was an error processing your payment"
|
67
|
+
@redirect_path = checkout_state_path(@order.state)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Instamojo < Gateway
|
3
|
+
|
4
|
+
preference :api_key, :string
|
5
|
+
preference :auth_token, :string
|
6
|
+
preference :salt, :string
|
7
|
+
preference :site_url, :string
|
8
|
+
|
9
|
+
def supports?(source)
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def provider_class
|
14
|
+
self.class
|
15
|
+
end
|
16
|
+
|
17
|
+
def provider
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def auto_capture?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_type
|
26
|
+
"instamojo"
|
27
|
+
end
|
28
|
+
|
29
|
+
def purchase(amount, source, gateway_options={})
|
30
|
+
ActiveMerchant::Billing::Response.new(true, "paytm success")
|
31
|
+
end
|
32
|
+
def redirect_url
|
33
|
+
preferred_site_url+"/instamojo/confirm"
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_instamojo_url
|
37
|
+
if preferred_test_mode
|
38
|
+
"https://test.instamojo.com/api/1.1/payment-requests/"
|
39
|
+
else
|
40
|
+
"https://www.instamojo.com/api/1.1/payment-requests/"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|