예제 #1
0
 /**
  * Send request with new payment to PinPayments gateway
  *
  * @param Mage_Payment_Model_Info $payment
  * @param string $requestType
  * @param Dwyera_Pinpay_Model_Request
  * @return boolean Returns true if order was successfully placed
  * @throws Mage_Core_Exception
  * @throws InvalidArgumentException
  */
 protected function _place($payment, $requestType, $request)
 {
     $payment->setAmount($request->getAmount());
     switch ($requestType) {
         case self::REQUEST_TYPE_AUTH_ONLY:
         case self::REQUEST_TYPE_AUTH_CAPTURE:
         case self::REQUEST_TYPE_CAPTURE_ONLY:
             break;
         default:
             throw new InvalidArgumentException("Invalid request type of {$requestType}");
     }
     $httpResponse = $this->_postRequest($request, $requestType);
     // wrap the gateway response in the pinpay/result model
     /** @var Dwyera_Pinpay_Model_Result $result */
     $result = Mage::getModel("pinpay/result", $httpResponse);
     switch ($result->getGatewayResponseStatus()) {
         case $result::RESPONSE_CODE_APPROVED:
             // Sets the response token
             $payment->setCcTransId('' . $result->getResponseToken());
             $payment->setTransactionId('' . $result->getResponseToken());
             return true;
         case $result::RESPONSE_CODE_SUSP_FRAUD:
             $payment->setIsTransactionPending(true);
             $payment->setIsFraudDetected(true);
             $payment->setCcTransId('' . $result->getErrorToken());
             $payment->setTransactionId('' . $result->getErrorToken());
             return true;
         default:
             Mage::log('Payment could not be processed. ' . $result->getErrorDescription(), Zend_Log::INFO, self::$logFile);
             Mage::throwException(Mage::helper('pinpay')->__($result->getErrorDescription() . self::RESPONSE_APPEND_MSG));
     }
 }