src/ShopBundle/objects/db/TShopPaymentHandler/TShopPaymentHandlerPayPal.class.php
public function ExecutePayment(TdbShopOrder &$oOrder, $sMessageConsumer = '')
    {
        $bPaymentOk = parent::ExecutePayment($oOrder);

        $oCurrency = null;
        if (method_exists($oOrder, 'GetFieldPkgShopCurrency')) {
            $oCurrency = $oOrder->GetFieldPkgShopCurrency();
        }
        $sCurrency = $this->GetCurrencyIdentifier($oCurrency);
        $request = $this->getCurrentRequest();
        $aCommand = array(
            'TOKEN' => $this->sPayPalToken,
            'PAYERID' => $this->aCheckoutDetails['PAYERID'],
            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
            'PAYMENTREQUEST_0_AMT' => round($oOrder->fieldValueTotal, 2),
            'PAYMENTREQUEST_0_CURRENCYCODE' => $sCurrency,
            'IPADDRESS' => null === $request ? '' : $request->getClientIp(),
            'PAYMENTREQUEST_0_INVNUM' => $this->GetOrderNumber($oOrder),
            'PAYMENTREQUEST_0_CUSTOM' => $this->id.','.$oOrder->id,
        );
        $sIPNURL = $this->GetInstantPaymentNotificationListenerURL($oOrder);
        if (!empty($sIPNURL)) {
            $aCommand['PAYMENTREQUEST_0_NOTIFYURL'] = $sIPNURL;
        }

        $aAnswer = $this->ExecutePayPalCall('DoExpressCheckoutPayment', $aCommand);
        $ack = strtoupper($aAnswer['ACK']);
        if ('SUCCESS' == $ack) {
            $bPaymentOk = true;
            // add the response data to the order
            foreach ($aAnswer as $sKey => $sVal) {
                if (!array_key_exists($sKey, $this->aPaymentUserData)) {
                    $this->aPaymentUserData[$sKey] = $sVal;
                }
            }
            //        $this->SaveUserPaymentDataToOrder($oOrder->id);

            if (array_key_exists('PAYMENTINFO_0_PAYMENTSTATUS', $aAnswer) && 'COMPLETED' == strtoupper($aAnswer['PAYMENTINFO_0_PAYMENTSTATUS'])) {
                $oOrder->SetStatusPaid();
            }
        } else {
            $bPaymentOk = false;
        }

        if (!$bPaymentOk) {
            // error!
            $oMsgManager = TCMSMessageManager::GetInstance();
            $oMsgManager->AddMessage($sMessageConsumer, 'ERROR-ORDER-REQUEST-PAYMENT-ERROR', array('errorMsg' => self::GetPayPalErrorMessage($aAnswer)));
            $logContext = array(
                'Command' => $aCommand,
                'PayPalAnswer' => $aAnswer,
            );
            $this->getPaypalLogger()->critical('PayPal payment could not be executed for order id '.$oOrder->id, $logContext);
        }

        return $bPaymentOk;
    }
public function ExecutePayment(TdbShopOrder &$oOrder, $sMessageConsumer = '')
    {
        $bPaymentOk = parent::ExecutePayment($oOrder);

        $oCurrency = null;
        if (method_exists($oOrder, 'GetFieldPkgShopCurrency')) {
            $oCurrency = $oOrder->GetFieldPkgShopCurrency();
        }
        $sCurrency = $this->GetCurrencyIdentifier($oCurrency);
        $request = $this->getCurrentRequest();
        $aCommand = array(
            'TOKEN' => $this->sPayPalToken,
            'PAYERID' => $this->aCheckoutDetails['PAYERID'],
            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
            'PAYMENTREQUEST_0_AMT' => round($oOrder->fieldValueTotal, 2),
            'PAYMENTREQUEST_0_CURRENCYCODE' => $sCurrency,
            'IPADDRESS' => null === $request ? '' : $request->getClientIp(),
            'PAYMENTREQUEST_0_INVNUM' => $this->GetOrderNumber($oOrder),
            'PAYMENTREQUEST_0_CUSTOM' => $this->id.','.$oOrder->id,
        );
        $sIPNURL = $this->GetInstantPaymentNotificationListenerURL($oOrder);
        if (!empty($sIPNURL)) {
            $aCommand['PAYMENTREQUEST_0_NOTIFYURL'] = $sIPNURL;
        }

        $aAnswer = $this->ExecutePayPalCall('DoExpressCheckoutPayment', $aCommand);
        $ack = strtoupper($aAnswer['ACK']);
        if ('SUCCESS' == $ack) {
            $bPaymentOk = true;
            // add the response data to the order
            foreach ($aAnswer as $sKey => $sVal) {
                if (!array_key_exists($sKey, $this->aPaymentUserData)) {
                    $this->aPaymentUserData[$sKey] = $sVal;
                }
            }
            //        $this->SaveUserPaymentDataToOrder($oOrder->id);

            if (array_key_exists('PAYMENTINFO_0_PAYMENTSTATUS', $aAnswer) && 'COMPLETED' == strtoupper($aAnswer['PAYMENTINFO_0_PAYMENTSTATUS'])) {
                $oOrder->SetStatusPaid();
            }
        } else {
            $bPaymentOk = false;
        }

        if (!$bPaymentOk) {
            // error!
            $oMsgManager = TCMSMessageManager::GetInstance();
            $oMsgManager->AddMessage($sMessageConsumer, 'ERROR-ORDER-REQUEST-PAYMENT-ERROR', array('errorMsg' => self::GetPayPalErrorMessage($aAnswer)));
            $logContext = array(
                'Command' => $aCommand,
                'PayPalAnswer' => $aAnswer,
            );
            $this->getPaypalLogger()->critical('PayPal payment could not be executed for order id '.$oOrder->id, $logContext);
        }

        return $bPaymentOk;
    }
