Skip to content

Commit

Permalink
Merge pull request #28 from payjp/nonz250/add-statement-api
Browse files Browse the repository at this point in the history
feat: add statement api.
  • Loading branch information
darai0512 authored Nov 9, 2023
2 parents a2a7113 + e1d41e8 commit e04b9da
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: push
jobs:
build-test:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
ruby-version: [2.0.0, 2.1, 2.2, 2.3.0, 2.7.0, jruby-9.2.17.0]
Expand Down
1 change: 1 addition & 0 deletions lib/payjp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
require 'payjp/event'
require 'payjp/transfer'
require 'payjp/card'
require 'payjp/statement'
require 'payjp/subscription'
require 'payjp/tenant'

Expand Down
16 changes: 16 additions & 0 deletions lib/payjp/statement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Payjp
class Statement < APIResource
include Payjp::APIOperations::List

def create_statement_urls(params = {}, opts = {})
response, opts = request(:post, create_statement_urls_url, params, opts)
response
end

private

def create_statement_urls_url
url + '/statement_urls'
end
end
end
1 change: 1 addition & 0 deletions lib/payjp/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def self.object_classes
'tenant' => Tenant,
'event' => Event,
'plan' => Plan,
'statement' => Statement,
'subscription' => Subscription,
'token' => Token,
'transfer' => Transfer
Expand Down
33 changes: 33 additions & 0 deletions test/payjp/statement_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require File.expand_path('../../test_helper', __FILE__)

module Payjp
class StatementTest < Test::Unit::TestCase
should "statement should be listable" do
@mock.expects(:get).once.returns(test_response(test_statement_array))
statements = Payjp::Statement.all.data
assert statements.is_a? Array
assert statements[0].is_a? Payjp::Statement
end

should "be retrievable" do
@mock.expects(:get).once.returns(test_response(test_statement))
statement = Payjp::Statement.retrieve('st_test')
assert statement.is_a? Payjp::Statement
assert_equal 'st_test', statement.id
assert_equal 'statement', statement.object
assert statement.to_hash.has_key?(:items)
assert statement.items[0].to_hash.has_key?(:amount)
assert statement.items[0].to_hash.has_key?(:name)
assert statement.items[0].to_hash.has_key?(:subject)
assert statement.items[0].to_hash.has_key?(:tax_rate)
end

should "create_statement_urls should be callable" do
@mock.expects(:get).never
@mock.expects(:post).once.returns(test_response({ :object => "statement_url", :url => 'https://pay.jp/_/statements/8f9ec721bc734dbcxxxxxxxxxxxxxxxx', :expires => 1476676539 }))
c = Payjp::Statement.new('st_test')
response = c.create_statement_urls()
assert_equal response[:url], 'https://pay.jp/_/statements/8f9ec721bc734dbcxxxxxxxxxxxxxxxx'
end
end
end
44 changes: 44 additions & 0 deletions test/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,49 @@ def test_over_capacity_error
}
}
end

def test_statement(params = {})
{
:created => 1695620296,
:id => "st_test",
:items => [
{
:amount => 282358654,
:name => "売上",
:subject => "gross_sales",
:tax_rate => "0.00"
},
{
:amount => -65699624,
:name => "返金",
:subject => "gross_refund",
:tax_rate => "0.00"
},
{
:amount => -7054912,
:name => "決済手数料",
:subject => "fee",
:tax_rate => "0.10"
},
{
:amount => 1644315,
:name => "返金による手数料返還",
:subject => "refund_fee_offset",
:tax_rate => "0.10"
}
],
:object => "statement",
:title => nil
}.merge(params)
end

def test_statement_array
{
:count => 2,
:data => [test_statement, test_statement],
:object => 'list',
:url => '/v1/statements'
}
end
end
end

0 comments on commit e04b9da

Please sign in to comment.