spree_komoju 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -1
- data/app/assets/javascripts/spree/backend/spree_komoju.js +0 -2
- data/app/assets/javascripts/spree/frontend/spree_komoju.js +0 -2
- data/app/assets/stylesheets/spree/frontend/spree_komoju.css +23 -0
- data/app/controllers/spree/admin/payments_controller_decorator.rb +3 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +1 -16
- data/app/controllers/spree/komoju_controller.rb +34 -0
- data/app/models/spree/bank_transfer.rb +1 -10
- data/app/models/spree/gateway/komoju_bank_transfer.rb +4 -0
- data/app/models/spree/gateway/komoju_konbini.rb +4 -0
- data/app/models/spree/gateway/komoju_pay_easy.rb +28 -0
- data/app/models/spree/gateway/komoju_web_money.rb +57 -0
- data/app/models/spree/konbini.rb +1 -10
- data/app/models/spree/pay_easy.rb +18 -0
- data/app/models/spree/web_money.rb +21 -0
- data/app/models/spree/web_money_decorator.rb +15 -0
- data/app/views/spree/admin/payments/source_forms/_komoju_bank_transfer.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_komoju_credit_card.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_komoju_konbini.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_komoju_pay_easy.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_komoju_web_money.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_komoju_bank_transfer.html.erb +13 -0
- data/app/views/spree/admin/payments/source_views/_komoju_pay_easy.html.erb +21 -0
- data/app/views/spree/admin/payments/source_views/_komoju_web_money.html.erb +13 -0
- data/app/views/spree/checkout/payment/_komoju_pay_easy.html.erb +36 -0
- data/app/views/spree/checkout/payment/_komoju_web_money.html.erb +74 -0
- data/app/views/spree/orders/_pay_easy.html.erb +24 -0
- data/bin/rails +6 -1
- data/config/locales/en.yml +32 -4
- data/config/locales/ja.yml +24 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20150402013829_create_spree_pay_easies.rb +24 -0
- data/db/migrate/20151209053401_create_spree_web_moneys.rb +17 -0
- data/lib/active_merchant/billing/gateways/komoju.rb +9 -4
- data/lib/ext/activemerchant/connection.rb +47 -0
- data/lib/generators/spree_komoju/install/images/pay-easy.png +0 -0
- data/lib/generators/spree_komoju/install/images/webmoney.png +0 -0
- data/lib/spree_komoju/controller_helpers.rb +29 -0
- data/lib/spree_komoju/engine.rb +3 -0
- data/lib/spree_komoju/errors.rb +5 -0
- data/lib/spree_komoju.rb +8 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +1 -1
- data/spec/controllers/spree/komoju_controller_spec.rb +82 -0
- data/spec/models/spree/bank_transfer_spec.rb +1 -57
- data/spec/models/spree/gateway/komoju_pay_easy_spec.rb +92 -0
- data/spec/models/spree/gateway/komoju_web_money_spec.rb +108 -0
- data/spec/models/spree/konbini_spec.rb +1 -57
- data/spec/models/spree/pay_easy_spec.rb +13 -0
- data/spec/models/spree/web_money_decorator_spec.rb +24 -0
- data/spec/models/spree/web_money_spec.rb +13 -0
- data/spree_komoju.gemspec +1 -1
- metadata +40 -2
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateSpreePayEasies < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spree_pay_easies do |t|
|
4
|
+
t.string :email
|
5
|
+
t.string :phone
|
6
|
+
t.string :given_name
|
7
|
+
t.string :family_name
|
8
|
+
t.string :given_name_kana
|
9
|
+
t.string :family_name_kana
|
10
|
+
t.integer :user_id
|
11
|
+
t.integer :payment_method_id
|
12
|
+
t.string :brand, default: "pay_easy"
|
13
|
+
t.string :instructions_url
|
14
|
+
t.string :bank_id
|
15
|
+
t.string :customer_id
|
16
|
+
t.string :confirmation_id
|
17
|
+
t.datetime :expires_at
|
18
|
+
|
19
|
+
t.timestamps null: false
|
20
|
+
end
|
21
|
+
add_index :spree_pay_easies, :user_id
|
22
|
+
add_index :spree_pay_easies, :payment_method_id
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSpreeWebMoneys < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spree_web_moneys do |t|
|
4
|
+
t.string :email
|
5
|
+
t.string :payment_uuid
|
6
|
+
t.integer :short_amount
|
7
|
+
t.text :prepaid_cards
|
8
|
+
t.integer :user_id
|
9
|
+
t.integer :payment_method_id
|
10
|
+
t.string :brand, default: "web_moneys"
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
add_index :spree_web_moneys, :user_id
|
15
|
+
add_index :spree_web_moneys, :payment_method_id
|
16
|
+
end
|
17
|
+
end
|
@@ -24,6 +24,11 @@ module ActiveMerchant #:nodoc:
|
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
27
|
+
def continue(uuid, payment_details)
|
28
|
+
details = {payment_details: payment_details}
|
29
|
+
commit("/payments/#{uuid}", details, :patch)
|
30
|
+
end
|
31
|
+
|
27
32
|
def purchase(money, payment, options = {})
|
28
33
|
post = {}
|
29
34
|
post[:amount] = amount(money)
|
@@ -91,10 +96,10 @@ module ActiveMerchant #:nodoc:
|
|
91
96
|
post[:fraud_details] = details unless details.empty?
|
92
97
|
end
|
93
98
|
|
94
|
-
def api_request(path, data)
|
99
|
+
def api_request(method, path, data)
|
95
100
|
raw_response = nil
|
96
101
|
begin
|
97
|
-
raw_response =
|
102
|
+
raw_response = ssl_request(method, "#{url}#{path}", data, headers)
|
98
103
|
rescue ResponseError => e
|
99
104
|
raw_response = e.response.body
|
100
105
|
end
|
@@ -102,8 +107,8 @@ module ActiveMerchant #:nodoc:
|
|
102
107
|
JSON.parse(raw_response)
|
103
108
|
end
|
104
109
|
|
105
|
-
def commit(path, params)
|
106
|
-
response = api_request(path, params.to_json)
|
110
|
+
def commit(path, params, method = :post)
|
111
|
+
response = api_request(method, path, params.to_json)
|
107
112
|
success = !response.key?("error")
|
108
113
|
message = (success ? "Transaction succeeded" : response["error"]["message"])
|
109
114
|
Response.new(
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
class Connection
|
3
|
+
def request(method, body, headers = {})
|
4
|
+
request_start = Time.now.to_f
|
5
|
+
|
6
|
+
retry_exceptions(:max_retries => max_retries, :logger => logger, :tag => tag) do
|
7
|
+
begin
|
8
|
+
info "connection_http_method=#{method.to_s.upcase} connection_uri=#{endpoint}", tag
|
9
|
+
|
10
|
+
result = nil
|
11
|
+
|
12
|
+
realtime = Benchmark.realtime do
|
13
|
+
result = case method
|
14
|
+
when :get
|
15
|
+
raise ArgumentError, "GET requests do not support a request body" if body
|
16
|
+
http.get(endpoint.request_uri, headers)
|
17
|
+
when :post
|
18
|
+
debug body
|
19
|
+
http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers))
|
20
|
+
when :patch
|
21
|
+
debug body
|
22
|
+
http.patch(endpoint.request_uri, body, headers)
|
23
|
+
when :put
|
24
|
+
debug body
|
25
|
+
http.put(endpoint.request_uri, body, headers)
|
26
|
+
when :delete
|
27
|
+
# It's kind of ambiguous whether the RFC allows bodies
|
28
|
+
# for DELETE requests. But Net::HTTP's delete method
|
29
|
+
# very unambiguously does not.
|
30
|
+
raise ArgumentError, "DELETE requests do not support a request body" if body
|
31
|
+
http.delete(endpoint.request_uri, headers)
|
32
|
+
else
|
33
|
+
raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
info "--> %d %s (%d %.4fs)" % [result.code, result.message, result.body ? result.body.length : 0, realtime], tag
|
38
|
+
debug result.body
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
ensure
|
44
|
+
info "connection_request_total_time=%.4fs" % [Time.now.to_f - request_start], tag
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SpreeKomoju
|
2
|
+
module ControllerHelpers
|
3
|
+
def permitted_source_attributes
|
4
|
+
super.push(permitted_komoju_konbini_attributes)
|
5
|
+
super.push(permitted_komoju_banktransfer_attributes)
|
6
|
+
super.push(permitted_komoju_pay_easy_attributes)
|
7
|
+
super.push(permitted_komoju_web_money_attributes)
|
8
|
+
super.flatten.uniq
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def permitted_komoju_konbini_attributes
|
14
|
+
:convenience
|
15
|
+
end
|
16
|
+
|
17
|
+
def permitted_komoju_banktransfer_attributes
|
18
|
+
[:email, :phone, :family_name, :given_name, :family_name_kana, :given_name_kana]
|
19
|
+
end
|
20
|
+
|
21
|
+
def permitted_komoju_pay_easy_attributes
|
22
|
+
[:email, :phone, :family_name, :given_name, :family_name_kana, :given_name_kana]
|
23
|
+
end
|
24
|
+
|
25
|
+
def permitted_komoju_web_money_attributes
|
26
|
+
[:email, :prepaid_number]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/spree_komoju/engine.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module SpreeKomoju
|
2
2
|
mattr_accessor :enable_customer_profiles
|
3
|
+
mattr_accessor :komoju_webhook_secret_token
|
3
4
|
|
4
5
|
class Engine < Rails::Engine
|
5
6
|
require 'spree/core'
|
@@ -10,6 +11,8 @@ module SpreeKomoju
|
|
10
11
|
app.config.spree.payment_methods << Spree::Gateway::KomojuCreditCard
|
11
12
|
app.config.spree.payment_methods << Spree::Gateway::KomojuKonbini
|
12
13
|
app.config.spree.payment_methods << Spree::Gateway::KomojuBankTransfer
|
14
|
+
app.config.spree.payment_methods << Spree::Gateway::KomojuPayEasy
|
15
|
+
app.config.spree.payment_methods << Spree::Gateway::KomojuWebMoney
|
13
16
|
end
|
14
17
|
|
15
18
|
# use rspec for tests
|
data/lib/spree_komoju.rb
CHANGED
@@ -1,2 +1,10 @@
|
|
1
1
|
require 'spree_core'
|
2
2
|
require 'spree_komoju/engine'
|
3
|
+
require 'spree_komoju/errors'
|
4
|
+
require 'spree_komoju/controller_helpers'
|
5
|
+
|
6
|
+
# This extension adds HTTP PATCH to ssl_request.
|
7
|
+
# This is needed for WebMoney multi-card in Komoju.
|
8
|
+
if ActiveMerchant::VERSION == "1.47.0"
|
9
|
+
require 'ext/activemerchant/connection'
|
10
|
+
end
|
@@ -6,7 +6,7 @@ describe Spree::CheckoutController, type: :controller do
|
|
6
6
|
source_attributes = [:number, :month, :year, :expiry, :verification_value, :first_name, :last_name, :cc_type,
|
7
7
|
:gateway_customer_profile_id, :gateway_payment_profile_id, :last_digits, :name,
|
8
8
|
:encrypted_data, :convenience, :email, :phone, :family_name, :given_name, :family_name_kana,
|
9
|
-
:given_name_kana]
|
9
|
+
:given_name_kana, :prepaid_number]
|
10
10
|
expect(controller.permitted_source_attributes).to eq source_attributes
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::KomojuController, type: :controller do
|
4
|
+
routes { Spree::Core::Engine.routes }
|
5
|
+
|
6
|
+
describe "#callback" do
|
7
|
+
context 'when callback is verified' do
|
8
|
+
before do
|
9
|
+
allow(OpenSSL::HMAC).to receive(:hexdigest) { "signature" }
|
10
|
+
request.env["HTTP_X_KOMOJU_SIGNATURE"] = "signature"
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when type is ping' do
|
14
|
+
it 'returns a successful response' do
|
15
|
+
post :callback, {type: "ping"}
|
16
|
+
|
17
|
+
expect(response.status).to eq(200)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when type is payment.captured' do
|
22
|
+
let(:payment) { double Spree::Payment, complete!: true, completed?: completed }
|
23
|
+
let(:capture_params) do
|
24
|
+
{
|
25
|
+
"type" => "payment.captured",
|
26
|
+
"data" => {
|
27
|
+
"external_order_num" => "SPREEORDER-PAYMENTID",
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when payment exists' do
|
33
|
+
context 'when payment has already been completed' do
|
34
|
+
let(:completed) { true }
|
35
|
+
|
36
|
+
it 'does nothing' do
|
37
|
+
allow(Spree::Payment).to receive(:find_by_number!) { payment }
|
38
|
+
|
39
|
+
post :callback, capture_params
|
40
|
+
|
41
|
+
expect(payment).to_not have_received(:complete!)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when payment has not been completed yet' do
|
46
|
+
let(:completed) { false }
|
47
|
+
|
48
|
+
it 'marks a payment as complete' do
|
49
|
+
allow(Spree::Payment).to receive(:find_by_number!) { payment }
|
50
|
+
|
51
|
+
post :callback, capture_params
|
52
|
+
|
53
|
+
expect(payment).to have_received(:complete!)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when payment doesnt exist' do
|
59
|
+
it 'raises an activerecord error' do
|
60
|
+
expect {
|
61
|
+
post :callback, capture_params
|
62
|
+
}.to raise_error(ActiveRecord::RecordNotFound)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when type is not recognized' do
|
68
|
+
it 'returns an unauthorized status code' do
|
69
|
+
post :callback, {type: "bad_type"}
|
70
|
+
expect(response.status).to eq(401)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when callback is unverified' do
|
76
|
+
it 'returns head unauthorized' do
|
77
|
+
post :callback
|
78
|
+
expect(response.status).to eq(401)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -4,63 +4,7 @@ describe Spree::BankTransfer, type: :model do
|
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
6
|
describe "#actions" do
|
7
|
-
it { expect(subject.actions).to eq [
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#can_capture?" do
|
11
|
-
let(:payment) { double(Spree::Payment, state: state) }
|
12
|
-
|
13
|
-
before do
|
14
|
-
allow(subject).to receive(:payment) { payment }
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when payment state is not checkout or pending" do
|
18
|
-
let(:state) { "void" }
|
19
|
-
|
20
|
-
it { expect(subject.can_capture?(payment)).to be_falsy }
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when payment state is pending" do
|
24
|
-
let(:payment) { double(Spree::Payment, state: state, source: source) }
|
25
|
-
let(:state) { "pending" }
|
26
|
-
let(:source) { double(Spree::BankTransfer, expires_at: expires_at) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(subject).to receive(:payment) { payment }
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when expires_at is tomorrow" do
|
33
|
-
let(:expires_at) { Date.tomorrow }
|
34
|
-
|
35
|
-
it { expect(subject.can_capture?(payment)).to be_truthy }
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when expires_at is yesterday" do
|
39
|
-
let(:expires_at) { Date.yesterday}
|
40
|
-
|
41
|
-
it { expect(subject.can_capture?(payment)).to be_falsy }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#can_void?" do
|
47
|
-
let(:payment) { double(Spree::Payment, state: state) }
|
48
|
-
|
49
|
-
before do
|
50
|
-
allow(subject).to receive(:payment) { payment }
|
51
|
-
end
|
52
|
-
|
53
|
-
context "when payment state is void" do
|
54
|
-
let(:state) { "void" }
|
55
|
-
|
56
|
-
it { expect(subject.can_void?(payment)).to be_falsy }
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when payment state is pending" do
|
60
|
-
let(:state) { "pending" }
|
61
|
-
|
62
|
-
it { expect(subject.can_void?(payment)).to be_truthy }
|
63
|
-
end
|
7
|
+
it { expect(subject.actions).to eq [] }
|
64
8
|
end
|
65
9
|
|
66
10
|
describe "#instructions_partial_path" do
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::Gateway::KomojuPayEasy, type: :model do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#authorize" do
|
7
|
+
let(:money) { 1000.0 }
|
8
|
+
let(:source) do
|
9
|
+
Spree::PayEasy.create!(
|
10
|
+
email: "email",
|
11
|
+
given_name: "given_name",
|
12
|
+
family_name: "family_name",
|
13
|
+
given_name_kana: "given_name_kana",
|
14
|
+
family_name_kana: "family_name_kana"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
let(:options) { { login: "api_key", shipping: 100.0, tax: 200.0, subtotal: 800.0, discount: 100.0,
|
18
|
+
currency: currency } }
|
19
|
+
let(:details) do
|
20
|
+
{
|
21
|
+
type: "pay_easy",
|
22
|
+
phone: nil,
|
23
|
+
email: "email",
|
24
|
+
given_name: "given_name",
|
25
|
+
family_name: "family_name",
|
26
|
+
given_name_kana: "given_name_kana",
|
27
|
+
family_name_kana: "family_name_kana"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
let(:params) do
|
31
|
+
{
|
32
|
+
"payment_deadline" => Time.now.iso8601.to_s,
|
33
|
+
"payment_details" => {
|
34
|
+
"bank_id" => "bank_id",
|
35
|
+
"customer_id" => "customer_id",
|
36
|
+
"confirmation_id" => "confirmation_id",
|
37
|
+
"instructions_url" => "instructions_url"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:response) { double(ActiveMerchant::Billing::Response, params: params, success?: true) }
|
43
|
+
|
44
|
+
before do
|
45
|
+
allow_any_instance_of(Spree::Gateway::KomojuPayEasy).to receive(:options) { options }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with currency is JPY" do
|
49
|
+
let(:currency) { "JPY" }
|
50
|
+
|
51
|
+
it 'updates the source payment' do
|
52
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase) { response }
|
53
|
+
|
54
|
+
subject.authorize(money, source, options)
|
55
|
+
expect(source.bank_id).to eq("bank_id")
|
56
|
+
expect(source.customer_id).to eq("customer_id")
|
57
|
+
expect(source.confirmation_id).to eq("confirmation_id")
|
58
|
+
expect(source.instructions_url).to eq("instructions_url")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "creates a payment with correct active merchant options" do
|
62
|
+
options_converted_to_dollars = { login: "api_key", shipping: 1.0, tax: 2.0, subtotal: 8.0, discount: 1.0, currency: currency }
|
63
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase).with(998.0, details, options_converted_to_dollars) { response }
|
64
|
+
|
65
|
+
subject.authorize(money, source, options)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with currency is USD" do
|
70
|
+
let(:currency) { "USD" }
|
71
|
+
|
72
|
+
it "creates a payment with correct active merchant options" do
|
73
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase).with(800.0, details, options) { response }
|
74
|
+
|
75
|
+
subject.authorize(money, source, options)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when response is not successful' do
|
80
|
+
let(:currency) { "JPY" }
|
81
|
+
|
82
|
+
it 'does not update the source payment' do
|
83
|
+
response = double(ActiveMerchant::Billing::Response, params: params, success?: false)
|
84
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase) { response }
|
85
|
+
|
86
|
+
subject.authorize(money, source, options)
|
87
|
+
|
88
|
+
expect(source.instructions_url).to be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::Gateway::KomojuWebMoney do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#auto_captured?" do
|
7
|
+
it { should be_auto_capture }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#purchase" do
|
11
|
+
let(:money) { 1000.0 }
|
12
|
+
let(:source) { Spree::WebMoney.create!( email: "foo@bar.com", prepaid_number: "1111111111111111") }
|
13
|
+
let(:options) { { login: "api_key", shipping: 100.0, tax: 200.0, subtotal: 800.0, discount: 100.0, order_id: "ORDERID-PAYMENTID", currency: "JPY" } }
|
14
|
+
let(:order) { double Spree::Order, payments: [] }
|
15
|
+
let(:response) { ActiveMerchant::Billing::Response.new(true, "success", response_params) }
|
16
|
+
let(:response_params) do
|
17
|
+
{
|
18
|
+
"status" => "captured",
|
19
|
+
"payment_deadline" => Time.now.iso8601.to_s,
|
20
|
+
"payment_details" => {
|
21
|
+
"short_amount" => 1000,
|
22
|
+
"prepaid_cards" => [
|
23
|
+
{
|
24
|
+
"last_four_digits" => "1111",
|
25
|
+
"points" => 100
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with valid parameters' do
|
33
|
+
context 'when its a new webmoney request' do
|
34
|
+
it "updates the source payment" do
|
35
|
+
stub_order(order)
|
36
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase) { response }
|
37
|
+
|
38
|
+
subject.purchase(money, source, options)
|
39
|
+
expect(source.prepaid_cards).to eq([{"last_four_digits" => "1111", "points" => 100}])
|
40
|
+
expect(source.short_amount).to eq(1000)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a payment with correct active merchant options" do
|
44
|
+
stub_order(order)
|
45
|
+
options_converted_to_dollars = options.merge({shipping: 1.0, tax: 2.0, subtotal: 8.0, discount: 1.0})
|
46
|
+
payment_details = {type: "web_money", email: "foo@bar.com", prepaid_number: "1111111111111111"}
|
47
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase).with(998.0, payment_details, options_converted_to_dollars) { response }
|
48
|
+
|
49
|
+
subject.purchase(money, source, options)
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when the status is pending' do
|
53
|
+
it 'returns an insufficient funds error' do
|
54
|
+
stub_order(order)
|
55
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:purchase) { response }
|
56
|
+
response_params["status"] = 'pending'
|
57
|
+
|
58
|
+
response = subject.purchase(money, source, options)
|
59
|
+
|
60
|
+
expect(response).to_not be_success
|
61
|
+
expect(response.message).to eq(I18n.t('spree.komoju.web_money.insufficient_funds'))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when webmoney request is continued' do
|
67
|
+
let(:webmoney) { double Spree::WebMoney, payment_uuid: "123" }
|
68
|
+
let(:payment) { double Spree::Payment, source: webmoney }
|
69
|
+
let(:order) { double Spree::Order, payments: [payment, payment] }
|
70
|
+
|
71
|
+
it 'makes an activemerchant continue request' do
|
72
|
+
stub_order(order)
|
73
|
+
expect_any_instance_of(ActiveMerchant::Billing::KomojuGateway).to receive(:continue).
|
74
|
+
with("123", {type: "web_money", email: "foo@bar.com", prepaid_number: "1111111111111111"}).
|
75
|
+
and_return(response)
|
76
|
+
|
77
|
+
subject.purchase(money, source, options)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'updates the prepaid cards hash on source' do
|
81
|
+
stub_order(order)
|
82
|
+
allow_any_instance_of(ActiveMerchant::Billing::KomojuGateway).
|
83
|
+
to receive(:continue).and_return(response)
|
84
|
+
|
85
|
+
subject.purchase(money, source, options)
|
86
|
+
|
87
|
+
expect(source.prepaid_cards).to eq(response_params["payment_details"]["prepaid_cards"])
|
88
|
+
expect(source.short_amount).to eq(response_params["payment_details"]["short_amount"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with invalid parameters' do
|
94
|
+
context 'when currency is not JPY' do
|
95
|
+
it 'raises an unsupported currency exception' do
|
96
|
+
expect {
|
97
|
+
subject.purchase(nil, nil, currency: "USD")
|
98
|
+
}.to raise_error(SpreeKomoju::Errors::UnsupportedCurrency)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def stub_order(order)
|
105
|
+
allow_any_instance_of(Spree::Gateway::KomojuWebMoney).to receive(:options) { options }
|
106
|
+
allow(Spree::Order).to receive(:find_by_number) { order }
|
107
|
+
end
|
108
|
+
end
|
@@ -4,63 +4,7 @@ describe Spree::Konbini, type: :model do
|
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
6
|
describe "#actions" do
|
7
|
-
it { expect(subject.actions).to eq [
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#can_capture?" do
|
11
|
-
let(:payment) { double(Spree::Payment, state: state) }
|
12
|
-
|
13
|
-
before do
|
14
|
-
allow(subject).to receive(:payment) { payment }
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when payment state is not checkout or pending" do
|
18
|
-
let(:state) { "void" }
|
19
|
-
|
20
|
-
it { expect(subject.can_capture?(payment)).to be_falsy }
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when payment state is pending" do
|
24
|
-
let(:payment) { double(Spree::Payment, state: state, source: source) }
|
25
|
-
let(:state) { "pending" }
|
26
|
-
let(:source) { double(Spree::Konbini, expires_at: expires_at) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(subject).to receive(:payment) { payment }
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when expires_at is tomorrow" do
|
33
|
-
let(:expires_at) { Date.tomorrow }
|
34
|
-
|
35
|
-
it { expect(subject.can_capture?(payment)).to be_truthy }
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when expires_at is yesterday" do
|
39
|
-
let(:expires_at) { Date.yesterday}
|
40
|
-
|
41
|
-
it { expect(subject.can_capture?(payment)).to be_falsy }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#can_void?" do
|
47
|
-
let(:payment) { double(Spree::Payment, state: state) }
|
48
|
-
|
49
|
-
before do
|
50
|
-
allow(subject).to receive(:payment) { payment }
|
51
|
-
end
|
52
|
-
|
53
|
-
context "when payment state is void" do
|
54
|
-
let(:state) { "void" }
|
55
|
-
|
56
|
-
it { expect(subject.can_void?(payment)).to be_falsy }
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when payment state is pending" do
|
60
|
-
let(:state) { "pending" }
|
61
|
-
|
62
|
-
it { expect(subject.can_void?(payment)).to be_truthy }
|
63
|
-
end
|
7
|
+
it { expect(subject.actions).to eq [] }
|
64
8
|
end
|
65
9
|
|
66
10
|
describe "#instructions_partial_path" do
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::PayEasy, type: :model do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#actions" do
|
7
|
+
it { expect(subject.actions).to eq [] }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#instructions_partial_path" do
|
11
|
+
it { expect(subject.instructions_partial_path).to eq "spree/orders/pay_easy" }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::WebMoneyDecorator, type: :model do
|
4
|
+
context 'when source is webmoney' do
|
5
|
+
it 'delegates methods' do
|
6
|
+
source = Spree::WebMoney.new(prepaid_cards: [], short_amount: 1000, payment_uuid: "123")
|
7
|
+
decorator = Spree::WebMoneyDecorator.new(source)
|
8
|
+
|
9
|
+
expect(decorator.prepaid_cards).to eq([])
|
10
|
+
expect(decorator.payment_uuid).to eq("123")
|
11
|
+
expect(decorator.short_amount).to eq(1000)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when source is nill' do
|
16
|
+
it 'delegates methods to nil' do
|
17
|
+
decorator = Spree::WebMoneyDecorator.new(nil)
|
18
|
+
|
19
|
+
expect(decorator.prepaid_cards).to be_nil
|
20
|
+
expect(decorator.payment_uuid).to be_nil
|
21
|
+
expect(decorator.short_amount).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Spree::WebMoney, type: :model do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#actions" do
|
7
|
+
it { expect(subject.actions).to eq [] }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#instructions_partial_path" do
|
11
|
+
it { expect(subject.instructions_partial_path).to eq "spree/orders/web_money" }
|
12
|
+
end
|
13
|
+
end
|
data/spree_komoju.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_komoju'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.6'
|
6
6
|
s.summary = 'Spree Komoju Payment Gateway'
|
7
7
|
s.description = 'Spree Payment gateway for Komoju payment gateway'
|
8
8
|
s.authors = ['Masahiro Saito', 'Chris Salzberg', 'Richard Ramsden']
|