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 create test shipment request #30 #220

Open hamzajamshed007 opened 6 months ago

hamzajamshed007 commented 6 months ago
Hi,

how to create test shipment request in FEDEX. I am having issues with packagecount i don't understand what i give that it will work .. Here My Code //USER CREDENTIALS $userCredential = new \FedEx\ShipService\ComplexType\WebAuthenticationCredential(); $userCredential ->setKey(config('services.fedex.key')) ->setPassword(config('services.fedex.password'));

    $webAuthenticationDetail = new \FedEx\ShipService\ComplexType\WebAuthenticationDetail();
    $webAuthenticationDetail->setUserCredential($userCredential);

    //ACCOUNT DETAILS
    $clientDetail = new \FedEx\ShipService\ComplexType\ClientDetail();
    $clientDetail
        ->setAccountNumber(config('services.fedex.account'))
        ->setMeterNumber(config('services.fedex.meter'));

    //VERSION
    $version = new \FedEx\ShipService\ComplexType\VersionId();
    $version
        ->setMajor(28)
        ->setIntermediate(0)
        ->setMinor(0)
        ->setServiceId('ship');

    //SHIPPER CONTACT DETAILS
    $shipperAddress = new \FedEx\ShipService\ComplexType\Address();
    $shipperAddress
        ->setStreetLines(array(
            '1202 Chalet Ln',
            'Do Not Delete - Test Account'
        ))
        ->setCity('Harrison')
        ->setStateOrProvinceCode('AR')
        ->setPostalCode('72601')
        ->setCountryCode('US');

    $shipperContact = new \FedEx\ShipService\ComplexType\Contact();
    $shipperContact
        ->setCompanyName('Company Name')
        ->setEMailAddress('test@example.com')
        ->setPersonName('Person Name')
        ->setPhoneNumber(('123-123-1234'));

    //SHIPPER ACCOUTN NUMBER
    $shipper = new \FedEx\ShipService\ComplexType\Party();
    $shipper
        ->setAccountNumber('510000000')
        ->setAddress($shipperAddress)
        ->setContact($shipperContact);

    //RECIPENT CONTACT DETAILS
    $recipientAddress = new \FedEx\ShipService\ComplexType\Address();
    $recipientAddress
        ->setStreetLines(array('54312 1st Ave'))
        ->setCity('Anytown')
        ->setStateOrProvinceCode('NY')
        ->setPostalCode('12345')
        ->setCountryCode('US');

    $recipientContact = new \FedEx\ShipService\ComplexType\Contact();
    $recipientContact
        ->setPersonName('Contact Name');

    $recipient = new \FedEx\ShipService\ComplexType\Party();
    $recipient
        ->setAddress($recipientAddress)
        ->setContact($recipientContact);

    //LABEL SPECS
    $labelSpecification = new \FedEx\ShipService\ComplexType\LabelSpecification();
    $labelSpecification
        ->setLabelStockType(new \FedEx\ShipService\SimpleType\LabelStockType(\FedEx\ShipService\SimpleType\LabelStockType::_PAPER_7X4POINT75))
        ->setImageType(new \FedEx\ShipService\SimpleType\ShippingDocumentImageType(\FedEx\ShipService\SimpleType\ShippingDocumentImageType::_PDF))
        ->setLabelFormatType(new \FedEx\ShipService\SimpleType\LabelFormatType(\FedEx\ShipService\SimpleType\LabelFormatType::_COMMON2D));

    //REQUESTED SHIPMENT
    $requestedShipment = new \FedEx\ShipService\ComplexType\RequestedShipment();
    $requestedShipment->setShipTimestamp(date('c'));
    $requestedShipment->setDropoffType(new \FedEx\ShipService\SimpleType\DropoffType(\FedEx\ShipService\SimpleType\DropoffType::_REGULAR_PICKUP));
    $requestedShipment->setServiceType(new \FedEx\ShipService\SimpleType\ServiceType(\FedEx\ShipService\SimpleType\ServiceType::_FEDEX_GROUND));
    $requestedShipment->setPackagingType(new \FedEx\ShipService\SimpleType\PackagingType(\FedEx\ShipService\SimpleType\PackagingType::_FEDEX_SMALL_BOX));
    $requestedShipment->setShipper($shipper);
    $requestedShipment->setRecipient($recipient);
    $requestedShipment->setLabelSpecification($labelSpecification);
    $requestedShipment->setRateRequestTypes(array(new \FedEx\ShipService\SimpleType\RateRequestType(\FedEx\ShipService\SimpleType\RateRequestType::_CUSTOM)));
    $requestedShipment->setPackageCount(1);

    //chatgpt
    $processShipmentRequest = new \FedEx\ShipService\ComplexType\ProcessShipmentRequest();
    $processShipmentRequest->setWebAuthenticationDetail($webAuthenticationDetail);
    $processShipmentRequest->setClientDetail($clientDetail);
    $processShipmentRequest->setVersion($version);
    $processShipmentRequest->setRequestedShipment($requestedShipment);

    // Create a request object
    $ship_request = new \FedEx\ShipService\Request();
    $ship_request->getSoapClient()->__setLocation('https://wsbeta.fedex.com/web-services/ship');
    $result = $ship_request->getProcessShipmentReply($processShipmentRequest);
    dd($result);

    In the response error
    "HighestSeverity" => "ERROR"
"Notifications" => array:1 [
  0 => FedEx\ShipService\ComplexType\Notification {#406
    #name: "Notification"
    #values: array:5 [
      "Severity" => "ERROR"
      "Source" => "ship"
      "Code" => "2021"
      "Message" => "Invalid package count or invalid package sequence number."
      "LocalizedMessage" => "Invalid package count or invalid package sequence number."
    ]
  }