-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is unknown at this point if Sylius will even accept this..
- Loading branch information
1 parent
09852fa
commit 245d508
Showing
22 changed files
with
2,538 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Alexrowesoap\Payumsagepay\Action\Api; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\ApiAwareInterface; | ||
use Payum\Core\ApiAwareTrait; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Alexrowesoap\Payumsagepay\Api; | ||
|
||
abstract class BaseApiAwareAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
use ApiAwareTrait; | ||
|
||
public function __construct() | ||
{ | ||
$this->apiClass = Api::class; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
namespace Alexrowesoap\Payumsagepay\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\Authorize; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
|
||
class AuthorizeAction implements ActionInterface, GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Authorize $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
throw new \LogicException('Not implemented'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Authorize && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
namespace Soapmedia\Payumsagepay\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\Cancel; | ||
|
||
class CancelAction implements ActionInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Cancel $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
throw new \LogicException('Not implemented'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Cancel && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
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,108 @@ | ||
<?php | ||
namespace Alexrowesoap\Payumsagepay\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\LogicException; | ||
use Payum\Core\Exception\UnsupportedApiException; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Reply\HttpRedirect; | ||
use Payum\Core\Request\Capture; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Alexrowesoap\Payumsagepay\Api; | ||
use Alexrowesoap\Payumsagepay\Api\State\StateInterface; | ||
|
||
class CaptureAction implements ActionInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* @var Api | ||
*/ | ||
protected $api; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setApi($api) | ||
{ | ||
if (false === $api instanceof Api) { | ||
throw new UnsupportedApiException('Not supported.'); | ||
} | ||
|
||
$this->api = $api; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Capture $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
$token = $request->getToken(); | ||
|
||
if (isset($model['Status'])) { | ||
return; | ||
} | ||
|
||
$details = $this->api->prepareOffsiteDetails($model->toUnsafeArray()); // filter model details for request | ||
|
||
$missing = $this->api->getMissingDetails($details); // sagepay's api is wayward we should check for presence of required minimum | ||
|
||
if (count($missing) > 0) { | ||
throw new LogicException( | ||
sprintf( | ||
'Missing: %s details are mandatory for current payment request!', | ||
implode(", ", array_keys($missing)) | ||
) | ||
); | ||
} | ||
|
||
$model['state'] = StateInterface::STATE_WAITING; | ||
|
||
// we do not need any sync action | ||
// but payum by default do not set any afterUrl to notify token | ||
if ($token) { | ||
$model['afterUrl'] = $token->getAfterUrl(); | ||
} | ||
|
||
$response = $this->api->createOffsitePurchase($details); | ||
|
||
$responseArr = json_decode( $response->getBody()->getContents() ); | ||
$model['state'] = $responseArr['Status'] == | ||
Api::STATUS_OK || $responseArr['Status'] == Api::STATUS_OK_REPEATED ? | ||
StateInterface::STATE_REPLIED : | ||
StateInterface::STATE_ERROR; | ||
|
||
/*$model->replace( | ||
array_merge( | ||
(array) $model->toUnsafeArray(), | ||
(array) $response->toArray() | ||
) | ||
);*/ | ||
|
||
if ($responseArr['Status'] == Api::STATUS_OK || | ||
$responseArr['Status'] == Api::STATUS_OK_REPEATED | ||
) { | ||
|
||
throw new HttpRedirect( | ||
$responseArr['NextURL'] . '=' . $responseArr['VPSTxId'] | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Capture && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
namespace Alexrowesoap\Payumsagepay\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Model\PaymentInterface; | ||
use Payum\Core\Request\Convert; | ||
use Payum\Core\Request\GetCurrency; | ||
|
||
class ConvertPaymentAction implements ActionInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Convert $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
/** @var PaymentInterface $payment */ | ||
$payment = $request->getSource(); | ||
|
||
$this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode())); | ||
$divisor = pow(10, $currency->exp); | ||
|
||
$details = ArrayObject::ensureArrayObject($payment->getDetails()); | ||
|
||
$details['VendorTxCode'] = $payment->getNumber(); | ||
$details['Amount'] = $payment->getTotalAmount() / $divisor; | ||
$details['Currency'] = $payment->getCurrencyCode(); | ||
$details['Description'] = $payment->getDescription(); | ||
$details['CustomerEMail'] = $payment->getClientEmail(); | ||
|
||
$request->setResult((array) $details); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Convert && | ||
$request->getSource() instanceof PaymentInterface && | ||
$request->getTo() == 'array' | ||
; | ||
} | ||
} |
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,122 @@ | ||
<?php | ||
namespace Alexrowesoap\Payumsagepay\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\Exception\UnsupportedApiException; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\GetHttpRequest; | ||
use Payum\Core\Request\Notify; | ||
use Alexrowesoap\Payumsagepay\Api; | ||
use Alexrowesoap\Payumsagepay\Api\Reply\NotifyResponse; | ||
use Alexrowesoap\Payumsagepay\Api\State\StateInterface; | ||
|
||
class NotifyAction implements ActionInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* @var Api | ||
*/ | ||
protected $api; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setApi($api) | ||
{ | ||
if (false === $api instanceof Api) { | ||
throw new UnsupportedApiException('Not supported.'); | ||
} | ||
|
||
$this->api = $api; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param Notify $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
if (!isset($model['state']) || | ||
!in_array( | ||
$model['state'], | ||
array( | ||
StateInterface::STATE_REPLIED, | ||
StateInterface::STATE_NOTIFIED, | ||
StateInterface::STATE_CONFIRMED, | ||
) | ||
) | ||
) { | ||
throw new RequestNotSupportedException("process only replied and notified payments"); | ||
} | ||
|
||
$httpRequest = new GetHttpRequest; | ||
$this->gateway->execute($httpRequest); | ||
|
||
if ($httpRequest->method != 'POST') { | ||
return; | ||
} | ||
|
||
$status = Api::STATUS_OK; | ||
$model['state'] = StateInterface::STATE_NOTIFIED; | ||
$notification = $httpRequest->request; | ||
$redirectUrl = $model['afterUrl']; | ||
// check signature hash | ||
|
||
if ($this->api->tamperingDetected((array) $notification, (array) $model->toUnsafeArray())) { | ||
$status = Api::STATUS_INVALID; | ||
$statusDetails = "Tampering detected. Wrong hash."; | ||
} else { | ||
if ($notification['Status'] == Api::STATUS_OK) { | ||
$model['state'] = StateInterface::STATE_CONFIRMED; | ||
} elseif ($notification['Status'] == Api::STATUS_PENDING) { | ||
$model['state'] = StateInterface::STATE_REPLIED; | ||
} else { | ||
$model['state'] = StateInterface::STATE_ERROR; | ||
} | ||
|
||
$statusDetails = 'Transaction processed'; | ||
|
||
if ($notification['Status'] == Api::STATUS_ERROR | ||
&& isset($notification['Vendor']) | ||
&& isset($notification['VendorTxCode']) | ||
&& isset($notification['StatusDetail']) | ||
) { | ||
$status = Api::STATUS_ERROR; | ||
$statusDetails = 'Status of ERROR is seen, together with your Vendor, VendorTxCode and the StatusDetail.'; | ||
} | ||
|
||
} | ||
|
||
$model['notification'] = (array) $notification; | ||
$model->replace( | ||
$model->toUnsafeArray() | ||
); | ||
|
||
$params = array( | ||
'Status' => $status, | ||
'StatusDetails' => $statusDetails, | ||
'RedirectURL' => $redirectUrl, | ||
); | ||
|
||
throw new NotifyResponse($params); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof Notify && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
Oops, something went wrong.