0

我一直在尝试通过以下示例在我的应用程序中实现贝宝功能:http ://www.alexventure.com/2011/04/02/zend-framework-and-paypal-api-part-2-of- 2/

这是我的控制器中的 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

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

4

1 回答 1

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

我希望您实现了构建构造函数的教程的第一部分。否则你可能只需要传递一个更好的uri。

[编辑] 我认为你的问题在这里:

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

ecSetExpressCheckout不构造 http 客户端,因此它不知道它从哪里请求令牌。

或者,您可以在 $paypal 下方和 $reply 上方添加这一行:

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

我只是希望你知道 url 应该是什么。

祝你好运。

于 2012-08-11T09:43:05.310 回答