kool_samule Posted August 24, 2010 Share Posted August 24, 2010 Hi Chaps, I'm integrating my app with PayPal WebPaymentsPro and at the ExpressCheckout part. I've contructed a parameter in NVP format: $nvpstr="&ADDRESSOVERRIDE=1$shiptoAddress&".$joined_nvp."&MAXAMT=".(string)$maxamt."&AMT=".(string)$amt."&ITEMAMT=".(string)$itemamt."&CALLBACKTIMEOUT=4&".$joined_nvp_ship."&INSURANCEAMT=0.00&INSURANCEOPTIONOFFERED=false&CALLBACK=https://www.ppcallback.com/callback.pl&SHIPPINGAMT=".$CALC_SHIP."&SHIPDISCAMT=0.00&TAXAMT=0.00&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&CURRENCYCODE=".$currencyCodeType."&PAYMENTACTION=".$paymentType; This, as an example, echo's: &ADDRESSOVERRIDE=1&SHIPTONAME=Name&SHIPTOSTREET=&SHIPTOCITY=&SHIPTOSTATE=&SHIPTOCOUNTRYCODE=GB&SHIPTOZIP=&L_NAME0=ITEM!&L_NUMBER0=40&L_DESC0=S&L_QTY0=1&L_AMT0=22.50&L_NAME1=ITEM2&L_NUMBER1=186&L_DESC1=S/M&L_QTY1=1&L_AMT1=14.00&L_NAME2=ITEM3&L_NUMBER2=105&L_DESC2=8&L_QTY2=1&L_AMT2=23.00&MAXAMT=66.5&AMT=59.5&ITEMAMT=59.5&CALLBACKTIMEOUT=4&L_SHIPPINGOPTIONLABEL0=UK - Free Delivery (UK orders over £50)&L_SHIPPINGOPTIONNAME0=UK - Free Delivery (UK orders over £50)&L_SHIPPINGOPTIONAMOUNT0=0&L_SHIPPINGOPTIONISDEFAULT0=true&L_SHIPPINGOPTIONLABEL1=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME1=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT1=4&L_SHIPPINGOPTIONISDEFAULT1=false&L_SHIPPINGOPTIONLABEL2=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME2=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT2=7&L_SHIPPINGOPTIONISDEFAULT2=false&INSURANCEAMT=0.00&INSURANCEOPTIONOFFERED=false&CALLBACK=https://www.ppcallback.com/callback.pl&SHIPPINGAMT=0&SHIPDISCAMT=0.00&TAXAMT=0.00&ReturnUrl=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FReviewOrder.php%3FcurrencyCodeType%3DGBP%26paymentType%3DSale&CANCELURL=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FSetExpressCheckout.php%3FpaymentType%3DSale&CURRENCYCODE=GBP&PAYMENTACTION=Sale If I attempt to pass the parameter to PayPal, I get an error stating that the Flat-rate shipping options are missing. However, if I echo the above code into a browser, then copy and paste in place of the variable parameter (so it is simply text): $nvpstr="&ADDRESSOVERRIDE=1&SHIPTONAME=Name&SHIPTOSTREET=&SHIPTOCITY=&SHIPTOSTATE=&SHIPTOCOUNTRYCODE=GB&SHIPTOZIP=&L_NAME0=ITEM!&L_NUMBER0=40&L_DESC0=S&L_QTY0=1&L_AMT0=22.50&L_NAME1=ITEM2&L_NUMBER1=186&L_DESC1=S/M&L_QTY1=1&L_AMT1=14.00&L_NAME2=ITEM3&L_NUMBER2=105&L_DESC2=8&L_QTY2=1&L_AMT2=23.00&MAXAMT=66.5&AMT=59.5&ITEMAMT=59.5&CALLBACKTIMEOUT=4&L_SHIPPINGOPTIONLABEL0=UK - Free Delivery (UK orders over £50)&L_SHIPPINGOPTIONNAME0=UK - Free Delivery (UK orders over £50)&L_SHIPPINGOPTIONAMOUNT0=0&L_SHIPPINGOPTIONISDEFAULT0=true&L_SHIPPINGOPTIONLABEL1=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME1=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT1=4&L_SHIPPINGOPTIONISDEFAULT1=false&L_SHIPPINGOPTIONLABEL2=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME2=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT2=7&L_SHIPPINGOPTIONISDEFAULT2=false&INSURANCEAMT=0.00&INSURANCEOPTIONOFFERED=false&CALLBACK=https://www.ppcallback.com/callback.pl&SHIPPINGAMT=0&SHIPDISCAMT=0.00&TAXAMT=0.00&ReturnUrl=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FReviewOrder.php%3FcurrencyCodeType%3DGBP%26paymentType%3DSale&CANCELURL=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FSetExpressCheckout.php%3FpaymentType%3DSale&CURRENCYCODE=GBP&PAYMENTACTION=Sale" This works, which has really stumped me. How can a parameter made up of variables fail, but the same output in it's place does? Is there something obvious that I am missing, because this is doing my brain in! Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/ Share on other sites More sharing options...
AbraCadaver Posted August 24, 2010 Share Posted August 24, 2010 You probably need to urlencode() all of the variables. Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103182 Share on other sites More sharing options...
schilly Posted August 24, 2010 Share Posted August 24, 2010 Yes you need to URL encode anything for the PayPal WSPP API. Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103230 Share on other sites More sharing options...
kool_samule Posted August 24, 2010 Author Share Posted August 24, 2010 Hi I have tried: urlencode, urldecode, utf8_encode, utf8_decode, and none of them work. When I echo my variables in $nvpstr , and then copy this, and replace the $nvpstr variables with a "string", it works fine. I do not understand! Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103251 Share on other sites More sharing options...
schilly Posted August 24, 2010 Share Posted August 24, 2010 Whats the response array give you? Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103269 Share on other sites More sharing options...
kool_samule Posted August 24, 2010 Author Share Posted August 24, 2010 Hi, this is the php that collects the form inputs from previous page, contructs the parameter and passes to payapl. require_once 'CallerService.php'; require_once 'constants.php'; $API_UserName=API_USERNAME; $API_Password=API_PASSWORD; $API_Signature=API_SIGNATURE; $API_Endpoint =API_ENDPOINT; $subject = SUBJECT; $token = $_REQUEST['token']; $getAuthModeFromConstantFile = true; $nvpHeader = ""; if(!$getAuthModeFromConstantFile) { $AuthMode = "THIRDPARTY"; } else { if(!empty($API_UserName) && !empty($API_Password) && !empty($API_Signature) && !empty($subject)) { $AuthMode = "THIRDPARTY"; }else if(!empty($API_UserName) && !empty($API_Password) && !empty($API_Signature)) { $AuthMode = "3TOKEN"; }else if(!empty($subject)) { $AuthMode = "FIRSTPARTY"; } } switch($AuthMode) { case "3TOKEN" : $nvpHeader = "&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature); break; case "FIRSTPARTY" : $nvpHeader = "&SUBJECT=".urlencode($subject); break; case "THIRDPARTY" : $nvpHeader = "&PWD=".urlencode($API_Password)."&USER=".urlencode($API_UserName)."&SIGNATURE=".urlencode($API_Signature)."&SUBJECT=".urlencode($subject); break; } if(! isset($token)) { $serverName = $_SERVER['SERVER_NAME']; $serverPort = $_SERVER['SERVER_PORT']; $url=dirname('http://'.$serverName.':'.$serverPort.$_SERVER['REQUEST_URI']); $currencyCodeType=$_REQUEST['currencyCodeType']; $paymentType=$_REQUEST['paymentType']; $personName = $_REQUEST['PERSONNAME']; $SHIPTOSTREET = $_REQUEST['SHIPTOSTREET']; $SHIPTOCITY = $_REQUEST['SHIPTOCITY']; $SHIPTOSTATE = $_REQUEST['SHIPTOSTATE']; $SHIPTOCOUNTRYCODE = $_REQUEST['SHIPTOCOUNTRYCODE']; $SHIPTOZIP = $_REQUEST['SHIPTOZIP']; $cartTotal = cartTotal(); $items = $_REQUEST['different_items']; $arr_items = array(); $arr_items_cost = array(); $i = 0; do{ $L_NAME = $_REQUEST['L_NAME'.$i]; $L_NUMBER = $_REQUEST['L_NUMBER'.$i]; $L_DESC = $_REQUEST['L_DESC'.$i]; $L_QTY = $_REQUEST['L_QTY'.$i]; $L_AMT = $_REQUEST['L_AMT'.$i]; $NVP = "L_NAME$i=$L_NAME&L_NUMBER$i=$L_NUMBER&L_DESC$i=$L_DESC&L_QTY$i=$L_QTY&L_AMT$i=$L_AMT"; $arr_items[] = $NVP; $arr_items_cost[] = $L_AMT; $i++; }while ($i < $items); $joined_nvp = join("&", $arr_items); $shipping_post = utf8_decode($_REQUEST['shippingname']); $shipping_iso = $_REQUEST['SHIPTOCOUNTRYCODE']; mysql_select_db($database_dbconnect, $dbconnect); $query_rsPostage = "SELECT * FROM tbl_postage INNER JOIN tbl_countries ON tbl_countries.shipping_zone=tbl_postage.shipping_zone WHERE tbl_countries.iso='$shipping_iso' ORDER BY postagetitle ASC"; $rsPostage = mysql_query($query_rsPostage, $dbconnect) or die(mysql_error()); $row_rsPostage = mysql_fetch_assoc($rsPostage); $totalRows_rsPostage = mysql_num_rows($rsPostage); $quantity = NoItems(); $arr_shipping = array(); $arr_ship_cost = array(); $pi = 0; do { $L_SHIPPINGOPTIONLABEL = $row_rsPostage['shipping_zone'].'-'.$row_rsPostage['postagetitle']; $L_SHIPPINGOPTIONNAME = $row_rsPostage['shipping_zone'].'-'.$row_rsPostage['postagetitle']; if($quantity != 1){ $surcharge_items = ($quantity-1); $surcharge_shipping = ($surcharge_items*$row_rsPostage['surcharge']); $L_SHIPPINGOPTIONAMOUNT = $row_rsPostage['postageprice']+$surcharge_shipping; } else { $additional_shipping = 0; $L_SHIPPINGOPTIONAMOUNT = $row_rsPostage['postageprice']; } if($L_SHIPPINGOPTIONLABEL == $shipping_post){ $L_SHIPPINGOPTIONISDEFAULT = "true"; $NVP_SHIP_OPTION = "SHIPPINGAMT=$L_SHIPPINGOPTIONAMOUNT"; $NVP_ARRAY_OPTION = "$L_SHIPPINGOPTIONAMOUNT"; $CALC_SHIP = $L_SHIPPINGOPTIONAMOUNT; } else{ $L_SHIPPINGOPTIONISDEFAULT = "false"; } $NVP_SHIP = "L_SHIPPINGOPTIONLABEL$pi=$L_SHIPPINGOPTIONLABEL&L_SHIPPINGOPTIONNAME$pi=$L_SHIPPINGOPTIONNAME&L_SHIPPINGOPTIONAMOUNT$pi=$L_SHIPPINGOPTIONAMOUNT&L_SHIPPINGOPTIONISDEFAULT$pi=$L_SHIPPINGOPTIONISDEFAULT"; $arr_shipping[] = $NVP_SHIP; $arr_ship_cost['price'] = $L_SHIPPINGOPTIONAMOUNT; $pi++; } while ($row_rsPostage = mysql_fetch_assoc($rsPostage)); $joined_nvp_ship = join("&", $arr_shipping); $returnURL =urlencode($url.'/ReviewOrder.php?currencyCodeType='.$currencyCodeType.'&paymentType='.$paymentType); $cancelURL =urlencode("$url/SetExpressCheckout.php?paymentType=$paymentType" ); $itemamt = array_sum($arr_items_cost); $items = number_format($itemamt, 2, '.', ''); $CALC_SHIP = number_format($CALC_SHIP, 2, '.', ''); $amt = $itemamt+$CALC_SHIP; $amt = number_format($amt, 2, '.', ''); $max_ship = max($arr_ship_cost); $maxamt= $itemamt+$max_ship; $maxamt = number_format($maxamt, 2, '.', ''); $shiptoAddress = "&SHIPTONAME=$personName&SHIPTOSTREET=$SHIPTOSTREET&SHIPTOCITY=$SHIPTOCITY&SHIPTOSTATE=$SHIPTOSTATE&SHIPTOCOUNTRYCODE=$SHIPTOCOUNTRYCODE&SHIPTOZIP=$SHIPTOZIP"; $nvpstr="&ADDRESSOVERRIDE=1$shiptoAddress&".$joined_nvp."&MAXAMT=".(string)$maxamt."&AMT=".(string)$amt."&ITEMAMT=".(string)$itemamt."&CALLBACKTIMEOUT=4&".$joined_nvp_ship."&INSURANCEAMT=0.00&INSURANCEOPTIONOFFERED=false&SHIPPINGAMT=".(string)$CALC_SHIP."&SHIPDISCAMT=0.00&TAXAMT=0.00&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&CURRENCYCODE=".$currencyCodeType."&PAYMENTACTION=".$paymentType."&CALLBACK=https://www.ppcallback.com/callback.pl"; $nvpstr = $nvpHeader.$nvpstr; $resArray=hash_call("SetExpressCheckout",$nvpstr); $_SESSION['reshash']=$resArray; $ack = strtoupper($resArray["ACK"]); if($ack=="SUCCESS"){ $token = urldecode($resArray["TOKEN"]); $payPalURL = PAYPAL_URL.$token; header("Location: ".$payPalURL); } else { $location = "APIError.php"; header("Location: $location"); } } else { $token =urlencode( $_REQUEST['token']); $nvpstr="&TOKEN=".$token; $nvpstr = $nvpHeader.$nvpstr; $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr); $_SESSION['reshash']=$resArray; $ack = strtoupper($resArray["ACK"]); if($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING'){ require_once "GetExpressCheckoutDetails.php"; } else { $location = "APIError.php"; header("Location: $location"); } } ?> Hope that is what you were on about, if not let me know and hopefully we can get it solved! cheers Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103296 Share on other sites More sharing options...
schilly Posted August 24, 2010 Share Posted August 24, 2010 Nope. I'm wonder what is in $resArray because that has all the info that PayPal sends back about the API call. If there was an error, it will be in there. Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103351 Share on other sites More sharing options...
kool_samule Posted August 25, 2010 Author Share Posted August 25, 2010 Hi, $nvpstr (without Header): &ADDRESSOVERRIDE=1&SHIPTONAME=Name&SHIPTOSTREET=Street&SHIPTOCITY=City&SHIPTOSTATE=State&SHIPTOCOUNTRYCODE=GB&SHIPTOZIP=ZIP&ORDERTOTAL=15.00&ITEMAMT=12&SHIPPINGAMT=3.00&AMT=15.00&HANDLINGAMT=0.00&SHIPDISCAMT=0.00&TAXAMT=0.00&MAXAMT=18.00&L_NAME0=Tribal Flowers Scarf&L_NUMBER0=204&L_DESC0=One Size &L_QTY0=1&L_AMT0=12.00&L_SHIPPINGOPTIONLABEL0=UK-Free Of Charge&L_SHIPPINGOPTIONNAME0=UK-Free Of Charge&L_SHIPPINGOPTIONAMOUNT0=0.00&L_SHIPPINGOPTIONISDEFAULT0=false&L_SHIPPINGOPTIONLABEL1=UK-Introductory Offer - Free UK Delivery&L_SHIPPINGOPTIONNAME1=UK-Introductory Offer - Free UK Delivery&L_SHIPPINGOPTIONAMOUNT1=0.00&L_SHIPPINGOPTIONISDEFAULT1=false&L_SHIPPINGOPTIONLABEL2=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME2=UK-Recorded Delivery - £3.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT2=3.00&L_SHIPPINGOPTIONISDEFAULT2=true&L_SHIPPINGOPTIONLABEL3=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONNAME3=UK-Special Next Day Delivery - £6.00 (plus 50p charge per extra item)&L_SHIPPINGOPTIONAMOUNT3=6.00&L_SHIPPINGOPTIONISDEFAULT3=false&CALLBACKTIMEOUT=4&ReturnUrl=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FReviewOrder.php%3FcurrencyCodeType%3DGBP%26paymentType%3DSale&CANCELURL=http%3A%2F%2Fwww.xxxxx.co.uk%3A80%2Fshop%2Fphp_nvp_samples%2FSetExpressCheckout.php%3FpaymentType%3DSale&CURRENCYCODE=GBP&PAYMENTACTION=Sale $resArray: Array ( [TIMESTAMP] => 2010-08-25T08:37:55Z [CORRELATIONID] => 1e91f230bd6a8 [ACK] => Failure [VERSION] => 64.0 [bUILD] => 1468257 [L_ERRORCODE0] => 10413 [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details. [L_LONGMESSAGE0] => The totals of the cart item amounts do not match order amounts. [L_SEVERITYCODE0] => Error ) Please note, the $nvpstr was made up of variable to produce the above. This resutls in failure (see $resArray). If I copy the value of $nvpstr, as it appears above, and send that as a string, it works. Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103478 Share on other sites More sharing options...
schilly Posted August 25, 2010 Share Posted August 25, 2010 Most of those variables you are using are deprecated as of v.63. https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103633 Share on other sites More sharing options...
kool_samule Posted August 25, 2010 Author Share Posted August 25, 2010 turns out it was a problem with the way i was contructing my parameter: changed '&' to &, and it worked fine! Link to comment https://forums.phpfreaks.com/topic/211589-nvp-problem/#findComment-1103644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.