Skip to content

Commit

Permalink
add term/balance
Browse files Browse the repository at this point in the history
  • Loading branch information
niheeeee committed Mar 29, 2024
1 parent aa50175 commit 9a371be
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/payjp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
require 'payjp/statement'
require 'payjp/subscription'
require 'payjp/tenant'
require 'payjp/term'
require 'payjp/balance'

# Errors
require 'payjp/errors/payjp_error'
Expand Down
5 changes: 5 additions & 0 deletions lib/payjp/balance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Payjp
class Balance < APIResource
include Payjp::APIOperations::List
end
end
5 changes: 5 additions & 0 deletions lib/payjp/term.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Payjp
class Term < APIResource
include Payjp::APIOperations::List
end
end
2 changes: 2 additions & 0 deletions lib/payjp/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def self.object_classes

# business objects
'account' => Account,
'balance' => Balance,
'card' => Card,
'charge' => Charge,
'customer' => Customer,
Expand All @@ -30,6 +31,7 @@ def self.object_classes
'plan' => Plan,
'statement' => Statement,
'subscription' => Subscription,
'term' => Term,
'token' => Token,
'transfer' => Transfer
}
Expand Down
2 changes: 1 addition & 1 deletion lib/payjp/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Payjp
VERSION = '0.0.13'
VERSION = '0.0.14'
end
26 changes: 26 additions & 0 deletions test/payjp/balance_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require File.expand_path('../../test_helper', __FILE__)

module Payjp
class BalanceTest < Test::Unit::TestCase
should "balances should be listable" do
@mock.expects(:get).once.returns(test_response(test_balance_array))
c = Payjp::Balance.all.data
assert c.is_a? Array
assert c[0].is_a? Payjp::Balance
end

should "retrieve should retrieve balance" do
@mock.expects(:get).once.returns(test_response(test_balance))
balance = Payjp::Balance.retrieve('ba_test_balance')
assert_equal 'ba_test_balance', balance.id
end

should "balances should not be deletable" do
assert_raises NoMethodError do
@mock.expects(:get).once.returns(test_response(test_balance))
balance = Payjp::Balance.retrieve('ba_test_balance')
balance.delete
end
end
end
end
26 changes: 26 additions & 0 deletions test/payjp/term_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require File.expand_path('../../test_helper', __FILE__)

module Payjp
class TermTest < Test::Unit::TestCase
should "terms should be listable" do
@mock.expects(:get).once.returns(test_response(test_term_array))
c = Payjp::Term.all.data
assert c.is_a? Array
assert c[0].is_a? Payjp::Term
end

should "retrieve should retrieve term" do
@mock.expects(:get).once.returns(test_response(test_term))
term = Payjp::Term.retrieve('tm_test_term')
assert_equal 'tm_test_term', term.id
end

should "terms should not be deletable" do
assert_raises NoMethodError do
@mock.expects(:get).once.returns(test_response(test_term))
term = Payjp::Term.retrieve('tm_test_term')
term.delete
end
end
end
end
52 changes: 52 additions & 0 deletions test/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,57 @@ def test_statement_array
:url => '/v1/statements'
}
end

def test_term_array
{
:count => 3,
:data => [test_term, test_term, test_term],
:object => 'list',
:url => '/v1/terms'
}
end

def test_term(params = {})
{
:created => 1438354800,
:id => "tm_test_term",
:livemode => false,
:object => "term",
:charge_count => 158,
:refund_count => 25,
:dispute_count => 2,
:end_at => 1439650800,
:start_at => 1438354800
}.merge(params)
end

def test_balance_array
{
:count => 3,
:data => [test_balance, test_balance, test_balance],
:object => 'list',
:url => '/v1/terms'
}
end

def test_balance(params = {})
{
:created => 1438354800,
:id => 'ba_test_balance',
:livemode => false,
:net => 1000,
:object => 'balance',
:type => 'collecting',
:statements => {
:count => 2,
:data => [test_statement,test_statement],
:object => 'list',
:url => '/v1/statements'
},
:closed => false,
:due_date => nil,
:bank_info => nil
}.merge(params)
end
end
end

0 comments on commit 9a371be

Please sign in to comment.