Quickbooks Online sdk add invoice exception - php

I am integrating my application with with Quickbook Online Sandbox account using php sdk version 3. I am able to connect and fetch/add data like customers without a problem. But I am unable to create an invoice using the sdk. Here is my code:
$invoiceObj = new IPPInvoice();
$Line = new IPPline();
$Line->Amount = 15;
$Line->DetailType = 'SalesItemLineDetail';
$saleItemLineDetail = new IPPSalesItemLineDetail();
$saleItemLineDetail->ItemRef = 1;
$saleItemLineDetail->UnitPrice = 15;
$saleItemLineDetail->Qty = 2;
$Line->SalesItemLineDetail = $saleItemLineDetail;
$invoiceObj->Line = $Line;
$invoiceObj->DocNumber = '23713';
$invoiceObj->TxnDate = 2015-10-11;
$invoiceObj->CustomerRef = 67;
try{
$resultingInvoiceObj = $connect->Add($invoiceObj);
} catch (Exception $e){
echo $e->getMessage();
}
I am writing this in a function which takes the connection object as parameter. I am able to add customer using this connection object in the same function.
The response i'm getting is
2015-04-22 06:46:15 - E:\wamp\www\test\application\libraries\QuickBooksOnline\DataService\DataService.php - 340 - CheckNullResponseAndThrowException - Response Null or Empty
I got stuck here. Please point out where i am doing wrong. Any help in this regard is highly appreciated.

Try this once to pass customerRef
$customerRef2 = new IPPReferenceType();
$customerRef2->value = "67";
$invoiceObj->CustomerRef = $customerRef2;

Related

Stripe issue when creating subscription: "Could not determine which URL to request"

I've setup stripe multiple times and never had this issue before. I'm processing the "customer created" web hook and using the payload to attach stripe id to my user and setup a new subscription.
I'm getting the following error:
Stripe\Exception\UnexpectedValueException: Could not determine which URL to request: Stripe\Subscription instance has invalid ID: in file /Users/mick/repos/askit/vendor/stripe/stripe-php/lib/ApiResource.php on line 107
This only happens when I try to create the new subscription. Here is my full controller:
public function handleCustomerCreated(Request $request)
{
$payload = json_decode($request->getContent(), true);
$user_id = $payload->data->object->subscriptions->data[0]->metadata->user_id;
$subscription_id = $payload->data->object->subscriptions->data[0]->id;
$stripe_customer_id = $payload->data->object->id;
$current_period_start = $payload->data->object->subscriptions->data[0]->current_period_start;
$current_period_end = $payload->data->object->subscriptions->data[0]->current_period_end;
$stripe_plan = $payload->data->object->subscriptions->data[0]->items->data[0]->plan->id;
$name = $payload->data->object->subscriptions->data[0]->items->data[0]->plan->nickname;
$stripe_status = $payload->data->object->subscriptions->data[0]->status;
$interval = $payload->data->object->subscriptions->data[0]->items->data[0]->plan->interval_count;
$user = User::query()->find($user_id);
$user->stripe_id = $stripe_customer_id;
$user->save();
$subscription = new Subscription();
$subscription->user_id = $user_id;
$subscription->name = $name;
$subscription->stripe_id = $stripe_customer_id;
$subscription->stripe_status = $stripe_status;
$subscription->stripe_plan = $stripe_plan;
$subscription->interval = $interval;
$subscription->current_period_start = $current_period_start;
$subscription->current_period_end = $current_period_end;
$subscription->subscription_id = $subscription_id;
$subscription->save();
}
If I remove the new Subscription stuff it works fine, the stripe is getting attached to my user model just fine. The error only happens on this part:
$subscription = new Subscription();
$subscription->user_id = $user_id;
$subscription->name = $name;
$subscription->stripe_id = $stripe_customer_id;
$subscription->stripe_status = $stripe_status;
$subscription->stripe_plan = $stripe_plan;
$subscription->interval = $interval;
$subscription->current_period_start = $current_period_start;
$subscription->current_period_end = $current_period_end;
$subscription->subscription_id = $subscription_id;
$subscription->save();
Any ideas? The table was created automagically by Laravel Cashier.
Try using \Stripe\Subscription::create() as shown in the Stripe API Docs, instead of manually creating and modifying a new Subscription(). You're current code is trying to update a Subscription that doesn't yet exist in the API, so it can't find its id.

