开发者

problem with my paypal express checkout payment?

im new to paypal express checkout and i have this code the payment to paypal

$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
    RedirectToPayPal ( $resArray["TOKEN"] );
} 
else  
{
    //Display a user friendly Error on the page using any of the following error information returned by PayPal
    $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
    $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
    $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
    $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);

    echo "SetExpressCheckout API call failed. ";
    echo "Detailed Error Message: " . $ErrorLongMsg;
    echo "Short Error Message: " . $ErrorShortMsg;
    echo "Error Code: " . $ErrorCode;
    echo "Error Severity Code: " . $ErrorSeverityCode;
}

and this the code for the CallShortcutExpressCheckout function

function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) 
    {
        //------------------------------------------------------------------------------------------------------------------------------------
        // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation

        $nvpstr="&PAYMENTREQUEST_0_AMT=". $paymentAmount;
        $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
        $nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
        $nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
        $nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;

        $_SESSION["currencyCodeType"] = $currencyCodeType;    
        $_SESSION["PaymentType"] = $paymentType;

        //'--------------------------------------------------------------------------------------------------------------- 
        //' Make the API call to PayPal
        //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.  
        //' If an error occured, show the resulting errors
        //'-------------------------------------------------------------------------------------------------------开发者_运维百科--------
        $resArray=hash_call("SetExpressCheckout", $nvpstr);
        $ack = strtoupper($resArray["ACK"]);
        if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
        {
            $token = urldecode($resArray["TOKEN"]);
            $_SESSION['TOKEN']=$token;
        }

        return $resArray;
    }

my problem that i don't know how to send the cart full info like the products title and code and that its what i need coz i have no orders sections into my shopping cart i want manage everything through email so what i need is to send the products description through the order and once the order i receive the order email confirmation have the items description


I'm trying to do the very same thing.

Let me start by saying that I have been trying to get the complete checkout to work for 2 days now and I still haven't completely succeeded :(

However it looks like I'm one step further than you.

Not sure if it's the correct way though but I'll show you what I got now and what I still have a problem with.

What I did was the following:

If the user clicks the checkout button a php file is called (let's call it checkout.php).

In the checkout.php file I construct an array with the items the user wants to order.

// fill array with two products
// normally you would loop through all products in the basket to create this array
$items = array('L_PAYMENTREQUEST_0_NAME0'=>'Productname 1',
               'L_PAYMENTREQUEST_0_NUMBER0'=>'Productcode 1',
               'L_PAYMENTREQUEST_0_DESC0'=>'Productdescription 1',
               'L_PAYMENTREQUEST_0_AMT0'=>39.99, // price per unit
               'L_PAYMENTREQUEST_0_QTY0'=>2, // quantity
               'L_PAYMENTREQUEST_0_NAME1'=>'Productname 2',
               'L_PAYMENTREQUEST_0_NUMBER1'=>'Productcode 2',
               'L_PAYMENTREQUEST_0_DESC1'=>'Productdescription 2',
               'L_PAYMENTREQUEST_0_AMT1'=>200.99,
               'L_PAYMENTREQUEST_0_QTY1'=>1,
               );

// set total amount of order in session (this will be used by paypal throughout the payment process)
$_SESSION['Payment_Amount'] = 280.97;

// now normally call CallShortcutExpressCheckout only with the addition of the $items array
$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items);

Now for the file with the functions that actually make the requests to PayPal:

I've created an extra function (generate_nvp_string) and changed the CallShortcutExpressCheckout function to use this string.

function generate_nvp_string($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items = array())
{
    $params = array('PAYMENTREQUEST_0_AMT'=>$paymentAmount,
                    'PAYMENTREQUEST_0_PAYMENTACTION'=>$paymentType,
                    'RETURNURL'=>$returnURL,
                    'CANCELURL'=>$cancelURL,
                    'PAYMENTREQUEST_0_CURRENCYCODE'=>$currencyCodeType,
                    );

    $params = array_merge($params, $items);

    $nvp_string = '';
    foreach($params as $name => $value) {
        $nvp_string.= '&'.$name.'='.$value;
    }

    return $nvp_string;
}

function CallShortcutExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items= array())
{
    $_SESSION['currencyCodeType'] = $this->currency;
    $_SESSION['PaymentType'] = $this->payment_type;

    $result = $this->hash_call('SetExpressCheckout', $this->generate_nvp_string($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $items));

    $ack = strtoupper($result['ACK']);
    if ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING') {
        $_SESSION['TOKEN'] = urldecode($result['TOKEN']);
    }

    return $result;
}

Now when the user clicks the checkout button the request string would also include the products. And when the user is redirected to PayPal checkout they will have a nice overview of all the products ordered.

I started this answer with:

and what I still have a problem with.

The checkout process seems to work now however when the user finishes the checkout process and is redirected back to my site ($returnURL) and don't get a transaction ID for some reason.

The transaction ID is kinda vital to be able to further process the payment on the backend.


I was trying to loop through items using a Form Submission. PayPal's sample code was only working for 1 item. Instead of making a function like PeeHaa's, I just checked to see if L_PAYMENTREQUEST_0_NAME0 was set, if it was, add all the variables to the $nvpstr string. Then continue to on to see if L_PAYMENTREQUEST_0_NAME1 was set, if it was, add it to the string, etc. Here is the code for anyone who needs it:

for($i=0; $i<99999; $i++){
    if(isset($paramsArray["L_PAYMENTREQUEST_0_NAME$i"])){
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NAME$i=" . $paramsArray["L_PAYMENTREQUEST_0_NAME$i"];
    }
    if(isset($paramsArray["L_PAYMENTREQUEST_0_NUMBER$i"])){
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_NUMBER$i=" . $paramsArray["L_PAYMENTREQUEST_0_NUMBER$i"];
    }
    if(isset($paramsArray["L_PAYMENTREQUEST_0_DESC$i"])){
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_DESC$i=" . $paramsArray["L_PAYMENTREQUEST_0_DESC$i"];
    }
    if(isset($paramsArray["L_PAYMENTREQUEST_0_AMT$i"])){
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_AMT$i=" . $paramsArray["L_PAYMENTREQUEST_0_AMT$i"];
    }
    if(isset($paramsArray["L_PAYMENTREQUEST_0_QTY$i"])){
        $nvpstr = $nvpstr . "&L_PAYMENTREQUEST_0_QTY$i=" . $paramsArray["L_PAYMENTREQUEST_0_QTY$i"];
    }
    if(!isset($paramsArray["L_PAYMENTREQUEST_0_NAME$i"])){
        break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