Bridge/Payum/OutstandingBalance/Action/ConvertAction.php
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getSource();

        $details = ArrayObject::ensureArrayObject($payment->getDetails());

        if (isset($details[Constants::FIELD_STATUS])) {
            return;
        }

        if (null === $sale = $payment->getSale()) {
            throw new RuntimeException("Payment's sale must be defined at this point.");
        }
        if (null === $customer = $sale->getCustomer()) {
            throw new RuntimeException("Sale's customer must be defined at this point.");
        }

        // Use parent if available
        if ($customer->hasParent()) {
            $customer = $customer->getParent();
        }

        // If sale has a customer limit
        if (0 < $limit = $sale->getOutstandingLimit()) {
            // Use sale's balance
            $balance = - $sale->getOutstandingAccepted() - $sale->getOutstandingExpired();
        } else {
            // Use customer's limit and balance
            $limit = $customer->getOutstandingLimit();
            $balance = $customer->getOutstandingBalance();
        }

        $details->defaults(array(
            Constants::FIELD_STATUS  => null,
            Constants::FIELD_AMOUNT  => $payment->getAmount(),
            Constants::FIELD_LIMIT   => $limit,
            Constants::FIELD_BALANCE => $balance,
        ));

        $request->setResult((array) $details);
    }
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getSource();

        $details = ArrayObject::ensureArrayObject($payment->getDetails());

        if (isset($details[Constants::FIELD_STATUS])) {
            return;
        }

        if (null === $sale = $payment->getSale()) {
            throw new RuntimeException("Payment's sale must be defined at this point.");
        }
        if (null === $customer = $sale->getCustomer()) {
            throw new RuntimeException("Sale's customer must be defined at this point.");
        }

        // Use parent if available
        if ($customer->hasParent()) {
            $customer = $customer->getParent();
        }

        // If sale has a customer limit
        if (0 < $limit = $sale->getOutstandingLimit()) {
            // Use sale's balance
            $balance = - $sale->getOutstandingAccepted() - $sale->getOutstandingExpired();
        } else {
            // Use customer's limit and balance
            $limit = $customer->getOutstandingLimit();
            $balance = $customer->getOutstandingBalance();
        }

        $details->defaults(array(
            Constants::FIELD_STATUS  => null,
            Constants::FIELD_AMOUNT  => $payment->getAmount(),
            Constants::FIELD_LIMIT   => $limit,
            Constants::FIELD_BALANCE => $balance,
        ));

        $request->setResult((array) $details);
    }
public function execute ( $ request ) { RequestNotSupportedException :: assertSupports ( $ this , $ request ) ; /** @var PaymentInterface $payment */ $ payment = $ request -> getSource ( ) ; $ details = ArrayObject :: ensureArrayObject ( $ payment -> getDetails ( ) ) ; if ( isset ( $ details [ Constants :: FIELD_STATUS ] ) ) { return ; } if ( null === $ sale = $ payment -> getSale ( ) ) { throw new RuntimeException ( "Payment's sale must be defined at this point." ) ; } if ( null === $ customer = $ sale -> getCustomer ( ) ) { throw new RuntimeException ( "Sale's customer must be defined at this point." ) ; } // Use parent if available if ( $ customer -> hasParent ( ) ) { $ customer = $ customer -> getParent ( ) ; } // If sale has a customer limit if ( 0 < $ limit = $ sale -> getOutstandingLimit ( ) ) { // Use sale's balance $ balance = - $ sale -> getOutstandingAccepted ( ) - $ sale -> getOutstandingExpired ( ) ; } else { // Use customer's limit and balance $ limit = $ customer -> getOutstandingLimit ( ) ; $ balance = $ customer -> getOutstandingBalance ( ) ; } $ details -> defaults ( array ( Constants :: FIELD_STATUS => null , Constants :: FIELD_AMOUNT => $ payment -> getAmount ( ) , Constants :: FIELD_LIMIT => $ limit , Constants :: FIELD_BALANCE => $ balance , ) ) ; $ request -> setResult ( ( array ) $ details ) ; }
{@inheritDoc}

@param Convert $request
{ @inheritDoc }