quickbooks online sdk create invoice - sdk

I am using the quickbooks sdk to connect with a quickbook online account. I am able to connect a get data like customers and invoice without a problem. But I am unable to create an invoice using the sdk. Here is my code:
$token = unserialize($_SESSION['token']);
$requestValidator = new OAuthRequestValidator(
$token['oauth_token'], $token['oauth_token_secret'], OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
$realmId = $_SESSION['realmId'];
$serviceType = $_SESSION['dataSource'];
$serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);
$dataService = new DataService($serviceContext);
//create an invoice
$invoiceObj = new IPPInvoice();
$invoiceObj->CustomerRef = 5;
$invoiceObj->Amount = 12.00;
$invoiceObj->DocNumber = 9999;
$invoiceObj->TaxnDate = "2014-05-01";
$Line = new IPPline();
$Line->DetailType ='SalesItemLineDetail';
//$Line->Amount = 10;
$Line->setDescription = 'Test description goes here.';
$saleItemLineDetail = new IPPSalesItemLineDetail();
$saleItemLineDetail->ItemRef = 1;
$saleItemLineDetail->Quantity = 1;
$saleItemLineDetail->UnitPrice = 10.00;
$line->SalesItemLineDetail = $saleItemLineDetail;
$invoiceObj->Line = $line;
$resultingInvoiceObj = $dataService->Add($invoiceObj);
When a run this an invoice isn't created and I get this error:
Fatal error: Uncaught IdsException: [0]: 2014-05-02 17:26:08 - /home/randy/test_apps/v3-php-sdk-2.0.4/DataService/DataService.php - 340 - CheckNullResponseAndThrowException - Response Null or Empty thrown in /home/randy/test_apps/v3-php-sdk-2.0.4/Core/CoreHelper.php on line 95
I don't think the Line data is getting added correctly. How do I correctly add line data or is it something else?
Thanks

You have to pass customer id as string as follows
$invoiceObj->CustomerRef = 5;
Below is working sample code
Sample Code

Related

Upload Offline Conversion migration to V9

I used to upload offline conversion using following code in v201809 version as provided at
https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201809/Remarketing/UploadOfflineConversions.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$session = (new AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->withClientCustomerId($customerid)->enablePartialFailure()->build();
$adWordsServices = new AdWordsServices();
$offlineConversionService = $adWordsServices->get($session, OfflineConversionFeedService::class);
$conversionName="OfflineConv";
$feed = new OfflineConversionFeed();
$feed->setConversionName($conversionName);
$feed->setConversionTime($conversionTime);
$feed->setConversionValue($conversionValue);
$feed->setGoogleClickId($gclid);
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->setOperator(Operator::ADD);
$offlineConversionOperation->setOperand($feed);
$offlineConversionOperations = [$offlineConversionOperation];
$result = $offlineConversionService->mutate($offlineConversionOperations);
Now I am upgrading to V9, I have used the code as provided at
https://github.com/googleads/google-ads-php/blob/main/examples/Remarketing/UploadOfflineConversion.php
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
//$conversionName="OfflineConv";
$conversionName = ConversionActionType::WEBPAGE;
$clickConversion = new ClickConversion([
'conversion_action' => ResourceNames::forConversionAction($customerId, $conversionName),
'gclid' => $gclid,
'conversion_value' => $conversionValue,
'conversion_date_time' => $conversionTime,
'currency_code' => 'USD'
]);
$conversionUploadServiceClient = $googleAdsClient->getConversionUploadServiceClient();
$result = $conversionUploadServiceClient->uploadClickConversions($customerid, [$clickConversion], true);
The problem is when we set $conversionName="OfflineConv"; we get following error.
Resource name 'customers/9025381111/conversionActions/OfflineConv' is malformed: expected 'customers/{customer_id}/conversionActions/{ConversionType.conversion_type_id}'., at conversions[0].conversion_action
and when we set $conversionName = ConversionActionType::WEBPAGE; we get following error.
This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action
Can someone help me?
Conversion Name must match the conversion action that you've already set up in your account. You're passing the enum value for the type.
It should be something like $conversionName = "OfflineConversions"
where "OfflineConversions" is exactly the name of the conversion in the conversions section of the web UI.
ConversionName has been removed from V9, use $conversionActionId as in example on github.
You need to try use parameter ctId from url your "OfflineConversions" in Google Ads UI as $conversionActionId.
Or try the solution from here.
For your example, replace this
$conversionName = ConversionActionType::WEBPAGE;
on this
$conversionName = {ctId from url};
You need to first create a click conversion
click_conversion = adwords_client.get_type("ClickConversion")
conversion_action_service = adwords_client.get_service('ConversionActionService')
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
The conversion_action_id is equivalent to conversion_name of previous version.
You can find the id using following snippet
ads: GoogleAdsServiceClient = self.adwords_client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action where conversion_action.name={conversion_name}", customer_id={customer_id})
for page in pages:
print(page.conversion_action)
Then you upload the conversion
click_conversion.gclid = gclid
click_conversion.conversion_value = conversion_value
click_conversion.conversion_date_time = conversion_time
click_conversion.currency_code = currency_code
conversion_upload_service = self.adwords_client.get_service("ConversionUploadService")
request = self.adwords_client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions.append(click_conversion)
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)