Docusign bulk send using php client

I have implemented bulk send using docusign php client. I'm getting following error message
{ "errorCode": "UNSPECIFIED_ERROR", "message": "Value cannot be
null. Parameter name: stream" }
when I run below source code.
$templateId = 'd756f973-...';
$apiClient = $this->getDocuSignClient();
// Get Template
$templatesApi = new TemplatesApi($apiClient);
$templateDetails = $templatesApi->get($this->getAccountId(), $templateId);
// Set documents
...
// Receipient
$signer = new Signer();
$signer->setIsBulkRecipient('true');
$signer->setRecipientId('1');
$recipients = new Recipients();
$recipients->setSigners([$signer]);
// Create draft template
$envelopDefinition = new EnvelopeDefinition();
$envelopDefinition->setStatus('created');
$envelopDefinition->setDocuments($documents);
$envelopDefinition->setRecipients($recipients);
$envelopDefinition->setEmailSubject('Sign bulk send');
$envelopeApi = new EnvelopesApi($apiClient);
$envelopSummary = $envelopeApi->createEnvelope($this->getAccountId(), $envelopDefinition);
// Update bulk recipients
$clients = Client::all();
$bulkRecipients = [];
foreach ($clients as $client) {
$bulkRecipient = new BulkRecipient();
$bulkRecipient->setEmail($client->email);
$bulkRecipient->setName($client->first_name);
$bulkRecipients[] = $bulkRecipient;
}
$bulkRequest = new BulkRecipientsRequest();
$bulkRequest->setBulkRecipients($bulkRecipients);
$bulkEnvelopesApi = new BulkEnvelopesApi($apiClient);
$bulkEnvelopesApi->updateRecipients($this->getAccountId(), $envelopSummary['envelope_id'], '1', $bulkRequest);
// ---------- the error message throws on above line ----------
Any help appreciated. Thanks in advance
can you please try to update to version 4 (https://github.com/docusign/docusign-php-client/releases/tag/v4.0.0) of the PHP client. This supports our new v2.1 API which has a much improved bulk send support https://developers.docusign.com/esign-rest-api/reference/BulkEnvelopes/BulkEnvelopes/

how do i authenticate against cybersource soap toolkit api on php

I have the following code on my index.php
<?php
// This sample demonstrates how to run a sale request, which combines an
// authorization with a capture in one request.
// Using Composer-generated autoload file.
require __DIR__ . '/vendor/autoload.php';
// Or, uncomment the line below if you're not using Composer autoloader.
//require_once(__DIR__ . '/lib/CybsSoapClient.php');
// Before using this example, you can use your own reference code for the transaction.
$referenceCode = 'holla';
$client = new CybsSoapClient();
$request = $client->createRequest($referenceCode);
// Build a sale request (combining an auth and capture). In this example only
// the amount is provided for the purchase total.
$ccAuthService = new stdClass();
$ccAuthService->run = 'true';
$request->ccAuthService = $ccAuthService;
$ccCaptureService = new stdClass();
$ccCaptureService->run = 'true';
$request->ccCaptureService = $ccCaptureService;
$billTo = new stdClass();
$billTo->firstName = 'John';
$billTo->lastName = 'Doe';
$billTo->street1 = '1295 Charleston Road';
$billTo->city = 'Mountain View';
$billTo->state = 'CA';
$billTo->postalCode = '94043';
$billTo->country = 'US';
$billTo->email = 'null#cybersource.com';
$billTo->ipAddress = '10.7.111.111';
$request->billTo = $billTo;
$card = new stdClass();
$card->accountNumber = '4111111111111111';
$card->expirationMonth = '12';
$card->expirationYear = '2020';
$request->card = $card;
$purchaseTotals = new stdClass();
$purchaseTotals->currency = 'USD';
$purchaseTotals->grandTotalAmount = '90.01';
$request->purchaseTotals = $purchaseTotals;
$reply = $client->runTransaction($request);
// This section will show all the reply fields.
print("\nRESPONSE: " . print_r($reply, true));
and the cybs.ini is like
merchant_id = "firefy"
transaction_key = "5430494897960177107046"
; Modify the URL to point to either a live or test WSDL file with the desired API version.
wsdl = "https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.109.wsdl"
when i run the code on my local machine i get the following error messaage.
Fatal error: Uncaught SoapFault exception: [wsse:FailedCheck] Security Data : UsernameToken authentication failed. in C:\xampp\htdocs\cybersourceTest\index.php:50 Stack trace: #0 C:\xampp\htdocs\cybersourceTest\index.php(50): SoapClient->__call('runTransaction', Array) #1 {main} thrown in C:\xampp\htdocs\cybersourceTest\index.php on line 50
How do i know what caused the error above and how can i solve the above error.
I am trying to add payout api to my app and this is giving a headache right now.
Please guys help me out if anyone can.
The error “authentication failed” is saying your merchant_id and transaction_key are not correct.
Assuming that your merchant_id is correct your transaction_key is not the correct format. You can get a transaction_key by going to the business center at https://ebctest.cybersource.com then go to Account Management-> Transaction Security Keys -> Security Keys for the SOAP Toolkit API. Generate a key there.
I found out that i the url that i was pointing to was not valid or something but i fixed it by changing the endpoint of the wsdl from
wsdl="https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.109.wsdl"
to
wsdl="https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.151.wsdl"
That took care of everything that was wrong with the error that was popping up.

PHP-EWS "Soap client returned status of 404"

So, I'm using php-ews library to connect to my Microsoft Office 365 Exchange Email account to read emails. I've connected successfully to it and I have managed to retrieve a list of emails that I need.
Now the problem is that I cannot get message body. Reading documentation about Exchange Web Services it says that body cannot be fetched with FindItem(), only with GetItem(), and that's okay.
Now the problem I'm seeing is following:
I tried all possible examples I could find about this, and the code doesn't have any errors, it just says "Soap client returned status of 404".
If anyone has any idea where to look for the solution, please tell me.
EDIT:
$ews = new Client('outlook.office365.com/EWS/OData/Me/Inbox/Messages', '###', '###', ClientEWS::VERSION_2010_SP2);
$request = new FindItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::DEFAULT_PROPERTIES;
$request->ItemShape->BodyType = BodyTypeResponseType::BEST;
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::INBOX;
// sort order
$request->SortOrder = new NonEmptyArrayOfFieldOrdersType();
$request->SortOrder->FieldOrder = array();
$order = new FieldOrderType();
// sorts mails so that oldest appear first
// more field uri definitions can be found from types.xsd (look for UnindexedFieldURIType)
$order->FieldURI = new PathToUnindexedFieldType();
$order->FieldURI->FieldURI = 'item:DateTimeReceived';
$order->Order = 'Ascending';
$request->SortOrder->FieldOrder[] = $order;
try{
//getting list of all emails - works perfectly
$result = $ews->FindItem($request);
if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success') {
$count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
for ($i = 0; $i < $count; $i++){
$message_id = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->Message[$i]->ItemId->Id;
$messageItem = new ItemIdType();
$messageItem->Id = $message_id;
$request->ItemIds->ItemId[] = $messageItem;
}
// Here is your response
// It throws an error here with the message "Soap client returned status of 404"
$response = $ews->GetItem($request);
print_r($response);
}
//print_r($result);
} catch(\Exception $e) {
echo $e->getMessage();
}
It looks like your trying to use the new REST endpoint for Office365
'outlook.office365.com/EWS/OData/Me/Inbox/Messages'
But your trying to make and EWS SOAP Request, the endpoint you should be using for EWS SOAP is
https://outlook.office365.com/EWS/Exchange.asmx
You might want to consider using the new REST interface as an alternative to EWS/SOAP but you then need to use a REST library.ouauth etc as per https://dev.outlook.com/restapi.
I'd suggest you use a newer version of this library that's maintained much more and has more features (In this case, it support OAuth logins for Office 365), garethp/php-ews. When using it, you can either use the endpoint provided by Glen Scales, or just use outlook.office365.com.

Salesforce API: Error on ->update(), "INVALID_TYPE: Must send a concrete entity type."

I've been researching this and trying many variations based off my understanding of how to update a record in an SObject, but I keep getting the following error:
SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: Must send a concrete entity type. in /home/public_html/soapclient/SforceBaseClient.php:509
I am able to login successfully to the page, but when I execute the code below, I am getting the error listed above.
$fieldsToUpdate = array (
"Name"=>$_POST['Name']
);
$sObject = new SObject();
$sObject->Id = $_POST['prospectID']; // this is the Id of the record
$sObject->fields = $fieldsToUpdate;
$sObject->type = 'Prospect__c'; // this is the API name of custom object
try {
$response = $mySforceConnection->update($sObject);
} catch (Exception $e) {
echo $e;
}
I am using PHP Toolkit 13.0 from the Force.com developer docs, but not able to get to the bottom of this error. Also, I am using the Enterprise WSDL in sandbox mode, and have the proper wsdl xml assigned.
Thanks.
sObject is the base type for all other Salesforce objects that can be updated. When using the enterprise API (SOAP), you'll need to pass instances that derive from sObject. (Lead, Contact, and Account are examples)
Here is the documentation for the update() method as well.
You need to supply an object type as the second update() argument. Also, the first argument of the update() method must be an array of objects you'd like to update:
$response = $mySforceConnection->update(array($object), 'Prospect__c');
Also, you do not need to use any object classes provided by the toolkit, a simple StdClass should work:
$prospect = new StdClass();
$prospect->Id = '006....';
$prospect->Name 'Foobar';
$response = $mySforceConnection->update(array($prospect), 'Prospect__c');
FYI, I have never found a way to update multiple object types at once, but you can update a batch of the same type of objects, hence why the first parameter needs to be an array. The Salesforce toolkit doesn't automatically account for someone passing a single object (i.e. it doesn't wrap it in an array for you). I have always used an abstraction layer between my application logic and Salesforce's SOAP toolkit, which provides conveniences like I just described.
if your are using Partner wsdl
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once ('../userAuth.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
/*--------------------------------------------------------\
| Please manage the values for OBJECT ID from file
| userAuth.php
\--------------------------------------------------------*/
$fieldsToUpdate = array (
'FirstName' => 'testupdate',
'City' => 'testupdateCity',
'Country' => 'US'
);
$sObject1 = new SObject();
$sObject1->fields = $fieldsToUpdate;
$sObject1->type = 'Lead';
$sObject1->Id = $UPDATEOBJECTID1;
$fieldsToUpdate = array (
'FirstName' => 'testupdate',
'City' => 'testupdate',
'State' => 'testupdate',
'Country' => 'US'
);
$sObject2 = new SObject();
$sObject2->fields = $fieldsToUpdate;
$sObject2->type = 'Lead';
$sObject2->Id = $UPDATEOBJECTID2;
$sObject2->fieldsToNull = array('Fax', 'Email');
$response = $mySforceConnection->update(array ($sObject1, $sObject2));
print_r($response);
} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo $e->faultstring;
}
?>
else for enterprises wsdl use
<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../userAuth.php');
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);
/*--------------------------------------------------------\
| Please manage the values for OBJECT ID from file
| userAuth.php
\--------------------------------------------------------*/
$sObject1 = new stdclass();
$sObject1->Id = $UPDATEOBJECTID1;
$sObject1->FirstName = 'testupdate';
$sObject1->City = 'testupdateCity';
$sObject1->Country = 'US';
$sObject2 = new stdclass();
$sObject2->Id = $UPDATEOBJECTID2;
$sObject2->FirstName = 'testupdate';
$sObject2->City = 'testupdate';
$sObject2->State = 'testupdate';
$sObject2->Country = 'US';
$sObject2->fieldsToNull = array('Fax', 'Email');
$response = $mySforceConnection->update(array ($sObject1, $sObject2), 'Lead');
print_r($response);
} catch (Exception $e) {
print_r($mySforceConnection->getLastRequest());
echo $e->faultstring;
}
?>

Categories