Skip to content
Closed
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,44 @@ try{
```


### Create terminal CloudPOS payment
#### API Documentation
https://apidoc.comgate.cz/api/rest-terminal
```php
use Comgate\SDK\Comgate;
use Comgate\SDK\Entity\Codes\CurrencyCode;
use Comgate\SDK\Entity\Codes\RequestCode;
use Comgate\SDK\Entity\Money;
use Comgate\SDK\Entity\TerminalPayment;
use Comgate\SDK\Entity\TerminalRefund;
use Comgate\SDK\Exception\ApiException;

$clientTerminal = Comgate::defaults()
->setMerchant('123456') // get on portal.comgate.cz
->setSecret('foobarbaz') // get on portal.comgate.cz
->createTerminalClient();

$terminalPayment = new TerminalPayment();
$terminalPayment
->setPrice(Money::ofInt(4))
->setCurr(CurrencyCode::CZK)
->setRefId('123456');

try {
$createTerminalPaymentResponse = $clientTerminal->createPayment($terminalPayment);
if ($createTerminalPaymentResponse->getCode() === RequestCode::OK) {

// save ID of terminal payment in your system
echo 'created terminal payment: ' . $createTerminalPaymentResponse->getTransId();

} else {
var_dump($createTerminalPaymentResponse->getMessage());
}
} catch (ApiException $e) {
var_dump($e->getMessage());
}
```

### Debugging

#### Logging
Expand Down
44 changes: 18 additions & 26 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public function __construct(ITransport $transport)
public function createPayment(Payment $payment): PaymentCreateResponse
{
$paymentCreateRequest = new PaymentCreateRequest($payment);
$paymentCreateResponse = $this->transport->post($paymentCreateRequest->getUrn(),
$paymentCreateResponse = $this->transport->postJson($paymentCreateRequest->getUrn(),
$paymentCreateRequest->toArray());
return new PaymentCreateResponse($paymentCreateResponse);
}

public function getStatus(string $transId): PaymentStatusResponse
{
$paymentStatusRequest = new PaymentStatusRequest($transId);
$statusResponse = $this->transport->post($paymentStatusRequest->getUrn(), $paymentStatusRequest->toArray());
$statusResponse = $this->transport->get($paymentStatusRequest->getUrn());
return new PaymentStatusResponse($statusResponse);
}

Expand All @@ -80,45 +80,43 @@ public function getMethods(?MethodsRequest $methodsRequest = null): MethodsRespo
$methodsRequest = new MethodsRequest();
}

$methodsResponse = $this->transport->post($methodsRequest->getUrn(), $methodsRequest->toArray());
$methodsResponse = $this->transport->get($methodsRequest->getUrn());

return new MethodsResponse($methodsResponse);
}

public function cancelPayment(string $transId): PaymentCancelResponse
{
$cancelPaymentRequest = new PaymentCancelRequest($transId);
$cancelResponse = $this->transport->post($cancelPaymentRequest->getUrn(), $cancelPaymentRequest->toArray());
$cancelResponse = $this->transport->delete($cancelPaymentRequest->getUrn());
return new PaymentCancelResponse($cancelResponse);
}

public function capturePreauth(string $transId, Money $amount): PreauthCaptureResponse
{
$capturePreauthRequest = new PreauthCaptureRequest($transId, $amount);
$captureResponse = $this->transport->post($capturePreauthRequest->getUrn(), $capturePreauthRequest->toArray());
$captureResponse = $this->transport->putJson($capturePreauthRequest->getUrn(), $capturePreauthRequest->toArray());
return new PreauthCaptureResponse($captureResponse);
}

public function cancelPreauth(string $transId): PreauthCancelResponse
{
$cancelPreauthRequest = new PreauthCancelRequest($transId);
$cancelResponse = $this->transport->post($cancelPreauthRequest->getUrn(), $cancelPreauthRequest->toArray());
$cancelResponse = $this->transport->delete($cancelPreauthRequest->getUrn());
return new PreauthCancelResponse($cancelResponse);
}

public function refundPayment(Refund $refund): RefundResponse
{
$refundRequest = new PaymentRefundRequest($refund);
$refundResponse = $this->transport->post($refundRequest->getUrn(), $refundRequest->toArray());
$refundResponse = $this->transport->postJson($refundRequest->getUrn(), $refundRequest->toArray());
return new RefundResponse($refundResponse);
}

public function initRecurringPayment(Payment $payment): RecurringPaymentResponse
{
$recurringRequest = new RecurringPaymentRequest($payment);
echo $recurringRequest->getUrn();
$recurringResponse = $this->transport->post($recurringRequest->getUrn(), $recurringRequest->toArray());
echo $recurringResponse->getContent();
$recurringResponse = $this->transport->postJson($recurringRequest->getUrn(), $recurringRequest->toArray());
return new RecurringPaymentResponse($recurringResponse);
}

Expand All @@ -130,7 +128,7 @@ public function initRecurringPayment(Payment $payment): RecurringPaymentResponse
public function simulation(array $params): SimulationResponse
{
$simulationRequest = new SimulationRequest($params);
$simulationResponse = $this->transport->post($simulationRequest->getUrn(), $simulationRequest->toArray());
$simulationResponse = $this->transport->postJson($simulationRequest->getUrn(), $simulationRequest->toArray());
return new SimulationResponse($simulationResponse);
}

Expand All @@ -143,52 +141,46 @@ public function simulation(array $params): SimulationResponse
public function transferList(DateTimeInterface $date, bool $test): TransferListResponse
{
$transferListRequest = new TransferListRequest($date, $test);
$transferListResponse = $this->transport->post($transferListRequest->getUrn(), $transferListRequest->toArray());
$transferListResponse = $this->transport->get($transferListRequest->getUrn());
return new TransferListResponse($transferListResponse);
}

public function singleTransfer(int $transferId, bool $test): SingleTransferResponse
{
$singleTransferRequest = new SingleTransferRequest($transferId, $test);
$singleTransferResponse = $this->transport->post($singleTransferRequest->getUrn(),
$singleTransferRequest->toArray());
$singleTransferResponse = $this->transport->get($singleTransferRequest->getUrn());
return new SingleTransferResponse($singleTransferResponse);
}

public function csvSingleTransfer(string $transferId, bool $test): CsvSingleTransferResponse
{
$csvSingleTransferRequest = new CsvSingleTransferRequest($transferId, $test);
$csvSingleTransferResponse = $this->transport->post($csvSingleTransferRequest->getUrn(),
$csvSingleTransferRequest->toArray());
$csvSingleTransferResponse = $this->transport->get($csvSingleTransferRequest->getUrn());
return new CsvSingleTransferResponse($csvSingleTransferResponse);
}

public function aboSingleTransfer(string $transferId, bool $test, string $type, string $encoding): AboSingleTransferResponse
{
$aboSingleTransferRequest = new AboSingleTransferRequest($transferId, $test, $type, $encoding);
$aboSingleTransferResponse = $this->transport->post($aboSingleTransferRequest->getUrn(),
$aboSingleTransferRequest->toArray());
$aboSingleTransferResponse = $this->transport->get($aboSingleTransferRequest->getUrn());
return new AboSingleTransferResponse($aboSingleTransferResponse);
}

public function getAppleDomainAssociation(string $method = '', string $currency = ''): AppleDomainAssociationResponse{
$appleDomainAssociationRequest = new AppleDomainAssociationRequest($method, $currency);
$appleDomainAssociationResponse = $this->transport->post($appleDomainAssociationRequest->getUrn(),
$appleDomainAssociationRequest->toArray());
$appleDomainAssociationResponse = $this->transport->get($appleDomainAssociationRequest->getUrn());
return new AppleDomainAssociationResponse($appleDomainAssociationResponse);
}
public function getCsvDownload(string $date, bool $test = false): void{
$csvDownloadRequest = new CsvDownloadRequest($date, $test);
$csvDownloadResponse = $this->transport->post($csvDownloadRequest->getUrn(),
$csvDownloadRequest->toArray());
$csvDownloadResponse = $this->transport->get($csvDownloadRequest->getUrn());

new CsvDownloadResponse($csvDownloadResponse);
}

public function getAboDownload(string $date, string $type = '', bool $test = false, string $encoding = 'utf8'): void{
$aboDownloadRequest = new AboDownloadRequest($date, $type, $test, $encoding);
$aboDownloadResponse = $this->transport->post($aboDownloadRequest->getUrn(),
$aboDownloadRequest->toArray());
$aboDownloadResponse = $this->transport->get($aboDownloadRequest->getUrn());

new AboDownloadResponse($aboDownloadResponse);
}
Expand All @@ -203,7 +195,7 @@ public function getAboDownload(string $date, string $type = '', bool $test = fa
public function createMotoPayment(Payment $payment, PaymentCard $paymentCard): ?MotoPaymentCreateResponse
{
$publicCryptoKeyRequest = new PublicCryptoKeyRequest();
$publicCryptoKeyResponse = new PublicCryptoKeyResponse($this->transport->post($publicCryptoKeyRequest->getUrn(), $publicCryptoKeyRequest->toArray()));
$publicCryptoKeyResponse = new PublicCryptoKeyResponse($this->transport->get($publicCryptoKeyRequest->getUrn()));

$publicJkwKey = null;
$jwkData = json_decode(base64_decode($publicCryptoKeyResponse->getKey(), true), true);
Expand Down Expand Up @@ -237,7 +229,7 @@ public function createMotoPayment(Payment $payment, PaymentCard $paymentCard): ?
}

$motoPaymentCreateRequest = new MotoPaymentCreateRequest($motoPayment);
$motoPaymentCreateResponse = $this->transport->post($motoPaymentCreateRequest->getUrn(), $motoPaymentCreateRequest->toArray());
$motoPaymentCreateResponse = $this->transport->postJson($motoPaymentCreateRequest->getUrn(), $motoPaymentCreateRequest->toArray());
return new MotoPaymentCreateResponse($motoPaymentCreateResponse);
}

Expand Down
122 changes: 122 additions & 0 deletions src/ClientTerminal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php declare(strict_types = 1);

namespace Comgate\SDK;

use Comgate\SDK\Entity\TerminalPayment;
use Comgate\SDK\Entity\TerminalRefund;
use Comgate\SDK\Entity\Request\TerminalPaymentCreateRequest;
use Comgate\SDK\Entity\Request\TerminalPaymentStatusRequest;
use Comgate\SDK\Entity\Request\TerminalPaymentCancelRequest;
use Comgate\SDK\Entity\Request\TerminalClosingRequest;
use Comgate\SDK\Entity\Request\TerminalRefundCreateRequest;
use Comgate\SDK\Entity\Request\TerminalRefundStatusRequest;
use Comgate\SDK\Entity\Request\TerminalRefundCancelRequest;
use Comgate\SDK\Entity\Request\TerminalStatusRequest;
use Comgate\SDK\Entity\Response\TerminalPaymentCreateResponse;
use Comgate\SDK\Entity\Response\TerminalPaymentStatusResponse;
use Comgate\SDK\Entity\Response\TerminalPaymentCancelResponse;
use Comgate\SDK\Entity\Response\TerminalClosingResponse;
use Comgate\SDK\Entity\Response\TerminalRefundCreateResponse;
use Comgate\SDK\Entity\Response\TerminalRefundStatusResponse;
use Comgate\SDK\Entity\Response\TerminalRefundCancelResponse;
use Comgate\SDK\Entity\Response\TerminalStatusResponse;
use Comgate\SDK\Http\ITransport;

class ClientTerminal
{
/** @var ITransport */
protected $transport;

public function __construct(ITransport $transport)
{
$this->transport = $transport;
}

/**
* Vytvoří novou platbu na terminálu
*/
public function createPayment(TerminalPayment $terminalPayment): TerminalPaymentCreateResponse
{
$request = new TerminalPaymentCreateRequest($terminalPayment);
$response = $this->transport->postJson($request->getUrn(), $request->toArray());
return new TerminalPaymentCreateResponse($response);
}

/**
* Zjistí stav platby na terminálu
*/
public function getPaymentStatus(string $transId): TerminalPaymentStatusResponse
{
$request = new TerminalPaymentStatusRequest($transId);
$response = $this->transport->get($this->replacePathParam($request->getUrn(), $transId));
return new TerminalPaymentStatusResponse($response);
}

/**
* Zruší platbu na terminálu
*/
public function cancelPayment(string $transId): TerminalPaymentCancelResponse
{
$request = new TerminalPaymentCancelRequest($transId);
$response = $this->transport->delete($this->replacePathParam($request->getUrn(), $transId));
return new TerminalPaymentCancelResponse($response);
}

/**
* Provede uzávěrku na terminálu
*/
public function createClosing(): TerminalClosingResponse
{
$request = new TerminalClosingRequest();
$response = $this->transport->postJson($request->getUrn(), $request->toArray());
return new TerminalClosingResponse($response);
}

/**
* Vytvoří nový návrat (refund) na terminálu
*/
public function createRefund(TerminalRefund $terminalRefund): TerminalRefundCreateResponse
{
$request = new TerminalRefundCreateRequest($terminalRefund);
$response = $this->transport->postJson($request->getUrn(), $request->toArray());
return new TerminalRefundCreateResponse($response);
}

/**
* Zjistí stav návratu na terminálu
*/
public function getRefundStatus(string $transId): TerminalRefundStatusResponse
{
$request = new TerminalRefundStatusRequest($transId);
$response = $this->transport->get($this->replacePathParam($request->getUrn(), $transId));
return new TerminalRefundStatusResponse($response);
}

/**
* Zruší návrat na terminálu
*/
public function cancelRefund(string $transId): TerminalRefundCancelResponse
{
$request = new TerminalRefundCancelRequest($transId);
$response = $this->transport->delete($this->replacePathParam($request->getUrn(), $transId));
return new TerminalRefundCancelResponse($response);
}

/**
* Zjistí stav terminálu
*/
public function getTerminalStatus(): TerminalStatusResponse
{
$request = new TerminalStatusRequest();
$response = $this->transport->get($request->getUrn());
return new TerminalStatusResponse($response);
}

/**
* Nahradí {transId} v URN skutečným transId
*/
private function replacePathParam(string $urn, string $transId): string
{
return str_replace('{transId}', $transId, $urn);
}
}
5 changes: 5 additions & 0 deletions src/Comgate.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function createClient(): Client
return new Client($this->createTransport());
}

public function createTerminalClient(): ClientTerminal
{
return new ClientTerminal($this->createTransport());
}

protected function createConfig(): Config
{
return new Config($this->merchant, $this->secret, $this->url);
Expand Down
3 changes: 2 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

class Config
{
public const URL = 'https://payments.comgate.cz/v1.0/';
public const URL = 'https://payments.comgate.cz/v2.0/';

/** @var string */
private $merchant;

Expand Down
20 changes: 20 additions & 0 deletions src/Entity/Codes/TerminalPaymentStatusCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types = 1);

namespace Comgate\SDK\Entity\Codes;

final class TerminalPaymentStatusCode
{

public const PENDING = 'PENDING';
public const PAID = 'PAID';
public const CANCELLED = 'CANCELLED';
public const ERROR = 'ERROR';

public const SELF = [
self::PENDING,
self::PAID,
self::CANCELLED,
self::ERROR,
];

}
21 changes: 21 additions & 0 deletions src/Entity/Codes/TerminalStatusCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);

namespace Comgate\SDK\Entity\Codes;

final class TerminalStatusCode
{

public const ONLINE = 'ONLINE';
public const OFFLINE = 'OFFLINE';
public const BUSY = 'BUSY';
public const UNKNOWN = 'UNKNOWN';

public const SELF = [
self::ONLINE,
self::OFFLINE,
self::BUSY,
self::UNKNOWN,
];

}

Loading
Loading