Skip to content

Commit

Permalink
Change status workflow in PayU Action
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbager committed Sep 4, 2017
1 parent 367e317 commit e248555
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 6 additions & 15 deletions src/Action/PayUAction.php
Expand Up @@ -10,9 +10,8 @@

namespace BitBag\PayUPlugin\Action;

use BitBag\PayUPlugin\Exception\PayUException;
use BitBag\PayUPlugin\Bridge\OpenPayUBridge;
use BitBag\PayUPlugin\Bridge\OpenPayUBridgeInterface;
use BitBag\PayUPlugin\Exception\PayUException;
use BitBag\PayUPlugin\SetPayU;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
Expand Down Expand Up @@ -68,30 +67,22 @@ public function execute($request)

$openPayU = $this->getOpenPayUBridge();
$openPayU->setAuthorizationDataApi($environment, $signature, $posId);

$model = ArrayObject::ensureArrayObject($request->getModel());

if (null !== $model['orderId']) {
$response = $openPayU->retrieve($model['orderId'])->getResponse();
Assert::keyExists($response->orders, 0);

if (OpenPayUBridge::SUCCESS_API_STATUS === $response->status->statusCode) {
$model['status'] = OpenPayUBridge::SUCCESS_API_STATUS;
$request->setModel($model);
}

if (OpenPayUBridge::NEW_API_STATUS !== $response->orders[0]->status) {
$statusCode = $response->status->statusCode;
$model['status'] = $statusCode;

return;
}
return;
}

/** @var TokenInterface $token */
$token = $request->getToken();
$order = $this->prepareOrder($token, $model, $posId);
$response = $openPayU->create($order)->getResponse();

if ($response && $response->status->statusCode === OpenPayUBridge::SUCCESS_API_STATUS) {
if (true === (bool)$response) {
$model['orderId'] = $response->orderId;
$request->setModel($model);

Expand Down Expand Up @@ -173,7 +164,7 @@ private function resolveProducts($model)
'name' => $model['description'],
'unitPrice' => $model['totalAmount'],
'quantity' => 1
]
],
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Action/StatusAction.php
Expand Up @@ -39,7 +39,7 @@ public function execute($request)
}

if (OpenPayUBridge::PENDING_API_STATUS === $status) {
$request->markPending();
$request->markCaptured();

return;
}
Expand Down

0 comments on commit e248555

Please sign in to comment.