/**
  * Fill in the values the order create request requires.
  *
  * @return self
  */
 protected function _buildNewPayload()
 {
     $this->_payload->setBillingAddress($this->_getRomBillingAddress($this->_order->getBillingAddress()))->setCurrency($this->_order->getOrderCurrencyCode())->setLevelOfService($this->_config->levelOfService)->setLocale($this->_getLocale())->setOrderHistoryUrl($this->_helper->getOrderHistoryUrl($this->_order))->setOrderId($this->_order->getIncrementId())->setOrderTotal($this->_order->getBaseGrandTotal())->setOrderType($this->_config->orderType)->setRequestId($this->_coreHelper->generateRequestId('OCR-'));
     $createdAt = $this->_getAsDateTime($this->_order->getCreatedAt());
     if ($createdAt) {
         $this->_payload->setCreateTime($createdAt);
     }
     return $this->_setCustomerData($this->_order, $this->_payload)->_setOrderContext($this->_order, $this->_payload)->_setShipGroups($this->_order, $this->_payload)->_setPaymentData($this->_order, $this->_payload);
 }
 /**
  * Fill out the request payload with payment data and update the API request
  * body with the complete request.
  * @param Api\IBidirectionalApi $api
  * @param Varien_Object         $payment Most likely a Mage_Sales_Model_Order_Payment
  * @return self
  */
 protected function _prepareApiRequest(Api\IBidirectionalApi $api, Varien_Object $payment)
 {
     $request = $api->getRequestBody();
     $order = $payment->getOrder();
     $billingAddress = $order->getBillingAddress();
     $shippingAddress = $order->getShippingAddress() ?: $billingAddress;
     $request->setIsEncrypted($this->_isUsingClientSideEncryption)->setRequestId($this->_coreHelper->generateRequestId('CCA-'))->setOrderId($order->getIncrementId())->setPanIsToken(false)->setCardNumber($payment->getCcNumber())->setExpirationDate($this->_coreHelper->getNewDateTime(sprintf('%s-%s', $payment->getCcExpYear(), $payment->getCcExpMonth())))->setCardSecurityCode($payment->getCcCid())->setAmount($payment->getBaseAmountAuthorized())->setCurrencyCode(Mage::app()->getStore()->getBaseCurrencyCode())->setEmail($order->getCustomerEmail())->setIp($this->_httpHelper->getRemoteAddr())->setBillingFirstName($billingAddress->getFirstname())->setBillingLastName($billingAddress->getLastname())->setBillingPhone($billingAddress->getTelephone())->setBillingLines($billingAddress->getStreet(-1))->setBillingCity($billingAddress->getCity())->setBillingMainDivision($billingAddress->getRegionCode())->setBillingCountryCode($billingAddress->getCountry())->setBillingPostalCode($billingAddress->getPostcode())->setShipToFirstName($shippingAddress->getFirstname())->setShipToLastName($shippingAddress->getLastname())->setShipToPhone($shippingAddress->getTelephone())->setShipToLines($shippingAddress->getStreet(-1))->setShipToCity($shippingAddress->getCity())->setShipToMainDivision($shippingAddress->getRegionCode())->setShipToCountryCode($shippingAddress->getCountry())->setShipToPostalCode($shippingAddress->getPostcode())->setIsRequestToCorrectCVVOrAVSError($this->_getIsCorrectionNeededForPayment($payment));
     return $this;
 }
 /**
  * Prepare an API instance for a balance request - fill out and set the
  * request payload with gift card data.
  * @param  Api\IBidirectionalApi $api
  * @return self
  */
 protected function _prepareApiForVoid(Api\IBidirectionalApi $api)
 {
     $this->setRedeemVoidRequestId($this->_coreHelper->generateRequestId(self::VOID_REQUST_ID_PREFIX));
     $payload = $api->getRequestBody();
     $payload->setRequestId($this->getRedeemVoidRequestId())->setPin($this->getPin())->setAmount($this->getAmountRedeemed())->setCurrencyCode($this->getRedeemCurrencyCode());
     $this->_setPayloadPaymentContext($payload);
     $api->setRequestBody($payload);
     return $this;
 }
 /**
  * Make a PayPal void request for the order identified by the order id.
  *
  * @param string
  * @param string
  * @return array
  * @throws EbayEnterprise_PayPal_Exception when the operation cannot be completed or fails.
  */
 protected function doVoid($orderId, $currencyCode)
 {
     $sdk = $this->getSdk($this->config->apiOperationDoVoid);
     $payload = $sdk->getRequestBody();
     $payload->setOrderId($orderId)->setRequestId($this->coreHelper->generateRequestId(self::PAYPAL_DOVOID_REQUEST_ID_PREFIX))->setCurrencyCode($currencyCode);
     Mage::dispatchEvent('ebayenterprise_paypal_do_void_before_send', ['payload' => $payload]);
     $sdk->setRequestBody($payload);
     $reply = $this->sendRequest($sdk);
     Mage::dispatchEvent('ebayenterprise_paypal_do_void_after_send', ['payload' => $reply]);
     $isVoided = $reply->isSuccess();
     if (!$reply->isSuccess()) {
         $logMessage = 'PayPal DoVoid failed. See exception log for details.';
         $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__));
         $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED));
         $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     return ['method' => EbayEnterprise_PayPal_Model_Method_Express::CODE, 'order_id' => $reply->getOrderId(), 'is_voided' => $isVoided];
 }
 /**
  * Do Void Request/Response
  *
  * @param  Mage_Sales_Model_Order
  * @return array
  *
  * @throws EbayEnterprise_PayPal_Exception when the operation cannot be completed or fails.
  */
 public function doVoid(Mage_Sales_Model_Order $order)
 {
     $sdk = $this->getSdk($this->config->apiOperationDoVoid);
     $payload = $sdk->getRequestBody();
     $payload->setOrderId($order->getIncrementId())->setRequestId($this->coreHelper->generateRequestId(self::PAYPAL_DOVOID_REQUEST_ID_PREFIX))->setCurrencyCode($order->getOrderCurrencyCode());
     $sdk->setRequestBody($payload);
     $this->logApiCall('do void', $sdk->getRequestBody()->serialize(), 'request');
     $reply = $this->sendRequest($sdk);
     $isVoided = $reply->isSuccess();
     if (!$reply->isSuccess()) {
         $logMessage = 'PayPal DoVoid failed. See exception log for details.';
         $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__));
         $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED));
         $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     $this->logApiCall('do void', $reply->serialize(), 'response');
     return ['method' => EbayEnterprise_PayPal_Model_Method_Express::CODE, 'order_id' => $reply->getOrderId(), 'is_voided' => $isVoided];
 }