I am trying to implement shipping rate quotes into our website during the checkout process and I am able to send a request to FedEx and get a reply back in XML. I have been able to pull just the relevant data I want out of the long XML Response but I need to be able to take that XML Data and make it a variable in PHP so I can use it in the website and pass it to the database.
Here is the FedEx Response:
CODE
Response
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/><soapenv:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v7:RateReply xmlns:v7="http://fedex.com/ws/rate/v7"><v7:HighestSeverity>SUCCESS</v7:HighestSeverity><v7:Notifications><v7:Severity>SUCCESS</v7:Severity><v7:Source>crs</v7:Source><v7:Code>0</v7:Code><v7:Message>Request was successfully processed. </v7:Message><v7:LocalizedMessage>Request was successfully processed. </v7:LocalizedMessage></v7:Notifications><ns1:TransactionDetail xmlns:ns1="http://fedex.com/ws/rate/v7" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><ns1:CustomerTransactionId> *** Rate Request v7 using PHP ***</ns1:CustomerTransactionId></ns1:TransactionDetail><ns1:Version xmlns:ns1="http://fedex.com/ws/rate/v7" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><ns1:ServiceId>crs</ns1:ServiceId><ns1:Major>7</ns1:Major><ns1:Intermediate>0</ns1:Intermediate><ns1:Minor>0</ns1:Minor></ns1:Version><v7:RateReplyDetails><v7:ServiceType>FEDEX_GROUND</v7:ServiceType><v7:PackagingType>YOUR_PACKAGING</v7:PackagingType><v7:DeliveryStation>BCBA </v7:DeliveryStation><v7:CommitDetails><v7:ServiceType>FEDEX_GROUND</v7:ServiceType><v7:TransitTime>THREE_DAYS</v7:TransitTime><v7:BrokerToDestinationDays>0</v7:BrokerToDestinationDays></v7:CommitDetails><v7:DestinationAirportId>IAD</v7:DestinationAirportId><v7:IneligibleForMoneyBackGuarantee>false</v7:IneligibleForMoneyBackGuarantee><v7:OriginServiceArea>AA</v7:OriginServiceArea><v7:DestinationServiceArea>A1</v7:DestinationServiceArea><v7:TransitTime>THREE_DAYS</v7:TransitTime><v7:SignatureOption>SERVICE_DEFAULT</v7:SignatureOption><v7:ActualRateType>PAYOR_ACCOUNT</v7:ActualRateType><v7:RatedShipmentDetails><v7:EffectiveNetDiscount><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:EffectiveNetDiscount><v7:ShipmentRateDetail><v7:RateType>PAYOR_ACCOUNT</v7:RateType><v7:RateZone>7</v7:RateZone><v7:RatedWeightMethod>ACTUAL</v7:RatedWeightMethod><v7:DimDivisor>0</v7:DimDivisor><v7:FuelSurchargePercent>5.25</v7:FuelSurchargePercent><v7:TotalBillingWeight><v7:Units>LB</v7:Units><v7:Value>3.0</v7:Value></v7:TotalBillingWeight><v7:TotalBaseCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:TotalBaseCharge><v7:TotalFreightDiscounts><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalFreightDiscounts><v7:TotalNetFreight><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:TotalNetFreight><v7:TotalSurcharges><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:TotalSurcharges><v7:TotalNetFedExCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:TotalNetFedExCharge><v7:TotalTaxes><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalTaxes><v7:TotalNetCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:TotalNetCharge><v7:TotalRebates><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalRebates><v7:Surcharges><v7:SurchargeType>FUEL</v7:SurchargeType><v7:Level>PACKAGE</v7:Level><v7:Description>FedEx Ground Fuel</v7:Description><v7:Amount><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:Amount></v7:Surcharges></v7:ShipmentRateDetail><v7:RatedPackages><v7:GroupNumber>0</v7:GroupNumber><v7:EffectiveNetDiscount><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:EffectiveNetDiscount><v7:PackageRateDetail><v7:RateType>PAYOR_ACCOUNT</v7:RateType><v7:RatedWeightMethod>ACTUAL</v7:RatedWeightMethod><v7:BillingWeight><v7:Units>LB</v7:Units><v7:Value>3.0</v7:Value></v7:BillingWeight><v7:BaseCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:BaseCharge><v7:TotalFreightDiscounts><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalFreightDiscounts><v7:NetFreight><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:NetFreight><v7:TotalSurcharges><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:TotalSurcharges><v7:NetFedExCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:NetFedExCharge><v7:TotalTaxes><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalTaxes><v7:NetCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:NetCharge><v7:TotalRebates><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalRebates><v7:Surcharges><v7:SurchargeType>FUEL</v7:SurchargeType><v7:Level>PACKAGE</v7:Level><v7:Description>FedEx Ground Fuel</v7:Description><v7:Amount><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:Amount></v7:Surcharges></v7:PackageRateDetail></v7:RatedPackages></v7:RatedShipmentDetails><v7:RatedShipmentDetails><v7:ShipmentRateDetail><v7:RateType>PAYOR_LIST</v7:RateType><v7:RateZone>7</v7:RateZone><v7:RatedWeightMethod>ACTUAL</v7:RatedWeightMethod><v7:DimDivisor>0</v7:DimDivisor><v7:FuelSurchargePercent>5.25</v7:FuelSurchargePercent><v7:TotalBillingWeight><v7:Units>LB</v7:Units><v7:Value>3.0</v7:Value></v7:TotalBillingWeight><v7:TotalBaseCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:TotalBaseCharge><v7:TotalFreightDiscounts><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalFreightDiscounts><v7:TotalNetFreight><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:TotalNetFreight><v7:TotalSurcharges><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:TotalSurcharges><v7:TotalNetFedExCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:TotalNetFedExCharge><v7:TotalTaxes><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalTaxes><v7:TotalNetCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:TotalNetCharge><v7:TotalRebates><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalRebates><v7:Surcharges><v7:SurchargeType>FUEL</v7:SurchargeType><v7:Level>PACKAGE</v7:Level><v7:Description>FedEx Ground Fuel</v7:Description><v7:Amount><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:Amount></v7:Surcharges></v7:ShipmentRateDetail><v7:RatedPackages><v7:GroupNumber>0</v7:GroupNumber><v7:PackageRateDetail><v7:RateType>PAYOR_LIST</v7:RateType><v7:RatedWeightMethod>ACTUAL</v7:RatedWeightMethod><v7:BillingWeight><v7:Units>LB</v7:Units><v7:Value>3.0</v7:Value></v7:BillingWeight><v7:BaseCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:BaseCharge><v7:TotalFreightDiscounts><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalFreightDiscounts><v7:NetFreight><v7:Currency>USD</v7:Currency><v7:Amount>6.47</v7:Amount></v7:NetFreight><v7:TotalSurcharges><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:TotalSurcharges><v7:NetFedExCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:NetFedExCharge><v7:TotalTaxes><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalTaxes><v7:NetCharge><v7:Currency>USD</v7:Currency><v7:Amount>6.81</v7:Amount></v7:NetCharge><v7:TotalRebates><v7:Currency>USD</v7:Currency><v7:Amount>0.0</v7:Amount></v7:TotalRebates><v7:Surcharges><v7:SurchargeType>FUEL</v7:SurchargeType><v7:Level>PACKAGE</v7:Level><v7:Description>FedEx Ground Fuel</v7:Description><v7:Amount><v7:Currency>USD</v7:Currency><v7:Amount>0.34</v7:Amount></v7:Amount></v7:Surcharges></v7:PackageRateDetail></v7:RatedPackages></v7:RatedShipmentDetails></v7:RateReplyDetails></v7:RateReply></soapenv:Body></soapenv:Envelope>
I know its fairly massive and the info I want out of it is just the TotalNetFedExCharge.
Here is the code I wrote to be able to pull the
CODE
$rsd = end($response->RateReplyDetails->RatedShipmentDetails);
printf($rsd->ShipmentRateDetail->TotalNetFedExCharge->Amount, $rsd->ShipmentRateDetail->TotalNetFedExCharge->Currency);
And finally here is my attempt to parse the xml.
CODE
function getXmlValueByTag($inXmlset,$needle){
$resource = xml_parser_create();//Create an XML parser
xml_parse_into_struct($resource, $inXmlset, $outArray);// Parse XML data into an array structure
xml_parser_free($resource);//Free an XML parser
for($i=0;$i<count($outArray);$i++){
if($outArray[$i]['TotalNetFedExCharge']==strtoupper($needle)){
$tagValue = $outArray[$i]['Amount'];
}
}
return $tagValue;
}
echo getXmlValueByTag($inXmlset,$needle);
I would really appreciate the help.