Skip to content

Commit

Permalink
add statement/balance/term resources
Browse files Browse the repository at this point in the history
  • Loading branch information
darai0512 committed Apr 1, 2024
1 parent a8b4bee commit 0c8fd28
Show file tree
Hide file tree
Showing 8 changed files with 213 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 @@ -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
15 changes: 15 additions & 0 deletions lib/Net/Payjp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,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;
41 changes: 41 additions & 0 deletions t/balance.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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->transfer->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');
40 changes: 40 additions & 0 deletions t/statement.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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->tenant, 'Net::Payjp::Statement');
can_ok($payjp->tenant, 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);

Check failure on line 22 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.30 on ubuntu-latest

Bareword "merchant" not allowed while "strict subs" in use

Check failure on line 22 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.38 on ubuntu-latest

Bareword "merchant" not allowed while "strict subs" in use
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/);
} );
$tenant->statement_urls(platformer => true);

Check failure on line 38 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.30 on ubuntu-latest

Global symbol "$tenant" requires explicit package name (did you forget to declare "my $tenant"?)

Check failure on line 38 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.30 on ubuntu-latest

Bareword "true" not allowed while "strict subs" in use

Check failure on line 38 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.38 on ubuntu-latest

Global symbol "$tenant" requires explicit package name (did you forget to declare "my $tenant"?)

Check failure on line 38 in t/statement.t

View workflow job for this annotation

GitHub Actions / Testing perl 5.38 on ubuntu-latest

Bareword "true" not allowed while "strict subs" in use
is($Mock_req->{new_args}[1], 'POST');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/statements/req1/application_urls');
41 changes: 41 additions & 0 deletions t/term.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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->transfer->all(since_start_at => 1111111);
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/terms?since_start_at=11111111');
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');

0 comments on commit 0c8fd28

Please sign in to comment.