Quickbooks Php SDK - CheckNullResponseAndThrowException - Response Null or Empty - php

Please kindly assist me on below error:
2015-04-16 10:45:10 - D:\projects\QuickBooksv3-php-sdk-2.0.5\DataService\DataService.php - 340 - CheckNullResponseAndThrowException - Response Null or Empty
3 days ago, I had successfully test quickbooks php sdk.
But today when I going to integrate with system, it hit error.
The code is same as 3 days ago.
Here is my code:
//Create new invoice
$invoiceObj2 = new IPPInvoice();
$invoiceObj2->DocNumber="1025";
//Add customer
$customerRef2= new IPPReferenceType();
$customerRef2->value= "1";
$invoiceObj2->CustomerRef= $customerRef2;
//Create Line
$line2 = new IPPLine();
$line2->Amount= 1*90.84;
$linetype2= new IPPLineDetailTypeEnum();
$linetype2->value="SalesItemLineDetail";
$lineDetail2 = new IPPSalesItemLineDetail();
$lineDetail2->ItemRef = "4";
$lineDetail2->UnitPrice = 90.84;
$lineDetail2->Qty= 1;
$line2->DetailType=$linetype2;
$line2->SalesItemLineDetail=$lineDetail2;
$invoiceObj2->Line=$line2;
$resultingInvoiceObj2 = $dataService->Add($invoiceObj2);
echo "Created Invoice Id={$resultingInvoiceObj2->Id}. Reconstructed response body:<br/><br/>";
$xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingInvoiceObj2, $urlResource);
echo "<pre>";
echo $xmlBody . "<br/>";
echo "</pre>";
Please kindly help to point out my mistake. Thanks

Please change the base url for using sandbox QBO account or use production tokens for connecting to existing QBO accounts.
Your issue might be related to this change-https://developer.intuit.com/v2/blog/2014/10/24/intuit-developer-now-offers-quickbooks-sandboxes
You can also try changing the values and then try integrating into QB

I have solved same problem checking required params. Please check required fields.
Required fields are at least:
DocNumber
TxnDate
CustomerRef
at least one Line record
Line.DetailType
Line.Amount
Line.Description
at least one Line.SalesItemLineDetail
Line.SalesItemLineDetail.ItemRef
Line.SalesItemLineDetail.Quantity
Line.SalesItemLineDetail.UnitPrice
I have modified your code and run. Its working
Final modified code:
//Create new invoice
$invoiceObj2 = new IPPInvoice();
$invoiceObj2->DocNumber="1025";
$invoiceObj2->TxnDate = "2016-10-19";
//Add customer
$customerRef2= new IPPReferenceType();
$customerRef2->value= "1";
$invoiceObj2->CustomerRef= $customerRef2;
//Create Line
$line2 = new IPPLine();
$line2->Amount= 1*90.84;
$Line2->Description = 'Test Product';
$linetype2= new IPPLineDetailTypeEnum();
$linetype2->value="SalesItemLineDetail";
$lineDetail2 = new IPPSalesItemLineDetail();
$lineDetail2->ItemRef = "4";
$lineDetail2->UnitPrice = 90.84;
$lineDetail2->Qty= 1;
$line2->DetailType=$linetype2;
$line2->SalesItemLineDetail=$lineDetail2;
$invoiceObj2->Line=$line2;
$resultingInvoiceObj2 = $dataService->Add($invoiceObj2);
echo "Created Invoice Id={$resultingInvoiceObj2->Id}. Reconstructed response body:<br/><br/>";
$xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingInvoiceObj2, $urlResource);
echo "<pre>";
echo $xmlBody . "<br/>";
echo "</pre>";

Related

How to show return values fom a PHP XML-RPC call?

