测试第三方购物车(Paypal)



我正在尝试测试第三方购物车api,并且总是得到空字符串作为结果。

这是我要测试的代码:

$ch = curl_init();
    $params = array();
    $params["cmd"]= "_cart";
    $url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
    $params["upload"] = 1;
    $params["business"] = "my business email";
    $params["item_name_1"] = "Item Name 1";
    $params["amount_1"]  = "1.00";
    $params["shipping_1"] = "1.75";
    $params["item_name_2"] = "Item Name 2";
    $params["amount_2"] = "2.00";
    $params["shipping_2"] ="2.50";
    $params["currency_code"] = "USD";
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params));
    $response = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    curl_close($ch);
我得到$response = "";

我有一些问题:

  1. 知道我做错了什么吗?
  2. 我应该得到哪个回复?
  3. 我应该做令牌api (https://api.sandbox.paypal.com/v1/oauth2/token)在这种情况下获得密钥?

首先你必须张贴到paypal服务器不是数组,但像查询使用http_build_query方法-遵循我的例子:

$padata['L_BILLINGAGREEMENTDESCRIPTION0']   = 'product description';
$padata['L_PAYMENTREQUEST_0_DESC0']         = $padata['L_BILLINGAGREEMENTDESCRIPTION0'] . ' price - 0,01$';
$padata['PAYMENTREQUEST_0_NOTIFYURL']       = 'http://yourdomain.com/paypal/ipn';
$padata['PAYMENTREQUEST_0_DESC']            = 'product name'; //enter code here
$padata['CANCELURL']                        = ''http://yourdomain.com/paypal/cancelurl';
$padata['RETURNURL']                        = ''http://yourdomain.com/paypal/returnurl';
$padata['PAYMENTREQUEST_0_CURRENCYCODE']    = 'USD';
$padata['PAYMENTREQUEST_0_PAYMENTACTION']   = 'SALE';
$padata['PAYMENTREQUEST_0_ITEMAMT']         = $product->price;
$padata['PAYMENTREQUEST_0_AMT']             = $product->price;
$padata['L_BILLINGTYPE0']                   = 'RecurringPayments';
$padata['L_PAYMENTREQUEST_0_NAME0']         = 'product name';
$padata['L_PAYMENTREQUEST_0_NUMBER0']       = 223; // 'product ID '
$padata['L_PAYMENTREQUEST_0_QTY0']          = '1';
$padata['L_PAYMENTREQUEST_0_AMT0']          = $product->price;
$paypal_data            = http_build_query($padata);
$httpParsedResponseAr   = $this->PPHttpPost('SetExpressCheckout', $paypal_data);

我使用一个分离的方法发送数据到paypal api:

private function PPHttpPost($methodName_, $nvpStr_) {$api_username = 'yourapiemail@paypal.com';$api_password = '111111';$api_signature = 'ASDdsasdaASDasdaDASDFzMjEzStQBLyke6Pi4vQhAy3JWRsdOpQybmHjpzasdsad.fT';$api_endpoint = "https://api-3t.paypal.com/nvp";$version = '124.0';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $api_endpoint);curl_setopt($ch, CURLOPT_VERBOSE, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setpt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$api_password&USER=$api_username&SIGNATURE=$api_signature&$nvpStr_";curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);$httpResponse = curl_exec($ch);如果(! $ httpResponse) {退出(" $ methodName_失败:".curl_error (ch美元)。"(".curl_errno (ch)美元。)");}//提取响应细节。$httpResponseAr = explosion ("&", $httpResponse);$httpParsedResponseAr = array();foreach ($httpResponseAr作为$i => $value) {$tmpAr = explosion ("=", $value);if(sizeof($tmpAr)> 1) {$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];}}if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {exit(" POST请求($nvpreq)到$api_endpoint无效的HTTP响应");}返回httpParsedResponseAr美元;} 

相关内容

  • 没有找到相关文章

最新更新