Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/gmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_request(name, args = {}, options = {})
# gmo.post_request("EntryTran.idPass", {:foo => "bar"})
# POST /EntryTran.idPass with params foo=bar
def post_request(name, args = {}, options = {})
args = associate_options_to_gmo_params args
args = associate_options_to_gmo_params(name, args)
api_call(name, args, "post", options)
end
alias :post! :post_request
Expand All @@ -82,8 +82,9 @@ def assert_required_options(required, options)
raise ArgumentError, "Required #{missing.join(', ')} were not provided." unless missing.empty?
end

def associate_options_to_gmo_params(options)
Hash[options.map { |k, v| [GMO::Const::INPUT_PARAMS[k], v] }]
def associate_options_to_gmo_params(api_method_name, options)
params = GMO::Const.input_params(api_method_name)
Hash[options.map { |k, v| [params[k], v] }]
end

def api_call(*args)
Expand Down
17 changes: 16 additions & 1 deletion lib/gmo/const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Const
order_id: '3'
}

INPUT_PARAMS = {
BASE_INPUT_PARAMS = {
:access_id => "AccessID",
:access_pass => "AccessPass",
:account_name => "Account_Name",
Expand Down Expand Up @@ -176,6 +176,21 @@ module Const
:trade_client_mail_address => "TradeClientMailAddress"
}.freeze

# NOTE: 決済方法によってはcaseに揺らぎがあるのでここで上書きする
PAYMENT_SPECIFIC_PARAMS = {
"ExecTran.idPass" => {
ret_url: "RetUrl" # NOTE: 3Dセキュア認証後にお戻しする加盟店様側のURLになります。
},
}.freeze

def self.input_params(api_method_name)
if PAYMENT_SPECIFIC_PARAMS.key?(api_method_name)
BASE_INPUT_PARAMS.dup.merge!(PAYMENT_SPECIFIC_PARAMS[api_method_name])
else
BASE_INPUT_PARAMS
end
end

API_ERROR_MESSAGES_EN = {
'000' => 'Token acquisition completed normally',
'100' => 'Card number Required check error',
Expand Down
28 changes: 28 additions & 0 deletions spec/gmo/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,32 @@
end
end

describe "#associate_options_to_gmo_params" do
let(:service) { GMO::Payment::API.new() }

context "with ExecTran.idPass" do
it "converts access_id and access_pass normally" do
options = {
access_id: "test_access_id",
access_pass: "test_access_pass",
ret_url: "https://example.com/callback"
}
result = service.send(:associate_options_to_gmo_params, "ExecTran.idPass", options)
expect(result).to eq({
"AccessID" => "test_access_id",
"AccessPass" => "test_access_pass",
"RetUrl" => "https://example.com/callback"
})
end
end

context "with other API methods" do
it "converts ret_url to RetURL for standard cases" do
options = { ret_url: "https://example.com/callback" }
result = service.send(:associate_options_to_gmo_params, "AnotherAPI", options)
expect(result).to eq({ "RetURL" => "https://example.com/callback" })
end
end
end

end
22 changes: 22 additions & 0 deletions spec/gmo/shop_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,28 @@
}.should_not raise_error("Required card_no, expire were not provided.")
end

it "converts ret_url to RetUrl for ExecTran.idPass" do
# Test that ret_url is converted to RetUrl by associate_options_to_gmo_params
actual_params = nil
allow(@service).to receive(:api_call) do |name, args, method, options|
actual_params = args
{}
end

@service.exec_tran({
:order_id => "test_order",
:access_id => "test_access",
:access_pass => "test_pass",
:method => 1,
:pay_times => 1,
:card_no => "4111111111111111",
:expire => "1405",
:ret_url => "https://example.com/3d-secure-callback"
})

expect(actual_params).to include("RetUrl" => "https://example.com/3d-secure-callback")
end

context "parameter contains Japanese characters" do
before { require "kconv" unless defined?(Kconv) }

Expand Down