quickbooks php sdk class not found - php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require "vendor/autoload.php";
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth1',
'consumerKey' => " ",
'consumerSecret' => " ",
'accessTokenKey' => " ",
'accessTokenSecret' => " ",
'QBORealmID' => "",
'baseUrl' => "https://quickbooks.api.intuit.com/"
));
for($i = 1; $i<= 3; $i ++){
$LineObj = Line::create([
"Id" => $i,
"LineNum" => $i,
"Description" => "Pest Control Services",
"Amount" => 35.0,
"DetailType" => "SalesItemLineDetail",
"SalesItemLineDetail" => [
"ItemRef" => [
"value" => "1",
"name" => "Pest Control"
],
"UnitPrice" => 35,
"Qty" => 1,
"TaxCodeRef" => [
"value" => "NON"
]
]
]);
$lineArray[] = $LineObj;
}
//Add a new Invoice
$theResourceObj = PurchaseOrder::create([
"Line" => $lineArray,
"CustomerRef"=> [
"value"=> "1"
],
"BillEmail" => [
"Address" => "Familiystore#intuit.com"
],
"BillEmailCc" => [
"Address" => "a#intuit.com"
],
"BillEmailBcc" => [
"Address" => "v#intuit.com"
]
]);
?>
Fatal error: Uncaught Error: Class 'Line' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/Test2.php:24
purchaseOrder.php:
<?php
//require "vendor/autoload.php";
include('src/config.php');
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
// OBOT Data service
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth1',
'consumerKey' => " ",
'consumerSecret' => " ",
'accessTokenKey' => " ",
'accessTokenSecret' => " ",
'QBORealmID' => " ",
'baseUrl' => "https://quickbooks.api.intuit.com/"
));
$linedet = new IPPPurchaseOrderItemLineDetail();
$linedet->CustomerRef = 86;
$line = new IPPLine();
$line->Id = 0;
$line->Description = 'test purchase order';
$line->Amount = 2.00;
$line->DetailType= 'ItemBasedExpenseLineDetail ';
$line->ItemBasedExpenseLineDetail = $linedet;
$line->BillableStatus = 'Notbillable';
$line->ItemRef = '19';
$line->UnitPrice = '25';
$line->Qty = '1';
$purchaseOrder = new IPPPurchaseOrder();
$purchaseOrder->Line = $line;
$purchaseOrder->VendorRef = 85;
$purchaseOrder->APAccountRef = 1;
$purchaseOrder->TotalAmt = 200.00;
$result = $dataService->Add($purchaseOrder); //add purchase order
?>
PHP Fatal error: Uncaught Error: Class 'IPPPurchaseOrderItemLineDetail' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/purchaseOrder.php:20
Why am I getting these errors? is the autoload not working? should I just directly include the class files that I need?

In regards your first error below:
Fatal error: Uncaught Error: Class 'Line' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/Test2.php:24
I don't see you including the Line class anywhere, from the GitHub page here I have truncated their advice:
Connecting to the QuickBooks Online API
Currently the below API entity Endpoints support creating Objects from Array:
Estimate
Line
Invoice
Item
For create/update above entity endpoints, you are going to import corresponding facade class:
use QuickBooksOnline\API\Facades\{Facade_Class_Name};
As such you need to update your first script to include this Facade, which should be as simple as:
<?php
require "vendor/autoload.php";
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
use QuickBooksOnline\API\Facades\Line; // <-- You are missing this line
In regards the second error below:
PHP Fatal error: Uncaught Error: Class 'IPPPurchaseOrderItemLineDetail' not found in /var/www/html/QuickBooks-V3-PHP-SDK-master/purchaseOrder.php:20
From searching the GitHub codebase again I can see this class is declared here. Therefore it should be as simple as declaring this again in your use statements at the top of the file that is using this, such as below:
<?php
//require "vendor/autoload.php";
include('src/config.php');
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Facades\Invoice;
use QuickBooksOnline\API\Facades\PurchaseOrder;
use QuickBooksOnline\API\Data\IPPPurchaseOrderItemLineDetail; // <-- You are missing this line
Looking at the rest of your code there seems to be a lot of classes that you are not declaring through use statements such as PurchaseOrder, IPPLine and IPPPurchaseOrder which you will also need to include.

Related

Error while making payments using Mollie API in php

