Dolibarr soap web service usage with php - php

I am trying to use a Dolibarr soap web service with php
Dolibarr web service
this is what i got for the moment:
$url = "http://localhost/seko/dollibar/dolibarr-3.7.1/htdocs/webservices/server_invoice.php?wsdl";
$client = new SoapClient($url);
$authentication = array(
"dolibarrkey" => "xxxxx",
"sourceapplication" => "",
"login" => "xxxx",
"password" => "xxxxxx",
"entity" => "1"
);
$line = array(
"id" => "57",
"type" => 0,
"desc" => "SEKO",
"vat_rate" => 16.000,
"qty" => 03,
"unitprice" => 10500.00000000,
"total_net" => 10500.0000000,
"total_vat" => 1680.00000000,
"total" => 12180.0000000,
"date_start" => "",
"date_end" => "",
"payment_mode_id" => "efectivo",
"product_id" => 1,
"product_ref" => "",
"product_label" => "",
"product_desc" => ""
);
$invoice = array(
"id" => "57",
"ref" => "0007",
"ref_ext" => "test",
"thirdparty_id" => 3,
"fk_user_author" => "1",
"fk_user_valid" => "1",
"date" => date("Y-m-d"),
"date_due" => date("Y-m-d"),
"date_creation" => date("Y-m-d h:i:sa"),
"date_validation" => date("Y-m-d h:i:sa"),
"date_modification" => "",
"type" => 0,
"total_net" => 10500.00000000,
"total_vat" => 1680.00000000,
"total" => 12180.0000000,
"note_private" => "",
"note_public" => "",
"status" => 2,
"close_code" => "",
"close_note" => "",
"project_id" => "",
"lines" => $lines
);
$res = $client->createInvoice($authentication, $invoice);
var_dump($res);
I get the following error:
An uncaught Exception was encountered
Type: SoapFault
Message: looks like we got no XML document
When I use the getInvoice method of the service it works fine. But not the creatInvoice method. I am sure the problem is with my $line array but I do not know how to fix it.

