spree_gtpay 1.0.0
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.
- data/LICENSE +26 -0
- data/README.md +77 -0
- data/app/assets/javascripts/admin/spree_gtpay.js +1 -0
- data/app/assets/javascripts/store/spree_gtpay.js +1 -0
- data/app/assets/stylesheets/admin/spree_gtpay.css +3 -0
- data/app/assets/stylesheets/store/spree_gtpay.css +3 -0
- data/app/controllers/spree/admin/gtpay_transactions_controller.rb +16 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +51 -0
- data/app/controllers/spree/gtpay_transactions_controller.rb +39 -0
- data/app/helpers/spree/admin/base_helper_decorator.rb +10 -0
- data/app/mailers/spree/transaction_notification_mailer.rb +17 -0
- data/app/models/spree/gateway/gtpay.rb +34 -0
- data/app/models/spree/gtpay_transaction.rb +97 -0
- data/app/models/spree/order_decorator.rb +21 -0
- data/app/models/spree/payment_decorator.rb +7 -0
- data/app/overrides/add_tab_for_gtpay_transactions.rb +5 -0
- data/app/views/spree/admin/gtpay_transactions/_search_form.html.erb +40 -0
- data/app/views/spree/admin/gtpay_transactions/index.html.erb +36 -0
- data/app/views/spree/admin/gtpay_transactions/query_interface.js.erb +10 -0
- data/app/views/spree/checkout/confirm.html.erb +16 -0
- data/app/views/spree/checkout/payment/_gateway.html.erb +0 -0
- data/app/views/spree/gtpay_transactions/index.html.erb +36 -0
- data/app/views/spree/transaction_notification_mailer/send_mail.html.erb +25 -0
- data/config/initializers/constants.rb +1 -0
- data/config/locales/en.yml +7 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20140117061910_gtpay_transaction.rb +19 -0
- data/lib/generators/spree_gtpay/install/install_generator.rb +31 -0
- data/lib/spree_gtpay/engine.rb +26 -0
- data/lib/spree_gtpay/factories.rb +6 -0
- data/lib/spree_gtpay.rb +2 -0
- data/lib/webpay_methods.rb +21 -0
- metadata +110 -0
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2014 Vinsol
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
SpreeGtpay [](https://codeclimate.com/github/vinsol/Spree-Gtpay) [](https://travis-ci.org/vinsol/Spree-Gtpay)
|
2
|
+
==========
|
3
|
+
|
4
|
+
Enable spree store to allow payment via [GtBank Payment](http://gtbank.com/) (a preferred e-payment service provider in Nigeria, Africa)
|
5
|
+
|
6
|
+
####For customer:
|
7
|
+
|
8
|
+
Customer can pay via GtBank payment method at Checkout. Customer can also see the list of GtBank Transactions initiated by them.
|
9
|
+
|
10
|
+
####For admin:
|
11
|
+
|
12
|
+
Admin can see the list of GtBank Transactions initiated by customers under admin section. Admin can also ping GtBank gateway for an updated status of a transaction and the transaction is then updated accordingly.
|
13
|
+
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
Add spree_gtpay to your Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'spree_gtpay'
|
22
|
+
```
|
23
|
+
|
24
|
+
Bundle your dependencies and run the installation generator:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
bundle
|
28
|
+
bundle exec rails g spree_gtpay:install
|
29
|
+
```
|
30
|
+
|
31
|
+
Configuration
|
32
|
+
--------
|
33
|
+
|
34
|
+
1. To setup the payment method Login as an admin and add a new Payment Method (under Configuration), using following details:
|
35
|
+
|
36
|
+
```
|
37
|
+
Name: GTBank
|
38
|
+
Environment: Production (or what ever environment you prefer)
|
39
|
+
Provider: Spree::Gateway::Gtpay
|
40
|
+
Active: yes
|
41
|
+
```
|
42
|
+
|
43
|
+
2. Click update after adding your credentials in the screen that follows:
|
44
|
+
|
45
|
+
```
|
46
|
+
Payment Url: Provide payment url provided by GTbank.
|
47
|
+
Merchant: provide merchant id provided bt GTbank
|
48
|
+
```
|
49
|
+
|
50
|
+
3. After this you need to create ```initializers/gtbank_constant.rb``` and add below mentioned to the same file.
|
51
|
+
|
52
|
+
```
|
53
|
+
GT_DATA = {:product_id => "xxxx", :mac_id => "xxxxxxxxx", :query_url => "xxxxxx" }
|
54
|
+
```
|
55
|
+
|
56
|
+
These are the details which are provided by interswitch(Ask about it from GTbank if you dont have it) and replace xxx with exact values provided.
|
57
|
+
|
58
|
+
|
59
|
+
Testing
|
60
|
+
-------
|
61
|
+
|
62
|
+
You need to do a quick one-time creation of a test application and then you can use it to run the tests.
|
63
|
+
|
64
|
+
bundle exec rake test_app
|
65
|
+
|
66
|
+
Then run the rspec tests with:
|
67
|
+
|
68
|
+
bundle exec rspec .
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
Credits
|
73
|
+
-------
|
74
|
+
|
75
|
+
[](http://vinsol.com)
|
76
|
+
|
77
|
+
Copyright (c) 2014 [vinsol.com](http://vinsol.com "Ruby on Rails, iOS and Android developers"), released under the New MIT License
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class GtpayTransactionsController < ResourceController
|
4
|
+
|
5
|
+
def index
|
6
|
+
@search = Spree::GtpayTransaction.ransack(params[:q])
|
7
|
+
@gtpay_transactions = @search.result.order('created_at desc').page(params[:page]).per(20)
|
8
|
+
end
|
9
|
+
|
10
|
+
def query_interface
|
11
|
+
@gtpay_transaction.update_transaction_on_query
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Spree::CheckoutController.class_eval do
|
2
|
+
before_filter :redirect_to_gtpay, :only => [:update]
|
3
|
+
helper_method :gtpay_payment_method
|
4
|
+
|
5
|
+
def confirm
|
6
|
+
@transaction = @order.gtpay_transactions.create { |t| t.user = spree_current_user }
|
7
|
+
if @transaction.persisted?
|
8
|
+
render :layout => false
|
9
|
+
else
|
10
|
+
set_flash_error
|
11
|
+
redirect_to checkout_state_path(@order.state) and return
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def redirect_to_gtpay
|
18
|
+
if payment_page?
|
19
|
+
payment_method = Spree::PaymentMethod.where(:id => (select_gtpay_payment(params[:order][:payments_attributes])[:payment_method_id])).first
|
20
|
+
if payment_method.kind_of?(Spree::Gateway::Gtpay)
|
21
|
+
if @order.update_attributes(object_params)
|
22
|
+
redirect_to(gtpay_confirm_path) and return
|
23
|
+
else
|
24
|
+
flash[:error] = "Something went wrong. Please try again"
|
25
|
+
redirect_to checkout_state_path("address") and return
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def payment_page?
|
32
|
+
params[:state] == "payment" && params[:order][:payments_attributes]
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_flash_error
|
36
|
+
if @transaction.errors[:gtpay_tranx_amount].present?
|
37
|
+
flash[:error] = "Minimum amount for order must be above #{Spree::Money.new(Spree::GtpayTransaction::MINIMUM_AMOUNT)}"
|
38
|
+
else
|
39
|
+
flash[:error] = "Something went wrong. Please try again"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_gtpay_payment(payment_attributes)
|
44
|
+
payment_attributes.select { |payment| payment["payment_method_id"] == gtpay_payment_method.id.to_s }.first
|
45
|
+
end
|
46
|
+
|
47
|
+
def gtpay_payment_method
|
48
|
+
Spree::Gateway::Gtpay.first
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Spree
|
2
|
+
class GtpayTransactionsController < StoreController
|
3
|
+
before_filter :load_gtpay_transaction, :only => :callback
|
4
|
+
skip_before_filter :verify_authenticity_token, :only => :callback
|
5
|
+
before_filter :authenticate_spree_user!, :only => :index
|
6
|
+
|
7
|
+
def callback
|
8
|
+
if @transaction.update_transaction(transaction_params) && @transaction.successful?
|
9
|
+
reset_redirect_to_order_detail
|
10
|
+
else
|
11
|
+
flash[:error] = "Your Transaction was not successful. <br/> Reason: #{@transaction.gtpay_tranx_status_msg}. <br/> Transaction reference: #{@transaction.gtpay_tranx_id}. <br/> Please Try again".html_safe
|
12
|
+
redirect_to checkout_state_path(current_order.state)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def index
|
17
|
+
@transactions = spree_current_user.gtpay_transactions.includes(:order).order('updated_at desc').page(params[:page]).per(20)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_gtpay_transaction
|
23
|
+
unless @transaction = current_order.gtpay_transactions.pending.where(:gtpay_tranx_id => params[:gtpay_tranx_id]).first
|
24
|
+
redirect_to checkout_state_path(current_order.state), :flash => { :error => "Your Order cannot be processed. Please contact customer support <br/> Reason: #{params[:gtpay_tranx_status_msg]} <br/> Transaction Reference: #{params[:gtpay_tranx_id]}".html_safe }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def transaction_params
|
29
|
+
{ :gtpay_tranx_amount => params[:gtpay_tranx_amt], :gtpay_tranx_status_code => params[:gtpay_tranx_status_code], :gtpay_tranx_status_msg => params[:gtpay_tranx_status_msg] }
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset_redirect_to_order_detail
|
33
|
+
session[:order_id] = nil
|
34
|
+
flash.notice = "Your Order has been processed successfully. <br/> Transaction Reference: #{params[:gtpay_tranx_id]} <br/> Transaction Code: #{params[:gtpay_tranx_status_code]} <br/> Transaction Message: #{params[:gtpay_tranx_status_msg]}".html_safe
|
35
|
+
redirect_to spree.order_path(current_order)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
class TransactionNotificationMailer < ActionMailer::Base
|
3
|
+
helper 'application'
|
4
|
+
|
5
|
+
def send_mail(transaction)
|
6
|
+
@transaction = transaction
|
7
|
+
|
8
|
+
email = @transaction.user.email
|
9
|
+
@order = @transaction.order
|
10
|
+
@status = @transaction.status
|
11
|
+
mail(
|
12
|
+
:to => email,
|
13
|
+
:subject => "#{Spree::Config[:site_name]} - GTbank Payment Transaction #{@status} notification"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Spree
|
2
|
+
class Gateway::Gtpay < Gateway
|
3
|
+
|
4
|
+
preference :payment_url, :string
|
5
|
+
preference :merchant_id, :string
|
6
|
+
|
7
|
+
attr_accessible :preferred_payment_url, :preferred_merchant_id
|
8
|
+
|
9
|
+
def actions
|
10
|
+
%w{capture void}
|
11
|
+
end
|
12
|
+
|
13
|
+
def can_capture?(payment)
|
14
|
+
['checkout', 'pending'].include?(payment.state)
|
15
|
+
end
|
16
|
+
|
17
|
+
def can_void?(payment)
|
18
|
+
payment.state != 'void'
|
19
|
+
end
|
20
|
+
|
21
|
+
def capture(*args)
|
22
|
+
ActiveMerchant::Billing::Response.new(true, "", {}, {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def void(*args)
|
26
|
+
ActiveMerchant::Billing::Response.new(true, "", {}, {})
|
27
|
+
end
|
28
|
+
|
29
|
+
def source_required?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Spree
|
2
|
+
class GtpayTransaction < ActiveRecord::Base
|
3
|
+
include WebpayMethods
|
4
|
+
|
5
|
+
CURRENCY_CODE = { "NGN" => "566", "USD" => "844" }
|
6
|
+
MINIMUM_AMOUNT = 25
|
7
|
+
PENDING = 'Pending'
|
8
|
+
SUCCESSFUL = 'Successful'
|
9
|
+
UNSUCCESSFUL = 'Unsuccessful'
|
10
|
+
|
11
|
+
attr_accessible :gtpay_tranx_status_code, :gtpay_tranx_memo, :gtpay_tranx_status_msg, :gtpay_tranx_amount
|
12
|
+
|
13
|
+
before_validation :generate_tranx_id, :set_default_attirbutes, :on => :create
|
14
|
+
before_update :set_status, :if => :gtpay_tranx_status_code_changed?
|
15
|
+
before_update :order_complete_and_finalize, :send_transaction_mail, :if => [:status_changed?, :successful?]
|
16
|
+
before_update :order_set_failure_for_payment, :if => [:status_changed?, :unsuccessful?]
|
17
|
+
|
18
|
+
validates :gtpay_tranx_id, :user, :gtpay_tranx_amount, :gtpay_tranx_currency, :presence => true
|
19
|
+
validates :gtpay_tranx_amount, :numericality => true
|
20
|
+
|
21
|
+
belongs_to :user
|
22
|
+
belongs_to :order
|
23
|
+
|
24
|
+
scope :pending, where(:status => PENDING)
|
25
|
+
scope :successful, where(:status => SUCCESSFUL)
|
26
|
+
|
27
|
+
delegate :total, :gtpay_payment, :complete_and_finalize, :set_failure_for_payment, :to => :order, :prefix => true
|
28
|
+
delegate :email, to: :user, allow_nil: true
|
29
|
+
|
30
|
+
def amount_in_cents
|
31
|
+
(gtpay_tranx_amount.to_f*100).round.to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def successful?
|
35
|
+
status == SUCCESSFUL
|
36
|
+
end
|
37
|
+
|
38
|
+
def pending?
|
39
|
+
status == PENDING
|
40
|
+
end
|
41
|
+
|
42
|
+
def unsuccessful?
|
43
|
+
status == UNSUCCESSFUL
|
44
|
+
end
|
45
|
+
|
46
|
+
def amount_valid?
|
47
|
+
gtpay_tranx_amount >= order_total
|
48
|
+
end
|
49
|
+
|
50
|
+
def successful_status_code?
|
51
|
+
gtpay_tranx_status_code == "00"
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_transaction(transaction_params)
|
55
|
+
self.gtpay_tranx_amount = transaction_params[:gtpay_tranx_amount]
|
56
|
+
self.gtpay_tranx_status_code = transaction_params[:gtpay_tranx_status_code]
|
57
|
+
self.gtpay_tranx_status_msg = transaction_params[:gtpay_tranx_status_msg]
|
58
|
+
if successful_status_code?
|
59
|
+
update_transaction_on_query
|
60
|
+
else
|
61
|
+
self.save
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_transaction_on_query
|
66
|
+
response = query_interswitch
|
67
|
+
update_attributes(:gtpay_tranx_status_code => response["ResponseCode"], :gtpay_tranx_status_msg => response["ResponseDescription"], :gtpay_tranx_amount => (response["Amount"].to_f/100))
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def set_status
|
73
|
+
if successful_status_code? && amount_valid?
|
74
|
+
self.status = SUCCESSFUL
|
75
|
+
else
|
76
|
+
self.status = UNSUCCESSFUL
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_tranx_id
|
81
|
+
begin
|
82
|
+
self.gtpay_tranx_id = "#{ENVIRONMENT_INITIALS}" + SecureRandom.hex(8)
|
83
|
+
end while GtpayTransaction.exists?(:gtpay_tranx_id => gtpay_tranx_id)
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_default_attirbutes
|
87
|
+
self.gtpay_tranx_currency = CURRENCY_CODE[order.currency]
|
88
|
+
self.gtpay_tranx_amount = order_total
|
89
|
+
self.status = PENDING
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_transaction_mail
|
93
|
+
Spree::TransactionNotificationMailer.delay.send_mail(self)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Spree::Order.class_eval do
|
2
|
+
|
3
|
+
has_many :gtpay_transactions
|
4
|
+
|
5
|
+
def gtpay_payment
|
6
|
+
@gtpay_payment_method = Spree::Gateway::Gtpay.where(:environment => Rails.env).first
|
7
|
+
payments.where("payment_method_id = #{@gtpay_payment_method.id} and state in ('checkout', 'processing', 'pending')").first if @gtpay_payment_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def complete_and_finalize
|
11
|
+
gtpay_payment.process_and_complete!
|
12
|
+
|
13
|
+
update_attributes({:state => "complete", :completed_at => Time.current}, :without_protection => true)
|
14
|
+
finalize!
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_failure_for_payment
|
18
|
+
gtpay_payment.started_processing!
|
19
|
+
gtpay_payment.failure!
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
|
2
|
+
:name => "add_gtpay_transaction_link_configuration_menu",
|
3
|
+
:insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
|
4
|
+
:text => %q{<%= configurations_sidebar_menu_item Spree.t("gtpay_transactions"), admin_gtpay_transactions_path %>},
|
5
|
+
:disabled => false)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<% content_for :table_filter_title do %>
|
2
|
+
<%= Spree.t(:search) %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :table_filter do %>
|
6
|
+
<div data-hook="admin_transactions_index_search">
|
7
|
+
<%= search_form_for [:admin, @search] do |f| %>
|
8
|
+
|
9
|
+
<div class="four columns">
|
10
|
+
<div class="field">
|
11
|
+
<%= label_tag nil, Spree.t(:gtpay_tranx_id) %>
|
12
|
+
<%= f.text_field :gtpay_tranx_id_eq %>
|
13
|
+
</div>
|
14
|
+
<div class="field">
|
15
|
+
<%= label_tag nil, Spree.t(:email) %>
|
16
|
+
<%= f.email_field :user_email_eq %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.hidden_field :status_eq, :value => params[:q][:status_eq] if params[:q] %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div class="clearfix"></div>
|
24
|
+
|
25
|
+
<div class="actions filter-actions">
|
26
|
+
<div data-hook="admin_orders_index_search_buttons">
|
27
|
+
<%= button Spree.t(:filter_results), 'icon-search' %>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
<% end %>
|
33
|
+
<%= link_to "All", admin_gtpay_transactions_path, :class => set_selected_class %>
|
34
|
+
|
|
35
|
+
<%= link_to "Successful", admin_gtpay_transactions_path('q[status_eq]' => "Successful"), :class => set_selected_class("Successful") %> |
|
36
|
+
<%= link_to "Pending", admin_gtpay_transactions_path('q[status_eq]' => "Pending"), :class => set_selected_class("Pending") %>
|
37
|
+
|
|
38
|
+
<%= link_to "Unsuccessful", admin_gtpay_transactions_path('q[status_eq]' => "Unsuccessful"), :class => set_selected_class("Unsuccessful") %>
|
39
|
+
<div class="clearfix"></div>
|
40
|
+
<br/>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
<% content_for :page_title do %>
|
3
|
+
<h1><%= Spree.t("gtpay_transactions") %></h1>
|
4
|
+
<% end %>
|
5
|
+
<%= render :partial => "search_form" %>
|
6
|
+
|
7
|
+
<table class="index">
|
8
|
+
<thead data-hook="admin_gtpay_transactions_index_headers">
|
9
|
+
<th><%= Spree.t("transaction_id") %></th>
|
10
|
+
<th><%= Spree.t("transaction_date") %></th>
|
11
|
+
<th><%= Spree.t("amount") %></th>
|
12
|
+
<th><%= Spree.t("order#") %></th>
|
13
|
+
<th><%= Spree.t("user") %></th>
|
14
|
+
<th><%= Spree.t("status") %></th>
|
15
|
+
<th><%= Spree.t("action") %></th>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @gtpay_transactions.each do |transaction|%>
|
19
|
+
<tr id="<%= dom_id transaction %>" data-hook="admin_trackers_index_rows">
|
20
|
+
<td><%= transaction.gtpay_tranx_id %></td>
|
21
|
+
<td><%= transaction.created_at %></td>
|
22
|
+
<td><%= Spree::Money.new(transaction.gtpay_tranx_amount) %></td>
|
23
|
+
<td><%= transaction.order.number if transaction.order.present? %></td>
|
24
|
+
<td><%= transaction.user.email %></td>
|
25
|
+
<td id= "<%= transaction.id%>" class="status"><%= transaction.status %></td>
|
26
|
+
<td id= "<%= transaction.id%>" class="action" >
|
27
|
+
<%= link_to_unless(transaction.pending?, "") do %>
|
28
|
+
<%= button_to(Spree.t(:query), query_interface_admin_gtpay_transaction_path(transaction), :remote => true, :confirm => "Are you sure?", :method => :get) %>
|
29
|
+
<% end %>
|
30
|
+
</td>
|
31
|
+
</tr>
|
32
|
+
<% end %>
|
33
|
+
</tbody>
|
34
|
+
</table>
|
35
|
+
|
36
|
+
<%= paginate @gtpay_transactions %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$("td#<%= @gtpay_transaction.id%>.status").html("<%= @gtpay_transaction.status %>");
|
2
|
+
<% if @gtpay_transaction.successful? %>
|
3
|
+
$("td#<%= @gtpay_transaction.id%>.action").html('');
|
4
|
+
alert("Transaction is successfully Completed");
|
5
|
+
<% elsif @gtpay_transaction.unsuccessful? %>
|
6
|
+
$("td#<%= @gtpay_transaction.id%>.action").html('');
|
7
|
+
alert("Transaction is unsuccessful, Reason: <%= @gtpay_transaction.gtpay_tranx_status_msg %>");
|
8
|
+
<% else %>
|
9
|
+
alert("No response from Webpay");
|
10
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<html>
|
2
|
+
<body onload="document.submit2gtpay_form.submit()" style="text-align:center; font-family:Arial, Helvetica, sans-serif; padding-top:100px;">
|
3
|
+
<h1 class="message">We are processing your request.<br/>Please do not press browser back button</h1>
|
4
|
+
<div style="text-align:center; padding:50px 0;" align="center"><img src="http://www.youth.athletics.ca/images/ajax-loader.gif"></div>
|
5
|
+
<form name="submit2gtpay_form" action="<%= gtpay_payment_method.preferred_payment_url%>" target="_self" method="post" style="diaplay:none;">
|
6
|
+
<input type="hidden" name="gtpay_mert_id" value="<%= gtpay_payment_method.preferred_merchant_id %>" />
|
7
|
+
<input type="hidden" name="gtpay_tranx_id" value="<%= @transaction.gtpay_tranx_id %>" />
|
8
|
+
<input type="hidden" name="gtpay_tranx_amt" value="<%= @transaction.amount_in_cents %>" />
|
9
|
+
<input type="hidden" name="gtpay_tranx_curr" value="<%= @transaction.gtpay_tranx_currency %>" />
|
10
|
+
<input type="hidden" name="gtpay_cust_id" value="<%= @transaction.user_id %>" />
|
11
|
+
<input type="hidden" name="gtpay_cust_name" value="<%= @transaction.email %>" />
|
12
|
+
<input type="hidden" name="gtpay_tranx_noti_url" value="<%= callback_gtpay_transactions_url %>" />
|
13
|
+
<input type="submit" value="Pay Via GTPay" name="btnSubmit" style="display:none"/>
|
14
|
+
</form>
|
15
|
+
</body>
|
16
|
+
</html>
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<div class="fieldset_style">
|
2
|
+
<h3>Transactions</h3>
|
3
|
+
<% if @transactions.present? %>
|
4
|
+
<table class="order-summary responsive_table" cellspacing="0" cellpadding="0" border="0">
|
5
|
+
<thead>
|
6
|
+
<tr>
|
7
|
+
<th>Payment Service</th>
|
8
|
+
<th>Transaction Status</th>
|
9
|
+
<th>Transaction Number</th>
|
10
|
+
<th><%= Spree.t(:approved_amount) %></th>
|
11
|
+
<th>Response(Code:Description)</th>
|
12
|
+
<th>Date</th>
|
13
|
+
</tr>
|
14
|
+
</thead>
|
15
|
+
<tbody>
|
16
|
+
<% @transactions.each do |transaction| %>
|
17
|
+
<tr class="<%= cycle('even', 'odd') %>">
|
18
|
+
<td data-title="Payment"><%= "Gtbank Online Payment" %></td>
|
19
|
+
<td data-title="Trans. Status"><%= transaction.status.try(:capitalize) %></td>
|
20
|
+
<td data-title="Trans. No."><%= transaction.gtpay_tranx_id %></td>
|
21
|
+
<td data-title="Approved"><%= Spree::Money.new(transaction.gtpay_tranx_amount) if transaction.order.present? %></td>
|
22
|
+
<% if transaction.gtpay_tranx_status_code? && transaction.gtpay_tranx_status_msg? %>
|
23
|
+
<td data-title="Response">ApprovalCode:<%= transaction.gtpay_tranx_status_code %><br/ > Description:<%= transaction.gtpay_tranx_status_msg %></td>
|
24
|
+
<% else %>
|
25
|
+
<td data-title="Response">No Response</td>
|
26
|
+
<% end %>
|
27
|
+
<td data-title="Date"><%= transaction.created_at.strftime("%d %b %Y, %I:%M%p") %></td>
|
28
|
+
</tr>
|
29
|
+
<% end %>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
32
|
+
<%= paginate @transactions %>
|
33
|
+
<% else %>
|
34
|
+
No Transactions
|
35
|
+
<% end %>
|
36
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<table border="0" cellpadding="5" cellspacing="0">
|
2
|
+
<tr>
|
3
|
+
<th colspan="2" align="left">Your GTbank Payment Transaction was <%= @status %>. Below mentioned are the details</th>
|
4
|
+
</tr>
|
5
|
+
<tr>
|
6
|
+
<td>Transaction Details</td>
|
7
|
+
</tr>
|
8
|
+
<tr>
|
9
|
+
<td>Transaction ID</td>
|
10
|
+
<td>: <%= @transaction.gtpay_tranx_id %></td>
|
11
|
+
</tr>
|
12
|
+
<tr>
|
13
|
+
<td>Transaction Amount</td>
|
14
|
+
<td>: <%= Spree::Money.new(@transaction.gtpay_tranx_amount) %></td>
|
15
|
+
</tr>
|
16
|
+
|
17
|
+
<tr>
|
18
|
+
<td>Order Description</td>
|
19
|
+
<% if @order.line_items.count == 1 %>
|
20
|
+
<td>: Payment for <%= @order.line_items.first.product.name + " at #{Spree::Config[:site_name]}"%></td>
|
21
|
+
<% else %>
|
22
|
+
<td>: Payment for <%= @order.line_items.count.to_s + " products at #{Spree::Config[:site_name]}"%></td>
|
23
|
+
<% end %>
|
24
|
+
</tr>
|
25
|
+
</table>
|
@@ -0,0 +1 @@
|
|
1
|
+
ENVIRONMENT_INITIALS = Rails.env.first(2)
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
|
3
|
+
get :gtpay_confirm, :controller => "checkout", :action => "confirm"
|
4
|
+
resources :gtpay_transactions, :only => [:index] do
|
5
|
+
collection do
|
6
|
+
post :callback
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :admin do
|
11
|
+
resources :gtpay_transactions, :only => [:index] do
|
12
|
+
get :query_interface, :on => :member
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class GtpayTransaction < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spree_gtpay_transactions do |t|
|
4
|
+
t.references :order
|
5
|
+
t.string :gtpay_tranx_id
|
6
|
+
t.decimal :gtpay_tranx_amount, :precision => 8, :scale => 2
|
7
|
+
t.string :gtpay_tranx_currency
|
8
|
+
t.integer :user_id
|
9
|
+
t.string :gtpay_tranx_status_code
|
10
|
+
t.string :gtpay_tranx_memo
|
11
|
+
t.string :gtpay_tranx_status_msg
|
12
|
+
t.string :status
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
add_index :spree_gtpay_transactions, :gtpay_tranx_id
|
16
|
+
add_index :spree_gtpay_transactions, :user_id
|
17
|
+
add_index :spree_gtpay_transactions, :status
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeGtpay
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_gtpay\n"
|
9
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_gtpay\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_gtpay\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_gtpay\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_gtpay'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SpreeGtpay
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_gtpay'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
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
|
+
initializer "spree.register.payment_methods" do |app|
|
21
|
+
app.config.spree.payment_methods << Spree::Gateway::Gtpay
|
22
|
+
end
|
23
|
+
|
24
|
+
config.to_prepare &method(:activate).to_proc
|
25
|
+
end
|
26
|
+
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 'spree_gtpay/factories'
|
6
|
+
end
|
data/lib/spree_gtpay.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module WebpayMethods
|
2
|
+
private
|
3
|
+
|
4
|
+
def query_interswitch
|
5
|
+
headers = {:headers => { "Hash" => transaction_hash} }
|
6
|
+
begin
|
7
|
+
HTTParty.get("#{GT_DATA[:query_url]}#{transaction_params}", headers).parsed_response
|
8
|
+
rescue
|
9
|
+
{}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def transaction_params
|
14
|
+
"?productid=#{GT_DATA[:product_id]}&transactionreference=#{gtpay_tranx_id}&amount=#{amount_in_cents}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def transaction_hash
|
18
|
+
Digest::SHA512.hexdigest(GT_DATA[:product_id] + gtpay_tranx_id + GT_DATA[:mac_id])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_gtpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Abhishek Jain
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spree_core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: delayed_job_active_record
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 4.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 4.0.0
|
46
|
+
description: Enable spree store to allow payment via GtPay
|
47
|
+
email: info@vinsol.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- app/assets/javascripts/admin/spree_gtpay.js
|
55
|
+
- app/assets/javascripts/store/spree_gtpay.js
|
56
|
+
- app/assets/stylesheets/admin/spree_gtpay.css
|
57
|
+
- app/assets/stylesheets/store/spree_gtpay.css
|
58
|
+
- app/controllers/spree/admin/gtpay_transactions_controller.rb
|
59
|
+
- app/controllers/spree/checkout_controller_decorator.rb
|
60
|
+
- app/controllers/spree/gtpay_transactions_controller.rb
|
61
|
+
- app/helpers/spree/admin/base_helper_decorator.rb
|
62
|
+
- app/mailers/spree/transaction_notification_mailer.rb
|
63
|
+
- app/models/spree/gateway/gtpay.rb
|
64
|
+
- app/models/spree/gtpay_transaction.rb
|
65
|
+
- app/models/spree/order_decorator.rb
|
66
|
+
- app/models/spree/payment_decorator.rb
|
67
|
+
- app/overrides/add_tab_for_gtpay_transactions.rb
|
68
|
+
- app/views/spree/admin/gtpay_transactions/_search_form.html.erb
|
69
|
+
- app/views/spree/admin/gtpay_transactions/index.html.erb
|
70
|
+
- app/views/spree/admin/gtpay_transactions/query_interface.js.erb
|
71
|
+
- app/views/spree/checkout/confirm.html.erb
|
72
|
+
- app/views/spree/checkout/payment/_gateway.html.erb
|
73
|
+
- app/views/spree/gtpay_transactions/index.html.erb
|
74
|
+
- app/views/spree/transaction_notification_mailer/send_mail.html.erb
|
75
|
+
- config/initializers/constants.rb
|
76
|
+
- config/locales/en.yml
|
77
|
+
- config/routes.rb
|
78
|
+
- lib/generators/spree_gtpay/install/install_generator.rb
|
79
|
+
- lib/spree_gtpay/engine.rb
|
80
|
+
- lib/spree_gtpay/factories.rb
|
81
|
+
- lib/spree_gtpay.rb
|
82
|
+
- lib/webpay_methods.rb
|
83
|
+
- db/migrate/20140117061910_gtpay_transaction.rb
|
84
|
+
homepage: http://www.vinsol.com
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.9.3
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements:
|
104
|
+
- none
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.23
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Enable spree store to allow payment via GtPay
|
110
|
+
test_files: []
|