Zend framework Zend框架:Paypal
我一直在尝试通过以下示例在我的应用程序中实现paypal功能: 这是我在控制器中的paymentActionZend framework Zend框架:Paypal,zend-framework,Zend Framework,我一直在尝试通过以下示例在我的应用程序中实现paypal功能: 这是我在控制器中的paymentAction public function paymentAction() { $auth= Zend_Auth::getInstance(); $user= $auth->getIdentity(); $username = $user->username; $cart = new Application_Model_DbTable_Cart()
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
我哪里出错了?如果需要,我很乐意提供我的应用程序其他领域的代码。谢谢。
Zend\u Http\u客户端::请求()
未收到Zend\u Uri\u 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);
我只是希望你知道网址应该是什么
祝你好运。我已经修复了新的My_Paypal_Client()行。我已经实现了教程的第1部分。我想问题在于我的返回和取消URL?