I can't seem to find any code to display returned values from the call.
I am running the xml-lib from the software vendor at the following link
https://support.sippysoft.com/support/solutions/articles/3000013653-xml-rpc-api-sign-up-html-page-fresh-version-
<?php
include 'xmlrpc/xmlrpc.inc';
function listAccounts()
{
//$params = array(new xmlrpcval(array("i_account"=> new xmlrpcval('14719', "string")), 'struct'));
$msg = new xmlrpcmsg('listAccounts');
/* replace here URL and credentials to access to the API */
$cli = new xmlrpc_client('https://DOMAINHERE/xmlapi/xmlapi');
$cli->setSSLVerifyPeer(false);
$cli->setSSLVerifyHost(false);
$cli->setCredentials('USERNAME', 'PASSWORD', CURLAUTH_DIGEST);
$r = $cli->send($msg, 20);
if ($r->faultCode()) {
error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
print_r ($r->faultString());
return false;
}
else
{
return $r->value();
// I need something here to write returned values to normal PHP variable
}
}
Ok thanks to the comment from halfer.
I managed to get the issue and digging through the code in the library I found a function that does the trick.
Thanks a million for your pointer it really helped.
I am new to php and xml and the learning curve is quite tall but thanks.
for someone else reference maybe in the future here is the corrected code with the last 2 lines that does the magic for me.
<?php
include 'xmlrpc/xmlrpc.inc';
// $params = array(new xmlrpcval(array("offset"=> new xmlrpcval("1", "int")
// ,"i_customer"=> new xmlrpcval("321", "int")
// ), 'struct'));
$params = array(new xmlrpcval(array("i_customer"=> new xmlrpcval("321", "int")
), 'struct'));
$msg = new xmlrpcmsg('listAccounts', $params);
/* replace here URL and credentials to access to the API */
$cli = new xmlrpc_client('DOMAIN');
$cli->setSSLVerifyPeer(false);
$cli->setdebug(0);
$r = $cli->send($msg, 20); /* 20 seconds timeout */
if ($r->faultCode()) {
error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
echo $r->faultString();
}
// now lets decode the xml response..
$values=php_xmlrpc_decode($r->value());
var_dump ($values['accounts'][0][username]);
?>

PHP Bitwasp, signing a bitcoin-cash transaction

