Skip to content
Merged
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 .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
API_MERCHANT=112233
API_SECRET=foobarfoobaz
API_URL=https://payments.comgate.cz/v1.0/
API_URL_REST=https://payments.comgate.cz/v2.0/
APPLICATION_ENV=dev
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ use Comgate\SDK\Entity\TerminalPayment;
use Comgate\SDK\Entity\TerminalRefund;
use Comgate\SDK\Exception\ApiException;

$clientTerminal = Comgate::defaultsRest()
$clientTerminal = Comgate::defaults()
->setMerchant('123456') // get on portal.comgate.cz
->setSecret('foobarbaz') // get on portal.comgate.cz
->createTerminalClient();
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
11 changes: 0 additions & 11 deletions src/Comgate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ public static function defaults(): self
return $self;
}

/**
* @return static
*/
public static function defaultsRest(): self
{
$self = new static();
$self->url = Config::URL_REST;

return $self;
}

/**
* @return static
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

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

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

Expand Down
10 changes: 9 additions & 1 deletion src/Entity/Request/AboDownloadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ public function __construct(string $date, string $type, bool $test, string $enco
*/
public function getUrn(): string
{
return 'aboDownload';
$urn = 'aboDownload/date/' . urlencode($this->getDate());
$params = [
'test' => $this->isTest() ? 'true' : 'false',
'encoding' => $this->getEncoding(),
];
if ($this->getType() !== '') {
$params['type'] = $this->getType();
}
return $urn . '?' . http_build_query($params);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/Entity/Request/AboSingleTransferRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class AboSingleTransferRequest implements IRequest
* @var string
*/
protected $encoding;
private bool $download = false; // just for method sync Cest to pass, should be always false
/** @var bool */
private $download = false; // just for method sync Cest to pass, should be always false

public function __construct(string $transferId, bool $test, string $type, string $encoding)
{
Expand All @@ -44,7 +45,13 @@ public function __construct(string $transferId, bool $test, string $type, string
*/
public function getUrn(): string
{
return 'aboSingleTransfer';
$urn = 'aboSingleTransfer/transferId/' . urlencode($this->getTransferId()) . '.json';
$params = [
'type' => $this->getType(),
'encoding' => $this->getEncoding(),
'test' => $this->isTest() ? 'true' : 'false',
];
return $urn . '?' . http_build_query($params);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/Entity/Request/AppleDomainAssociationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class AppleDomainAssociationRequest implements IRequest
* @var string
*/
protected $method;
protected string $currency;
/** @var string */
protected $currency;

public function __construct(string $method, string $currency)
{
Expand All @@ -18,7 +19,15 @@ public function __construct(string $method, string $currency)

public function getUrn(): string
{
return 'appleDomainAssociation';
$params = [];
if ($this->getCurrency() !== '') {
$params['currency'] = $this->getCurrency();
}
$urn = 'appleDomainAssociation.json';
if (count($params) > 0) {
$urn .= '?' . http_build_query($params);
}
return $urn;
}

public function toArray(): array
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/Request/CsvDownloadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function __construct(string $date, bool $test)
*/
public function getUrn(): string
{
return 'csvDownload';
$urn = 'csvDownload/date/' . urlencode($this->getDate());
$params = ['test' => $this->isTest() ? 'true' : 'false'];
return $urn . '?' . http_build_query($params);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Entity/Request/CsvSingleTransferRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CsvSingleTransferRequest implements IRequest
* @var bool
*/
protected $test;
private bool $download = false; // just for method sync Cest to pass, should be always false
/** @var bool */
private $download = false; // just for method sync Cest to pass, should be always false

public function __construct(string $transferId, bool $test)
{
Expand All @@ -26,7 +27,9 @@ public function __construct(string $transferId, bool $test)
*/
public function getUrn(): string
{
return 'csvSingleTransfer';
$urn = 'csvSingleTransfer/transferId/' . urlencode($this->getTransferId()) . '.json';
$params = ['test' => $this->isTest() ? 'true' : 'false'];
return $urn . '?' . http_build_query($params);
}

/**
Expand Down
19 changes: 15 additions & 4 deletions src/Entity/Request/MethodsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ class MethodsRequest implements IRequest

public function getUrn(): string
{
return 'methods';
$params = $this->toArray();
unset($params['type']);

$urn = 'method.json';
if (count($params) > 0) {
$urn .= '?' . http_build_query($params);
}
return $urn;
}

/**
Expand Down Expand Up @@ -198,12 +205,16 @@ public function getPrice(): ?string
}

/**
* @param string|null $price
* @param string|int|float|null $price
* @return void
*/
public function setPrice(?string $price): void
public function setPrice($price): void
{
$this->price = $price;
if ($price === null) {
$this->price = null;
} else {
$this->price = (string) $price;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/MotoPaymentCreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(MotoPayment $payment)
*/
public function getUrn(): string
{
return 'moto';
return 'moto.json';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/PaymentCancelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(string $transId)
*/
public function getUrn(): string
{
return 'cancel';
return 'payment/transId/' . urlencode($this->getTransId()) . '.json';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/PaymentCreateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(Payment $payment)
*/
public function getUrn(): string
{
return 'create';
return 'payment.json';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/PaymentRefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Refund $refund)
*/
public function getUrn(): string
{
return 'refund';
return 'refund.json';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/PaymentStatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(string $transId)
*/
public function getUrn(): string
{
return 'status';
return 'payment/transId/' . urlencode($this->getTransId()) . '.json';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Request/PreauthCancelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(string $transId){
*/
public function getUrn(): string
{
return 'cancelPreauth';
return 'preauth/transId/' . urlencode($this->getTransId()) . '.json';
}

/**
Expand Down
Loading
Loading