From 9bee22e95b6ada68912f9504a3c732b48136bad4 Mon Sep 17 00:00:00 2001 From: yalab Date: Mon, 3 Sep 2018 13:47:38 +0900 Subject: [PATCH 1/3] Add const for recurring API. --- lib/gmo/const.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/gmo/const.rb b/lib/gmo/const.rb index 1daa933..84647ad 100644 --- a/lib/gmo/const.rb +++ b/lib/gmo/const.rb @@ -12,6 +12,12 @@ module Const apple_pay: 'APay' }.freeze + RECURRING_REGIST_TYPE = { + member_id: '1', + card_number: '2', + order_id: '3' + } + INPUT_PARAMS = { :access_id => "AccessID", :access_pass => "AccessPass", @@ -36,6 +42,10 @@ module Const :card_no => "CardNo", :card_pass => "CardPass", :card_seq => "CardSeq", + :charge_day => "ChargeDay", + :charge_month => "ChargeMonth", + :charge_start_date => "ChargeStartDate", + :charge_stop_date => "ChargeStopDate", :client_field_1 => "ClientField1", :client_field_2 => "ClientField2", :client_field_3 => "ClientField3", @@ -98,7 +108,9 @@ module Const :receipts_disp_11 => "ReceiptsDisp11", :receipts_disp_12 => "ReceiptsDisp12", :receipts_disp_13 => "ReceiptsDisp13", + :recurring_id => "RecurringID", :redirect_url => "RedirectURL", + :regist_type => "RegistType", :register_disp_1 => "RegisterDisp1", :register_disp_2 => "RegisterDisp2", :register_disp_3 => "RegisterDisp3", @@ -118,6 +130,7 @@ module Const :shop_pass => "ShopPass", :site_id => "SiteID", :site_pass => "SitePass", + :src_order_id => "SrcOrderID", :suica_add_info_1 => "SuicaAddInfo1", :suica_add_info_2 => "SuicaAddInfo2", :suica_add_info_3 => "SuicaAddInfo3", From 560e71a96c8c82200da5c7d44dd60ec5245e587f Mon Sep 17 00:00:00 2001 From: yalab Date: Mon, 3 Sep 2018 18:42:59 +0900 Subject: [PATCH 2/3] Add #register_recurring_credit. --- .../_register_recurring_credit_got_data.yml | 36 ++++++++++++ lib/gmo/shop_and_site_api.rb | 55 +++++++++++++++++++ spec/gmo/shop_and_site_api_spec.rb | 14 +++++ 3 files changed, 105 insertions(+) create mode 100644 fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_register_recurring_credit_got_data.yml diff --git a/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_register_recurring_credit_got_data.yml b/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_register_recurring_credit_got_data.yml new file mode 100644 index 0000000..80ab7e7 --- /dev/null +++ b/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_register_recurring_credit_got_data.yml @@ -0,0 +1,36 @@ +--- +http_interactions: +- request: + method: post + uri: https:///payment/RegisterRecurringCredit.idPass + body: + encoding: UTF-8 + string: RecurringID=53596492&Amount=00&ChargeDay=3&RegistType=&MemberID=smama_development_user_&SiteID=&SitePass=&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Mon, 03 Sep 208 08:55:2 GMT + Content-Type: + - text/plain;charset=Windows-3J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: ShopID=&RecurringID=53596492&Amount=00&Tax=0&ChargeDay=3&ChargeMonth=0|02|03|04|05|06|07|08|09|0||2&ChargeStartDate=2080904&ChargeStopDate=&NextChargeDate=2080930&Method=RECURRING_CREDIT&CardNo=&Expire=&SiteID=&MemberID=smama_development_user_ + http_version: + recorded_at: Mon, 03 Sep 2018 08:55:22 GMT +recorded_with: VCR 4.0.0 diff --git a/lib/gmo/shop_and_site_api.rb b/lib/gmo/shop_and_site_api.rb index 73c1d97..c2b60b4 100644 --- a/lib/gmo/shop_and_site_api.rb +++ b/lib/gmo/shop_and_site_api.rb @@ -103,6 +103,61 @@ def exec_tran_brandtoken(options = {}) post_request name, options end + ### @params ### + # ShopID + # ShopPass + # RecurringID + # Amount + # Tax + # ChargeDay + # ChargeMonth + # ChargeStartDate + # ChargeStopDate + # RegistType + # SiteID + # SitePass + # MemberID + # CardNo + # Expire + # SrcOrderID + # ClientField1 + # ClientField2 + # ClientField3 + ### @return ### + # ShopID + # RecurringID + # Amount + # Tax + # ChargeDay + # ChargeMonth + # ChargeStartDate + # ChargeStopDate + # NextChargeDate + # Method + ### example ### + # gmo.register_recurring_credit({ + # recurring_id: "1535964921", + # amount: 100, + # regist_type: GMO::Const::RECURRING_REGIST_TYPE[:member_id], + # member_id: "mem10001" + # }) + # => {"ShopID"=>"tshop0001", "RecurringID"=>"1535964921", "Amount"=>"100", "Tax"=>"0", "ChargeDay"=>"31", "ChargeMonth"=>"01|02|03|04|05|06|07|08|09|10|11|12", "ChargeStartDate"=>"20180904", "ChargeStopDate"=>"", "NextChargeDate"=>"20180930", "Method"=>"RECURRING_CREDIT", "CardNo"=>"", "Expire"=>"", "SiteID"=>"", "MemberID"=>"mem1001"} + def register_recurring_credit(options = {}) + name = "RegisterRecurringCredit.idPass" + required = [:recurring_id, :charge_day, :amount, :regist_type] + required += case options[:regist_type].to_i + when 1 + options.update(site_id: @site_id, site_pass: @site_pass) + [:member_id] + when 2 + [:card_no, :expire] + when 3 + [:src_order_id] + end + assert_required_options(required, options) + post_request name, options + end + private def api_call(name, args = {}, verb = "post", options = {}) diff --git a/spec/gmo/shop_and_site_api_spec.rb b/spec/gmo/shop_and_site_api_spec.rb index efe6c28..c969d21 100644 --- a/spec/gmo/shop_and_site_api_spec.rb +++ b/spec/gmo/shop_and_site_api_spec.rb @@ -171,4 +171,18 @@ end end + describe "#register_recurring_credit" do + it "got data", :vcr do + recurring_id = generate_id + member_id = 'mem1001' + result = @service.register_recurring_credit({ + :recurring_id => recurring_id, + :amount => 100, + :charge_day => 31, + :regist_type => GMO::Const::RECURRING_REGIST_TYPE[:member_id], + :member_id => member_id, + }) + result["NextChargeDate"].nil?.should_not be true + end + end end From ce50aa3b5adb953d1719f0ff9efff9dea904af5c Mon Sep 17 00:00:00 2001 From: yalab Date: Tue, 4 Sep 2018 14:39:14 +0900 Subject: [PATCH 3/3] Add #unregister_recurring. --- ...nregister_recurring_success_unregister.yml | 69 +++++++++++++++++++ lib/gmo/shop_and_site_api.rb | 35 ++++++++++ spec/gmo/shop_and_site_api_spec.rb | 10 +++ 3 files changed, 114 insertions(+) create mode 100644 fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_unregister_recurring_success_unregister.yml diff --git a/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_unregister_recurring_success_unregister.yml b/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_unregister_recurring_success_unregister.yml new file mode 100644 index 0000000..0c607eb --- /dev/null +++ b/fixtures/vcr_cassettes/GMO_Payment_ShopAndSiteAPI/_unregister_recurring_success_unregister.yml @@ -0,0 +1,69 @@ +--- +http_interactions: +- request: + method: post + uri: https:///payment/RegisterRecurringCredit.idPass + body: + encoding: UTF-8 + string: RecurringID=536039393&Amount=00&ChargeDay=3&RegistType=&MemberID=smama_development_user_&SiteID=&SitePass=&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 04 Sep 208 05:36:34 GMT + Content-Type: + - text/plain;charset=Windows-3J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: ShopID=&RecurringID=536039393&Amount=00&Tax=0&ChargeDay=3&ChargeMonth=0|02|03|04|05|06|07|08|09|0||2&ChargeStartDate=2080905&ChargeStopDate=&NextChargeDate=2080930&Method=RECURRING_CREDIT&CardNo=&Expire=&SiteID=&MemberID=smama_development_user_ + http_version: + recorded_at: Tue, 04 Sep 2018 05:36:34 GMT +- request: + method: post + uri: https:///payment/UnregisterRecurring.idPass + body: + encoding: UTF-8 + string: RecurringID=536039393&SiteID=&SitePass=&ShopID=&ShopPass= + headers: + Accept-Encoding: + - gzip;q=.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + response: + status: + code: 200 + message: OK + headers: + Server: + - nginx + Date: + - Tue, 04 Sep 208 05:36:34 GMT + Content-Type: + - text/plain;charset=Windows-3J + Transfer-Encoding: + - chunked + Connection: + - close + body: + encoding: UTF-8 + string: ShopID=&RecurringID=536039393&Amount=00&Tax=0&ChargeDay=3&ChargeMonth=0|02|03|04|05|06|07|08|09|0||2&ChargeStartDate=2080905&ChargeStopDate=&NextChargeDate=&Method=RECURRING_CREDIT&CardNo=&Expire=&SiteID=&MemberID=smama_development_user_&PrintStr= + http_version: + recorded_at: Tue, 04 Sep 2018 05:36:34 GMT +recorded_with: VCR 4.0.0 diff --git a/lib/gmo/shop_and_site_api.rb b/lib/gmo/shop_and_site_api.rb index c2b60b4..db3bbf7 100644 --- a/lib/gmo/shop_and_site_api.rb +++ b/lib/gmo/shop_and_site_api.rb @@ -158,6 +158,41 @@ def register_recurring_credit(options = {}) post_request name, options end + ### @params ### + # ShopID + # ShopPass + # RecurringID + ### @return ### + # ShopID + # RecurringID + # Amount + # Tax + # ChargeDay + # ChargeMonth + # ChargeStartDate + # ChargeStopDate + # NextChargeDate + # Method + # SiteID + # MemberID + # CardNo + # Expire + # PrintStr + # ErrCode + # ErrInfo + ### example ### + # gmo.unregister_recurring({ + # recurring_id: "1535964921" + # }) + # => {"ShopID"=>"tshop0001", "RecurringID"=>"1536039145", "Amount"=>"100", "Tax"=>"0", "ChargeDay"=>"31", "ChargeMonth"=>"01|02|03|04|05|06|07|08|09|10|11|12", "ChargeStartDate"=>"20180905", "ChargeStopDate"=>"", "NextChargeDate"=>"", "Method"=>"RECURRING_CREDIT", "CardNo"=>"", "Expire"=>"", "SiteID"=>"tsite0001", "MemberID"=>"mem1001", "PrintStr"=>""} + def unregister_recurring(options = {}) + name = "UnregisterRecurring.idPass" + options.merge!(site_id: @site_id, site_pass: @site_pass) + required = [:recurring_id] + assert_required_options(required, options) + post_request name, options + end + private def api_call(name, args = {}, verb = "post", options = {}) diff --git a/spec/gmo/shop_and_site_api_spec.rb b/spec/gmo/shop_and_site_api_spec.rb index c969d21..2437eb1 100644 --- a/spec/gmo/shop_and_site_api_spec.rb +++ b/spec/gmo/shop_and_site_api_spec.rb @@ -185,4 +185,14 @@ result["NextChargeDate"].nil?.should_not be true end end + + describe "#unregister_recurring" do + it "success unregister", :vcr do + recurring_id = generate_id + result = @service.unregister_recurring({ + recurring_id: recurring_id + }) + result["Method"].should == "RECURRING_CREDIT" + end + end end