Laravel - FexEd发货请求API响应ERROR

时间:2017-04-30 07:09:52

标签: php laravel fedex

当我将FedEx货件API与Laravel集成时,我遇到了以下错误。我使用这个包 - https://github.com/JeremyDunn/php-fedex-api-wrapper

如果有人知道如何使用FedEx API创建出货请求,请帮助我解决此问题,我播下了此类型错误消息“此请求不允许操作类型TRANSFER”。错误代码3630。

我还添加了我的响应输出代码,所以你们都很了解

我的Laravel代码

$userCredential = new \FedEx\ShipService\ComplexType\WebAuthenticationCredential();
    $userCredential
        ->setKey('NCimB3Bq5GtxAQx7')
        ->setPassword('Zr1Bb3P1pjYtz0miXdIjut2OW');

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

    $clientDetail = new \FedEx\ShipService\ComplexType\ClientDetail();
    $clientDetail
        ->setAccountNumber('510087160')
        ->setMeterNumber('118814986');

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

    $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 = new \FedEx\ShipService\ComplexType\Party();
    $shipper
        ->setAccountNumber('510087020')
        ->setAddress($shipperAddress)
        ->setContact($shipperContact);

    $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);

    $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));


    $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_BOX));
    $requestedShipment->setShipper($shipper);
    $requestedShipment->setRecipient($recipient);
    $requestedShipment->setLabelSpecification($labelSpecification);
    $requestedShipment->setRateRequestTypes(array(new \FedEx\ShipService\SimpleType\RateRequestType(\FedEx\ShipService\SimpleType\RateRequestType::_ACCOUNT)));
    $requestedShipment->setPackageCount(2);




    $createPendingShipmentRequest = new \FedEx\ShipService\ComplexType\CreatePendingShipmentRequest();
    // dd($webAuthenticationDetail::_NAME);
    $createPendingShipmentRequest->setWebAuthenticationDetail($webAuthenticationDetail);
    $createPendingShipmentRequest->setClientDetail($clientDetail);
    $createPendingShipmentRequest->setVersion($version);
    $createPendingShipmentRequest->setRequestedShipment($requestedShipment);
    // dd($createPendingShipmentRequest);




    $shipService = new \FedEx\ShipService\Request();
    $shipService->getSoapClient()->__setLocation('https://wsbeta.fedex.com/web-services/ship');
    $result = $shipService->getCreatePendingShipmentReply($createPendingShipmentRequest);
    dd($result);

我的回复输出

{#389 ▼
  +"HighestSeverity": "ERROR"
  +"Notifications": array:2 [▼
    0 => {#390 ▼
      +"Severity": "ERROR"
      +"Source": "ship"
      +"Code": "3630"
      +"Message": "Action type TRANSFER is not allowed for this request."
      +"LocalizedMessage": "Action type TRANSFER is not allowed for this request."
      +"MessageParameters": {#391 ▼
        +"Id": "ACTION"
        +"Value": "TRANSFER"
      }
    }
    1 => {#392 ▼
      +"Severity": "ERROR"
      +"Source": "ship"
      +"Code": "2021"
      +"Message": "Invalid package count or invalid package sequence number."
      +"LocalizedMessage": "Invalid package count or invalid package sequence number."
    }
  ]
  +"Version": {#393 ▼
    +"ServiceId": "ship"
    +"Major": 12
    +"Intermediate": 1
    +"Minor": 0
  }
}

1 个答案:

答案 0 :(得分:0)

添加此代码:

$pendingShipmentDetail = new ComplexType\PendingShipmentDetail();
    $pendingShipmentDetail
        ->setType(SimpleType\PendingShipmentType::_EMAIL)
        ->setExpirationDate('06/12/2017')
        ->setEmailLabelDetail(new ShipComplexType\EMailLabelDetail(array(
            'NotificationEMailAddress' => 'test@gmail.com',
            'NotificationMessage' => 'pending shipment notification message'
        )));
    $specialServicesRequested = new ComplexType\ShipmentSpecialServicesRequested();
    $specialServicesRequested
        ->setSpecialServiceTypes(array(SimpleType\ShipmentSpecialServiceType::_PENDING_SHIPMENT))
        ->setPendingShipmentDetail($pendingShipmentDetail);


$requestedShipment->setSpecialServicesRequested($specialServicesRequested);