public function ExecutePayment ( TdbShopOrder & $ oOrder , $ sMessageConsumer = '' ) { $ bPaymentOk = parent :: ExecutePayment ( $ oOrder ) ; $ oCurrency = null ; if ( method_exists ( $ oOrder , 'GetFieldPkgShopCurrency' ) ) { $ oCurrency = $ oOrder -> GetFieldPkgShopCurrency ( ) ; } $ sCurrency = $ this -> GetCurrencyIdentifier ( $ oCurrency ) ; $ request = $ this -> getCurrentRequest ( ) ; $ aCommand = array ( 'TOKEN' => $ this -> sPayPalToken , 'PAYERID' => $ this -> aCheckoutDetails [ 'PAYERID' ] , 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale' , 'PAYMENTREQUEST_0_AMT' => round ( $ oOrder -> fieldValueTotal , 2 ) , 'PAYMENTREQUEST_0_CURRENCYCODE' => $ sCurrency , 'IPADDRESS' => null === $ request ? '' : $ request -> getClientIp ( ) , 'PAYMENTREQUEST_0_INVNUM' => $ this -> GetOrderNumber ( $ oOrder ) , 'PAYMENTREQUEST_0_CUSTOM' => $ this -> id . ',' . $ oOrder -> id , ) ; $ sIPNURL = $ this -> GetInstantPaymentNotificationListenerURL ( $ oOrder ) ; if ( ! empty ( $ sIPNURL ) ) { $ aCommand [ 'PAYMENTREQUEST_0_NOTIFYURL' ] = $ sIPNURL ; } $ aAnswer = $ this -> ExecutePayPalCall ( 'DoExpressCheckoutPayment' , $ aCommand ) ; $ ack = strtoupper ( $ aAnswer [ 'ACK' ] ) ; if ( 'SUCCESS' == $ ack ) { $ bPaymentOk = true ; // add the response data to the order foreach ( $ aAnswer as $ sKey => $ sVal ) { if ( ! array_key_exists ( $ sKey , $ this -> aPaymentUserData ) ) { $ this -> aPaymentUserData [ $ sKey ] = $ sVal ; } } //        $this->SaveUserPaymentDataToOrder($oOrder->id); if ( array_key_exists ( 'PAYMENTINFO_0_PAYMENTSTATUS' , $ aAnswer ) && 'COMPLETED' == strtoupper ( $ aAnswer [ 'PAYMENTINFO_0_PAYMENTSTATUS' ] ) ) { $ oOrder -> SetStatusPaid ( ) ; } } else { $ bPaymentOk = false ; } if ( ! $ bPaymentOk ) { // error! $ oMsgManager = TCMSMessageManager :: GetInstance ( ) ; $ oMsgManager -> AddMessage ( $ sMessageConsumer , 'ERROR-ORDER-REQUEST-PAYMENT-ERROR' , array ( 'errorMsg' => self :: GetPayPalErrorMessage ( $ aAnswer ) ) ) ; $ logContext = array ( 'Command' => $ aCommand , 'PayPalAnswer' => $ aAnswer , ) ; $ this -> getPaypalLogger ( ) -> critical ( 'PayPal payment could not be executed for order id ' . $ oOrder -> id , $ logContext ) ; } return $ bPaymentOk ; }
executes payment for order - in this case, we commit the paypal payment.

@param TdbShopOrder $oOrder
@param string       $sMessageConsumer - send error messages here

@return bool
executes payment for order - in this case we commit the paypal payment .