Quickbook online service gives 500 internal server - php

I am trying to call service via curl and here is my code and every time I got the attached error
error_reporting(-1);
$qbsite = "https://qbo.sbfinance.intuit.com/resource/account/v2/960432556";
$headers = array(
'Content-Type'=>'application/xml',
'oauth_version' => "1.0",
'oauth_signature_method'=>"HMAC-SHA1",
'oauth_nonce'=>"xxx",
'oauth_timestamp'=>"xxx",
'oauth_consumer_key'=>"qyprdvZraQrBVbrPIptwd6gl6C6knP",
'oauth_token'=>"qyprdyLcCq9KMGVzqxtObeOkTvSWhhi7sNSW62u9gwqDXsc7",
'oauth_signature'=>"LnVYSgE9YZ77KgKZ1kLT3ouIu1M=",
);
$xmlData = '<?xml version="1.0" encoding="utf-16"?>
<Account xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2">
<Name>Loan Account </Name>
<Desc>Loan Account</Desc>
<Subtype>Savings</Subtype>
<AcctNum>5001</AcctNum>
<OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
</Account>';
$ch = curl_init($qbsite);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "\n{$xmlData}");
$response = curl_exec($ch);
print($response);die; !

This:
$headers = array(
'Content-Type'=>'application/xml',
'oauth_version' => "1.0",
'oauth_signature_method'=>"HMAC-SHA1",
'oauth_nonce'=>"xxx",
'oauth_timestamp'=>"xxx",
'oauth_consumer_key'=>"qyprdvZraQrBVbrPIptwd6gl6C6knP",
'oauth_token'=>"qyprdyLcCq9KMGVzqxtObeOkTvSWhhi7sNSW62u9gwqDXsc7",
'oauth_signature'=>"LnVYSgE9YZ77KgKZ1kLT3ouIu1M=",
);
Is not even close to a correct OAuth signature. OAuth signatures place all of that information in a single Authorization: ... HTTP header, whereas you've slapped each piece of OAuth data in a separate HTTP header.
For example, a correct OAuth header looks something like this:
Authorization: OAuth realm="",
oauth_consumer_key="dpf43f3p2l4k3l03",
oauth_nonce="kllo9940pd9333jh",
oauth_timestamp="1191242096",
oauth_signature_method="HMAC-SHA1",
oauth_version="1.0",
oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D"
Additionally, OAuth signatures are not static values - they must be calculated and they change with EVERY request.
You should download the nightly build of the QuickBooks PHP DevKit (disclaimer: I'm the author) - it's a library that is specifically designed to do exactly what you're doing (integrate with QuickBooks), and it takes care of building the correct OAuth requests for you.
Specifically, download it and look at these examples:
docs/example_ipp_oauth.php
docs/example_ipp_ids_5.php

Have you tried removing the , at the end of this line
'oauth_signature'=>"LnVYSgE9YZ77KgKZ1kLT3ouIu1M=",

Related

Why is the curl code not executed in PHP script? (WAMP Server)

I am trying to get a token to use the Microsoft Graph API (https://learn.microsoft.com/en-us/graph/auth-v2-user?context=graph%2Fapi%2F1.0&view=graph-rest-1.0) via Curl. I have set up a simple Php file with this function:
function getToken() {
echo "start gettoken";
var_dump(extension_loaded('curl'));
$jsonStr = http_build_query(Array(
"client_id" => "***",
"scope" => "https://graph.microsoft.com/.default",
"client_secret" => "***",
"grant_type" => "client_credentials"
));
$headers = Array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($jsonStr));
$ch = curl_init("https://login.microsoftonline.com/***.onmicrosoft.com/oauth2/v2.0/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$token = curl_exec($ch);
echo "test after curl";
return $token;
curl_error($ch);
}
However, what I want to know is why the curl request is not working. Also the echo after the curl codeblock is not being executed, while 'start gettoken' is. PHP_curl is enabled in my WAMP. Why is this?
Are you sure CURL is enabled because that code you have posted is ok and giving echo response before and after curl execution.
you're sending the token request in a JSON-format, and then you're lying to the server saying it's application/x-www-form-urlencoded-encoded when it's actually application/json-encoded! since these 2 formats are completely incompatible, the server fails to parse it, and... ideally it should have responded HTTP 400 bad request (because your request can't be parsed as x-www-form-urlencoded)
anyhow, to actually send it in the application/x-www-form-urlencoded-format, replace json_encode() with http_build_query()
also get rid of the "Content-Length:"-header, it's easy to mess up (aka error-prone) if you're doing it manually (and indeed, you messed it up! there's supposed to be a space between the : and the number, you didn't add the space, but the usual error is supplying the wrong length), but if you don't do it manually, then curl will create the header for you automatically, which is not error-prone.

PHP xml SOAP and laravel

I have been trying to figure out how to make a soap request using php/laravel. But from all the research on internet since two days now the only things that I can find are old rusty php codes to make soap requests non of them even worked:
Here is a snipped that I am trying to make it work so I have a general view of those soap requests but I only get errors not able to make a soapclient:
<?php
$aHTTP['http']['header'] = "User-Agent: PHP-SOAP/5.5.11\r\n";
$aHTTP['http']['header'].= "username: XXXXXXXXXXX\r\n"."password: XXXXX\r\n";
$context = stream_context_create($aHTTP);
$client=new SoapClient("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl",array('trace' => 1,"stream_context" => $context));
$result = $client::__getFunctions();
var_dump($result);
since it looks super hard to me to find any info about the soap with php any idea ?
This is a sample of a soap request I currently make to a payment provider via php using curl statements. Basically map the xml request you want to make in a string. The string will be sent in the curl post fields and the response returned.
$soapdata="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tns='tns:ns'>
<soapenv:Header>
<tns:CheckOutHeader>
<MERCHANT_ID>$merchantid</MERCHANT_ID>
<PASSWORD>$password</PASSWORD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:CheckOutHeader>
</soapenv:Header>
<soapenv:Body>
<tns:processCheckOutRequest>
<MERCHANT_TRANSACTION_ID>$merchanttransactionid</MERCHANT_TRANSACTION_ID>
<REFERENCE_ID>$referenceid</REFERENCE_ID>
<AMOUNT>$amount</AMOUNT>
<MSISDN>$mobileno</MSISDN>
<!--Optional:-->
<ENC_PARAMS></ENC_PARAMS>
<CALL_BACK_URL>$callbackurl</CALL_BACK_URL>
<CALL_BACK_METHOD>$callbackmethod</CALL_BACK_METHOD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:processCheckOutRequest>
</soapenv:Body>
</soapenv:Envelope>";
//End Soap data
//We call the server for the first time
//end calling function
function makesoaprequest($url, $soapdata)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Authorization: Basic'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$soapdata");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Begin SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//End SSL
$response = curl_exec($ch);
return $response;
curl_close($ch);
}

Laravel OAuth Authorization Header for FitBit API

I have been struggling for days now to find a decent solution for Laravel but to no avail.
There are many libraries out there that at one point may have worked to provide a Laravel - FitBit API OAuth integration however after trying over 15 different ones and none of them working I am stuck.
Reading the FitBit Documentation I see that once you receive a token you must swap the authorization code with an access token. To do this you need to send an authorization header like this:
POST https://api.fitbit.com/oauth2/token
Authorization: Basic Y2xpZW50X2lkOmNsaWVudCBzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
client_id=22942C&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fexample.com%2Fcallback&code=1234567890
I have tried using guzzle and a few other libraries for sending the requests but none of them support the format that FitBit require.
I've seen sites with FitBit API integrated so there must be a solution for this.
If anyone has managed to integrate the FitBit API please let me know where I am going wrong.
Thanks.
I don't have a fitbit account, so I can't test this and it will probably need some tweaking, but I would start with something like:
class FitbitConnection{
public function getToken($request_url, $client_id, $client_secret, $code, $redirect_uri){
// base64 encode the client_id and client_secret
$auth = base64_encode("{$client_id}:{$client_secret}");
// urlencode the redirect_url
$redirect_uri = urlencode($redirect_uri);
$request_url .= "?client_id={$client_id}&grant_type=authorization_code&redirect_uri={$redirect_uri}&code={$code}";
// Set the headers
$headers = [
"Authorization: Basic {$auth}",
"Content-Type: application/x-www-form-urlencoded",
];
// Initiate curl session
$ch = curl_init();
// Set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Options (see: http://php.net/manual/en/function.curl-setopt.php)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_POST, 1);
// Execute the curl request and get the response
$response = curl_exec($ch);
// Throw an exception if there was an error with curl
if($response === false){
throw new Exception(curl_error($ch), curl_errno($ch));
}
// Get the body of the response
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$responseBody = substr($response, $header_size);
// Close curl session
curl_close($ch);
// Return response body
return $responseBody;
}
}
You should note that I've commented out
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
You can put this option back in if you get an SSL certificate problem on your localhost, but you shouldn't use it in production .
You can then just do something like:
try{
$fitbitConnection = new FitbitConnection();
$token_response = $fitbitConnection->getToken("https://api.fitbit.com/oauth2/token","22942C","client_secret","1234567890","http://www.example.com");
echo $token_response;
}catch(Exception $e){
// curl error
echo $e->getMessage();
}

eBay Trading API GetCategories request returns 'Application name invalid'

When I tried to retreive all categories through the eBay Trading API with the method getCategories, I got this error:
FailureApplication name invalid.API application "222277"
invalid.127Error222277RequestError895E895_INTL_APICATALOG_17257399_R1
The header used is:
$headers = array(
'Content-Type:text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: 895',
'X-EBAY-API-DEV-NAME: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'X-EBAY-API-APP-NAME: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
'X-EBAY-API-CERT-NAME: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'X-EBAY-API-CALL-NAME: GetCategories',
'X-EBAY-API-SITEID: 0'
);
The XML postfields:
$body = <<<BODY
<?xml version="1.0" encoding="utf-8"?>
<GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>auth token......</eBayAuthToken>
</RequesterCredentials>
<CategorySiteID>0</CategorySiteID>
<DetailLevel>ReturnAll</DetailLevel>
</GetCategoriesRequest>
BODY;
and curl code:
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $endpoint);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $body);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
Ebay provides an API test tool.
It will pre-populate your credentials and let you make a test call.
Test Tool
This will help you debug any errors that you might get.
Unfortunately, eBay recently discontinued their API test tool. However, there are some 3rd party ones that may suffice.
For your issue, I recommend using the simpler Shopping API call called GetCategoryInfo. You don't need to POST your request or send any HTTP headers, and you can build your entire call into 1 URL/REST/GET request. This makes debugging much easier.
Either way you go about it, I don't think you can retrieve all of eBay's categories with 1 request. Instead, plan to loop through the category tree at each level, collecting the child category names and IDs.

