2012-08-11 69 views
0

我一直在试图按照这里的例子来实现一个PayPal功能集成到我的应用程序:http://www.alexventure.com/2011/04/02/zend-framework-and-paypal-api-part-2-of-2/Zend框架:贝宝

这是我在我的控制器paymentAction。

public function paymentAction() 
{ 
    $auth= Zend_Auth::getInstance(); 
    $user= $auth->getIdentity(); 
    $username = $user->username; 

    $cart = new Application_Model_DbTable_Cart(); 

    $select = $cart->select() 
    ->from(array('c' => 'cart')) 
    ->join(array('p' => 'product'), 'p.productid = c.productid') 
    ->where('username = ?', $username) 
    ->setIntegrityCheck(false); 

    $fetch = $cart->fetchAll($select)->toArray(); 

    $paypal = new My_Paypal_Client; 
    $amount = 0.0; 

    foreach($fetch as $item) { 
     $amount = $amount + ($item['price']*$item['quantity']); 
     } 

    $returnURL = 'http://www.google.com'; 
    $cancelURL = 'http://www.yahoo.com'; 
    $currency_code = 'USD'; 

    $reply = $paypal->ecSetExpressCheckout(
     $amount, 
     $returnURL, 
     $cancelURL, 
     $currency_code 
     ); 

    if ($reply->isSuccessfull()) 
    { 
     $replyData = $paypal->parse($reply->getBody()); 
     if ($replyData->ACK == 'SUCCESS' || $replyData->ACK == 'SUCCESSWITHWARNING') 
     { 
      $token = $replyData->TOKEN; 
      $_SESSION['CHECKOUT_AMOUNT'] = $amount; 

      header(
      'Location: ' . 
      $paypal->api_expresscheckout_uri . 
      '?&cmd=_express-checkout&token=' . $token 
      ); 
     } 
    } 

    else 
    { 
     throw new Exception('ECSetExpressCheckout: We failed to get a successfull response from PayPal.'); 
    } 

} 

但是,这是返回的错误。

Message: No valid URI has been passed to the client 

我哪里出错了?如果需要,我很乐意提供来自我的应用程序其他区域的代码。谢谢。

回答

0

Zend_Http_Client::request()尚未收到Zend_Uri_Http的有效实例。

下面是发生错误:

/** 
    * Send the HTTP request and return an HTTP response object 
    * 
    * @param string $method 
    * @return Zend_Http_Response 
    * @throws Zend_Http_Client_Exception 
    */ 
    public function request($method = null) 
    { 
     if (! $this->uri instanceof Zend_Uri_Http) { 
      /** @see Zend_Http_Client_Exception */ 
      require_once 'Zend/Http/Client/Exception.php'; 
      throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');//Note the exact message. 
     }//Truncated 

唯一明显的错误,我在你提供的代码中看到的是:

$paypal = new My_Paypal_Client;//no() at end of declaration 

我希望你实现部分tutorial之一,构造函数是建成。否则,你可能只需要通过一个更好的uri。

[编辑] 我觉得你的问题是在这里:

//needs a uri value for Zend_Http_Client to construct 
$paypal = new My_Paypal_Client($url); 

ecSetExpressCheckout不建立HTTP客户端,因此没有在那里的请求从令牌的想法。

或者你可以只添加这条线之下$ PayPal和上面$回答:

//pass the uri required to construct Zend_Http_Client  
$paypal->setUri($url); 

我只是希望你知道的网址shouild是什么。

祝你好运。

+0

我已经修复了新的My_Paypal_Client()行。我已经实现了教程的第1部分。我认为问题出在我的退货和取消网址上? – Ayrx 2012-08-11 10:25:09