Skip to content
Open
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
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@
"php": ">=7.0.0",
"ext-json": "*",
"firebase/php-jwt": "^5.5 || ^6.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0"
"psr/http-client": "^1.0",
"psr/http-message": "^1.0 || ^2.0"
},
"suggest": {
"guzzlehttp/guzzle": "^7.0 - PSR-18 implementation",
"symfony/http-client": "^6.0 || ^7.0 - PSR-18 implementation"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16 || ^3.0",
"php-coveralls/php-coveralls": "^2.2",
"phpstan/phpstan": "^0.12.33 || ^1.0.0",
"phpunit/phpunit": "^9"
"phpunit/phpunit": "^9",
"guzzlehttp/guzzle": "^7.0"
},
"scripts": {
"test": "./vendor/bin/phpunit --testdox tests",
Expand Down
18 changes: 9 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PayPay\OpenPaymentAPI;

use GuzzleHttp\Client as GuzzleHttpClient;
use Psr\Http\Client\ClientInterface;
use PayPay\OpenPaymentAPI\Controller\Code;
use PayPay\OpenPaymentAPI\Controller\Payment;
use PayPay\OpenPaymentAPI\Controller\Refund;
Expand Down Expand Up @@ -43,9 +43,9 @@ class Client
*/
private $versions;
/**
* Guzzle client to handle http calls
* PSR Http compatible client to handle http calls
*
* @var GuzzleHttpClient
* @var ClientInterface
*/
private $requestHandler;
/**
Expand Down Expand Up @@ -90,10 +90,10 @@ class Client
* optional auth handler, and options
* @param array|null $auth API credentials
* @param boolean|string $productionmode Sandbox environment flag
* @param GuzzleHttpClient|boolean $requestHandler
* @param ClientInterface|null $requestHandler
* @throws ClientException
*/
public function __construct($auth = null, $productionmode = false, $requestHandler = false)
public function __construct($auth = null, $productionmode = false, $requestHandler = null)
{
if (!isset($auth['API_KEY']) || !isset($auth['API_SECRET'])) {
throw new ClientException("Invalid auth credentials", 1);
Expand All @@ -106,10 +106,10 @@ public function __construct($auth = null, $productionmode = false, $requestHandl
$this->endpoints = require(__DIR__ . '/conf/endpoints.php');
$this->apiMappings = require(__DIR__ . '/conf/apiMappings.php');
$this->versions = require(__DIR__ . '/conf/apiVersions.php');
if (!$requestHandler) {
$this->requestHandler = new GuzzleHttpClient(['base_uri' => $this->config["API_URL"]]);
if ($requestHandler === null) {
$this->requestHandler = new \GuzzleHttp\Client(['base_uri' => $this->config["API_URL"]]);
} else {
if ($requestHandler instanceof GuzzleHttpClient) {
if ($requestHandler instanceof ClientInterface) {
$this->requestHandler = $requestHandler;
} else {
throw new ClientException('Invalid request handler.', 500);
Expand Down Expand Up @@ -189,7 +189,7 @@ function ($mapping) use ($apiName) {
/**
* get client request handler for controller
*
* @return GuzzleHttpClient
* @return ClientInterface
*/
public function http()
{
Expand Down
12 changes: 6 additions & 6 deletions src/Controllers/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace PayPay\OpenPaymentAPI\Controller;

use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\RequestExceptionInterface;
use PayPay\OpenPaymentAPI\Client;
use PayPay\OpenPaymentAPI\Models\CapturePaymentAuthPayload;
use PayPay\OpenPaymentAPI\Models\CreateContinuousPaymentPayload;
Expand Down Expand Up @@ -41,7 +41,7 @@ public function __construct($MainInstance, $auth)
* @return array
* @throws ClientControllerException
* @throws ModelException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
public function createPayment($payload, $agreeSimilarTransaction = false)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ public function cancelPayment($merchantPaymentId, $paymentType = 'web_cashier')
* @return array
* @throws ClientControllerException
* @throws ModelException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
public function createPaymentAuth($payload, $agreeSimilarTransaction = false)
{
Expand Down Expand Up @@ -220,7 +220,7 @@ public function revertAuth($payload)
* @param array $data
* @return array
* @throws ClientControllerException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
private function doSimilarTransactionCall($apiId, $url, $options, $data)
{
Expand All @@ -240,7 +240,7 @@ private function doSimilarTransactionCall($apiId, $url, $options, $data)
'timeout' => $options['TIMEOUT']
]
);
} catch (RequestException $e) {
} catch (RequestExceptionInterface $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Controllers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace PayPay\OpenPaymentAPI\Controller;

use Firebase\JWT;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\RequestExceptionInterface;
use PayPay\OpenPaymentAPI\Models\AccountLinkPayload;
use PayPay\OpenPaymentAPI\Models\ModelException;

Expand Down Expand Up @@ -86,7 +86,7 @@ public function decodeUserAuth($encodedString)
* @param string $userAuthorizationId
* @return array
* @throws ClientControllerException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
public function getUserAuthorizationStatus($userAuthorizationId)
{
Expand All @@ -106,7 +106,7 @@ public function getUserAuthorizationStatus($userAuthorizationId)
* @param string $userAuthorizationId
* @return array
* @throws ClientControllerException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
public function getMaskedUserProfile($userAuthorizationId)
{
Expand All @@ -128,7 +128,7 @@ public function getMaskedUserProfile($userAuthorizationId)
* @param string $userAuthorizationId
* @return array
* @throws ClientControllerException
* @throws GuzzleException
* @throws ClientExceptionInterface
*/
private function doAuthCall($apiId, $url, $options, $userAuthorizationId)
{
Expand All @@ -141,7 +141,7 @@ private function doAuthCall($apiId, $url, $options, $userAuthorizationId)
'query' => ['userAuthorizationId' => $userAuthorizationId]
]
);
} catch (RequestException $e) {
} catch (RequestExceptionInterface $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
Expand Down
10 changes: 6 additions & 4 deletions src/core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PayPay\OpenPaymentAPI\Controller;

use GuzzleHttp\Exception\RequestException;
use Psr\Http\Client\RequestExceptionInterface;
use PayPay\OpenPaymentAPI\Client;

use function PayPay\OpenPaymentAPI\Helpers\PayPayEncryptHeader;
Expand Down Expand Up @@ -130,7 +130,8 @@ protected function doCall($lookupApi, $apiId, $url, $data, $options)
$response = null;
try {
if ($callType === 'post') {
$response = $request->$callType(
$response = $request->request(
$callType,
$url,
[
'headers' => $options["HEADERS"],
Expand All @@ -140,14 +141,15 @@ protected function doCall($lookupApi, $apiId, $url, $data, $options)
);
}
if ($callType === 'get' || $callType === 'delete') {
$response = $request->$callType(
$response = $request->request(
$callType,
$url,
[
'headers' => $options["HEADERS"]
]
);
}
} catch (RequestException $e) {
} catch (RequestExceptionInterface $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
}
Expand Down