From f8681995872e278d8acbe1e30a867df0fadfc167 Mon Sep 17 00:00:00 2001 From: jiikko Date: Sun, 20 Jul 2025 19:27:58 +0900 Subject: [PATCH] =?UTF-8?q?RetURL=E3=81=A8RetUrl=E3=81=8C=E6=B7=B7?= =?UTF-8?q?=E5=9C=A8=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E4=BB=B6=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/gmo.rb | 7 ++++--- lib/gmo/const.rb | 17 ++++++++++++++++- spec/gmo/api_spec.rb | 28 ++++++++++++++++++++++++++++ spec/gmo/shop_api_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/lib/gmo.rb b/lib/gmo.rb index a412b1b..f6dc1d2 100644 --- a/lib/gmo.rb +++ b/lib/gmo.rb @@ -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 @@ -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) diff --git a/lib/gmo/const.rb b/lib/gmo/const.rb index 2a2a8ce..e16fc03 100644 --- a/lib/gmo/const.rb +++ b/lib/gmo/const.rb @@ -20,7 +20,7 @@ module Const order_id: '3' } - INPUT_PARAMS = { + BASE_INPUT_PARAMS = { :access_id => "AccessID", :access_pass => "AccessPass", :account_name => "Account_Name", @@ -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', diff --git a/spec/gmo/api_spec.rb b/spec/gmo/api_spec.rb index 87965a0..c5372bb 100644 --- a/spec/gmo/api_spec.rb +++ b/spec/gmo/api_spec.rb @@ -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 diff --git a/spec/gmo/shop_api_spec.rb b/spec/gmo/shop_api_spec.rb index 38af9de..659afff 100644 --- a/spec/gmo/shop_api_spec.rb +++ b/spec/gmo/shop_api_spec.rb @@ -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) }