-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* card-charge: update README * card-charge: done
- Loading branch information
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Omnipay\Przelewy24\Message; | ||
|
||
class CardChargeRequest extends AbstractRequest | ||
{ | ||
public function getData(): array | ||
{ | ||
$this->validate('token'); | ||
|
||
return [ | ||
'token' => $this->getToken(), | ||
]; | ||
} | ||
|
||
public function sendData($data): CardChargeResponse | ||
{ | ||
$httpResponse = $this->sendRequest('POST', 'card/charge', $data); | ||
|
||
$responseData = json_decode($httpResponse->getBody()->getContents(), true); | ||
|
||
return $this->response = new CardChargeResponse($this, $responseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Omnipay\Przelewy24\Message; | ||
|
||
use Omnipay\Common\Message\RequestInterface; | ||
|
||
class CardChargeResponse extends AbstractResponse | ||
{ | ||
/** | ||
* @var null|string | ||
*/ | ||
private $transactionId = null; | ||
|
||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
parent::__construct($request, $data); | ||
if (isset($data['data'])) { | ||
if (isset($data['data']['orderId'])) { | ||
$this->transactionId = (string) $data['data']['orderId']; | ||
} | ||
} | ||
} | ||
|
||
public function getTransactionId(): ?string | ||
{ | ||
return $this->transactionId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Message; | ||
|
||
use Omnipay\Przelewy24\Message\CardChargeRequest; | ||
use Omnipay\Przelewy24\Message\CardChargeResponse; | ||
use Omnipay\Tests\TestCase; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CardChargeRequestTest extends TestCase | ||
{ | ||
/** | ||
* @var CardChargeRequest | ||
*/ | ||
private $request; | ||
|
||
public function setUp() | ||
{ | ||
$this->request = new CardChargeRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->initialize([ | ||
"token" => "29fa01f8-6bb8-4187-9fb0-ec6e1a62a731", | ||
]); | ||
} | ||
|
||
public function testGetData(): void | ||
{ | ||
$data = $this->request->getData(); | ||
|
||
$this->assertSame('29fa01f8-6bb8-4187-9fb0-ec6e1a62a731', $data['token']); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('CardChargeSuccess.txt'); | ||
/** @var CardChargeResponse $response */ | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardChargeResponse::class, $response); | ||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertSame('1234567890', $response->getTransactionId()); | ||
} | ||
|
||
public function testSendAuthFailure() | ||
{ | ||
$this->setMockHttpResponse('CardChargeAuthFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardChargeResponse::class, $response); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getCode()); | ||
$this->assertSame('Incorrect authentication', $response->getMessage()); | ||
} | ||
|
||
public function testSendInvalidDataFailure() | ||
{ | ||
$this->setMockHttpResponse('CardChargeInvalidDataFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertInstanceOf(CardChargeResponse::class, $response); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertSame(Response::HTTP_BAD_REQUEST, $response->getCode()); | ||
$this->assertSame('Invalid input data', $response->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
HTTP/1.1 422 Unprocessable Entity | ||
Server: nginx/1.4.4 | ||
Date: Sat, 20 May 2022 07:00:00 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 101 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
Strict-Transport-Security: max-age=31556926; includeSubDomains | ||
|
||
{ | ||
"error": "Incorrect authentication", | ||
"code": 401 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
HTTP/1.1 422 Unprocessable Entity | ||
Server: nginx/1.4.4 | ||
Date: Sat, 20 May 2022 07:00:00 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 101 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
Strict-Transport-Security: max-age=31556926; includeSubDomains | ||
|
||
{ | ||
"error": "Invalid input data", | ||
"code": 400 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
HTTP/1.1 422 Unprocessable Entity | ||
Server: nginx/1.4.4 | ||
Date: Sat, 20 May 2022 07:00:00 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 101 | ||
Connection: keep-alive | ||
Access-Control-Allow-Credentials: true | ||
Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, DELETE | ||
Access-Control-Max-Age: 300 | ||
Cache-Control: no-cache, no-store | ||
Strict-Transport-Security: max-age=31556926; includeSubDomains | ||
|
||
{ | ||
"data": { | ||
"orderId": 1234567890 | ||
}, | ||
"responseCode": 0 | ||
} |