Set new placement in Group Criterion via API

How can I add new placement (website, for example www.example.com) in AdGroup using AdWords API?
I have found
AdGroupCriterionService->mutate,
but I need to know ID of website
$adGroupCriterion->criterion = new Criterion($criterionId);
So my question:
How I can found ID for any website or exist another way to add new Placement in AdGroup?
I found an answer:
$adGroupService = $user->GetService('AdGroupCriterionService', 'v201509');
$AdGroupCriterionOperation = new AdGroupCriterionOperation();
$AdGroupCriterionOperation->operator = 'ADD';
$AdGroupCriterion = new BiddableAdGroupCriterion();
$AdGroupCriterion->adGroupId = $adGroupId;
$AdGroupCriterion->criterionUse = 'BIDDABLE';
$AdGroupCriterion->AdGroupCriterionType = 'PLACEMENT';
$Placement = new Placement();
$Placement->id = null;
$Placement->CriterionType = 'PLACEMENT';
$Placement->type = 'PLACEMENT';
$Placement->url = $url;
$AdGroupCriterion->criterion = $Placement;
$AdGroupCriterionOperation->operand = $AdGroupCriterion;
$operations = array($AdGroupCriterionOperation);
// Make the mutate request.
$result = $adGroupService->mutate($operations);

error when add multiple OBX segments to NHapi.Model.V25.Group.VXU_V04_ORDER