integrating POLi payment with PHP

I need help in integrating POLi payment with custom PHP(no cms)
here is a link to a official pdf file
May be i need this section of code to integrate with php (from this pdf file)
->GenerateURL Request
To generate a Payment URL, the merchant performs a HTTP(S) post to the POLi™
PaymentAPI REST URL with the request content-­‐type set to ‘text/xml’ and the following
XML data in the request body.
Manual request (RequestType = ‘Manual’)
<?xml version="1.0" encoding="utf-­‐8"?>
<PaymentDataRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-­‐instance">
<MerchantCode>PriceBusterDVD</MerchantCode>
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<RequestType>Manual</RequestType>
<PaymentAmount>123.11</PaymentAmount>
<PaymentReference>LandingPageReferenceText</PaymentReference>
<ConfirmationEmail>No</ConfirmationEmail>
<CustomerReference>No</CustomerReference>
<RecipientName></RecipientName>
<RecipientEmail></RecipientEmail>
</PaymentDataRequest>
To do this without any framework will require the use of CURL and sending the XML with the post fields.
$payload = '<?xml version="1.0" encoding="utf-­‐8"?>
<PaymentDataRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-­‐instance">
<MerchantCode>PriceBusterDVD</MerchantCode>
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<RequestType>Manual</RequestType>
<PaymentAmount>123.11</PaymentAmount>
<PaymentReference>LandingPageReferenceText</PaymentReference>
<ConfirmationEmail>No</ConfirmationEmail>
<CustomerReference>No</CustomerReference>
<RecipientName></RecipientName>
<RecipientEmail></RecipientEmail>
</PaymentDataRequest>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://polipaymenturl.com');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
See the PHP cURL book for more information about using cURL.
(Note the example I have given isn't tested and is missing the correct URL but this should set you on the right path)

Categories