-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32b9724
commit da2a11b
Showing
9 changed files
with
347 additions
and
27 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
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
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,50 @@ | ||
<?php | ||
/** | ||
* Yandex.Kassa driver for Omnipay payment processing library | ||
* | ||
* @link https://github.com/hiqdev/omnipay-yandex-kassa | ||
* @package omnipay-yandex-kassa | ||
* @license MIT | ||
* @copyright Copyright (c) 2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace Omnipay\YandexKassa\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidRequestException; | ||
use Throwable; | ||
|
||
/** | ||
* Class CompletePurchaseRequest. | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
*/ | ||
class CaptureRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('shopId', 'secret', 'transactionId', 'transactionReference', 'amount', 'currency'); | ||
|
||
return $this->httpRequest->request->all(); | ||
} | ||
|
||
/** | ||
* @param mixed $data | ||
* @return \Omnipay\Common\Message\ResponseInterface|CaptureResponse | ||
* @throws InvalidRequestException | ||
*/ | ||
public function sendData($data) | ||
{ | ||
try { | ||
$result = $this->client->capturePayment([ | ||
'amount' => [ | ||
'value' => $this->getAmount(), | ||
'currency' => $this->getCurrency(), | ||
], | ||
], $this->getTransactionReference(), 'capture-' . $this->getTransactionId()); | ||
|
||
return $this->response = new CaptureResponse($this, $result); | ||
} catch (Throwable $e) { | ||
throw new InvalidRequestException('Failed to capture payment: ' . $e->getMessage(), 0, $e); | ||
} | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
/** | ||
* Yandex.Kassa driver for Omnipay payment processing library | ||
* | ||
* @link https://github.com/hiqdev/omnipay-yandex-kassa | ||
* @package omnipay-yandex-kassa | ||
* @license MIT | ||
* @copyright Copyright (c) 2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace Omnipay\YandexKassa\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use YandexCheckout\Model\PaymentStatus; | ||
use YandexCheckout\Request\Payments\Payment\CreateCaptureResponse; | ||
|
||
/** | ||
* Class CaptureResponse | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
* @property CreateCaptureResponse $data | ||
*/ | ||
class CaptureResponse extends DetailsResponse | ||
{ | ||
protected function ensureResponseIsValid(): void | ||
{ | ||
parent::ensureResponseIsValid(); | ||
|
||
if ($this->getState() !== PaymentStatus::SUCCEEDED) { | ||
throw new InvalidResponseException(sprintf('Failed to capture payment "%s"', $this->getTransactionReference())); | ||
} | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Omnipay\YandexKassa\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\Common\Message\ResponseInterface; | ||
|
||
/** | ||
* Class DetailsRequest | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
*/ | ||
class DetailsRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('transactionReference'); | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* @return DetailsResponse|ResponseInterface | ||
* @throws InvalidResponseException | ||
*/ | ||
public function sendData($data): ResponseInterface | ||
{ | ||
try { | ||
$response = $this->client->getPaymentInfo($this->getTransactionReference()); | ||
|
||
return new DetailsResponse($this, $response); | ||
} catch (\Throwable $e) { | ||
throw new InvalidResponseException( | ||
'Error communicating with payment gateway: ' . $e->getMessage(), | ||
$e->getCode() | ||
); | ||
} | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
|
||
namespace Omnipay\YandexKassa\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface; | ||
use YandexCheckout\Model\PaymentInterface; | ||
|
||
/** | ||
* Class DetailsResponse | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
* @property PaymentInterface $data | ||
*/ | ||
class DetailsResponse extends AbstractResponse | ||
{ | ||
/** | ||
* @return RequestInterface|DetailsRequest | ||
*/ | ||
public function getRequest() | ||
{ | ||
return parent::getRequest(); | ||
} | ||
|
||
public function __construct(RequestInterface $request, PaymentInterface $payment) | ||
{ | ||
parent::__construct($request, $payment); | ||
|
||
$this->ensureResponseIsValid(); | ||
} | ||
|
||
protected function ensureResponseIsValid(): void | ||
{ | ||
if ($this->getTransactionId() === null) { | ||
throw new InvalidResponseException(sprintf( | ||
'Transaction ID is missing in payment "%s"', | ||
$this->getTransactionReference() | ||
)); | ||
} | ||
} | ||
|
||
/** | ||
* Is the response successful? | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSuccessful(): bool | ||
{ | ||
return $this->data->paid; | ||
} | ||
|
||
public function getAmount(): string | ||
{ | ||
return $this->data->getAmount()->getValue(); | ||
} | ||
|
||
public function getCurrency(): string | ||
{ | ||
return $this->data->getAmount()->getCurrency(); | ||
} | ||
|
||
public function getPaymentDate(): \DateTime | ||
{ | ||
return $this->data->getCreatedAt(); | ||
} | ||
|
||
public function getTransactionReference(): string | ||
{ | ||
return $this->data->getId(); | ||
} | ||
|
||
public function getTransactionId(): ?string | ||
{ | ||
return $this->data->getMetadata()['transactionId'] ?? null; | ||
} | ||
|
||
public function getState(): string | ||
{ | ||
return $this->data->getStatus(); | ||
} | ||
|
||
public function getPayer(): string | ||
{ | ||
$method = $this->data->getPaymentMethod(); | ||
|
||
return $method->getTitle(); | ||
} | ||
|
||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Omnipay\YandexKassa\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\Common\Message\ResponseInterface; | ||
|
||
/** | ||
* Class IncomingNotificationRequest | ||
* | ||
* @author Dmytro Naumenko <d.naumenko.a@gmail.com> | ||
*/ | ||
class IncomingNotificationRequest extends AbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$body = $this->httpRequest->getContent(); | ||
|
||
return json_decode($body, true); | ||
} | ||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* @return ResponseInterface | ||
* @throws InvalidResponseException | ||
*/ | ||
public function sendData($data): ResponseInterface | ||
{ | ||
try { | ||
return new IncomingNotificationResponse($this, $data); | ||
} catch (\Throwable $e) { | ||
throw new InvalidResponseException( | ||
'Error communicating with payment gateway: ' . $e->getMessage(), | ||
$e->getCode() | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.