According to XML documentation (open this http://localhost/seko/dollibar/dolibarr-3.7.1/htdocs/webservices/server_invoice.php?wsdl in your webbrowser)
please note that you need to remove the "payment_mode_id" field from the $line array and move it to your $invoice array
Like this :
$line = array(
"id" => "57",
"type" => 0,
"desc" => "SEKO",
"vat_rate" => 16.000,
"qty" => 03,
"unitprice" => 10500.00000000,
"total_net" => 10500.0000000,
"total_vat" => 1680.00000000,
"total" => 12180.0000000,
"date_start" => "",
"date_end" => "",
"product_id" => 1,
"product_ref" => "",
"product_label" => "",
"product_desc" => ""
);
$invoice = array(
"id" => "57",
"ref" => "0007",
"ref_ext" => "test",
"thirdparty_id" => 3,
"fk_user_author" => "1",
"fk_user_valid" => "1",
"date" => date("Y-m-d"),
"date_due" => date("Y-m-d"),
"date_creation" => date("Y-m-d h:i:sa"),
"date_validation" => date("Y-m-d h:i:sa"),
"date_modification" => "",
"payment_mode_id" => "efectivo",
"type" => 0,
"total_net" => 10500.00000000,
"total_vat" => 1680.00000000,
"total" => 12180.0000000,
"note_private" => "",
"note_public" => "",
"status" => 2,
"close_code" => "",
"close_note" => "",
"project_id" => "",
"lines" => $lines
);
Hoping help
Regards

Related

Add a dynamic key => value options in 3 level array option

I have an array as main options in my code.
In case, I want to add dynamic key => values into specific options array key.
This is my main options array:
$configarray1 = array(
"name" => "Addon",
"description" => "module for whmcs",
"version" => "1.1",
"author" => "Me",
"language" => "english",
"fields" => array(
"sender" => array (
"FriendlyName" => "Sender",
"Type" => "dropdown",
"Options" => strtolower($GatewaysIM),
"Description" => $getBalance,
"Default" => $Defaultsender,
),
"validateday" => array (
"FriendlyName" => "Days for Re-validation",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "90",
),
)
);
I want to add this sender array options in configarray1 fields key:
if($sender == 'sender1'){
$configarray2['fields'] = array(
"username" => array (
"FriendlyName" => "username",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "",
),
"password" => array (
"FriendlyName" => "password",
"Type" => "password",
"Size" => "25",
"Description" => "",
"Default" => "",
)
);
} elseif($sender == 'sender2'){
$configarray2['fields'] = array(
"line" => array (
"FriendlyName" => "line",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "",
)
);
}
Output array must be like this below when sender is sender1:
$configarray = array(
"name" => "Addon",
"description" => "module for whmcs",
"version" => "1.1",
"author" => "Me",
"language" => "english",
"fields" => array(
"sender" => array (
"FriendlyName" => "Sender",
"Type" => "dropdown",
"Options" => strtolower($GatewaysIM),
"Description" => $getBalance,
"Default" => $Defaultsender,
),
"username" => array (
"FriendlyName" => "username",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "",
),
"password" => array (
"FriendlyName" => "password",
"Type" => "password",
"Size" => "25",
"Description" => "",
"Default" => "",
),
"validateday" => array (
"FriendlyName" => "Days for Re-validation",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "90",
),
)
);
I tested array push but this adds a key in arrays first place and not in 'fields' key, my code was this $configarray = array_push($configarray1,$configarray2); but this not works !
I also tested sum of two arrays ($configarray = $configarray1 + $configarray2) but this is the same as array_push and returns wrong output for me.
How can i resolve this problem ?!
You should just declare it. You don't need a new variable.
Assuming you have the original array named as $configarray1, just:
if($sender == 'sender1'){
$configarray1['fields']['username'] = array(
"FriendlyName" => "username",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "",
);
$configarray1['fields']['password'] => array(
"FriendlyName" => "password",
"Type" => "password",
"Size" => "25",
"Description" => "",
"Default" => "",
);
} elseif($sender == 'sender2'){
$configarray1['fields']['line'] = array (
"FriendlyName" => "line",
"Type" => "text",
"Size" => "25",
"Description" => "",
"Default" => "",
);
}

Cannot create order Woocommerce rest Api php

I tried the following code and tried to post values from android to place an order but every time i test it on chrome it give http 500 error, and Android gives volly server error. Dont know where i am messing up, serious help would be appriciated. Thank You
Ask me if you need to take a look at the android Code, but i think that doesnot matter here because i am giving hard coded values in $data.
<?php
require_once( 'lib/woocommerce-api.php' );
$pageNum=1;
$pageNum=$_GET['page_num'];
$options = array(
'debug' => true,
'return_as_array' => false,
'validate_url' => false,
'timeout' => 30,
'ssl_verify' => false,
);
try {
$client = new WC_API_Client( 'https://www.move2mart.com/', 'ck_0afa3a49305683160fe34189553a660053bd4e6239', 'cs_7dc38a7b52c3fdd34qw61e34090be636ae3364b196', $options );
//$data=array();
$data=[
'payment_method' => 'cod',
'payment_method_title' => 'Cash on Delivery',
'set_paid' => false,
'billing' => [
'first_name' => 'John',
'last_name' => 'Doe',
'address_1' => '969 Market',
'city' => 'Karachi',
'email' => 'princeali#testing.com',
'phone' => '03123121995'
], 'line_items' => [
[
'product_id' => 779,
'quantity' => 1
]
]
];
print_r($client->post('orders', $data));
if($_POST !=null) {
}
else{
echo "Null POST Request";
}
} catch ( WC_API_Client_Exception $e ) {
echo $e->getMessage() . PHP_EOL;
echo $e->getCode() . PHP_EOL;
if ( $e instanceof WC_API_Client_HTTP_Exception ) {
print_r( $e->get_request() );
print_r( $e->get_response() );
}
}
$orderData = array(
"order" => array(
"billing_address" => array(
array(
"first_name" => "",
"last_name" => "",
"company" => "",
"address_1" => "",
"address_2" => "",
"city" => "",
"state" => "",
"postcode" => "",
"country" => "",
"email" => "",
"phone" => "",
)
),
"shipping_address" => array(
array(
"first_name" => "",
"last_name" => "",
"company" => "",
"address_1" => "",
"address_2" => "",
"city" => "",
"state" => "",
"postcode" => "",
"country" => "",
)
),
"customer_id" => 1,
"line_items" => array(
array(
"product_id" => 1,
"quantity" => 1
)
)
)
);
$client->orders->create($orderData);
Would you please try above code?
Finally, I figured it out after some research. Below is working code of woocommerce checkout webservice that may Help you -
/*** Just Copy & Paste and change your varriables **/
//do your initial stuff
header('Content-type: application/json');
$json_file=file_get_contents('php://input');
$jsonvalue= json_decode($json_file,true);
$user_id = $jsonvalue['user_id'];
$product_id = $jsonvalue['product_id'];
$quantity = $jsonvalue['quantity'];
//start order data
$orderData = array(
"order" => array(
'payment_method' => 'paypal',
'payment_method_title' => 'Paypal',
'set_paid' => true,
"billing_address" => array(
"first_name" => "bfname",
"last_name" => "blname",
"company" => "testcompanybilling",
"address_1" => "sec8",
"address_2" => "e32",
"city" => "noida",
"state" => "Noida",
"postcode" => "99999",
"country" => "IN",
"email" => "test#gmail.com",
"phone" => "888899999999"
),
"shipping_address" => array(
"first_name" => "sfname",
"last_name" => "slname",
"company" => "testcompanyshipping",
"address_1" => "shakkarpur",
"address_2" => "laxminigar",
"city" => "New Delhi",
"state" => "Delhi",
"postcode" => "110092",
"country" => "IN",
"email" => "testsh#gmail.com",
"phone" => "11009999"
),
"customer_id" => $user_id,
"line_items" => array(
array(
"product_id" => $product_id,
"quantity" => $quantity
)
),
'shipping_lines' => array(
array(
'method_id' => 'flat_rate',
'method_title' => 'Flat Rate',
'total' => 10
)
)
)
);
//Create order usind order data
$data = $client->orders->create($orderData);
//echo '<pre>';
//print_r($data);
$result['success']='true';
$result['error']="0";
$result['msg']='Your order has been successfully placed.';
$result['data']=$data;
echo json_encode($result); `
cheers!!!

PHP SOAP Object Reference Not Set to Reference of Object

I'm attempting to communicate with a SOAP Service to post some data to the database.
Here's the WSDL.
As you can see, the required data is quite cumbersome so apologies for the length of the code, you will need to scroll through to see everything. Here is how I am attempting to communicate with the service, however I'm getting the error System.NullReferenceException: Object reference not set to an instance of an object
PHP:
$soapClient = new soapClient("https://secure.quickflora.com/Admin/scripts/ws/QuickfloraOrders.asmx?WSDL");
$orderArray = array(
"Token" => $token,
"OrderErrorEmail" => "edwardsalexk#gmail.com",
"Billing" => array("CustomerID" => "1",
"FullName" => "Jack Nichols",
"FirstName" => "Jack",
"LastName" => "Nichols",
"Address1" => "9725 E Windrose Drive",
"Address2" => "",
"Address3" => "",
"City" => "Scottsdale",
"State" => "Arizona",
"Zip" => "85260",
"Phone"=> "4807218374",
"PhoneExt" => "123",
"Fax" => "1234",
"Email"=> "edwardsalexk#gmail.com",
"Cell" =>"480 721 8374",
),
"Shipping" => array("Attention "=> "Alexander",
"Salutation" => "Alexander",
"FirstName" => "Alexander",
"LastName" => "Edwards",
"Address1"=> "9725 E Windrose Drive",
"Address2" => "",
"Address3" => "",
"City"=>"Scottsdale",
"State" =>"Arizona",
"Zip" => "85260",
"Country" => "United States",
"Phone" => "480 721 8374",
"PhoneExt" => "123",
"Fax" => "123",
"Email" => "edwardsalexk#gmail.com",
"Cell" => "480 721 8374",
"CardMessage" => "I hope these flowers find you well!",
"DestinationType" => "House",
"DriverRouteInfo" => "None",
"Priority" => "Highest",
"Order Ship Date" => "4/20/2017",
),
"Payment" => array("MethodID" => "1",
"Check" =>array("Number" => "123",
"CheckID" => "1",
"ChkDate" => "4/20/2017,"),
"CreditCard" => array("TypeID" => "1",
"Name" => "Alexander Edwards",
"Account Number" => "12345678",
"Expiration Date" => "11/14/1993",
"SecurityCode" => "123",
"ApprovalCode" => "123")),
"WireServiceInfo" => array("WireService" => "Alexander Service",
"WireServiceCode" => "123",
"ReferenceID" => "123",
"TransmitMethod" => "123",
"RepresentativeTalkedTo" => "Alexander",
"FloristName" => "Alexander",
"FloristPhone" => "480 721 8734",
"FloristCity" => "Scottsdale",
"FloristState" => "Arizona"),
"Orderdetails" => array("OccasionCodeID" => "123",
"SourceCodeID" => "123",
"Comments" => "Hello",
"TaxGroupID" => "123",
"Currency" => array("ID" => "123",
"ExchangeRate" => 1.2),
"DeliveryCharge" => 12.5,
"ServiceCharge" => 12.5,
"Discounts" => array("Percentage" => 12.5,
"Amount" => 12.5),
"Tax" => array("Percentage" => 12.5,
"Amount" => 12.5),
"GSTTax" => array("Percentage" => 12.5,
"Amount" => 12.5),
"PSTTax" => array("Percentage" => 12.5,
"Amount" => 12.5),
"Total" => 123.34
),
"OrderItemsdetails" => array(
"Itemno" => array("String", "String"),
"Itemid" => array("String", "String"),
"UpcCode" => array("String", "String"),
"ItemName" => array("String", "String"),
"Description" => array("String", "String"),
"Quantity" => array("String", "String"),
"UnitOfMeasurement" => array("String", "String"),
"DiscountPercentage" => array("String", "String"),
"UnitPrice" => array("String", "String")
)
);
$response = $soapClient->PostOrder($orderArray);
echo var_dump($response);

Elastic Transcoder error "Start of list found where not expected"

I am trying to use ElasticTranscoderPHP to create a new preset with php, but I am getting the error "start of list found where not expected"
https://github.com/LPology/ElasticTranscoderPHP
What would cause this error?
$photo_info = getimagesize($_FILES["photo-file"]['tmp_name']);
$photo_width = $photo_info[0];
$photo_height = $photo_info[1];
$options = array(
"Name" => $vivaloo_id,
"Description" => "testing 123",
"Container" => "mp4",
"Audio" => array(
"Codec" => "AAC",
"CodecOptions" => array(
"Profile" => "AAC-LC"
),
"SampleRate" => "44100",
"BitRate" => "128",
"Channels" => "2",
),
"Video" => array(
"Codec" => "H.264",
"CodecOptions" => array(
"Profile" => "baseline",
"Level" => "3",
"MaxReferenceFrames" => "3"
),
"KeyframesMaxDist" => "90",
"FixedGOP" => "false",
"BitRate" => "600",
"FrameRate" => "29.97",
"MaxWidth" => $photo_width,
"MaxHeight" => $photo_height,
"SizingPolicy" => "Fill",
"PaddingPolicy" => "NoPad",
"DisplayAspectRatio" => "auto"
),
"Thumbnails" => array(
"Format" => "jpg",
"Interval" => "9999",
"MaxWidth" => "480",
"MaxHeight" => "480",
"SizingPolicy" => "Fit",
"PaddingPolicy" => "NoPad"
)
);
$presetResult = AWS_ET::createPreset( array($options) );
if (!$presetResult) {
echo AWS_ET::getErrorMsg();
}else{
echo 'New preset ID: ';
}
Answering my own question - hope it helps others...
I ultimately solved this issue by separating Audio, Video, and Thumbs settings into their own individual arrays. Here is an example:
//create a preset
$presetAudio = array(
"Codec" => "AAC",
"CodecOptions" => array( "Profile" => "AAC-LC"),
"SampleRate" => "32000",
"BitRate" => "64",
"Channels" => "2"
);
$presetVideo = array(
"Codec" => "H.264",
"CodecOptions" => array("Profile" => "baseline","Level" => "3","MaxReferenceFrames" => "3","BufferSize" => null, "MaxBitRate" => null),
"KeyframesMaxDist" => "90",
"FixedGOP" => "false",
"BitRate" => "500",
"FrameRate" => "29.97",
"MaxFrameRate" => null,
"MaxWidth" => "500", //note: MUST BE AN EVEN NUMBER
"MaxHeight" => "500", //note: MUST BE AN EVEN NUMBER
"SizingPolicy" => "Fill",
"PaddingPolicy" => "NoPad",
"DisplayAspectRatio" => "auto"
);
$presetThumbs = array(
"Format" => "jpg",
"Interval" => "9999",
"MaxWidth" => "100", //note: MUST BE AN EVEN NUMBER
"MaxHeight" => "100", //note: MUST BE AN EVEN NUMBER
"SizingPolicy" => "Fit",
"PaddingPolicy" => "NoPad"
);
$presetResult = AWS_ET::createPreset("name of preset", "description of preset", "mp4", $presetAudio, $presetVideo, $presetThumbs);
if (!$presetResult) {
echo AWS_ET::getErrorMsg();
} else {
$preset_id = $presetResult['Preset']['Id'];
echo $preset_id;
}

PHP and SOAP data loss when sending to client

I have an array of data that I want to send to a SOAP client.
It all works, but one piece of data isn't transmitted, as revealed by __getLastRequest().
Here's my code
<?php
$test_array = array(
"request" => array(
"dateTime" => "2011-12-05T11:37:06.0000000+00:00",
"brandId" => 2,
"extSysId" => 11,
"extSysPassword" => "xxxxx",
"customer" => array(
"title" => "Mr",
"firstName" => "Dec",
"lastName" => "Test-Two",
"address" => array(
"type" => "Residential",
"pafValidated" => TRUE,
"houseNumber" => "xx",
"houseName" => "",
"line1" => "xx xx",
"line2" => "",
"line3" => "xx",
"line4" => "",
"line5" => "",
"postcode" => "xxx xxx"
),
"phones" => array(
0 => array(
"type" => "Home",
"_" => "xxx xxxxxx"
),
1 => array(
"type" => "Work",
"preferred" => TRUE,
"_" => ""
),
2 => array(
"type" => "Mobile",
"preferred" => TRUE,
"_" => ""
)
),
"email" => "xxxx.xxxx#gmail.com"
),
"nextPurchase" => array(
"date" => "2014-05-01"
),
"dataProtection" => array(
"group" => FALSE,
"thirdParty" => FALSE
),
"futureContactChannels" => array(
0 => array(
"type" => "Whitemail",
"option" => FALSE
),
1 => array(
"type" => "Email",
"option" => FALSE
),
2 => array(
"type" => "Phone",
"option" => FALSE
),
3 => array(
"type" => "SMS",
"option" => FALSE
)
),
"vehicleRequests" => array(
0 => array(
"derivativeCode" => "xxxxx",
"type" => "T"
)
),
"Retailer" => array(
0 => array (
"dealerCode" => "00082"
)
),
"company" => array(
"companyName" => "",
"jobTitle" => ""
),
"campaign" => array(
"code" => "xxxxxxxxx",
"source" => 69
),
"notes" => "blah balh: ."
)
);
$client = new SoapClient("/xxx/xxxx/xxxxxx/xxxxx.wsdl", array(
"login" => "xxx",
"password" => "xxx",
"location" => "http://xxx.xxx.xxx.xxx/xxxxxx/Some.asmx",
"uri" => "urn:xmethods-delayed-quotes",
'trace' => 1,
'exceptions' => 1,
'soap_version' => 'SOAP_1_1',
'encoding' => 'UTF-8',
'features' => 'SOAP_USE_XSI_ARRAY_TYPE'
));
$client->CallComeFunction($test_array);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
echo "*************************************************\n";
echo "Response:\n" . $client->__getLastResponse() . "\n";
The Retailed[0]['dealerCode'] is the only piece of info that is omitted from the sent XML.
Any ideas?
Many thanks.
As mac says, formatting the code would be nice, but one thing I notice is the 'Retailer' field is the only one that's capitalized. Not sure if the WSDL has any influence on what is sent by the client but it might.
Double check the WSDL and see if the field should be 'retailer' instead. Any chance you can share the WSDL, btw?
EDIT
After reviewing the WSDL, 'retailer' is the way to go:
<s:element minOccurs="0" maxOccurs="1" name="retailer" type="tns:Retailer"/>
The payload should be formatted differently as well, it should be
"retailer" => array(
"dealerCode" => "00082"
)
per the WSDL
<s:complexType name="Retailer">
<s:attribute name="dealerCode" type="s:string"/>
</s:complexType>

Categories