Payum\Paypal\ProHosted\Nvp\Action\StatusAction::execute PHP Method

execute() public method

{@inheritDoc}
public execute ( Payum\Core\Request\GetStatusInterface $request )
$request Payum\Core\Request\GetStatusInterface
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);
        $model = ArrayObject::ensureArrayObject($request->getModel());
        foreach (range(0, 9) as $index) {
            if ($model['L_ERRORCODE' . $index]) {
                $request->markFailed();
                return;
            }
        }
        if (isset($model['CANCELLED'])) {
            $request->markCanceled();
            return;
        }
        if (null === ($paymentStatus = $model['PAYMENTSTATUS'])) {
            $request->markUnknown();
            return;
        }
        $refundStatuses = [Api::PAYMENTSTATUS_REFUNDED, Api::PAYMENTSTATUS_PARTIALLY_REFUNDED];
        if (in_array($paymentStatus, $refundStatuses)) {
            $request->markRefunded();
            return;
        }
        if ($paymentStatus == Api::PAYMENTSTATUS_COMPLETED) {
            $request->markCaptured();
            return;
        }
        $pendingStatuses = [Api::PAYMENTSTATUS_IN_PROGRESS, Api::PAYMENTSTATUS_PENDING];
        if (in_array($paymentStatus, $pendingStatuses)) {
            if (Api::PENDINGREASON_AUTHORIZATION == $model['PENDINGREASON']) {
                $request->markAuthorized();
                return;
            }
        }
        if ($paymentStatus == Api::PAYMENTSTATUS_PENDING) {
            $request->markPending();
            return;
        }
        $failedStatuses = array(Api::PAYMENTSTATUS_FAILED, Api::PAYMENTSTATUS_EXPIRED, Api::PAYMENTSTATUS_DENIED, Api::PAYMENTSTATUS_CANCELED_REVERSAL);
        if (in_array($paymentStatus, $failedStatuses)) {
            $request->markFailed();
            return;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @test
  */
 public function shouldMarkAuthorizedIfPaymentStatusPendingAndReasonAuthorization()
 {
     $action = new StatusAction();
     $request = new GetHumanStatus(array('AMT' => 12, 'PAYMENTSTATUS' => Api::PAYMENTSTATUS_PENDING, 'PENDINGREASON' => Api::PENDINGREASON_AUTHORIZATION));
     $action->execute($request);
     $this->assertTrue($request->isAuthorized());
 }