-
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.
- Loading branch information
Showing
4 changed files
with
178 additions
and
2 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,90 @@ | ||
<?php | ||
|
||
namespace DachcomDigital\Payum\Powerpay\Action\Api; | ||
|
||
use DachcomDigital\Payum\Powerpay\Api; | ||
use DachcomDigital\Payum\Powerpay\Exception\PowerpayException; | ||
use DachcomDigital\Payum\Powerpay\Request\Api\Cancel; | ||
use DachcomDigital\Payum\Powerpay\Request\Api\Confirm; | ||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\ApiAwareInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\Exception\UnsupportedApiException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
|
||
class CancelAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
use PowerpayAwareTrait; | ||
|
||
/** | ||
* @var Api | ||
*/ | ||
protected $api; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function setApi($api) | ||
{ | ||
if (false == $api instanceof Api) { | ||
throw new UnsupportedApiException('Not supported.'); | ||
} | ||
$this->api = $api; | ||
} | ||
|
||
/** | ||
* @param Cancel $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$details = ArrayObject::ensureArrayObject($request->getModel()); | ||
$details->validateNotEmpty(['card_number']); | ||
|
||
try { | ||
$result = $this->api->generateCancelRequest($details); | ||
|
||
$resultData['response_date'] = $result['ResponseDate']; | ||
$resultData['skipped'] = false; | ||
|
||
//there was an error. | ||
if (isset($result['ResponseCode'])) { | ||
$resultData['response_code'] = $result['ResponseCode']; | ||
} else { | ||
|
||
$resultData['card_statistics_total_number'] = $result['CardStatistics']['Total']['@attributes']['number']; | ||
$resultData['card_statistics_total_amount'] = $result['CardStatistics']['Total']['@attributes']['amount']; | ||
$resultData['card_statistics_purchase_number'] = $result['CardStatistics']['Purchase']['@attributes']['number']; | ||
$resultData['card_statistics_purchase_amount'] = $result['CardStatistics']['Purchase']['@attributes']['amount']; | ||
$resultData['card_statistics_credit_number'] = $result['CardStatistics']['Credit']['@attributes']['number']; | ||
$resultData['card_statistics_credit_amount'] = $result['CardStatistics']['Credit']['@attributes']['amount']; | ||
$resultData['card_statistics_reversal_number'] = $result['CardStatistics']['Reversal']['@attributes']['number']; | ||
$resultData['card_statistics_reversal_amount'] = $result['CardStatistics']['Reversal']['@attributes']['amount']; | ||
|
||
if (isset($result['Skipped'])) { | ||
$resultData['skipped'] = true; | ||
$resultData['skipped_reason'] = $result['Skipped']['Reason']; | ||
} | ||
} | ||
|
||
$request->setResult($resultData); | ||
|
||
} catch (PowerpayException $e) { | ||
$this->populateDetailsWithError($details, $e, $request); | ||
} | ||
} | ||
|
||
/** | ||
* {@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
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,30 @@ | ||
<?php | ||
|
||
namespace DachcomDigital\Payum\Powerpay\Request\Api; | ||
|
||
use Payum\Core\Request\Generic; | ||
|
||
class Cancel extends Generic | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $result; | ||
|
||
/** | ||
* @param $result | ||
*/ | ||
public function setResult($result) | ||
{ | ||
$this->result = $result; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getResult() | ||
{ | ||
return $this->result; | ||
} | ||
|
||
} |