I try to sign test bitcoin-cash transaction, and then broadcast.
For bitwasp version 0.0.35.0, the code is:
$utxoOwnerPrivateKey = 'MyPrIvAtEKey';//public key is "16Dbmp13CqdLVwjXrd6amF48t7L8gYSGBj", note - the real private key is another
$utxo = '5e44cdab9cb4a4f1871f2137ab568bf9ef2760e52816971fbaf0198f19e28378';
$utxoAmount = 598558;
$reciverPublicKey = '1EjCxux1FcohsBNGzY9KdF59Dz7MYHQyPN';
$fee = 1000;
$addressCreator = new \Btccom\BitcoinCash\Address\AddressCreator();
$networkObject = \Btccom\BitcoinCash\Network\NetworkFactory::bitcoinCash();
$keyPairInput = \BitWasp\Bitcoin\Key\PrivateKeyFactory::fromWif($utxoOwnerPrivateKey, null, $networkObject);
$outpoint = new \BitWasp\Bitcoin\Transaction\OutPoint(\BitWasp\Buffertools\Buffer::hex($utxo, 32), 0);
$transaction = \BitWasp\Bitcoin\Transaction\TransactionFactory::build()
->spendOutPoint($outpoint)
->payToAddress($utxoAmount - $fee, $addressCreator->fromString($reciverPublicKey, $networkObject) )
->get();
echo "Unsigned transaction: " . $transaction->getHex() . '<BR><BR>';
$signScript = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash($keyPairInput->getPublicKey()->getPubKeyHash());
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount - $fee, $signScript);
$signer = new \BitWasp\Bitcoin\Transaction\Factory\Signer($transaction);
$signatureChecker = \Btccom\BitcoinCash\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter( \BitWasp\Bitcoin\Bitcoin::getEcAdapter() ); // for version 0.0.35
$signer->setCheckerCreator( $signatureChecker ); // for version 0.0.35
$input = $signer->input(0, $txOut);
$signatureType = \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::ALL | \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::BITCOINCASH;
$input->sign($keyPairInput, $signatureType);
$signed = $signer->get();
echo "Witness serialized transaction: " . $signed->getHex() . '<BR><BR>';
echo "Base serialized transaction: " . $signed->getBaseSerialization()->getHex() . '<BR><BR>';
echo "Script validation result: " . ($input->verify() ? "yes\n" : "no\n"). '<BR><BR>';
die();
In this case I get the result:
Script validation result: no
Trying to broadcast the BCH transaction gives an error:
An error occured:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation). Code:-26
I think, it means, that signature is wrong. If we remove the flag $signatureType (keep this default), then Script validation result will be yes, but broadcasting will give an error:
16: mandatory-script-verify-flag-failed (Signature must use SIGHASH_FORKID). Code:-26
I think, it means - transaction signed as in bitcoin network, must to be signed by bitcoin-cash rules. Maybe I'm wrong. But bitcoin transaction signing is fine. Bitwasp has no manuals, how to sign a bitcoin-cash transactions, I have the same code for bitwasp v.0.0.34.2 (without addon "btccom/bitwasp-bitcoin-bch-addon", using $signer->redeemBitcoinCash(true); function) but it gives the same result.
It is interesting that in code of bitcoin-cash signer it takes the inner variable amount and include it in hash:
$hasher = new V1Hasher($this->transaction, $this->amount);
But for bitcoin bitwasp doesn't take the amount, presumably it takes an amount from the transaction.
Help me please to sign the transaction, bitwasp has only bitcoin examples, not bitcoin-cash. It is very difficult to find any informaion about php altcoins signing without third-party software. Regards.
This code to sign a bitcoin-cash transaction with PHP bitwasp v.0.0.35 library is works!
$unspendedTx = '49343e0a4ef29b819f87df1371c6f8eafa1f235074a27fb6aa5f4ab4c48e5c16';
$utxOutputIndex = 0;
$utxoPrivateKey = 'MyPrIvAtEKey';
$utxoAmount = 300000;
$reciverPublicKey = '1E8XaWNsCWyVaZaWTLh8uBdAZjLQqwWmzM';
$fee = 1000;
$networkObject = \Btccom\BitcoinCash\Network\NetworkFactory::bitcoinCash();
$outpoint = new \BitWasp\Bitcoin\Transaction\OutPoint(\BitWasp\Buffertools\Buffer::hex($unspendedTx, 32), $utxOutputIndex /* index of utxo in transaction, generated it */);
$destination = \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash( (new \Btccom\BitcoinCash\Address\AddressCreator())->fromString($reciverPublicKey)->getHash() );
$transaction = \BitWasp\Bitcoin\Transaction\TransactionFactory::build()
->spendOutPoint($outpoint)
->output($utxoAmount - $fee, $destination)
->get();
echo "Unsigned transaction: " . $transaction->getHex() . '<BR><BR>';
$keyPairInput = \BitWasp\Bitcoin\Key\PrivateKeyFactory::fromWif($utxoPrivateKey, null, $networkObject);
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount, \BitWasp\Bitcoin\Script\ScriptFactory::scriptPubKey()->payToPubKeyHash( $keyPairInput->getPubKeyHash() ) );
$signer = new \BitWasp\Bitcoin\Transaction\Factory\Signer($transaction);
$signatureChecker = \Btccom\BitcoinCash\Transaction\Factory\Checker\CheckerCreator::fromEcAdapter( \BitWasp\Bitcoin\Bitcoin::getEcAdapter() ); // for version 0.0.35
$signer->setCheckerCreator( $signatureChecker ); // for version 0.0.35
$input = $signer->input(0, $txOut);
$signatureType = \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::ALL | \Btccom\BitcoinCash\Transaction\SignatureHash\SigHash::BITCOINCASH;
$input->sign($keyPairInput, $signatureType);
$signed = $signer->get();
echo "Transaction: " . $signed->getHex() . '<BR><BR>';
die();
I had broadcasted this PHP-generated test transaction, see link to tx. Problaly the problem was in
->payToAddress($utxoAmount - $fee, $addressCreator->fromString($reciverPublicKey, $networkObject) )
Maybe payToAddress has a bug, because "hand" script creation gives another transaction. Second:
$txOut = new \BitWasp\Bitcoin\Transaction\TransactionOutput($utxoAmount - $fee, $signScript);
We must to create tx input(previous output) without the fee.
Used libraries ( composer.json ):
{
"require" : {
"php" : ">=7.0",
"bitwasp/bitcoin": "0.0.35.0",
"btccom/bitwasp-bitcoin-bch-addon" : "0.0.2"
}
}
Hope, this will help for all altcoin api creators on PHP.