I am making payments using mollie API in php. But its giving me some errors . I have posted my code and screenshot of the errors.
THIS IS MY CODE:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
try {
require_once "vendor/autoload.php";
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_XXXX");
$orderId = time();
$amount = $_POST['amount'];
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "$amount", // You must send the correct number of decimals, thus we enforce the use of strings
],
"description" => "Order #{$orderId}",
"redirectUrl" => "https://example.com/Mollie/return/".$orderId."/",
"webhookUrl" => "https://example.com/Mollie/webhook/",
"metadata" => [
"order_id" => $orderId,
],
]);
print_r($payment);
$payment_data = array(
'payment_id' => $payment->id,
'user_id' => $_POST['user_id'],
'order_id' => $orderId,
'mode' => $payment->mode,
'description' => $payment->description,
'status' => $payment->status,
'added_date' => date('Y-m-d'),
'added_time' => date('H:i:s')
);
print_r($payment_data);
header("Location: " . $payment->getCheckoutUrl(), true, 303);
} catch (\Mollie\Api\Exceptions\ApiException $e) {
echo "API call failed: ". htmlspecialchars($e->getMessage());
}
THE SCREENSHOT:
The first image shows "Uncaught SyntaxError: Unexpected token M in JSON at position 0" in RED color.
The second image is the warning I am getting
First image
Second Image

How to insert customBatch in Google Content API (Shopping)

I am trying to insert products on Google Merchant Center. I am currently using Google API PHP client, and I am unable to find toSimpleObject function in any of the class and class extending it.
$this->service = new Google_Service_ShoppingContent($client);
$product = array("batchId" => $batchID,
"merchantId" => $this->googleapi->merchantID,
"method" => "insert",
"product" => array(
"kind" => "content#product",
"offerId" => $skuDetails['SKU'],
"title" => $skuDetails['TITLE'],
"description" => $skuDetails['DESCRIPTION'],
"imageLink" => $skuDetails['IMAGE'],
"contentLanguage" => "en",
"targetCountry" => "US",
"channel" => "online",
"availability" => ($skuDetails['QUANTITY'] > 0)?'in stock':'out of stock',
"brand" => $skuDetails['BRAND'],
"condition" => $skuDetails['CONDITION'],
"minHandlingTime" => $skuDetails['HANDLING_TIME'],
"ageGroup" => 'adult',
"maxHandlingTime" => ($skuDetails['HANDLING_TIME'] + 2),
"googleProductCategory" => (empty($skuDetails['CATEGORYID']))?$skuDetails['CATEGORYPATH']:$skuDetails['CATEGORYID'],
"price" => [
"value" => $price['lp'],
"currency" => "USD"
]
)
);
$productObject = new Google_Service_ShoppingContent_ProductsCustomBatchRequest();
$productObject->setEntries($product);
$result = $this->service->products->custombatch($productObject);
Error:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Google_Service_ShoppingContent_ProductsCustomBatchRequest::toSimpleObject()
Line Number: 108
Backtrace:
File: vendor/google/apiclient-services/src/Google/Service/ShoppingContent/Resource/Products.php
Line: 40
Function: call
You should be using Google_Service_ShoppingContent_Product to insert data to your product instance then you can use custombatch to upload it
$product = new Google_Service_ShoppingContent_Product();
$product->setId($id);
$product->setTitle($title);

How do I deal with Class 'PHPUnit_Framework_TestCase' not found error?

I am trying to integrate to visa direct API. I decided to to it in PHP. However, as I am doing some tests from a sample code they have provided, I got stuck at Fatal error: Class 'PHPUnit_Framework_TestCase' not found error.
I have PHPUnit installed since when I check via phpunit --version ..I get PHPUnit 5.6.2 by Sebastian Bergmann and contributors.
Below is my code using PHPUnit, would someone direct me where my mistake is? Thank you.
<?php
class MVisaTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$this->visaAPIClient = new VisaAPIClient;
$strDate = date('Y-m-d\TH:i:s', time());
$this->mVisaTransactionRequest = json_encode ([
"acquirerCountryCode" => "643",
"acquiringBin" => "400171",
"amount" => "124.05",
"businessApplicationId" => "CI",
"cardAcceptor" => [
"address" => [
"city" => "Bangalore",
"country" => "IND"
],
"idCode" => "ID-Code123",
"name" => "Card Accpector ABC"
],
"localTransactionDateTime" => $strDate,
"merchantCategoryCode" => "4829",
"recipientPrimaryAccountNumber" => "4123640062698797",
"retrievalReferenceNumber" => "430000367618",
"senderAccountNumber" => "4541237895236",
"senderName" => "Mohammed Qasim",
"senderReference" => "1234",
"systemsTraceAuditNumber" => "313042",
"transactionCurrencyCode" => "USD",
"transactionIdentifier" => "381228649430015"
]);
}
public function testMVisaTransactions() {
$baseUrl = "visadirect/";
$resourcePath = "mvisa/v1/cashinpushpayments";
$statusCode = $this->visaAPIClient->doMutualAuthCall ( 'post', $baseUrl.$resourcePath, 'M Visa Transaction Test', $this->mVisaTransactionRequest );
$this->assertEquals($statusCode, "200");
}
}
You can just use TestCase class instead so you can say:
use PHPUnit\Framework\TestCase;
class MVisaTest extends TestCase {
// your tests goes here
}

Different output in AWS PHP SDK than in AWSCLI

