I can't figure out what I'm doing wrong I've set the authentication and version number but I just can get authenticated.
I get the following error when I try the sample code.
Severity: ERROR
Source: prof
Code: 1000
Message: Authentication Failed
Can anyone advise me on this please?! This is the first part of code, which is a barely modified copy of the example.
$path_to_wsdl = "./RateService_v18.wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'PmzmlFAKEKEYVha',
'Password' => 'myfedex-website-password'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => '123456789',
'MeterNumber' => '123456789'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => 'testing');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '18',
'Intermediate' => '0',
'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_PRIORITY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['TotalInsuredValue']=array('Ammount'=>100,'Currency'=>'USD');
$request['RequestedShipment']['Shipper'] = addShipper();
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem1();
try
{
if(setEndpoint('changeEndpoint'))
{
$newLocation = $client->__setLocation(setEndpoint('endpoint'));
}
$response = $client ->getRates($request);
if ($response -> HighestSeverity != 'FAILURE' && $response -> HighestSeverity != 'ERROR')
{
$rateReply = $response -> RateReplyDetails;
echo '<table border="1">';
echo '<tr><td>Service Type</td><td>Amount</td><td>Delivery Date</td></tr><tr>';
$serviceType = '<td>'.$rateReply -> ServiceType . '</td>';
$amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount,2,".",",") . '</td>';
if(array_key_exists('DeliveryTimestamp',$rateReply)){
$deliveryDate= '<td>' . $rateReply->DeliveryTimestamp . '</td>';
}else if(array_key_exists('TransitTime',$rateReply)){
$deliveryDate= '<td>' . $rateReply->TransitTime . '</td>';
}else {
$deliveryDate='<td> </td>';
}
echo $serviceType . $amount. $deliveryDate;
echo '</tr>';
echo '</table>';
printSuccess($client, $response);
}
else
{
printError($client, $response);
}
writeToLog($client); // Write to log file
} catch (SoapFault $exception) {
printFault($exception, $client);
}
function addShipper(){
$shipper = array(
'Contact' => array(
'PersonName' => 'Sender Name',
'CompanyName' => 'Sender Company Name',
'PhoneNumber' => '9012638716'),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'Collierville',
'StateOrProvinceCode' => 'TN',
'PostalCode' => '38017',
'CountryCode' => 'US')
);
return $shipper;
}
function addRecipient(){
$recipient = array(
'Contact' => array(
'PersonName' => 'Recipient Name',
'CompanyName' => 'Company Name',
'PhoneNumber' => '9012637906'
),
'Address' => array(
'StreetLines' => array('Address Line 1'),
'City' => 'Richmond',
'StateOrProvinceCode' => 'BC',
'PostalCode' => 'V7C4V4',
'CountryCode' => 'CA',
'Residential' => false)
);
return $recipient;
}
function addShippingChargesPayment(){
$shippingChargesPayment = array(
'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
'Payor' => array(
'ResponsibleParty' => array(
'AccountNumber' => getProperty('billaccount'),
'CountryCode' => 'US')
)
);
return $shippingChargesPayment;
}
function addLabelSpecification(){
$labelSpecification = array(
'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG
'LabelStockType' => 'PAPER_7X4.75');
return $labelSpecification;
}
function addSpecialServices(){
$specialServices = array(
'SpecialServiceTypes' => array('COD'),
'CodDetail' => array(
'CodCollectionAmount' => array('Currency' => 'USD', 'Amount' => 150),
'CollectionType' => 'ANY')// ANY, GUARANTEED_FUNDS
);
return $specialServices;
}
function addPackageLineItem1(){
$packageLineItem = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => 50.0,
'Units' => 'LB'
),
'Dimensions' => array(
'Length' => 108,
'Width' => 5,
'Height' => 5,
'Units' => 'IN'
)
);
return $packageLineItem;
}
Thank you in advance for ANY help! :)
the password is not your password you already have. it is another one they email you later. :/
Related
So my team have cloned a project that have a hook that can track the activity of the users like anything that they POST or GET. The previous project have work perfectly on local and on server. But on the recent project, it only work normal when I run it on local. But on server the hook only track user when they log out.
here's the hooks.php "application/config":
$hook['post_controller_constructor'][] = array(
'class' => 'Activity_user',
'function' => 'log_activity',
'filename' => 'log_activity_user.php',
'filepath' => 'hooks',
// 'params' => array('red', 'yellow', 'blue')
);
here's the log_activity_user "application/hooks/":
class Activity_user {
function __construct() {
$this->CI =& get_instance();
$this->CI->load->library('session');
$this->CI->load->library('lactivityuser');
}
public function log_activity() {
$post = $this->CI->input->post();
$get = $this->CI->input->get();
$timezone = new DateTimeZone('Asia/Jakarta');
$date = new DateTime();
$date->setTimeZone($timezone);
$result = $date->format('Y-m-d H:i:s');
if(count($post) > 0){
if (strpos($_SERVER["REQUEST_URI"], '/login')) {
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'melakukan login',
'created_date' => $result,
);
}else if (strpos($_SERVER["REQUEST_URI"], '/Log_data')) {
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'Melihat Log Data',
'created_date' => $result,
);
}else if (strpos($_SERVER["REQUEST_URI"], '/History_IO')) {
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'Melihat History IO',
'created_date' => $result,
);
}else if (strpos($_SERVER["REQUEST_URI"], '/Dashboard')) {
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'Melihat Dashboard',
'created_date' => $result,
);
}else if (strpos($_SERVER["REQUEST_URI"], '/api/rule')) {
$data = array(
'email' => ' ',
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'Rule',
'created_date' => $result,
);
}else if (strpos($_SERVER["REQUEST_URI"], '/API/Rule')) {
$data = array(
'email' => ' ',
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => 'Rule',
'created_date' => $result,
);
}
else{
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => json_encode($post),
'created_date' => $result,
);
}
$this->CI->db->insert('tb_activity_user', $data);
}else if(count($get) > 0){
$data = array(
'email' => $_SESSION["email"] ?? $post["email"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => json_encode($get),
'created_date' => $result,
);
$this->CI->db->insert('tb_activity_user', $data);
}
}
}
edit: they have enable the hook to TRUE in the config file
I have been battling with the royal mail shipment soap api for a while now and I am not getting anywhere. The error I am getting is a validation error but it isn't telling me what is not right.
I tried the sample code that Royal Mail offers and that doesn't seem to be working properly either.
Does anyone have a really basic xml example for creating a shipment?
Thanks
<?php
ini_set('soap.wsdl_cache_enabled', 1);
ini_set('soap.wsdl_cache_ttl', 1);
class royalmaillabelRequest
{
private $apiapplicationid = "application id";
private $api_password = "password ";
private $api_username = ""; //"rxxxxxAPI"
private $locationforrequest = 'https://api.royalmail.net/shipping/v2';
private $api_service_enhancements = "";
private function preparerequest()
{
//PASSWORD DIGEST
$api_password = "";
$clientId = ""; //royal mail credentials
$clientSecret = "";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$creationDate = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = $nonce . $creationDate . base64_encode(sha1($api_password, TRUE));
$passwordDigest = base64_encode(sha1($nonce_date_pwd, TRUE));
$ENCODEDNONCE = base64_encode($nonce);
//SET CONNECTION DETAILS
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['stream_context'] = stream_context_create(array(
'http' => array(
'header' => implode("\r\n", array(
'Accept: application/soap+xml',
'X-IBM-Client-Id: ' . $clientId,
'X-IBM-Client-Secret: ' . $clientSecret
))
)
));
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = $this->locationforrequest;
$soapclient_options['soap_version'] = 'SOAP_1_1';
//launch soap client
$client = new SoapClient(dirname(__FILE__) . "/SAPI/ShippingAPI_V2_0_9.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
//headers needed for royal mail//D8D094Fd2716E3Es142588808s317
$HeaderObjectXML = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-D8D094FC22716E3EDE14258880881317">
<wsse:Username>' . $this->api_username . '</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">' . $passwordDigest . '</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">' . $ENCODEDNONCE . '</wsse:Nonce>
<wsu:Created>' . $created . '</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
//push the header into soap
$HeaderObject = new SoapVar($HeaderObjectXML, XSD_ANYXML);
//push soap header
$header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject);
$client->__setSoapHeaders($header);
return $client;
}
public function CreateShippiment($data)
{
$request = $this->buildCreateshippiment($data);
$type = 'createShipment';
return $this->makerequest($type, $request);
}
public function PrintLabel($shipmentNumber, $order_tracking_id)
{
$time = gmdate('Y-m-d\TH:i:s');
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $order_tracking_id
)
),
'shipmentNumber' => $shipmentNumber,
'outputFormat' => 'PDF'
);
$type = 'printLabel';
$response = $this->makerequest($type, $request);
return $response->label;
}
public function PrintDocument($shipmentNumber, $order_tracking_id)
{
$time = gmdate('Y-m-d\TH:i:s');
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $order_tracking_id
)
),
'shipmentNumber' => $shipmentNumber,
'documentName' => 'CN22',
'documentCopies' => '1',
'documentFormat' => 'PDF'
);
$type = 'printDocument';
$response = $this->makerequest($type, $request);
return $response->internationalDocument;
}
private function makerequest($type, $request)
{
$client = $this->preparerequest();
$response = false;
$times = 1;
while (true) {
try {
$response = $client->__soapCall($type, array(
$request
), array(
'soapaction' => $this->locationforrequest
));
// echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
}
catch (Exception $e) {
print_r($e);
if ($e->detail->exceptionDetails->exceptionCode == "E0010" && $times <= 25) {
sleep(1.5);
$times++;
continue;
} else {
echo $e->getMessage();
echo "<pre>";
print_r($e->detail);
echo $client->__getLastResponse();
echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
}
}
break;
}
return $response;
}
private function buildCreateshippiment($data2)
{
$time = gmdate('Y-m-d\TH:i:s');
$data = new ArrayObject();
foreach ($data2 as $key => $value) {
$data->$key = $value;
}
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array(
'code' => 'Delivery'
),
'serviceOccurrence' => 1,
'serviceType' => array(
'code' => $data->api_service_type
),
'serviceOffering' => array(
'serviceOfferingCode' => array(
'code' => $data->api_service_code
)
),
'serviceFormat' => array(
'serviceFormatCode' => array(
'code' => $data->api_service_format
)
),
'shippingDate' => date('Y-m-d'),
'recipientContact' => array(
'name' => $data->shipping_name,
'complementaryName' => $data->shipping_company
),
'recipientAddress' => array(
'addressLine1' => $data->shipping_address1,
'addressLine2' => $data->shipping_address2,
'addressLine3' => $data->shipping_county,
'stateOrProvince' => array(
stateOrProvinceCode => array(
name => $data->shipping_county
)
),
'postTown' => $data->shipping_town,
'postcode' => $data->shipping_postcode,
'country' => array(
'countryCode' => array(
'code' => 'US'
)
)
),
'items' => array(
'item' => array(
'numberOfItems' => $data->order_tracking_boxes,
'weight' => array(
'unitOfMeasure' => array(
'unitOfMeasureCode' => array(
'code' => 'g'
)
),
'value' => $data->order_tracking_weight
)
)
),
// 'internationalInfo' => array('parcels' => array('parcel' => array( 'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')),
// 'value' => $data->parcel_weight)),
// 'purposeOfShipment'=> '999',
// 'contentDetails' => $data->content
// )
// ),
'senderReference' => $data->sendersReference
//'signature' => 0,
)
);
if ($data->api_service_enhancements == 6 && $data->api_service_type == 1) {
$request['requestedShipment']['serviceEnhancements'] = array(
'enhancementType' => array(
'serviceEnhancementCode' => array(
'code' => $data->api_service_enhancements
)
)
);
}
return $request;
}
}
// $new= new royalmaillabelRequest();
// $data['order_tracking_id']="";
// $data['api_service_type']="";
// echo $data['api_service_code']="";
// $data['api_service_format']="";
// $data['shipping_name']="";
// $data['shipping_company']="";
// $data['shipping_address1']="";
// $data['shipping_address2']="";
// $data['shipping_town']="";
// $data['shipping_postcode']="";
// $data['order_tracking_boxes']="";
// $data['order_tracking_weight']="";
// $data['api_service_enhancements']="";
// $data['value']="600";
// $data['shipping_postcode']="123456";
// $data['serviceEnhancementCode']="";
// $new->CreateShippiment($data);
?>
I am have trouble converting array to xml here as the CustomerOrderLines are getting repeated, the xml generated gets only the last [CustomerOrderLines] value, how do i generate an xml with all the objects.
public function ProcessOrderAction(){
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$customerData = Mage::getSingleton('customer/session')->getCustomer();
$customerAddress = array();
$_orders = Mage::getModel('sales/order')->getCollection()- >addFieldToFilter('customer_id',$customerData->getId());
$_orderCnt = $_orders->count(); //orders count
if($_orderCnt == 0){
$CustomerOperation="Create";
}else{
$CustomerOperation="Find";
}
$soapClient = new SoapClient("https://api.ongoingsystems.se/Colliflow/service.asmx?wsdl", array('trace' => 1));
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$store = Mage::app('checkout/session')->getStore();
$ap_param = array(
'GoodsOwnerCode'=>'Test',
'UserName' => 'test',
'Password' => 'test',
'co'=> [
'OrderInfo'=>[
'OrderIdentification' => 'SystemId',
'OrderOperation' => 'Create',
'GoodsOwnerOrderNumber' => '1111',
'OrderId' => '',
'GoodsOwnerOrderId' => '102',
'DeliveryDate' => '2016-05-14T22:16:00',
'OrderType'=> [
'OrderTypeOperation' => 'CreateOrFind',
'OrderTypeIdentification' => 'OrderTypeCode'
]
],
'Customer'=> [
'CustomerOperation' => $CustomerOperation,
'CustomerIdentification' => 'CustomerNumber',
'ExternalCustomerCode' => 'ExternalCustomerCode',
'CustomerNumber' => ''.$customerData->getId(),
'CustomerId' => ''.$customerData->getId(),
'Name' => ''.$customerData->getName(),
'Address' => ''.$customerAddress['region'],
'PostCode' => ''.$customerAddress['postcode'],
'City' => ''.$customerAddress['city'],
'TelePhone' => ''.$customerAddress['telephone'],
'Remark' => 'Remarks',
'IsVisible'=>'true',
'NotifyBySMS'=> 'true',
'NotifyByEmail'=> 'false',
'NotifyByTelephone'=>'false',
'Email' => ''.$customerData->getEmail(),
'MobilePhone' => ''.$customerAddress['telephone'],
'CountryCode' =>'NO',
'CountryStateCode' => '90'
],
'CustomerOrderLines' => [
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '123',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '123',
'ArticleNumber' => ''.$item->getSku(),
'ArticleName' => ''.$item->getName(),
'NumberOfItems' => '6',
'ProductCode' => ''.$item->getProductId()
],
'CustomerOrderLine'=> [
'OrderLineIdentification' => 'ArticleNumber',
'ArticleIdentification' => 'ArticleNumber',
'OrderLineSystemId' => '1231',
'ExternalOrderLineCode' => 'ExternalOrderLineId',
'ArticleSystemId' => '1230',
'ArticleNumber' => '0000099',
'ArticleName' => 'test222',
'NumberOfItems' => '6',
'ProductCode' => '6786978'
]
]
]
);
print_r($ap_param);
$error = 0;
try {
$info = $soapClient->__call("ProcessOrder", array($ap_param));
}catch (SoapFault $fault) {
$error = 1;
print("
alert('Sorry, returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
window.location = 'main.php'; ");
}
if ($error == 0) {
$auth_num = $info->ProcessOrderResult;
print_r($auth_num);
}
}
I am using Codeigniter library to get fedex rates i have created my own library to get rates and i grab data on my controller the request processes but its returns me array(0) { } error, i have searched a lot i can't find why it returns array 0 what is this error what i am doing wrong.
My library file.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class fedex{
function rates(){
$weight = '46';
$this->path_to_wsdl = base_url()."assets/wsdl/RateService_v14.wsdl";
$key = 'acess_key';
$password = 'password';
$shipAccount = 'accound_no';
$meter = 'meter_no';
$dropofftype = 'dropofftype';
$service = 'FEDEX_1_DAY_FREIGHT';
$package = 'package';
$handling_method = 'price';
$handling_amount = '5';
$pkg_width = '6';
$pkg_height = '6';
$pkg_length = '5';
$insurance = true;
$billAccount = $shipAccount;
// Build Request
$package = $this->package_types['FEDEX_10KG_BOX'] = 'FEDEX_10KG_BOX';
$dropofftype = $this->dropoff_types['REGULAR_PICKUP'] = 'REGULAR_PICKUP';
ini_set("soap.wsdl_cache_enabled", 0);
ini_set('soap.wsdl_cache_ttl',0);
$client = new SoapClient($this->path_to_wsdl, array('trace' => 1, "exception" => 0));
// Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => $key,
'Password' => $password
)
);
$request['ClientDetail'] = array(
'AccountNumber' => $shipAccount,
'MeterNumber' => $meter
);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Rate Request v14 using PHP ***');
$request['Version'] = array(
'ServiceId' => 'crs',
'Major' => '14',
'Intermediate' => '0',
'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = false;
$request['RequestedShipment']['RequestedCurrency'] ='$';
$request['RequestedShipment']['DropoffType'] = $dropofftype;
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['PackagingType'] = $package;
if($insurance=='yes')
{
$request['RequestedShipment']['TotalInsuredValue']=array(
'Ammount'=> '5',
'Currency'=> '$',
);
}
$request['RequestedShipment']['Shipper'] = array(
'Contact' => array(
'CompanyName' => 'companyname',
'EMailAddress' => 'EMailAddress'
),
'Address' => array(
'StreetLines' => 'StreetLines',
'City' => 'City',
'StateOrProvinceCode' => 'StateOrProvinceCode',
'PostalCode' => 'PostalCode',
'CountryCode' => 'CountryCode'
)
);
$request['RequestedShipment']['Recipient'] = array(
'Contact' => array(
'PersonName' => " ",
'CompanyName' => '',
'PhoneNumber' => '',
),
'Address' => array(
'StreetLines' => '',
'City' => '',
'StateOrProvinceCode' => '',
'PostalCode' => 'postalcode',
'CountryCode' => '',
//'Residential' => false // no way to determine this
)
);
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
$request['RequestedShipment']['PackageCount'] = '1';
$request['RequestedShipment']['RequestedPackageLineItems'] = array(
'SequenceNumber'=>1,
'GroupPackageCount'=>1,
'Weight' => array(
'Value' => $weight,
'Units' => 'lbs'
),
'Dimensions' => array(
'Length' => $pkg_length,
'Width' => $pkg_width,
'Height' => $pkg_height,
'Units' => 'feet'
)
);
// Send the request to FedEx
$response = $client->getRates($request);
// Handle response
if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR' )
{
if(!is_array(#$response->RateReplyDetails))
{
return array(); // No Results
}
foreach ($response->RateReplyDetails as $rateReply)
{
if(in_array($rateReply->ServiceType, $service))
{
$amount = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
if(is_numeric($handling_amount)) // valid entry?
{
if($handling_method=='price')
{
$amount += $handling_amount;
}
elseif($handling_method=='percent')
{
$amount += $amount * ($handling_amount/100);
}
}
$rates[$this->service_list[$rateReply->ServiceType]] = number_format($amount,2,".",",");
}
}
return $rates;
}
else
{
return array(); // fail
}
}
}
My controller.
public function fedex(){
$this->load->library('fedex/fedex');
$fedex = new Fedex;
$weight = 46;
$dest_zip = '10001';
$fexed_rates = $fedex->rates();
var_dump($fexed_rates); die;
}
from the last you can see the line
Error Line No : $amount = $rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
Correct:
$amount = $rateReply->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount;
I have a mysql table which contains is:
folder_id (int(11), auto increment)
folder_name (varchar)
folder_class(varchar)
folder_link (varchar)
What I want to do is somehow loop through the table and store each row like this:
$packs = array( array( 'Name' => 'DarkUIPack',
'Class' => 'ui',
'Link' => 'http://graphicriver.net/item/dark-minimalist-ui-pack/662762'
),
array( 'Name' => 'MinimalistIcons',
'Class' => 'min',
'Link' => 'http://graphicriver.net/item/small-minimalist-icons-pack/670469'
),
array( 'Name' => 'BlueMediaIcons',
'Class' => 'blue',
'Link' => 'http://graphicriver.net/item/blue-media-icons-set/705319'
),
array( 'Name' => 'MediaIcons',
'Class' => 'med',
'Link' => 'http://graphicriver.net/item/media-icons-set/679835'
),
array( 'Name' => 'ToTheTopButtons',
'Class' => 'top',
'Link' => 'http://graphicriver.net/item/to-the-top-buttons/673221'
),
array( 'Name' => 'Sunglasses',
'Class' => 'sun',
'Link' => ''
),
array( 'Name' => 'RealEstate',
'Class' => 'est',
'Link' => 'http://graphicriver.net/item/simple-real-estate-logo/724697'
),
array( 'Name' => 'PhotoStudio',
'Class' => 'std',
'Link' => 'http://graphicriver.net/item/photo-studio-logo/724694'
),
array( 'Name' => 'PayDayCity',
'Class' => 'std',
'Link' => ''
),
array( 'Name' => 'MoleculeCorp',
'Class' => 'mol',
'Link' => 'http://graphicriver.net/item/molecule-corp-logo/719307'
),
array( 'Name' => 'ClubbGX',
'Class' => 'gx',
'Link' => ''
),
array( 'Name' => 'AerialVision',
'Class' => 'aer',
'Link' => ''
),
array( 'Name' => 'ServiceCompany',
'Class' => 'ser',
'Link' => 'http://graphicriver.net/item/service-company-logo/727091'
),
array( 'Name' => 'ElectroTech',
'Class' => 'ele',
'Link' => 'http://graphicriver.net/item/electro-tech-logo/720904'
),
array( 'Name' => 'CreativeStudio',
'Class' => 'cre',
'Link' => 'http://graphicriver.net/item/creative-studio-logo/719494'
),
array( 'Name' => 'NanoCorp',
'Class' => 'nan',
'Link' => 'http://graphicriver.net/item/nano-corp-logo/719098'
),
array( 'Name' => 'RehabPlace',
'Class' => 'reh',
'Link' => ''
),
array( 'Name' => 'MyLocalMix',
'Class' => 'mix',
'Link' => ''
),
array( 'Name' => 'SevenBySeven',
'Class' => 'sev',
'Link' => ''
),
array( 'Name' => 'ComingSoon',
'Class' => 'com',
'Link' => ''
),
array( 'Name' => 'AlienIcons',
'Class' => 'aln',
'Link' => 'http://graphicriver.net/item/alien-icons-set/698515'
),
array( 'Name' => 'PreloaderPortfolio',
'Class' => 'pre',
'Link' => ''
),
array( 'Name' => 'BioTech',
'Class' => 'bio',
'Link' => ''
),
array( 'Name' => 'ConstructionCompany',
'Class' => 'con',
'Link' => ''
),
array( 'Name' => 'EagleMedia',
'Class' => 'egl',
'Link' => ''
),
array( 'Name' => 'ElectronicWays',
'Class' => 'elw',
'Link' => ''
),
array( 'Name' => 'EnvironmentalCompany',
'Class' => 'env',
'Link' => ''
),
array( 'Name' => 'SecureData',
'Class' => 'sec',
'Link' => 'http://graphicriver.net/item/secure-data-company-logo/907334'
),
array( 'Name' => 'ConstructSimple',
'Class' => 'cns',
'Link' => 'http://graphicriver.net/item/simple-construction-company-logo/907538'
),
array( 'Name' => 'ConstructRoof',
'Class' => 'cnr',
'Link' => 'http://graphicriver.net/item/construction-company-logo/907549'
)
);
where 'Name' corresponds to folder_name, 'Class' to folder_class and 'Link' to folder_link.
I'm using this within a class and the class looks like this till now:
class folder
{
private $connect;
public function __construct() {
$this->connect = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
$error = true;
$message['error'] = true;
$message['message'] = mysqli_connect_error();
return json_encode($message);
}
else {
return true;
}
}
public function crtFolder($fldName,$fldClass,$fldLink,$fldPath) {
$fldName = preg_replace('/\s+/', '', $fldName);
$fldPN = $fldPath."\\".$fldName;
$modArray = array(array('1'));
if ((!is_dir($fldPN))) {
if(mkdir($fldPN,0777,true)) {
$sql = "INSERT INTO folders (folder_name,folder_class,folder_link) VALUES (?, ?, ?)";
if($stmt = $this->connect->prepare($sql)) {
$stmt->bind_param("sss", $fldName, $fldClass, $fldLink);
$stmt->execute();
$stmt->close();
$error = false;
$message['error'] = false;
$message['message'] = "Folder Created | Data Successfuly Inserted";
return json_encode($message);
}
else {
$error = true;
$message['error'] = true;
$message['message'] = "Folder Created | Data Failed To Insert";
return json_encode($message);
}
}
else {
$error = true;
$message['error'] = true;
$message['message'] = "Folder Failed To Create";
return json_encode($message);
}
}
else {
$error = true;
$message['error'] = true;
$message['message'] = "Folder Already Exists";
return json_encode($message);
}
}
public function __destruct() {
$closeConnection = $this->connect->close();
if($closeConnection) {
return true;
}
}
}
I'm showing the class because I want to keep the same method for the creating the array as the other methods are created. Because I found something on Google, but it was making an array from multiple tables. I only have one table.
Write below given function in to your class. Hope this will help things.
public function getTableData(){
$sql = "SELECT * FROM folders";
if($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
$stmt->close();
$arrFinalArray = array();
while ($arrFolder = $stmt->fetch()){
$arrFinalArray[] = array(
'Name' => $arrFolder['folder_name'],
'Class' => $arrFolder['folder_class'],
'Link' => $arrFolder['folder_link']
);
}
}
}
Following your format:
if($stmt = $this->connect->prepare($sql)) {
$stmt->bind_param("sss", $fldName, $fldClass, $fldLink);
$stmt->execute();
$result = array();
while ($stmt->fetch()) {
$result[] = array('Name' => $fldName, 'Class' => $fldClass, 'Link' => $fldLink);
}
print_r($result);
}
It should work.
Try something like this :
$result = SOMETHING_FROM_QUERY;
$packs = new array();
while ($row = mysql_fetch_assoc($result)) {
array_push($packs,array('Name' => $row['folder_name'], 'Class' => $row['folder_class'], 'Link' => $row['folder_link']));
}