'Error validating payment, payment not completed!' ); protected function _prepareData($orderData, $cartData) { $data = array(); if (!empty($orderData)) { $subtotal = Zend_Locale_Math::Sub($orderData['subtotal'], $orderData['promo'], 4); $subtotal = Zend_Locale_Math::Sub($subtotal, $orderData['giftCard'], 4); $returnUrl = BASE_URL . '/' . CURRENT_PAGE . '?type=' . $this->_paymentService . '&id=' . $orderData['invoice'] . '&action='; $data = array( 'invoice' => $orderData['invoice'], 'amount' => Zend_Locale_Math::round($orderData['total'], 2), 'subtotal' => Zend_Locale_Math::round($subtotal, 2), 'tax' => Zend_Locale_Math::round($orderData['tax'], 2), 'promo' => Zend_Locale_Math::round($orderData['promo'], 2), 'giftCard' => Zend_Locale_Math::round($orderData['giftCard'], 2), 'itemList' => array(), 'cancelUrl' => $returnUrl . 'cancelOrder', 'returnUrl' => $returnUrl . 'completeOrder', 'custom' => array( 'ADDROVERRIDE' => true, 'ALLOWNOTE' => false, ) ); if ($orderData['shippingCity'] && $orderData['shippingAddress']) { $data['custom'] = $data['custom'] + [ 'PAYMENTREQUEST_0_SHIPTOSTREET' => $orderData['shippingAddress'] ? $orderData['shippingAddress'] : '', 'PAYMENTREQUEST_0_SHIPTOCITY' => $orderData['shippingCity'] ? : $orderData['shippingCity'], 'PAYMENTREQUEST_0_SHIPTOSTATE' => $orderData['shippingState'] ? $orderData['shippingState'] : '', 'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => $orderData['shippingZip'] ? 'US' : '', 'PAYMENTREQUEST_0_SHIPTOZIP' => $orderData['shippingZip'] ? $orderData['shippingZip'] : '' ]; } $data['shipping'] = Zend_Locale_Math::round($orderData['shippingRate'], 2); $data['handling'] = Zend_Locale_Math::round($orderData['shippingHandling'], 2); } foreach ($cartData as $cartItem) { $data['itemList'][] = array( 'L_PAYMENTREQUEST_0_AMT' => Zend_Locale_Math::round($cartItem['price'], 2), 'L_PAYMENTREQUEST_0_NAME' => $cartItem['title'], 'L_PAYMENTREQUEST_0_QTY' => $cartItem['quantity'], ); if (!empty($cartItem['promoValuePrice'])) { $data['promo'] = Zend_Locale_Math::round($cartItem['promoValuePrice'], 2); } } return $data; } public function getErrors() { if (empty($this->_errors)) { $paymentData = $this->getProcessResponse()->getData(); $error = $paymentData['L_LONGMESSAGE0']; } else { $error = $this->_errors; $this->_errors = null; } return $error; } protected function _setCustomErrors($errorMap) { $this->_errors = $this->_errorMessages[$errorMap]; return $this; } protected function _refundTransaction($id) { $this->process(array('transactionId' => $id), App_Service_Payment_PayPalExpressCheckout::REFUND_TRANSACTION); return $this; } public function verifyOrder() { $this->process( array('token' => Qs_Request::getGetValue('token')), App_Service_Payment_PayPalExpressCheckout::GET_EXPRESS_CHECKOUT_DETAILS_TYPE ); if (!$this->getProcessResponse()->isSuccess()) { return false; } $result = $this->getPayment()->verifyOrder( Qs_Request::getRequestValue('id'), $this->getProcessResponse()->getData('AMT') ); if (!$result) { $this->_setCustomErrors(self::MSG_ERROR_VALIDATE); return false; } $paymentResponse = $this->getProcessResponse(); $data = array( 'token' => Qs_Request::getGetValue('token'), 'amount' => $paymentResponse->getData('PAYMENTREQUEST_0_AMT'), 'currency' => $paymentResponse->getData('PAYMENTREQUEST_0_CURRENCYCODE'), 'payerId' => $paymentResponse->getData('PAYERID') ); $this->process($data, App_Service_Payment_PayPalExpressCheckout::DO_EXPRESS_CHECKOUT_PAYMENT_TYPE); if ($this->getProcessResponse()->isSuccess()) { $this->getPayment()->updateOrder(Qs_Request::getRequestValue('id')); return true; } $this->_refundTransaction($this->getProcessResponse()->getData('TRANSACTIONID')); return false; } }