The primary goal that I'm trying to achieve is to iterate over my running EC2 instances in PHP.
It's really easy to get the data using a bash script, as shown below:
Bash script:
#!/bin/bash
export AWS_ACCESS_KEY_ID="AKIDEXAMPLE"
export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"
aws ec2 describe-instances --region="eu-west-1" --filter "Name=instance-state-name,Values=running"
Bash output:
{
"Reservations": [
{
"OwnerId": "58728357357",
"ReservationId": "r-0e0283649826935",
"Instances": [
{
"SecurityGroups": [
{
"GroupId": "sg-2fe333148",
"GroupName": "WEB"
}
],
"PublicDnsName": "ec2-53-13-121-72.eu-west-1.compute.amazonaws.com",
"Architecture": "x86_64",
"LaunchTime": "2016-07-11T08:28:23.000Z",
"RootDeviceName": "/dev/sda1",
"BlockDeviceMappings": [
{
"Ebs": {
// ...
}
]
}
However, when I try the following example, using the same keys, I am presented with what seems to be an unusable object - or at least the object looks like it is representing an empty data structure.
PHP File:
<?php
require __DIR__ . "/vendor/autoload.php";
$settings = [
"version" => "latest",
"region" => "eu-west-1",
"credentials" => [
"key" => "AKIDEXAMPLE",
"secret" => "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
],
];
$client = new \Aws\Ec2\Ec2Client($settings);
$result = $client->describeInstances([
"Filters" => [
[
"Name" => "instance-state-name",
"Value" => "running",
]
],
]);
var_dump($result);
PHP Output:
What the hell am I meant to do with this AWS\Result?
class Aws\Result#82 (1) {
private $data =>
array(2) {
'Reservations' =>
array(0) {
}
'#metadata' =>
array(4) {
'statusCode' =>
int(200)
'effectiveUri' =>
string(35) "https://ec2.eu-west-1.amazonaws.com"
'headers' =>
array(5) {
...
}
'transferStats' =>
array(1) {
...
}
}
}
}
Am I missing something in the PHP configuration? Please can someone help point me in the right direction?
P.S. I've masked the API keys in the above examples.
EC2::DescribeInstances takes an array of filters, each of which has a string Name and an array of string Values. In your CLI example, you've supplied something for Values, whereas in your PHP example you've supplied a Value instead. This field is not recognized by the SDK and will be ignored. See the SDK API docs for more information.
Your PHP should be updated to read:
<?php
require __DIR__ . "/vendor/autoload.php";
$settings = [
"version" => "latest",
"region" => "eu-west-1",
"credentials" => [
"key" => "AKIDEXAMPLE",
"secret" => "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
],
];
$client = new \Aws\Ec2\Ec2Client($settings);
$result = $client->describeInstances([
"Filters" => [
[
"Name" => "instance-state-name",
"Values" => ["running"],
]
],
]);
var_dump($result);

ebaySOAP sample example gives error - unable to find the wrapper "https"

Why i am getting the following
error
Warning: SoapClient::__doRequest(): Unable to find the wrapper "https"
- did you forget to enable it when you configured PHP
What is my mistake?
My code is following
$config = parse_ini_file('ebay.ini', true);
$site = $config['settings']['site'];
$compatibilityLevel = $config['settings']['compatibilityLevel'];
$dev = $config[$site]['devId'];
$app = $config[$site]['appId'];
$cert = $config[$site]['cert'];
$token = $config[$site]['authToken'];
$location = $config[$site]['gatewaySOAP'];
// Create and configure session
$session = new eBaySession($dev, $app, $cert);
$session->token = $token;
$session->site = 203; // 0 = US;
$session->location = $location;
// Make an AddItem API call and print Listing Fee and ItemID
try {
$client = new eBaySOAP($session);
$PrimaryCategory = array('CategoryID' => 357);
$Item = array('ListingType' => 'Chinese',
'Currency' => 'INR',
'Country' => 'US',
'PaymentMethods' => 'PaymentSeeDescription',
'RegionID' => 0,
'ListingDuration' => 'Days_3',
'Title' => 'The new item',
'Description' => "It's a great new item",
'Location' => "San Jose, CA",
'Quantity' => 1,
'StartPrice' => 24.99,
'PrimaryCategory' => $PrimaryCategory,
);
$params = array('Version' => $compatibilityLevel, 'Item' => $Item);
$results = $client->AddItem($params);
// The $results->Fees['ListingFee'] syntax is a result of SOAP classmapping
print "Listing fee is: " . $results->Fees['ListingFee'] . " <br> \n";
print "Listed Item ID: " . $results->ItemID . " <br> \n";
print "Item was listed for the user associated with the auth token code herer>\n";`enter code here`
} catch (SOAPFault $f) {
print $f; // error handling
}
Thanks in advance
Murali
You have to add (or uncomment it) extension=php_openssl.dll; to your php.ini file.

Categories