$shipping_country_code = isset($_POST['SHIPTOCOUNTRY']) ? $_POST['SHIPTOCOUNTRY'] : ''; // Here, we may setup static shipping and tax options, or we could hit a 3rd party // web service API (eg. UPS, FedEx, USPS) to gather rates in real-time. // // // // Now we can generate a response for PayPal based on our new shipping values we got back from our carrier API. $CBFields = array(); // Gather shipping options. If you're pulling rates from a carrier API you would be looping through // their response in order to populate $ShippingOptions. Here, we're doing it manually for sample purposes. $ShippingOptions = array(); $Option = array('l_shippingoptionisdefault' => 'true', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '5.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00'); array_push($ShippingOptions, $Option); $Option = array('l_shippingoptionisdefault' => 'false', 'l_shippingoptionname' => 'UPS', 'l_shipingpoptionlabel' => 'UPS', 'l_shippingoptionamount' => '20.00', 'l_taxamt' => '0.00', 'l_insuranceamount' => '1.00'); array_push($ShippingOptions, $Option); $callback_data_request_array = array('CBFields' => $CBFields, 'ShippingOptions' => $ShippingOptions); // Now we pass the data into the class library which will return an NVP string $callback_data_response = $paypal->CallbackResponse($callback_data_request_array); // Gather the request data that PayPal sent us in case we need to log it somehow to see what's available. $request_content = ''; foreach ($_POST as $var => $val) { $request_content .= '&' . $var . '=' . urldecode($val); } // Pass the shipping/tax data into the library to obtain an NVP string that we'll // simply output as a web service response back to PayPal. $response_content_body = ''; $response_content = $paypal->NVPToArray($callback_data_response); foreach ($response_content as $var => $val) { $response_content_body .= $var . ': ' . urldecode($val) . '<br />'; } echo $callback_data_response;