Skip to content

Commit

Permalink
add tds_finish, add three_d_secure_request
Browse files Browse the repository at this point in the history
  • Loading branch information
natsuki-yamanaka committed Nov 14, 2024
1 parent b8fa7f3 commit d68fb87
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
36 changes: 36 additions & 0 deletions lib/Net/Payjp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use Net::Payjp::Statement;
use Net::Payjp::Balance;
use Net::Payjp::Term;
use Net::Payjp::Object;
use Net::Payjp::ThreeDSecureRequest;

# ABSTRACT: API client for pay.jp

Expand Down Expand Up @@ -489,6 +490,41 @@ sub transfer{
return Net::Payjp::Transfer->new(%$self);
}

=head1 ThreeDSecureRequest Methods
=head2 create
Create a three_d_secure_request
L<https://pay.jp/docs/api/#顧客を作成>
$payjp->three_d_secure_request->create(
"resource_id" => "car_xxxx",
);
=head2 retrieve
Retrieve a three_d_secure_request
L<https://pay.jp/docs/api/#顧客情報を取得>
$payjp->three_d_secure_request->retrieve('tdsr_xxxx');
=head2 all
Returns the three_d_secure_request list
L<https://pay.jp/docs/api/#顧客リストを取得>
$res = $payjp->three_d_secure_request->all(limit => 2, offset => 1);
=cut

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

=head1 Event Methods
=head2 retrieve
Expand Down
34 changes: 34 additions & 0 deletions lib/Net/Payjp/ThreeDSecureRequest.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package Net::Payjp::ThreeDSecureRequest;

use strict;
use warnings;

use base 'Net::Payjp';

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

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

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 _class_url{
my $self = shift;
return $self->api_base.'/v1/three_d_secure_requests';
}
1;
6 changes: 6 additions & 0 deletions lib/Net/Payjp/Token.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ sub retrieve{
$self->_request(method => 'GET', url => $self->_instance_url);
}

sub tds_finish{
my $self = shift;

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

1;
40 changes: 40 additions & 0 deletions t/three_d_secure_request.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 Net::Payjp;
use Test::More tests => 11;

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

isa_ok($payjp->three_d_secure_request, 'Net::Payjp::ThreeDSecureRequest');
can_ok($payjp->three_d_secure_request, qw(retrieve create all));

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

#Create
$Mock_req->mock( content => sub {
my $p = $_[1];
is($p, 'resource_id=car_xxxx');
} );
my $tds_request = $payjp->three_d_secure_request;
my $res = $tds_request->create(resource_id => 'car_xxxx');
is($Mock_req->{new_args}[1], 'POST');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/three_d_secure_requests');
is($res->id, 'tdsr_xxx');
is($tds_request->id, 'tdsr_xxx');

#Retrieve
$tds_request->retrieve;
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/three_d_secure_requests/tdsr_xxx');

#tds_finish
$tds_request->all;
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/three_d_secure_requests');
9 changes: 7 additions & 2 deletions t/token.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use warnings;

use Test::Mock::LWP;
use Net::Payjp;
use Test::More tests => 12;
use Test::More tests => 14;

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

isa_ok($payjp->token, 'Net::Payjp::Token');
can_ok($payjp->token, qw(retrieve create));
can_ok($payjp->token, qw(retrieve create tds_finish));
ok(!$payjp->token->can('all'));
ok(!$payjp->token->can('save'));
ok(!$payjp->token->can('delete'));
Expand All @@ -36,3 +36,8 @@ is($token->id, 'res1');
$token->retrieve;
is($Mock_req->{new_args}[1], 'GET');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/tokens/res1');

#tds_finish
$token->tds_finish;
is($Mock_req->{new_args}[1], 'POST');
is($Mock_req->{new_args}[2], 'https://api.pay.jp/v1/tokens/res1/tds_finish');

0 comments on commit d68fb87

Please sign in to comment.