Skip to content

Commit

Permalink
Merge pull request #95 from Ticketpark/qestoppey-feature/InquireRequest
Browse files Browse the repository at this point in the history
Add Transaction/Inquire request
  • Loading branch information
sprain authored Jun 27, 2024
2 parents 091a8d8 + e34552b commit 546e415
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
48 changes: 48 additions & 0 deletions example/Transaction/example-inquire.php
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";
53 changes: 53 additions & 0 deletions lib/SaferpayJson/Request/Transaction/InquireRequest.php
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;
}
}
66 changes: 66 additions & 0 deletions lib/SaferpayJson/Response/Transaction/InquireResponse.php
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;
}
}
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()
);
}
}

0 comments on commit 546e415

Please sign in to comment.