Skip to content

Commit

Permalink
Merge pull request #44 from payjp/nonz250/feat-three-d-secure-endpoint
Browse files Browse the repository at this point in the history
feat: add endpoints about ThreeDSecureRequest object.
  • Loading branch information
nonz250 authored Nov 13, 2024
2 parents 4e33305 + 7d55fea commit f8fe318
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.1
1.7.0
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
require(dirname(__FILE__) . '/lib/Tenant.php');
require(dirname(__FILE__) . '/lib/TenantTransfer.php');
require(dirname(__FILE__) . '/lib/Term.php');
require(dirname(__FILE__) . '/lib/ThreeDSecureRequest.php');
require(dirname(__FILE__) . '/lib/Token.php');
require(dirname(__FILE__) . '/lib/Transfer.php');
44 changes: 44 additions & 0 deletions lib/ThreeDSecureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Payjp;

class ThreeDSecureRequest extends ApiResource
{
public static function className()
{
return 'three_d_secure_request';
}

/**
* @param string $id The ID of the three d secure request to retrieve.
* @param array|string|null $opts
*
* @return ThreeDSecureRequest
*/
public static function retrieve($id, $opts = null)
{
return self::_retrieve($id, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return array An array of ThreeDSecureRequests.
*/
public static function all($params = null, $opts = null)
{
return self::_all($params, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return ThreeDSecureRequest The created three d secure request.
*/
public static function create($params = null, $opts = null)
{
return self::_create($params, $opts);
}
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class Util
'tenant_transfer' => \Payjp\TenantTransfer::class,
'term' => \Payjp\Term::class,
'transfer' => \Payjp\Transfer::class,
'three_d_secure_request' => \Payjp\ThreeDSecureRequest::class,
);

/**
Expand Down
82 changes: 82 additions & 0 deletions tests/ThreeDSecureRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Payjp;

class ThreeDSecureRequestTest extends TestCase
{

private function managedThreeDSecureRequestResource($id)
{
return [
'created' => 1730084767,
'expired_at' => null,
'finished_at' => null,
'id' => $id,
'livemode' => true,
'object' => 'three_d_secure_request',
'resource_id' => 'car_xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'result_received_at' => null,
'started_at' => null,
'state' => 'created',
'tenant_id' => null,
'three_d_secure_status' => 'unverified'
];
}

private function managedThreeDSecureRequestResources($ids)
{
return [
'count' => count($ids),
'data' => array_map(function ($id) {
return $this->managedThreeDSecureRequestResource($id);
}, $ids),
'has_more' => false,
'object' => 'list',
'url' => '/v1/three_d_secure_requests'
];
}

public function testRetrieve()
{
$expectedThreeDSecureRequestId = 'tdsr_125192559c91c4011c1ff56f50a';
$expectedThreeDSecureRequestResource = $this->managedThreeDSecureRequestResource($expectedThreeDSecureRequestId);
$this->mockRequest('GET', '/v1/three_d_secure_requests/' . $expectedThreeDSecureRequestId, [], $expectedThreeDSecureRequestResource);
$threeDSecureRequest = ThreeDSecureRequest::retrieve($expectedThreeDSecureRequestId);
$this->assertSame($expectedThreeDSecureRequestResource['created'], $threeDSecureRequest->created);
$this->assertSame($expectedThreeDSecureRequestResource['expired_at'], $threeDSecureRequest->expired_at);
$this->assertSame($expectedThreeDSecureRequestResource['finished_at'], $threeDSecureRequest->finished_at);
$this->assertSame($expectedThreeDSecureRequestResource['id'], $threeDSecureRequest->id);
$this->assertSame($expectedThreeDSecureRequestResource['livemode'], $threeDSecureRequest->livemode);
$this->assertSame($expectedThreeDSecureRequestResource['object'], $threeDSecureRequest->object);
$this->assertSame($expectedThreeDSecureRequestResource['resource_id'], $threeDSecureRequest->resource_id);
$this->assertSame($expectedThreeDSecureRequestResource['result_received_at'], $threeDSecureRequest->result_received_at);
$this->assertSame($expectedThreeDSecureRequestResource['started_at'], $threeDSecureRequest->started_at);
$this->assertSame($expectedThreeDSecureRequestResource['state'], $threeDSecureRequest->state);
$this->assertSame($expectedThreeDSecureRequestResource['tenant_id'], $threeDSecureRequest->tenant_id);
$this->assertSame($expectedThreeDSecureRequestResource['three_d_secure_status'], $threeDSecureRequest->three_d_secure_status);
}

public function testAll()
{
$expectedThreeDSecureRequestIds = array('tdsr_125192559c91c4011c1ff56f50a', 'tdsr_125192559c91c4011c1ff56f50b');
$this->mockRequest('GET', '/v1/three_d_secure_requests', array(), $this->managedThreeDSecureRequestResources($expectedThreeDSecureRequestIds));
$threeDSecureRequests = ThreeDSecureRequest::all();
$this->assertSame(count($expectedThreeDSecureRequestIds), $threeDSecureRequests['count']);
$this->assertCount(count($expectedThreeDSecureRequestIds), $threeDSecureRequests['data']);
$this->assertSame($expectedThreeDSecureRequestIds[0], $threeDSecureRequests['data'][0]->id);
$this->assertSame($expectedThreeDSecureRequestIds[1], $threeDSecureRequests['data'][1]->id);
}

public function testCreate()
{
$expectedThreeDSecureRequestId = 'tdsr_125192559c91c4011c1ff56f50a';
$expectedCustomerCardId = 'car_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$params = [
'resource_id' => $expectedCustomerCardId
];
$this->mockRequest('POST', '/v1/three_d_secure_requests', $params, $this->managedThreeDSecureRequestResource($expectedThreeDSecureRequestId));
$threeDSecureRequest = ThreeDSecureRequest::create($params);
$this->assertSame($expectedThreeDSecureRequestId, $threeDSecureRequest->id);
$this->assertSame($expectedCustomerCardId, $threeDSecureRequest->resource_id);
}
}

0 comments on commit f8fe318

Please sign in to comment.