Skip to content

Commit

Permalink
Merge pull request #31 from jiraffeinc/recurring
Browse files Browse the repository at this point in the history
Recurring API
  • Loading branch information
jiikko authored Jul 8, 2022
2 parents 6973815 + ce50aa3 commit 1718e1f
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 0 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.

13 changes: 13 additions & 0 deletions lib/gmo/const.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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",
Expand All @@ -38,6 +44,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",
Expand Down Expand Up @@ -102,7 +112,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",
Expand All @@ -122,6 +134,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",
Expand Down
90 changes: 90 additions & 0 deletions lib/gmo/shop_and_site_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,96 @@ 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

### @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 = {})
Expand Down
24 changes: 24 additions & 0 deletions spec/gmo/shop_and_site_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,28 @@
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

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

0 comments on commit 1718e1f

Please sign in to comment.