-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Ticketpark/qestoppey-feature/InquireRequest
Add Transaction/Inquire request
- Loading branch information
Showing
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Ticketpark\SaferpayJson\Request\Exception\SaferpayErrorException; | ||
use Ticketpark\SaferpayJson\Request\Container; | ||
use Ticketpark\SaferpayJson\Request\RequestConfig; | ||
use Ticketpark\SaferpayJson\Request\Transaction\InquireRequest; | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../credentials.php'; | ||
// A transaction id you received with a successful assert request (see ../PaymentPage/example-assert.php) | ||
|
||
$transactionId = 'xxx'; | ||
|
||
// ----------------------------- | ||
// Step 1: | ||
// Prepare the capture request | ||
// https://saferpay.github.io/jsonapi/#Payment_v1_Transaction_Inquire | ||
|
||
$requestConfig = new RequestConfig( | ||
$apiKey, | ||
$apiSecret, | ||
$customerId, | ||
true | ||
); | ||
|
||
$transactionReference = (new Container\TransactionReference()) | ||
->setTransactionId($transactionId); | ||
|
||
// ----------------------------- | ||
// Step 2: | ||
// Create the request with required data | ||
|
||
$captureRequest = new InquireRequest( | ||
$requestConfig, | ||
$transactionReference | ||
); | ||
|
||
// ----------------------------- | ||
// Step 3: | ||
// Execute and check for successful response | ||
|
||
try { | ||
$response = $captureRequest->execute(); | ||
} catch (SaferpayErrorException $e) { | ||
die ($e->getErrorResponse()->getErrorMessage()); | ||
} | ||
|
||
echo 'The information of this transaction has been fetched. Transaction type: ' . $response->getTransaction()->getType()."\n"; |
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ticketpark\SaferpayJson\Request\Transaction; | ||
|
||
use JMS\Serializer\Annotation\SerializedName; | ||
use Ticketpark\SaferpayJson\Request\Container\TransactionReference; | ||
use Ticketpark\SaferpayJson\Request\Request; | ||
use Ticketpark\SaferpayJson\Request\RequestCommonsTrait; | ||
use Ticketpark\SaferpayJson\Request\RequestConfig; | ||
use Ticketpark\SaferpayJson\Response\Transaction\InquireResponse; | ||
|
||
final class InquireRequest extends Request | ||
{ | ||
use RequestCommonsTrait; | ||
public const API_PATH = '/Payment/v1/Transaction/Inquire'; | ||
public const RESPONSE_CLASS = InquireResponse::class; | ||
|
||
/** | ||
* @SerializedName("TransactionReference") | ||
*/ | ||
private TransactionReference $transactionReference; | ||
|
||
public function __construct( | ||
RequestConfig $requestConfig, | ||
TransactionReference $transactionReference | ||
) { | ||
$this->transactionReference = $transactionReference; | ||
|
||
parent::__construct($requestConfig); | ||
} | ||
|
||
public function getTransactionReference(): TransactionReference | ||
{ | ||
return $this->transactionReference; | ||
} | ||
|
||
public function setTransactionReference(TransactionReference $transactionReference): self | ||
{ | ||
$this->transactionReference = $transactionReference; | ||
|
||
return $this; | ||
} | ||
|
||
public function execute(): InquireResponse | ||
{ | ||
/** @var InquireResponse $response */ | ||
$response = $this->doExecute(); | ||
|
||
return $response; | ||
} | ||
} |
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 Ticketpark\SaferpayJson\Response\Transaction; | ||
|
||
use JMS\Serializer\Annotation\SerializedName; | ||
use Ticketpark\SaferpayJson\Response\Container\Dcc; | ||
use Ticketpark\SaferpayJson\Response\Container\Liability; | ||
use Ticketpark\SaferpayJson\Response\Container\Payer; | ||
use Ticketpark\SaferpayJson\Response\Container\PaymentMeans; | ||
use Ticketpark\SaferpayJson\Response\Container\Transaction; | ||
use Ticketpark\SaferpayJson\Response\Response; | ||
|
||
final class InquireResponse extends Response | ||
{ | ||
/** | ||
* @SerializedName("Transaction") | ||
*/ | ||
private ?Transaction $transaction = null; | ||
|
||
/** | ||
* @SerializedName("PaymentMeans") | ||
*/ | ||
private ?PaymentMeans $paymentMeans = null; | ||
|
||
/** | ||
* @SerializedName("Payer") | ||
*/ | ||
private ?Payer $payer = null; | ||
|
||
/** | ||
* @SerializedName("Liability") | ||
*/ | ||
private ?Liability $liability = null; | ||
|
||
/** | ||
* @SerializedName("Dcc") | ||
*/ | ||
private ?Dcc $dcc = null; | ||
|
||
public function getTransaction(): ?Transaction | ||
{ | ||
return $this->transaction; | ||
} | ||
|
||
public function getPaymentMeans(): ?PaymentMeans | ||
{ | ||
return $this->paymentMeans; | ||
} | ||
|
||
public function getPayer(): ?Payer | ||
{ | ||
return $this->payer; | ||
} | ||
|
||
public function getLiability(): ?Liability | ||
{ | ||
return $this->liability; | ||
} | ||
|
||
public function getDcc(): ?Dcc | ||
{ | ||
return $this->dcc; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/SaferpayJson/Tests/Request/Transaction/InquireRequestTest.php
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 | ||
|
||
namespace SaferpayJson\Tests\Request\Transaction; | ||
|
||
use Ticketpark\SaferpayJson\Request\Container\TransactionReference; | ||
use Ticketpark\SaferpayJson\Request\Transaction\InquireRequest; | ||
use Ticketpark\SaferpayJson\Response\Transaction\InquireResponse; | ||
use Ticketpark\SaferpayJson\Tests\Request\CommonRequestTest; | ||
|
||
class InquireRequestTest extends CommonRequestTest | ||
{ | ||
public function testSuccessfulResponse(): void | ||
{ | ||
parent::doTestSuccessfulResponse( | ||
InquireResponse::class | ||
); | ||
} | ||
|
||
protected function getInstance() | ||
{ | ||
return new InquireRequest( | ||
$this->getRequestConfig(), | ||
new TransactionReference() | ||
); | ||
} | ||
} |