paypal快速结账php

i ve been playing with the paypal api for exprescheckout. the problem: i can not call the L_PAYMENTREQUEST_n_ methods. the PAYMENTREQUEST_0_ works. but i can use this only for price or itemprice. for the description and quantity i need to use L_PAYMENTREQUEST_n_ methods.

thx for any help

<?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>

Your request is coming out like this...

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
)

You need to use double quotes around the param name in order to use $k directly inside like that, so you need this...

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'];
}

That change then gives me this, which should go through just fine.

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
)

On another note, though, you don't want to use localhost in your return and cancel URL's. PayPal's server is the one redirecting to that URL, so localhost at that time is their own server, which isn't going to do what you want, of course.

You need to use your public IP address or setup a domain that resolves to your IP that you can use.

In fact, it's funny, I just tried to use http:// on the front of localhost here, and Stack won't let me post links with that because of that very reason...they would be linking to themselves.