Skip to content

Commit

Permalink
chore: add phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
enggar appkey committed Apr 5, 2022
1 parent 3987b68 commit b64eb99
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialize_package":4,"Warning":6,"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialization":4},"times":{"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialize_package":3.092,"Warning":0.001,"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialization":2.054}}
{"version":1,"defects":{"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialize_package":4,"Warning":6,"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialization":4},"times":{"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialize_package":2.122,"Warning":0.001,"Nekoding\\GmoPaymentGateway\\Tests\\GmoPaymentGatewayTest::test_initialization":2.054}}
14 changes: 12 additions & 2 deletions src/Contracts/Shop/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ abstract class CreditCard implements Api3DSv1, Api3DSv2, Basic
{
const TDSV1 = 1;
const TDSV2 = 2;


/**
* API Credential to connect GMO API
*
* @var array
*/
protected $apiCredential = [];

public function __construct(array $apiCredential)
{
$this->apiCredential = $apiCredential;
}


/**
* Get API credential
*
* @return array
*/
public function getApiCredential(): array
{
return $this->apiCredential;
Expand Down
8 changes: 7 additions & 1 deletion src/Core/ErrorMessageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
namespace Nekoding\GmoPaymentGateway\Core;

class ErrorMessageCollection
{
{
/**
* Error message collection
*
* @return array
* @see https://docs.mul-pay.jp/payment/credit/errorcode
*/
public static function getErrorMessages(): array
{
return [
Expand Down
16 changes: 14 additions & 2 deletions src/Core/Traits/ErrorParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
use Nekoding\GmoPaymentGateway\Core\ErrorMessageCollection;

trait ErrorParser
{
{
/**
* Parsing error message
*
* @param mixed $errorResponse
* @return array
*/
public function parseErrorMessages(string $errorResponse): array
{
parse_str($errorResponse, $res);
Expand All @@ -18,7 +24,13 @@ public function parseErrorMessages(string $errorResponse): array

return $errorMessages;
}


/**
* Get error message
*
* @param mixed $key
* @return string
*/
private function getErrorMessage(string $key): string
{
if (array_key_exists($key, ErrorMessageCollection::getErrorMessages())) {
Expand Down
78 changes: 55 additions & 23 deletions src/Core/Traits/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,77 @@

trait HttpClient
{


/**
* GMO Production endpoint
*
* @var string
*/
private $prodEndpoint = 'https://p01.mul-pay.jp';


/**
* GMO Sandbox endpoint
*
* @var string
*/
private $sandboxEndpoint = 'https://pt01.mul-pay.jp';

protected $httpClient;

protected $httpClientConfig;

public function initHttpClient()
/**
* @var \GuzzleHttp\Client $httpClient
*/
private $httpClient;

/**
* Initalize Http Client
*
* @return Client
*/
protected function initHttpClient(): Client
{
$this->httpClient = new Client([
'base_uri' => config('gmo-payment-gateway.is_sandbox') ?? env('GMO_API_SANDBOX_MODE', true) ? $this->sandboxEndpoint : $this->prodEndpoint,
'timeout' => config('gmo-payment-gateway.timeout') ?? env('GMO_API_TIMEOUT', 2),
]);
if (!$this->httpClient) {
$this->httpClient = new Client([
'base_uri' => config('gmo-payment-gateway.is_sandbox') ?? env('GMO_API_SANDBOX_MODE', true) ? $this->sandboxEndpoint : $this->prodEndpoint,
'timeout' => config('gmo-payment-gateway.timeout') ?? env('GMO_API_TIMEOUT', 2),
]);
}

return $this->httpClient;
}

/**
* Send HTTP Post Request
*
* @param string $url
* @param array $body
*/
public function post(string $url, array $body)
{
if (!$this->httpClient) {
$this->initHttpClient();
}

return $this->httpClient->post($url, [
return $this->initHttpClient()->post($url, [
'form_params' => $body
]);
}


/**
* Send HTTP Get Request
*
* @param string $url
* @param array $body
*/
public function get(string $url, array $body)
{
if (!$this->httpClient) {
$this->initHttpClient();
}

return $this->httpClient->get($url, [
return $this->initHttpClient()->get($url, [
'query' => $body
]);
}


/**
* Send HTTP Request
*
* @param string $url
* @param array $body
* @param string $httpMethod
* @throws \Nekoding\GmoPaymentGateway\Exceptions\HttpMethodException
*/
public function request(string $url, array $body, string $httpMethod = 'POST')
{
if ($httpMethod == GMOConst::HTTP_POST) {
Expand Down

0 comments on commit b64eb99

Please sign in to comment.