I am working on creating HL7 VXU V04 type message using NHapi V2.5.
Below is the required message outcome( from NIST site:http://hl7v2-iz-testing.nist.gov/mu-immunization/)
The issue I am running into is how to create four OBX segments("NHapi.Model.V25.Segment.OBX ") and add it to the "NHapi.Model.V25.Group.VXU_V04_ORDER" ?
Below is my code, Line#5 works, it create multiple ORDER but if i try to do the same to create multiple OBSERVATION (Line#8), I get the below error:
"Can't create repetition #1 of Structure OBSERVATION - this Structure is non-repeating"
As per HL7 specifications OBSERVATION is repeating structure, Anyone please help here?
Any pointers or any suggestions are greatly appreciated.
NHapi.Model.V25.Message.VXU_V04 vxuMsg = new VXU_V04();
PipeParser parser = new PipeParser();
for (int i = 0; i < person.Immunizations.Count; i++)
{
NHapi.Model.V25.Group.VXU_V04_ORDER orc = (NHapi.Model.V25.Group.VXU_V04_ORDER)vxuMsg.GetStructure("ORDER", i);
for (int j = 0; j < 2; j++)
{
NHapi.Model.V25.Group.VXU_V04_OBSERVATION observation = (NHapi.Model.V25.Group.VXU_V04_OBSERVATION)orc.GetStructure("OBSERVATION", j);
NHapi.Model.V25.Segment.OBX obx1 = (NHapi.Model.V25.Segment.OBX)obx.GetStructure("OBX");
}
NHapi.Model.V25.Segment.RXA im = orc.RXA;
NHapi.Model.V25.Segment.ORC oc = orc.ORC;
NHapi.Model.V25.Segment.RXR rxr = orc.RXR;
}
Required message outcome
MSH|^~\&|Test EHR Application|X68||NIST Test Iz Reg|201207010822||VXU^V04^VXU_V04|NIST-IZ-001.00|P|2.5.1|||AL|ER
PID|1||D26376273^^^NIST MPI^MR||Snow^Madelynn^Ainsley^^^^L|Lam^Morgan|20070706|F||2076-8^Native Hawaiian or Other Pacific Islander^CDCREC|32 Prescott Street Ave^^Warwick^MA^02452^USA^L||^PRN^PH^^^657^5558563|||||||||2186-5^non Hispanic or Latino^CDCREC
PD1|||||||||||02^Reminder/Recall - any method^HL70215|||||A|20120701|20120701
NK1|1|Lam^Morgan^^^^^L|MTH^Mother^HL70063|32 Prescott Street Ave^^Warwick^MA^02452^USA^L|^PRN^PH^^^657^5558563
ORC|RE||IZ-783274^NDA|||||||I-23432^Burden^Donna^A^^^^^NIST-AA-1||57422^RADON^NICHOLAS^^^^^^NIST-AA-1^L
RXA|0|1|20120814||140^Influenza, seasonal, injectable, preservative free^CVX|0.5|mL^MilliLiter [SI Volume Units]^UCUM||00^New immunization record^NIP001|7832-1^Lemon^Mike^A^^^^^NIST-AA-1|^^^X68||||Z0860BB|20121104|CSL^CSL Behring^MVX|||CP|A
RXR|C28161^Intramuscular^NCIT|LD^Left Arm^HL70163
OBX|1|CE|64994-7^Vaccine funding program eligibility category^LN|1|V05^VFC eligible - Federally Qualified Health Center Patient (under-insured)^HL70064||||||F|||20120701|||VXC40^Eligibility captured at the immunization level^CDCPHINVS
OBX|2|CE|30956-7^vaccine type^LN|2|88^Influenza, unspecified formulation^CVX||||||F
OBX|3|TS|29768-9^Date vaccine information statement published^LN|2|20120702||||||F
OBX|4|TS|29769-7^Date vaccine information statement presented^LN|2|20120814||||||F
Dim vxuMsg As NHapi.Model.V25.Message.VXU_V04 = New VXU_V04()
Dim orc As NHapi.Model.V25.Group.VXU_V04_ORDER = DirectCast(vxuMsg.GetStructure("ORDER", 0), NHapi.Model.V25.Group.VXU_V04_ORDER)
Dim observation As NHapi.Model.V25.Group.VXU_V04_OBSERVATION = orc.GetOBSERVATION(0) 'DirectCast(orc.GetStructure("OBSERVATION", 0), NHapi.Model.V25.Group.VXU_V04_OBSERVATION)
Dim orderobservation As VXU_V04_ORDER = vxuMsg.GetORDER(0)
Dim obx1 As NHapi.Model.V25.Segment.OBX = DirectCast(observation.GetStructure("OBX"), NHapi.Model.V25.Segment.OBX)
obx1 = orderobservation.GetOBSERVATION(0).OBX
obx1.SetIDOBX.Value = "1"
obx1.ValueType.Value = "CE"
obx1.ObservationIdentifier.Identifier.Value = "64994-7"
obx1.ObservationIdentifier.Text.Value = "Vaccine funding program eligibility category"
obx1.ObservationIdentifier.NameOfCodingSystem.Value = "LN"
obx1.ObservationSubID.Value = "1"
Dim ce As New CE(oru01)
ce.Identifier.Value = "V05"
ce.Text.Value = "VFC eligible - Federally Qualified Health Center Patient(under-insured)"
ce.NameOfCodingSystem.Value = "HL70064"
obx1.GetObservationValue(0).Data = ce
obx1.ObservationResultStatus.Value = "F"
obx1.DateTimeOfTheObservation.Time.Value = "20120701"
obx1.GetObservationMethod(0).Identifier.Value = "VXC40"
obx1.GetObservationMethod(0).Text.Value = "Eligibility captured at the immunization level"
obx1.GetObservationMethod(0).NameOfCodingSystem.Value = "CDCPHINVS"
Dim obx2 As NHapi.Model.V25.Segment.OBX = obx1
obx2 = orderobservation.GetOBSERVATION(1).OBX
obx2.SetIDOBX.Value = "2"
obx2.ValueType.Value = "CE"
obx2.ObservationIdentifier.Identifier.Value = "30956-7"
obx2.ObservationIdentifier.Text.Value = "vaccine type"
obx2.ObservationIdentifier.NameOfCodingSystem.Value = "LN"
obx2.ObservationSubID.Value = "2"
Dim ce2 As New CE(oru01)
ce2.Identifier.Value = "88"
ce2.Text.Value = "Influenza, unspecified formulation"
ce2.NameOfCodingSystem.Value = "CVX"
obx2.GetObservationValue(0).Data = ce2
obx2.ObservationResultStatus.Value = "F"
Dim obx3 As NHapi.Model.V25.Segment.OBX = obx1 'DirectCast(observation.GetStructure("OBX"), NHapi.Model.V251.Segment.OBX)
obx3 = orderobservation.GetOBSERVATION(2).OBX
obx3.SetIDOBX.Value = "3"
obx3.ValueType.Value = "TS"
obx3.ObservationIdentifier.Identifier.Value = "29768-9"
obx3.ObservationIdentifier.Text.Value = "Date vaccine information statement published"
obx3.ObservationIdentifier.NameOfCodingSystem.Value = "LN"
obx3.ObservationSubID.Value = "2"
Dim ts3 As New TS(oru01)
ts3.Time.Value = "20120702"
obx3.GetObservationValue(0).Data = ts3
obx3.ObservationResultStatus.Value = "F"

Getting Error In Journal Entry Quickbooks

I am trying to add a journal entry. But it returns like an error
Uncaught IdsException: [0]: 2014-01-29 08:13:07 - D:\DummyApps\v3-php-sdk-2.0.1\v3-php-sdk-2.0.1\DataService\DataService.php - 341 - CheckNullResponseAndThrowException -
Response Null or Empty thrown in D:\DummyApps\v3-php-sdk-2.0.1\v3-php-sdk-2.0.1\Core\CoreHelper.php on line 95'
I am using QuickBooks PHP SDK. My code is below:
// Prep Data Services
$dataService = new DataService($serviceContext);
if (!$dataService)
exit("Problem while initializing DataService.\n");
$linedet = new IPPJournalEntryLineDetail();
$linedet->PostingType = 'Credit';
$linedet->AccountRef = 9;
$line = new IPPLine();
$line->Id = 0;
$line->Description = 'test journal';
$line->Amount = 2.00;
$line->DetailType= 'test ';
$line->JournalEntryLineDetail = $linedet;
$linedet2 = new IPPJournalEntryLineDetail();
$linedet2->PostingType = 'Debit';
$linedet2->AccountRef = 9;
$line2 = new IPPLine();
$line2->Id = 1;
$line2->Description = 'test journal';
$line2->Amount = 2.00;
$line2->DetailType= 'test ';
$line2->JournalEntryLineDetail = $linedet2;
// Add a journal
$journalObj = new IPPJournalEntry();
$journalObj->SyncToken = '1';
$journalObj->DocNumber = '1';
$journalObj->TxnDate = '2014-12-30';
$journalObj->RefNumber = 't123';
$journalObj->PrivateNote = 'Just testing';
$journalObj->Line = array($line, $line2);
$journalObj->Adjustment = TRUE;
$journalObj->IsAdjustment = TRUE;
$resultingObj = $dataService->Add($journalObj );
Please help me....I am stuck here.
Thanks in Advance
I found the error here.
The 'DetailType' in the line object must have 'JournalEntryLineDetail'

FedEx Webservice for printing Multiple shipping labels

I am trying to connect to the FedEx shipping webservice v8.
Everything works fine when I only have one RequestedPackageLineItems set. When I add two items I get the following error.
"Invalid package count or invalid package sequence number."
My Code is as follows
ProcessShipmentRequest request = CreatePendingShipmentRequest();
ShipService service = new ShipService();
ProcessShipmentReply reply = service.processShipment(request);
...
private static ProcessShipmentRequest CreatePendingShipmentRequest()
{
ProcessShipmentRequest request = new ProcessShipmentRequest();
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.UserCredential.Key = "XXX";
request.WebAuthenticationDetail.UserCredential.Password = "XXX";
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = "XXX";
request.ClientDetail.MeterNumber = "XXX";
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "*** Ground Domestic Shipping Request v8 using C# ***";
request.Version = new VersionId();
//Inside this method I set request.RequestedShipment.PackageCount = "2";
SetShipmentDetails(request);
SetPackageLineItems(request);
return request;
}
private static void SetPackageLineItems(ProcessShipmentRequest request)
{
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 50.0M;
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[0].ItemDescription = "Item";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "108";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "5";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "5";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences = new CustomerReference[3];
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].CustomerReferenceType = CustomerReferenceType.CUSTOMER_REFERENCE;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].Value = "[LOT NUMBER]";
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].CustomerReferenceType = CustomerReferenceType.INVOICE_NUMBER;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].Value = "45646";
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].CustomerReferenceType = CustomerReferenceType.P_O_NUMBER;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].Value = "456446";
request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2";
request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 50.0M;
request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[1].ItemDescription = "Item";
....
}
Found out how to do this.
In order to get multiple shipping labels into one pdf the process is as follows.
Create a request
Fill in the shipping info
Post and get a reply.
Save that replay and the byte array and MasterShippingID
Create a new request and assign the master shipping id to it.
Added shipping weight and dimensions
Post and get reply
Save byte array with the other
Continue until all shipments are generated (max 200 per master shipping id)
Merge all the pdfs returned from FedEx into one pdf.
Do a happy dance.
A simpler approach, (though there is a cost) is the Shiprush SDK. It lets you build a single XML block and let ShipRush do all the funny stuff with fedex (or whoever).
They also support their tool.

Resources