首先,我精通php:)
但我是NeOB在贝宝:)所以…如何使单件商品的购买按钮自动?像这样:我做了一个CMS,这样我可以添加新的项目出售。但每次我添加一个项目,那么我必须去贝宝创建这个项目,所以它可以购买…有什么办法可以自动完成吗?这样,当我添加一个新的项目,它可以只是买…这有PayPal解决方案吗?API中有什么?
谢谢您!

最佳答案

如果您有一个商家帐户,您可以使用Paypal NVP API来完全处理来自服务器的支付。我已经开发了几个这样的系统。文档没问题,但有些大的地方你可能会迷路。
这是我的支付对象方法中的一个示例,它使用Paypal API并返回一个响应代码:

// this line gets a query string out of the posted payment data
$details = $this->___prepare_for_paypal($details);
if (!$details)
    return false;

$API_USERNAME = 'USERNAMEHERE';
$API_PASSWORD = 'PASSWORDHERE';
$API_CERTIFICATE = '/usr/web/paypal/cert_key_pem';
$API_SIGNATURE = '';
$API_ENDPOINT = 'https://api.paypal.com/nvp';
$PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
$VERSION = '51.0';

//setting the curl parameters.
$ch = curl_init();

curl_setopt($ch, CURLOPT_SSLCERT, $API_CERTIFICATE);
curl_setopt($ch, CURLOPT_URL,$API_ENDPOINT);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);

//NVPRequest for submitting to server
$nvpreq="METHOD=doDirectPayment&VERSION=".urlencode($VERSION)."&PWD=".urlencode($API_PASSWORD)."&USER=".urlencode($API_USERNAME).$details;

//setting the nvpreq as POST FIELD to curl
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
//getting response from server
$response = curl_exec($ch);
//convrting NVPResponse to an Associative Array
$nvpResArray=$this->___deformat_NVP($response);
// check the API response array.  ACK will contain the word 'Success' if everything went through ok
$ack = strtoupper($nvpResArray["ACK"]);
// if we get no love from paypal, stick the transaction into the DB for reference
if($ack=="FAILURE") {
    $err_details = addslashes(serialize($nvpResArray));
    $err_details .= '||||'.addslashes($nvpreq);
    $sql = 'INSERT INTO payment_errors (time, user_id, details) VALUES ('.time().','.(user::export()->id ? user::export()->id : '0').',"'.$err_details.'")';
    db::update($sql);
    if (isset($nvpResArray['L_LONGMESSAGE0']))
        $this->_data['error_message'] = $nvpResArray['L_LONGMESSAGE0'];
    if (isset($nvpResArray['L_LONGMESSAGE0']))
        $this->_data['error_code'] = $nvpResArray['L_ERRORCODE0'];
    return false;
}

return $nvpResArray['TRANSACTIONID'];

09-11 02:49
查看更多