Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add statement/balance/term resources #12

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
perl: [ '5.10', '5.30' ]
perl: [ '5.30', '5.38' ]
name: Testing perl ${{ matrix.perl }} on ${{ matrix.os }}
env:
PERL_VERSION: ${{ matrix.perl }}
Expand Down
18 changes: 18 additions & 0 deletions lib/Net/Payjp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use Net::Payjp::Transfer;
use Net::Payjp::Event;
use Net::Payjp::Tenant;
use Net::Payjp::TenantTransfer;
use Net::Payjp::Statement;
use Net::Payjp::Balance;
use Net::Payjp::Term;
use Net::Payjp::Object;

# ABSTRACT: API client for pay.jp
Expand Down Expand Up @@ -538,6 +541,21 @@ sub tenant_transfer{
return Net::Payjp::TenantTransfer->new(%$self);
}

sub statement{
my $self = shift;
return Net::Payjp::Statement->new(%$self);
}

sub balance{
my $self = shift;
return Net::Payjp::Balance->new(%$self);
}

sub term{
my $self = shift;
return Net::Payjp::Term->new(%$self);
}

sub _request{
my $self = shift;
my %p = @_;
Expand Down
23 changes: 23 additions & 0 deletions lib/Net/Payjp/Balance.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Net::Payjp::Balance;

use strict;
use warnings;

use base 'Net::Payjp';

sub retrieve{
my $self = shift;
my $id = shift;
$self->id($id) if $id;

$self->_request(method => 'GET', url => $self->_instance_url);
}

sub all{
my $self = shift;
my %p = @_;

$self->_request(method => 'GET', url => $self->_class_url, param => \%p);
}

1;
29 changes: 29 additions & 0 deletions lib/Net/Payjp/Statement.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Net::Payjp::Statement;

use strict;
use warnings;

use base 'Net::Payjp';

sub retrieve{
my $self = shift;
my $id = shift;
$self->id($id) if $id;

$self->_request(method => 'GET', url => $self->_instance_url);
}

sub all{
my $self = shift;
my %p = @_;

$self->_request(method => 'GET', url => $self->_class_url, param => \%p);
}

sub statement_urls{
my $self = shift;

$self->_request(method => 'POST', url => $self->_instance_url . '/statement_urls');
}

1;
23 changes: 23 additions & 0 deletions lib/Net/Payjp/Term.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Net::Payjp::Term;

use strict;
use warnings;

use base 'Net::Payjp';

sub retrieve{
my $self = shift;
my $id = shift;
$self->id($id) if $id;

$self->_request(method => 'GET', url => $self->_instance_url);
}

sub all{
my $self = shift;
my %p = @_;

$self->_request(method => 'GET', url => $self->_class_url, param => \%p);
}

1;
43 changes: 43 additions & 0 deletions t/balance.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::Mock::LWP;
use Test::More;

use Net::Payjp;

my $payjp = Net::Payjp->new(api_key => 'api_key');

isa_ok($payjp->balance, 'Net::Payjp::Balance');
can_ok($payjp->balance, qw(retrieve all));
ok(!$payjp->transfer->can('create'));
ok(!$payjp->transfer->can('save'));
ok(!$payjp->transfer->can('delete'));

$Mock_resp->mock( content => sub { '{"object":"list"}' } );
$Mock_resp->mock( code => sub {200} );
$Mock_ua->mock( timeout => sub {} );
$Mock_ua->mock( default_header => sub {} );

#List
my $res = $payjp->balance->all(type => 'collecting');
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/balances?type=collecting');
is($res->object, 'list');

#Set id.
$payjp->id('req1');

#Retrieve
$Mock_resp->mock( content => sub { '{"id":"req2"}' } );
my $balance = $payjp->balance;
is($balance->id, 'req1');
$balance->retrieve;
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/balances/req1');
is($balance->id, 'req2');
is($payjp->id, 'req1');

done_testing();
42 changes: 42 additions & 0 deletions t/statement.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::Mock::LWP;
use Test::More;

use Net::Payjp;

my $payjp = Net::Payjp->new(api_key => 'api_key');

isa_ok($payjp->statement, 'Net::Payjp::Statement');
can_ok($payjp->statement, qw(retrieve all statement_urls));

$Mock_resp->mock( content => sub { '{"object":"list"}' } );
$Mock_resp->mock( code => sub {200} );
$Mock_ua->mock( timeout => sub {} );
$Mock_ua->mock( default_header => sub {} );

#List
my $res = $payjp->statement->all(owner => 'merchant');
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/statements?owner=merchant');
is($res->object, 'list');

#Retrieve
my $statement = $payjp->statement;
$statement->retrieve('req1');
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/statements/req1');
is($statement->id, 'req1');

$Mock_req->mock( content => sub {
my $p = $_[1];
like($p, qr/platformer=true/);
} );
$statement->statement_urls(platformer => 'true');
is($Mock_req->{new_args}[1], 'POST');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/statements/req1/statement_urls');

done_testing();
43 changes: 43 additions & 0 deletions t/term.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::Mock::LWP;
use Test::More;

use Net::Payjp;

my $payjp = Net::Payjp->new(api_key => 'api_key');

isa_ok($payjp->term, 'Net::Payjp::Term');
can_ok($payjp->term, qw(retrieve all));
ok(!$payjp->transfer->can('create'));
ok(!$payjp->transfer->can('save'));
ok(!$payjp->transfer->can('delete'));

$Mock_resp->mock( content => sub { '{"object":"list"}' } );
$Mock_resp->mock( code => sub {200} );
$Mock_ua->mock( timeout => sub {} );
$Mock_ua->mock( default_header => sub {} );

#List
my $res = $payjp->term->all(since_start_at => 1);
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/terms?since_start_at=1');
is($res->object, 'list');

#Set id.
$payjp->id('req1');

#Retrieve
$Mock_resp->mock( content => sub { '{"id":"req2"}' } );
my $term = $payjp->term;
is($term->id, 'req1');
$term->retrieve;
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/terms/req1');
is($term->id, 'req2');
is($payjp->id, 'req1');

done_testing();
Loading