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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ext-dom": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.2.1",
"guzzlehttp/guzzle": "^7.0.1",
"psr/log": "^1.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion example/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getSecretKey(): string

public function getBaseUrl(): string
{
return getenv('OTPSP_BASE_URL') ?: 'http://127.0.0.1:1234';
return getenv('OTPSP_BASE_URL') ?: 'http://otpsp-client.test';
}

public function twig()
Expand Down
46 changes: 46 additions & 0 deletions example/docroot/start-query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types = 1);

use Cheppers\OtpspClient\Checksum;
use Cheppers\OtpspClient\DataType\QueryRequest;
use Cheppers\OtpspClient\OtpSimplePayClient;
use GuzzleHttp\Client;
use Psr\Log\Test\TestLogger;

require_once '../../vendor/autoload.php';
require_once '../App.php';

$app = new App();

$now = new DateTime('now');
$guzzle = new Client();
$serializer = new Checksum();
$logger = new TestLogger();
$otpSimple = new OtpSimplePayClient($guzzle, $serializer, $logger);
$otpSimple->setSecretKey($app->getSecretKey());
$timeout = new DateInterval('PT5M');

$queryRequest = new QueryRequest();
$queryRequest->merchant = $app->getMerchantId();
//$queryRequest->orderRefs[] = 'my-order-id-2020-12-07-09-35-51';
$queryRequest->salt = 'd471d2fb24c5a395563ff60f8ba769d1';
$queryRequest->transactionIds[] = '500748082';
//$queryRequest->salt = 'TV0ywJZVdf62p5nAJkldHWDzr2dLJRPe';

$startQueryResponse = $otpSimple->startQuery($queryRequest);