Is this conversion script efficient?

I wrote this piece of script to get the conversion rates from Yahoo API . What it does is I have a config file which has currency details I have to make an array of rates of all the currency present in the config here is my script .
Please review it and let me know if there is a better way to do this .
$cur = $this->parent->parent->config->conversionCurrencies;
//$cur=array(11=>'USD/CRC');
foreach($cur as $key=>$val){
$get_cur = str_replace("/","",$val);echo "<br>";
$code=file_get_contents('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22'.$get_cur.'%22)&format=json&env=store://datatables.org/alltableswithkeys&callback=');
var_dump($array1 = json_decode($code, true));
$rates_array = array();
$myaskRate = $array1['query']['results']['rate']['Ask'];
$mybidRate = $array1['query']['results']['rate']['Bid'];
$rates_array[$key] = round(($myaskRate+$mybidRate)/2,2);
}
var_dump( $rates_array);

PayPal phone number not shown (using PP php sdk)

We have the following code to transfer our buyer's details to the PayPal:
$ShippingAddr = new AddressType;
// more code ...
$ShippingAddr->Phone = $_userdata['user_phone'];
$BillingAddr = new AddressType;
// more code ...
$BillingAddr->Phone = $_userdata['user_phone'];
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
// more code ...
$setECReqDetails->Address = $ShippingAddr;
$setECReqDetails->BillingAddress = $BillingAddr;
$setECReqType = new SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
Working fine apart from the phone number which remains empty on PayPal checkout site.
Any idea what we did wrong?
I believe you are trying to get users information as per this webservice. https://developer.paypal.com/docs/api/#get-user-information
So you should call it this way according to the paypal doc,
$_userdata['phone_number'];

Reading Web Service using PHP with GUID and Namespace

I am new to Web Services and am struggling to access/read the XML data using PHP (my website that will be using the data is in PHP).
The WSDL Url: http://services.mywheels.co.za/BWAVehicleStockService.svc?wsdl
I need to get access and read the Vehicle stock information but cant see to access anything.
the Array vehicle are stored under: http://services.mywheels.co.za/BWAVehicleStockService.svc?xsd=xsd2 .
i am using this code but it doesnt give my any data. I also have a GUID that i need to pass but have no idea how to add it to the header.
<?PHP
define('NEWLINE', "<br />\n");
// SOAP client
$wsdl = 'http://services.mywheels.co.za/BWAVehicleStockService.svc?wsdl';
$soapClient = new SoapClient($wsdl, array('cache_wsdl' => 0));
// SOAP call
$parameters->ArrayOfVehicle->Vehicle;
try
{
$result = $soapClient->GetVehicleStock($parameters);
}
catch (SoapFault $fault)
{
echo "Fault code: {$fault->faultcode}" . NEWLINE;
echo "Fault string: {$fault->faultstring}" . NEWLINE;
if ($soapClient != null)
{
$soapClient = null;
}
exit();
}
$soapClient = null;
echo "<pre>\n";
print_r($result);
echo "</pre>\n";
echo "Return value: {$result->GetDataResult}" . NEWLINE;
?>
if someone can help or point me in the right direction with this that would be great.
Thanks
You can add headers using __setSoapHeaders():
$h = new SoapHeader('http://tempuri.org/', 'Guid', '123');
$soapClient->__setSoapHeaders($h);
I had to read the WSDL itself to find out what namespace I should use; in this case they refer to Guid as tns:Guid and from the top you can read what URI is used to express that, hence http://tempuri.org.

Categories