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

Rate Request - Invalid currency type #155

Closed vikicoder007 closed 2 years ago

vikicoder007 commented 4 years ago

I don't why but even after supplying PreferedCurrency to INR its still returning a error message ,

i have downloaded this repo and added some options which were not present in rate request php file . below i have added the new options accroding to the need this should work fine however they are not i am getting error message Invalid currency type, only INR is allowed

$rateRequest->RequestedShipment->ServiceType = "FEDEX_EXPRESS_SAVER";
$rateRequest->RequestedShipment->CustomsClearanceDetail->CommercialInvoice->Purpose = "SOLD";

My full code :

<?php
/**
 * This test will send the same test data as in FedEx's documentation:
 * /php/RateAvailableServices/RateAvailableServices.php5
 */

//remember to copy example.credentials.php as credentials.php replace 'FEDEX_KEY', 'FEDEX_PASSWORD', 'FEDEX_ACCOUNT_NUMBER', and 'FEDEX_METER_NUMBER'
require_once 'credentials.php';
require_once 'bootstrap.php';

use FedEx\RateService\Request;
use FedEx\RateService\ComplexType;
use FedEx\RateService\SimpleType;

$rateRequest = new ComplexType\RateRequest();

//authentication & client details
$rateRequest->WebAuthenticationDetail->UserCredential->Key = FEDEX_KEY;
$rateRequest->WebAuthenticationDetail->UserCredential->Password = FEDEX_PASSWORD;
$rateRequest->ClientDetail->AccountNumber = FEDEX_ACCOUNT_NUMBER;
$rateRequest->ClientDetail->MeterNumber = FEDEX_METER_NUMBER;

$rateRequest->TransactionDetail->CustomerTransactionId = md5(date("Y-m-d h:i:s"));

//version
$rateRequest->Version->ServiceId = 'crs';
$rateRequest->Version->Major = 24;
$rateRequest->Version->Minor = 0;
$rateRequest->Version->Intermediate = 0;

$rateRequest->ReturnTransitAndCommit = true;

//shipper
$rateRequest->RequestedShipment->PreferredCurrency = 'INR';
// $rateRequest->RequestedShipment->Shipper->Address->StreetLines = ['H Block'];
$rateRequest->RequestedShipment->Shipper->Address->City = 'Gurgaon';
$rateRequest->RequestedShipment->Shipper->Address->StateOrProvinceCode = 'HR';
$rateRequest->RequestedShipment->Shipper->Address->PostalCode = 122002;
$rateRequest->RequestedShipment->Shipper->Address->CountryCode = 'IN';

//recipient
// $rateRequest->RequestedShipment->Recipient->Address->StreetLines = ['13450 Farmcrest Ct'];
$rateRequest->RequestedShipment->Recipient->Address->City = 'Delhi';
$rateRequest->RequestedShipment->Recipient->Address->StateOrProvinceCode = 'DL';
$rateRequest->RequestedShipment->Recipient->Address->PostalCode = 110024;
$rateRequest->RequestedShipment->Recipient->Address->CountryCode = 'IN';

//shipping charges payment
$rateRequest->RequestedShipment->ShippingChargesPayment->PaymentType = SimpleType\PaymentType::_SENDER;

//rate request types
$rateRequest->RequestedShipment->RateRequestTypes = [SimpleType\RateRequestType::_PREFERRED, SimpleType\RateRequestType::_LIST];

$rateRequest->RequestedShipment->PackageCount = 1;

$rateRequest->RequestedShipment->ServiceType = "FEDEX_EXPRESS_SAVER";

//create package line items
$rateRequest->RequestedShipment->RequestedPackageLineItems = [new ComplexType\RequestedPackageLineItem()];

$rateRequest->RequestedShipment->CustomsClearanceDetail->CommercialInvoice->Purpose = "SOLD";

//package 1
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Weight->Value = 2;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Weight->Units = SimpleType\WeightUnits::_LB;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Length = 10;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Width = 10;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Height = 3;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Units = SimpleType\LinearUnits::_IN;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->GroupPackageCount = 1;

// //package 2
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Weight->Value = 5;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Weight->Units = SimpleType\WeightUnits::_LB;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Length = 20;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Width = 20;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Height = 10;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Units = SimpleType\LinearUnits::_IN;
// $rateRequest->RequestedShipment->RequestedPackageLineItems[1]->GroupPackageCount = 1;

$rateServiceRequest = new Request();
//$rateServiceRequest->getSoapClient()->__setLocation(Request::PRODUCTION_URL); //use production URL

$rateReply = $rateServiceRequest->getGetRatesReply($rateRequest); // send true as the 2nd argument to return the SoapClient's stdClass response.

if (!empty($rateReply->RateReplyDetails)) {
    foreach ($rateReply->RateReplyDetails as $rateReplyDetail) {
        echo '<pre>' . var_export($rateReplyDetail->ServiceType, true) . '</pre>';
        if (!empty($rateReplyDetail->RatedShipmentDetails)) {
            foreach ($rateReplyDetail->RatedShipmentDetails as $ratedShipmentDetail) {
                echo '<pre>' . var_export($ratedShipmentDetail->ShipmentRateDetail->RateType . ": " . $ratedShipmentDetail->ShipmentRateDetail->TotalNetCharge->Amount, true) . '</pre>';
            }
        }
        echo "<hr />";
    }
}
echo '<pre>' . var_export($rateReply, true) . '</pre>';

Response Code :

FedEx\RateService\ComplexType\RateReply::__set_state(array(
   'name' => 'RateReply',
   'values' => 
  array (
    'HighestSeverity' => 'ERROR',
    'Notifications' => 
    array (
      0 => 
      FedEx\RateService\ComplexType\Notification::__set_state(array(
         'name' => 'Notification',
         'values' => 
        array (
          'Severity' => 'ERROR',
          'Source' => 'crs',
          'Code' => '742',
          'Message' => 'Invalid currency type, only INR is allowed. ',
          'LocalizedMessage' => 'Invalid currency type, only INR is allowed. ',
          'MessageParameters' => 
          array (
            0 => 
            FedEx\RateService\ComplexType\NotificationParameter::__set_state(array(
               'name' => 'NotificationParameter',
               'values' => 
              array (
                'Id' => 'CURRENCY_TYPE',
                'Value' => 'INR',
              ),
            )),
          ),
        ),
      )),
    ),
    'TransactionDetail' => 
    FedEx\RateService\ComplexType\TransactionDetail::__set_state(array(
       'name' => 'TransactionDetail',
       'values' => 
      array (
        'CustomerTransactionId' => '547bf1b72b28d74aad1e80f1fdad3e31',
      ),
    )),
    'Version' => 
    FedEx\RateService\ComplexType\VersionId::__set_state(array(
       'name' => 'VersionId',
       'values' => 
      array (
        'ServiceId' => 'crs',
        'Major' => 24,
        'Intermediate' => 0,
        'Minor' => 0,
      ),
    )),
  ),
))
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.