0

我长期使用 Paypal API 进行开发。

现在,我的网站上线了,我在将代码迁移到生活中时遇到了问题,我认为我需要添加 clientid+clientSecret,而我在开发网站上没有。

(正如我在https://github.com/paypal/rest-api-sdk-php和一些 workarround 上看到的)。

另外,我希望对下面的代码进行最小的更改,即使让它在生活网站中工作似乎已经过时了。

作为开发人员,我使用这样的“setExressCheckout”方法(注意回显 $response - 我不希望这条线。该怎么做?)

// =========== 代码开始

<?php

/*.
require_module 'standard';
    require_module 'standard_reflection';
    require_module 'spl';
    require_module 'mysqli';
    require_module 'hash';
    require_module 'session';
    require_module 'streams';
.*/

    require_once __DIR__ . "/stdlib/all.php";

/*. array .*/ $body_data = null;

$body_data_txt = "";

/*. string .*/ $htmlpage  = "";

/*. array .*/ $tokenAr = array();

$response = "";

session_start();

$url = trim('https://www.sandbox.paypal.com/cgi-bin/webscr');

$body_data = array( 'USER' => "*******",
                    'PWD' => "*******",                                    
                    'SIGNATURE' => "******",
                    'VERSION' => "95.0",
                    'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
                    'PAYMENTREQUEST_0_AMT' => (string)$_SESSION["AMOUNT"],
                    'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
                    'RETURNURL' => "*****",
                    'CANCELURL' => "******",
                    'METHOD' => "SetExpressCheckout"
                                );

$body_data_txt = http_build_query($body_data, '', chr(38));
try
{
    //create request and add headers
    $params = array(
        'http' => array(
            'protocol_version' => "1.1",
            'method' => "POST",
            'header' => "".
            "Connection: close\r\n".
            "Content-Length: ".strlen($body_data_txt)."\r\n".
            "Content-type: "."application/x-www-form-urlencoded"."\r\n",
            'content' => $body_data_txt
    ));

    //create stream context
     $ctx = stream_context_create($params);

    //open the stream and send request
    try {
        $fp = fopen($url, 'r', false, $ctx);
    } catch(ErrorException $e) {
        throw new ErrorException("cannot open url" . $url . " error:" . $e->getMessage());
    }
     //get response
     $response = (string)stream_get_contents($fp);
     //check to see if stream is open
     if ($response === "") {
        throw new Exception("php error message = " . "$php_errormsg");
     }

     //close the stream
     fclose($fp);   

     $key = explode("&", $response);
     if (substr($response, 0, 1) === "<") {
        echo $response; // ******************************
     }
     ....

// ============ 代码结束

代码没有按预期工作,因为“echo $response ...”行不应该运行。它的屏幕内容标题为:

“没有买家或卖家

免费注册。

……”

正如我调查的那样,我需要客户端 ID 和客户端密钥。我在https://developer.paypal.com上制作的。但是如何使用它 - 对我的代码进行最小的更改?

谢谢 :)

4

1 回答 1

0

我找到了我的问题的解决方案 - 不需要 clientid 和 clientsecret。

该代码对开发模式和生活模式的工作方式相同。

url 错误,应该是: $url = trim(' https://api-3t.paypal.com/nvp ');

不管怎么说,还是要谢谢你 :)

于 2014-07-14T22:47:32.547 回答