paypal快速结账php

时间:2014-08-02 17:23:31

标签: php paypal

我一直在玩paypal api for exprescheckout。 问题:我无法调用L_PAYMENTREQUEST_n_方法。 PAYMENTREQUEST_0_有效。但我只能将它用于价格或迭代。 对于我需要使用L_PAYMENTREQUEST_n_方法的描述和数量。

thx任何帮助

<?php
// EXpress Checkout Paypal
$paketdata = array(
    array(

"name" => "Premium",
"desc" => "Mein Beschreibung",
"preis" => '9.96',
"count" => '2'
        )
);


$endpreis = "18.97";
$desc = 'meine beschreibung name';
$paypal ="#";
$user = "paypalap@email.com";
$password = "passwd1234";
$signature ="fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434";
$version = "93";
$currency = "EUR";

$params = array(
    'METHOD' => 'SetExpressCheckout',
    'USER' => $user,
    'SIGNATURE' => $signature,
    'PWD' => $password,
    'RETURNURL' => 'https://localhost/env/paypal/geschafft.php',
    'CANCELURL' => 'https://localhost/env/paypal/cancel.php',
    'VERSION' => $version,

    'PAYMENTREQUEST_0_AMT' => $endpreis,
    'PAYMENTREQUEST_0_CURRENCYCODE' => $currency,
   );

    foreach ($paketdata as $k => $paket){
    $params['L_PAYMENTREQUEST_0_NAME$k'] = $paket['name'];
    $params['L_PAYMENTREQUEST_0_DESC$k'] = '';
    $params['L_PAYMENTREQUEST_0_ITEMAMT$k'] = $paket['preis'];
  }

    $params = http_build_query($params);
    $endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $endpoint,
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => $params,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_VERBOSE => 1
    ));
    $response = curl_exec($curl);
    $responseArray = array();
    parse_str($response, $responseArray);

    if (curl_errno($curl)) {
    var_dump(curl_errno($curl));
    curl_close($curl);
    die();
    }else{
        if ($responseArray['ACK'] == 'Success') {

    }else{      
        curl_close($curl);
        }
}
    curl_close($curl);
    $paypal = 'https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token=' . $responseArray['TOKEN']; 
    echo '<pre>';
    print_r($paket);
    echo '</pre>';
    print_r($paypal)
?>


<a href="<?php echo urldecode($paypal) ?>">PAyPal</a>

1 个答案:

答案 0 :(得分:0)

您的要求就是这样......

Array
(
    [METHOD] => SetExpressCheckout
    [USER] => paypalap@email.com
    [SIGNATURE] => fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434
    [PWD] => passwd1234
    [RETURNURL] => https://localhost/env/paypal/geschafft.php
    [CANCELURL] => https://localhost/env/paypal/cancel.php
    [VERSION] => 93
    [PAYMENTREQUEST_0_AMT] => 18.97
    [PAYMENTREQUEST_0_CURRENCYCODE] => EUR
    [L_PAYMENTREQUEST_0_NAME$k] => Premium
    [L_PAYMENTREQUEST_0_DESC$k] => 
    [L_PAYMENTREQUEST_0_ITEMAMT$k] => 9.96
)

你需要在param名称周围使用双引号才能直接在里面使用$ k,所以你需要这个......

foreach ($paketdata as $k => $paket){
    $params["L_PAYMENTREQUEST_0_NAME$k"] = $paket['name'];
    $params["L_PAYMENTREQUEST_0_DESC$k"] = '';
    $params["L_PAYMENTREQUEST_0_ITEMAMT$k"] = $paket['preis'];
}

然后,这种变化给了我这个,这应该很好。

Array
(
    [METHOD] => SetExpressCheckout
    [USER] => paypalap@email.com
    [SIGNATURE] => fhhasHDJKHSAHJAL74327327dbsasahbsdcsadb7434
    [PWD] => passwd1234
    [RETURNURL] => https://localhost/env/paypal/geschafft.php
    [CANCELURL] => https://localhost/env/paypal/cancel.php
    [VERSION] => 93
    [PAYMENTREQUEST_0_AMT] => 18.97
    [PAYMENTREQUEST_0_CURRENCYCODE] => EUR
    [L_PAYMENTREQUEST_0_NAME0] => Premium
    [L_PAYMENTREQUEST_0_DESC0] => 
    [L_PAYMENTREQUEST_0_ITEMAMT0] => 9.96
)

另外请注意,您不想在退货时使用localhost并取消网址。 PayPal的服务器是重定向到该URL的服务器,因此当时的localhost是他们自己的服务器,当然,它不会做你想做的事情。

您需要使用公共IP地址或设置解析为您可以使用的IP的域。

事实上,它很有趣,我只是试图在localhost的前面使用http://,而且Stack不会让我发布链接,因为这个原因......他们会联系自己。