JeremyDunn / php-fedex-api-wrapper

This library provides a fluid interface for constructing requests to the FedEx web service API.
269 stars 184 forks source link

How to send multipe shpiment for get tracking details, is there way to short? #176

Closed noor1726 closed 2 years ago

noor1726 commented 3 years ago

How to send multiple tracking number to get details, FedEx support up to 30 tracking numbers, so I send like this is there a way to send simply up to 30 tracking numbers

public function testTrackingMultiple()
{
    $trackRequest = new ComplexType\TrackRequest();

    // User Credential
    $trackRequest->WebAuthenticationDetail->UserCredential->Key = env('FEDEX_KEY');
    $trackRequest->WebAuthenticationDetail->UserCredential->Password = env('FEDEX_PASSWORD');

    // Client Detail
    $trackRequest->ClientDetail->AccountNumber = env('FEDEX_ACCOUNT_NUMBER');
    $trackRequest->ClientDetail->MeterNumber = env('FEDEX_METER_NUMBER');

    // Version
    $trackRequest->Version->ServiceId = 'trck';
    $trackRequest->Version->Major = 19;
    $trackRequest->Version->Intermediate = 0;
    $trackRequest->Version->Minor = 0;

    // Track shipments up to 30 
    $trackingData = [1234456778900, 12211313000, 30009999999, 131313131300, 131313114400, 90908989800]; 

     $trackCount = sizeof($trackingData);

     switch ($trackCount) {
         case '1':
              $trackRequest->SelectionDetails = [new ComplexType\TrackSelectionDetail()];
             break;
         case '2':
              $trackRequest->SelectionDetails = [new ComplexType\TrackSelectionDetail(), new ComplexType\TrackSelectionDetail()];
             break;
          // .........

         case '5':
             $trackRequest->SelectionDetails = [new ComplexType\TrackSelectionDetail(), new ComplexType\TrackSelectionDetail(), new ComplexType\TrackSelectionDetail(), new ComplexType\TrackSelectionDetail(), new ComplexType\TrackSelectionDetail()];
             break;

         case '30':
              // ......
             break;
          default:
             $trackRequest->SelectionDetails = [new ComplexType\TrackSelectionDetail()];
             break;
      }
    $trackRequest->ProcessingOptions = [SimpleType\TrackRequestProcessingOptionType::_INCLUDE_DETAILED_SCANS];

    for ($i=0; $i < $trackCount; $i++) {
        $trackRequest->SelectionDetails[$i]->PackageIdentifier->Value = $trackingData[$i];
        $trackRequest->SelectionDetails[$i]->PackageIdentifier->Type = SimpleType\TrackIdentifierType::_TRACKING_NUMBER_OR_DOORTAG;
    }
    $request = new Request();
    $trackReply = $request->getTrackReply($trackRequest);
   return  $shipment = $trackReply->toArray();
}

Thanks in advance.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.