// In a real application do not print anything,
// just redirect the client to $startPaymentResponse->paymentURL.
echo $app
->twig()
->render(
'start-query.html.twig',
[
'queryRequest' => $queryRequest,
'queryRequestJson' => $app->jsonEncode($queryRequest),
'queryPaymentResponse' => $startQueryResponse,
'startQueryResponseJson' => $app->jsonEncode($startQueryResponse),
'logEntriesJson' => $app->jsonEncode($logger->records),
]
);
32 changes: 32 additions & 0 deletions example/templates/start-query.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="https://sandbox.simplepay.hu/pay/support/favicon.ico">
<title>Start query response</title>
</head>
<body>
<main>
<h1>Start payment response</h1>
<section>
<h2>queryRequestJson</h2>
<pre><code>{{ queryRequestJson }}</code></pre>
</section>
<section>
<h2>startQueryResponseJson</h2>
<pre><code>{{ startQueryResponseJson }}</code></pre>
</section>
<section>
<h2>logEntriesJson</h2>
<pre><code>{{ logEntriesJson }}</code></pre>
</section>
{# {% if startQueryResponse.paymentUrl -%}#}
{# <section>#}
{# <h2>paymentURL</h2>#}
{# <a href="{{ startQueryResponse.paymentUrl }}">Go to SimplePay</a>#}
{# </section>#}
{# {%- endif %}#}
</main>
{% include 'footer.html.twig' %}
</body>
</html>
12 changes: 0 additions & 12 deletions src/DataType/InstantPaymentNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
class InstantPaymentNotification extends ResponseBase implements JsonSerializable
{

/**
* @var string
*/
public $cardMask = '';

/**
* @var string
*/
Expand All @@ -24,11 +19,6 @@ class InstantPaymentNotification extends ResponseBase implements JsonSerializabl
*/
public $finishDate = '';

/**
* @var string
*/
public $expiry = '';

/**
* @var string
*/
Expand Down Expand Up @@ -57,10 +47,8 @@ public function jsonSerialize()
case 'merchant':
case 'orderRef':
case 'transactionId':
case 'cardMask':
case 'method':
case 'finishDate':
case 'expiry':
case 'paymentDate':
case 'status':
case 'receiveDate':
Expand Down
10 changes: 10 additions & 0 deletions src/DataType/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public static function __set_state($values)
return $instance;
}

/**
* @var string
*/
public $orderRef = '';

/**
* @var string
*/
public $currency = '';

/**
* @var string
*/
Expand Down
45 changes: 45 additions & 0 deletions src/DataType/QueryRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types = 1);

namespace Cheppers\OtpspClient\DataType;

/**
* Represent a data structure to create a transaction.
*
* Endpoint https://sandbox.simplepay.hu/payment/v2/start
*
* @see http://simplepartner.hu/download.php?target=v21docen Chapter 3.3
*/
class QueryRequest extends RequestBase
{

/**
* @var string
*/
public $merchant = '';

/**
* @var array
*/
public $transactionIds = [];

// /**
// * @var array
// */
// public $orderRefs = [];

/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
$data = [];

foreach (get_object_vars($this) as $key => $value) {
$data[$key] = $value;

}
return $data;
}
}
15 changes: 15 additions & 0 deletions src/DataType/QueryResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types = 1);
namespace Cheppers\OtpspClient\DataType;

class QueryResponse extends ResponseBase
{
/**
* @var double
*/
public $totalCount = 0;
/**
* @var array
*/
public $transactions = [];
}
10 changes: 10 additions & 0 deletions src/DataType/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class RefundRequest extends RequestBase
*/
public $transactionId = '';

/**
* @var string
*/
public $orderRef = '';

/**
* @var string
*/
public $currency = '';

/**
* @var float
*/
Expand Down
13 changes: 2 additions & 11 deletions src/DataType/RequestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public static function __set_state($values)
*/
public $merchant = '';

/**
* @var string
*/
public $orderRef = '';

/**
* @var string
*/
Expand All @@ -41,10 +36,6 @@ public static function __set_state($values)
/**
* @var string
*/
public $currency = '';

/**
* @var string
*/
public $sdkVersion = 'SimplePay_PHP_SDK_2.0_180930:33ccd5ed8e8a965d18abfae333404184';
public $sdkVersion = 'SimplePayV2.1_Payment_PHP_SDK_2.0.7_190701:dd236896400d7463677a82a47f53e36e';
// public $sdkVersion = 'SimplePay_PHP_SDK_2.0_180930:33ccd5ed8e8a965d18abfae333404184';
}
22 changes: 19 additions & 3 deletions src/OtpSimplePayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Cheppers\OtpspClient\DataType\BackResponse;
use Cheppers\OtpspClient\DataType\InstantPaymentNotification;
use Cheppers\OtpspClient\DataType\PaymentRequest;
use Cheppers\OtpspClient\DataType\QueryRequest;
use Cheppers\OtpspClient\DataType\QueryResponse;
use Cheppers\OtpspClient\DataType\RefundRequest;
use Cheppers\OtpspClient\DataType\RefundResponse;
use Cheppers\OtpspClient\DataType\RequestBase;
Expand All @@ -15,6 +17,7 @@
use DateTimeInterface;
use Exception;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\MessageInterface;
Expand Down Expand Up @@ -180,7 +183,7 @@ public function __construct(
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
* @throws Exception
*/
public function startPayment(PaymentRequest $paymentRequest): PaymentResponse
Expand All @@ -192,7 +195,7 @@ public function startPayment(PaymentRequest $paymentRequest): PaymentResponse
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
* @throws Exception
*/
public function startRefund(RefundRequest $refundRequest): RefundResponse
Expand All @@ -203,6 +206,19 @@ public function startRefund(RefundRequest $refundRequest): RefundResponse
return RefundResponse::__set_state($body);
}

/**
* @param QueryRequest $queryRequest
* @return QueryResponse
* @throws GuzzleException
*/
public function startQuery(QueryRequest $queryRequest): QueryResponse
{
$response = $this->sendRequest($queryRequest, 'query');
$body = $this->getMessageBody($response);

return QueryResponse::__set_state($body);
}

/**
* @throws Exception
*/
Expand Down Expand Up @@ -286,7 +302,7 @@ public function getInstantPaymentNotificationSuccessParts(InstantPaymentNotifica
}

/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function sendRequest(RequestBase $requestType, string $path): ResponseInterface
{
Expand Down