Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11 Add support for Sberbank fiscal part of api #12

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"require": {
"php": "^7.1",
"ext-json": "*",
"omnipay/common": "v3.0.2"
},
"require-dev": {
Expand Down
22 changes: 22 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Omnipay\Sberbank\Message\GetLastOrdersForMerchantsRequest;
use Omnipay\Sberbank\Message\OrderStatusRequest;
use Omnipay\Sberbank\Message\PurchaseRequest;
use Omnipay\Sberbank\Message\OrderReceiptStatusRequest;
use Omnipay\Sberbank\Message\RefundRequest;
use Omnipay\Sberbank\Message\UnBindCardRequest;
use Omnipay\Sberbank\Message\UpdateSSLCardListRequest;
Expand Down Expand Up @@ -310,6 +311,27 @@ public function supportsExtendedOrderStatus()
return method_exists($this, 'extendedOrderStatus');
}

/**
* Receipt status request
*
* @param array $options
* @return RequestInterface
*/
public function orderReceiptStatus(array $options = []): RequestInterface
{
return $this->createRequest(OrderReceiptStatusRequest::class, $options);
}

/**
* Supports receiptStatus
*
* @return boolean True if this gateway supports the orderReceiptStatus() method
*/
public function supportsOrderReceiptStatus()
{
return method_exists($this, 'orderReceiptStatus');
}

/**
* Request to verify the involvement of the card in 3DS
*
Expand Down
49 changes: 43 additions & 6 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,51 @@ public function sendData($data)
public function specifyAdditionalParameters(array $data, array $additionalParams): array
{
foreach ($additionalParams as $param) {
$method = 'get' . ucfirst($param);
if (method_exists($this, $method)) {
$value = $this->{$method}();
if ($value) {
$data[$param] = $value;
}
$value = $this->getParameterValue($param);
if ($value !== null) {
$data[$param] = $value;
}
}

return $data;
}

/**
* Add additional json encoded params to data
*
* @param array $data
* @param array $additionalParams
* @return array
*/
public function specifyAdditionalJsonParameters(array $data, array $additionalParams): array
{
foreach ($additionalParams as $param) {
$value = $this->getParameterValue($param);
if ($value !== null) {
$data[$param] = json_encode($value);
}
}

return $data;
}

/**
* Get parameter value by name
*
* @param string $param
*
* @return mixed|null
*/
protected function getParameterValue($param)
{
$method = 'get' . ucfirst($param);
if (method_exists($this, $method)) {
$value = $this->{$method}();
if ($value) {
return $value;
}
}

return null;
}
}
57 changes: 54 additions & 3 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Omnipay\Sberbank\Message;

use Fiscal\OFD\OrderInterface;
use Omnipay\Common\Exception\RuntimeException;
use Omnipay\Sberbank\Util\FiscalOFDAdapter;

/**
* Class AuthorizeRequest
Expand Down Expand Up @@ -32,13 +34,21 @@ public function getData()
'pageView',
'clientId',
'merchantLogin',
'jsonParams',
'sessionTimeoutSecs',
'expirationDate',
'bindingId'
'bindingId',
'taxSystem'
];

$additionalJsonParams = [
'jsonParams',
'orderBundle',
];

return $this->specifyAdditionalParameters($data, $additionalParams);
return array_merge(
$this->specifyAdditionalParameters($data, $additionalParams),
$this->specifyAdditionalJsonParameters($data, $additionalJsonParams)
);
}

/**
Expand Down Expand Up @@ -229,6 +239,47 @@ public function setBindingId($value)
return $this->setParameter('bindingId', $value);
}

/**
* @return array|null
*/
public function getOrderBundle()
{
return $this->getParameter('orderBundle');
}

/**
* @param OrderInterface|array|null $value
*
* @return \Omnipay\Common\Message\AbstractRequest
* @throws \Omnipay\Common\Exception\RuntimeException
*/
public function setOrderBundle($value)
{
if(interface_exists('Fiscal\\OFD\\OrderInterface') && $value instanceof OrderInterface) {
$adapter = new FiscalOFDAdapter($value);
$value = $adapter->getOrderBundle();
}
return $this->setParameter('orderBundle', $value);
}

/**
* @return mixed
*/
public function getTaxSystem()
{
return $this->getParameter('taxSystem');
}

/**
* @param int $value
* @return \Omnipay\Common\Message\AbstractRequest
* @throws \Omnipay\Common\Exception\RuntimeException
*/
public function setTaxSystem($value)
{
return $this->setParameter('taxSystem', $value);
}

/**
* @param mixed $data
* @return object|\Omnipay\Common\Message\ResponseInterface
Expand Down
34 changes: 33 additions & 1 deletion src/Message/CaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

namespace Omnipay\Sberbank\Message;

use Fiscal\OFD\OrderInterface;
use Fiscal\OFD\OrderItemInterface;
use Omnipay\Sberbank\Util\FiscalOFDAdapter;

/**
* Class CaptureRequest
*
* @package Omnipay\Sberbank\Message
*/
class CaptureRequest extends AbstractRequest
Expand All @@ -21,7 +26,11 @@ public function getData()
'amount' => $this->getAmountInteger(),
];

return $data;
$additionalJsonParams = [
'depositItems',
];

return $this->specifyAdditionalJsonParameters($data, $additionalJsonParams);
}

/**
Expand All @@ -31,4 +40,27 @@ public function getMethod()
{
return 'deposit.do';
}

/**
* @return array|null
*/
public function getDepositItems()
{
return $this->getParameter('depositItems');
}

/**
* @param OrderInterface|array|null $value
*
* @return \Omnipay\Common\Message\AbstractRequest
* @throws \Omnipay\Common\Exception\RuntimeException
*/
public function setDepositItems($value)
{
if(interface_exists('Fiscal\\OFD\\OrderInterface') && $value instanceof OrderInterface) {
$adapter = new FiscalOFDAdapter($value);
$value = $adapter->getDepositItems();
}
return $this->setParameter('depositItems', $value);
}
}
69 changes: 69 additions & 0 deletions src/Message/OrderReceiptStatusRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Omnipay\Sberbank\Message;


use Omnipay\Common\Exception\InvalidRequestException;

class OrderReceiptStatusRequest extends AbstractRequest
{
/**
* @return array|mixed
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function getData()
{
if (!$this->getOrderId() && !$this->getOrderNumber()) {
throw new InvalidRequestException('You must specify one of the parameters - orderId or orderNumber');
}

return $this->specifyAdditionalParameters([], ['orderId', 'orderNumber', 'language', 'uuid']);
}

/**
* @return string
*/
public function getMethod()
{
return 'getReceiptStatus.do';
}

/**
* @return mixed
*/
public function getOrderNumber()
{
return $this->getParameter('orderNumber');
}

/**
* @param $value
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setOrderNumber($value)
{
return $this->setParameter('orderNumber', $value);
}

/**
* Get receipt ID in the fiscalizer
*
* @return string
*/
public function getUuid()
{
return $this->getParameter('uuid');
}

/**
* Set receipt ID in the fiscalizer
*
* @param string $value
*
* @return OrderReceiptStatusRequest
*/
public function setUuid($value)
{
return $this->setParameter('uuid', $value);
}
}
Loading