Skip to content

Commit

Permalink
Merge pull request #65 from ken1flan/Add_gmopg_remittance_link_url
Browse files Browse the repository at this point in the history
送金サービス リンクタイプURL取得を追加
  • Loading branch information
jiikko authored Nov 1, 2023
2 parents 3d37c04 + 69a809e commit b228916
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions lib/gmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ def api(path, args = {}, verb = "post", options = {}, &error_checking_block)
raise GMO::Payment::ServerError.new(result.body, error_detail)
end
# Transform the body to Hash
# "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" }
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten
response = Hash[*key_values]
if /\.json\Z/ =~ path
# Parse the body as JSON
parsed_result = ::JSON.parse(result.body)
response = parsed_result.is_a?(Array) ? parsed_result[0] : parsed_result
else
# Parse the body as Query string
# "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" }
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten
response = Hash[*key_values]
end
# converting to UTF-8
body = response = Hash[response.map { |k,v| [k, NKF.nkf('-S -w',v)] }]
# Check for errors if provided a error_checking_block
Expand Down
4 changes: 4 additions & 0 deletions lib/gmo/const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ module Const
:register_disp_6 => "RegisterDisp6",
:register_disp_7 => "RegisterDisp7",
:register_disp_8 => "RegisterDisp8",
:remit_method_amazongift => "Remit_Method_Amazongift",
:remit_method_aupay => "Remit_Method_Aupay",
:remit_method_bank => "Remit_Method_Bank",
:remit_method_sevenatm => "Remit_Method_Sevenatm",
:reserve_no => "ReserveNo",
:ret_url => "RetURL",
:security_code => "SecurityCode",
:select_key => "Select_Key",
:seq_mode => "SeqMode",
:service_name => "ServiceName",
:service_tel => "ServiceTel",
:sevenatm_payment_term_day => "Sevenatm_Payment_Term_Day",
:shop_id => "ShopID",
:shop_mail_address => "ShopMailAddress",
:shop_pass => "ShopPass",
Expand Down
7 changes: 6 additions & 1 deletion lib/gmo/http_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def self.make_request(path, args, verb, options = {})

http.start do |h|
response = if verb == "post"
h.post(path, encode_params(args))
if /\.json\Z/ =~ path
headers = { "Content-Type" => "application/json" }
h.post(path, args.to_json, headers)
else
h.post(path, encode_params(args))
end
else
h.get("#{path}?#{encode_params(args)}")
end
Expand Down
51 changes: 51 additions & 0 deletions lib/gmo/remittance_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,57 @@ def search_mail_deposit(options = {})
post_request name, options
end

#########
# Deposit_ID
# Call_Back_Url
# Amount
# Auth_Code
# Auth_Code2
# Auth_Code3
# Remit_Method_Bank
# Remit_Method_Sevenatm
# Sevenatm_Payment_Term_Day
# Remit_Method_Amazongift
# Remit_Method_Aup ay
# Bank_ID
# Client_Name
### @return ###
# Deposit_ID
# Redirect_Url
# Method
### example ###
# gmo.create_link_redirect_url({
# deposit_id: 'dep00001',
# call_back_url: 'https://XXXX/XXXX/XXXX/XXXX',
# amount: '1000',
# auth_code: 'auth00001',
# })
# {"Deposit_ID"=>"dep00001", "Redirect_Url"=>"https://XXXX/XXXX/XXXX/XXXX", "Method"=>"1"}
def create_link_redirect_url(options = {})
name = "/api/shop/LinkRedirectUrl.json"
required = %i(deposit_id call_back_url amount auth_code)
assert_required_options(required, options)
post_request name, options
end

#########
# Deposit_ID
### @return ###
# Deposit_ID
# Method
### example ###
# gmo.cancel_link_redirect_url({
# deposit_id: 'dep00001',
# })
# {"Deposit_ID"=>"dep00001", "Method"=>"2"}
def cancel_link_redirect_url(options = {})
name = "/api/shop/LinkRedirectUrl.json"
required = %i(deposit_id)
options[:method] = 2
assert_required_options(required, options)
post_request name, options
end

private

def api_call(name, args = {}, verb = "post", options = {})
Expand Down
65 changes: 65 additions & 0 deletions spec/gmo/remittance_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,69 @@
end
end

describe "#create_link_redirect_url" do
subject(:do_api_call) { @service.create_link_redirect_url(options) }

context 'with valid options', :vcr do
let(:deposit_id) { "dep00001" }
let(:options) do
{
deposit_id: deposit_id,
call_back_url: "https://example.com/callback",
amount: "1000",
auth_code: "auth00005",
auth_code_2: "auth00002",
auth_code_3: "auth00003",
remit_method_bank: "1",
remit_method_sevenatm: "1",
sevenatm_payment_term_day: "15",
remit_method_amazongift: "1",
remit_method_aupay: "1",
bank_id: "bank_id00001",
client_name: "リンクユーアールエル",
}
end

it "gets data about link redirect url" do
result = do_api_call
expect(result["Deposit_ID"]).to eq(deposit_id)
expect(result["Redirect_Url"]).not_to be_nil
expect(result["Method"]).to eq("1")
end
end

context "with invalid options", :vcr do
let(:options) { {} }

it "got error" do
expect { do_api_call }.to raise_error("Required deposit_id, call_back_url, amount, auth_code were not provided.")
end
end
end

describe "#cancel_link_redirect_url" do
subject (:do_api_call) { @service.cancel_link_redirect_url(options) }

before { @service.create_link_redirect_url(deposit_id: deposit_id, call_back_url: 'https://example.com/callback', amount: '100', auth_code: 'AUTH001') }

context 'with valid options', :vcr do
let(:options) { { deposit_id: deposit_id } }
let(:deposit_id) { "dep00001" }

it "gets data about a link edirect url" do
result = do_api_call
expect(result["Deposit_ID"]).not_to be_nil
expect(result["Method"]).to eq "2"
end
end

context "with invalid options", :vcr do
let(:options) { {} }
let(:deposit_id) { "dep00001" }

it "got error" do
expect { do_api_call }.to raise_error("Required deposit_id were not provided.")
end
end
end
end

0 comments on commit b228916

Please sign in to comment.