NetSuite PHP SDK - Set entityStatus for customer is being ignored - php

I am creating customers for NetSuite from my application by using the NetSuite PHP SDK, version 2013_2.
This mostly works, but I can not set a status for new Customers. No matter what, the status will always be CUSTOMER-Won Customer, which I don't want. I can't find any documentation about this, so I basically tried whatever seemed to make sense and tried to understand the code of the SDK. Here are some of the things I tried:
$customer->entityStatus = 17;
$customer->entityStatus = new \RecordRef(array('internalId' => 17, 'type' => 'customer'));
$customer->entityStatus = new \RecordRef();
$customer->entityStatus->internalId = 17;
All of these are simply ignored. I tried different internal IDs (and of course, I made sure all of them exist in the system). I tried using strings ('17' instead of 17), but nothing helped.
Documentation has nothing about this either.
Here's my full working code:
$ns = new \NS_NetSuiteService();
$customer = new \Customer();
$customer->companyName = $company->getName();
$customer->entityStatus = 17;
$customer->email = $user->getEmail();
$request = new \AddRequest();
$request->record = $customer;
$res = $ns->add($request);

I always create the RecordRef first, then set the field. Seems to keep things in order for me:
$entityStatus = new RecordRef();
$entityStatus->internalId = 17;
$entityStatus->recordType = "customerStatus";
$customer->entityStatus = $entityStatus;
Or, take my example and shorten the code once you see it working this way.

Related

Vtiger. API create PurchaseOrder

There is a problem over which I am puzzling for the second day.
$purchaseOrders = new PurchaseOrder();
$lists = new ItemLists();
$lists->productid->set(201);
$lists->hdnGrandTotal->set($balance);
$lists->hdnSubTotal->set($balance);
$lists->quantity->set(1);
$lists->listprice->set($balance);
$arrayDataLineItems = [];
$arrayDataLineItems[] = $lists;
$purchaseOrders->dataLineItems->set($arrayDataLineItems);
$purchaseOrders->subject->set($data['caseId']);
$purchaseOrders->purchaseorderNo->set('PO');
$purchaseOrders->vendorid->set($getVendor->id->getCrmValue());
$purchaseOrders->postatus->set('Created');
$purchaseOrders->bill_street->set($getVendor->street->getCrmValue());
$purchaseOrders->ship_street->set($getVendor->street->getCrmValue());
$purchaseOrders->productid->set(201);
$purchaseOrders->balance->set($balance);
$purchaseOrders->assignedUserId->set(6);
$purchaseOrders->conversion_rate->set(1);
$purchaseOrders->currency_id->set('21x1');
$purchaseOrders->hdnTaxType->set('group');
$purchaseOrders->terms_conditions->set('SEE FULL TERMS OF SERVICE AT https://www.salvagedata.com/about/service-terms/');
$valueMapPurchase = $purchaseOrders->toCrmMap();
$crmPurchase = $api->doCreate(PurchaseOrder::getModuleName(),$valueMapPurchase);
There is such a code. It does not add a PurchaseOrder and does not even return any errors. When I do an error check, it returns just Null. Please help, nothing in my head does not climb as it could be corrected.
Now i have database mysql 5.6
Try something like this:
$po = Vtiger_Record_Model::getCleanInstance('PurchaseOrder');
$po->set('subject', 'my po');
$po->set('assigned_user_id', 1);
//set other variables as needed...
$po->save();

Search NetSuite Custom Record Type in PHP

I have a Custom Record Type and I am having trouble searching the barcode from the item value:
I am using the NetSuite PHPToolkit_2015_2 and this stackoverflow answer https://stackoverflow.com/a/13366947/2120512 and http://burnignorance.com/netsuite-tips-and-hacks/working-with-custom-records-in-suitetalk/ to attempt to build this request:
$service = new NetSuiteService();
// Perform an AdvancedSearch for Items
// https://netsuite.custhelp.com/app/answers/detail/a_id/12203/kw/php%20search%20criteria
$service->setSearchPreferences(false, 1000, false);
$savedSearchId = 'customsearch_barcode_view'; //customsearch## from UI ID field
$searchAdvanced = new CustomRecordSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));
$request = new SearchRequest();
$request->searchRecord = $searchAdvanced;
// PHP Toolkit 2012.2: Sample Code to Perform Search that Uses a Custom Field as Filter
// https://netsuite.custhelp.com/app/answers/detail/a_id/25066/kw/php%20custom%20field
$custSearchField = new SearchMultiSelectCustomField();
$custSearchField->value = new ListOrRecordRef();
$custSearchField->value->internalId = "custrecord_barcode_item";
$custSearchField->value->value = "00001 Beer Mug";
$searchAdvanced->customFieldList = $custSearchField;
$results = $service->search($request);
I still get all the results for the Custom Record Type and never able to figure out how to search by the item. I have made changes and still receive the entire results.
I'm pretty sure this won't immediately solve your problem, but at the first glance I can see an error in your code.
The customFieldList is of type array, so you need to change this:
$searchAdvanced->customFieldList = $custSearchField;
To this
$searchAdvanced->customFieldList = [$custSearchField];

How do I submit an address to Paypal Express Checkout?

I'm in the process of writing some code that will submit an order to Paypal Express Checkout. Unforunately I can't seem to get the whole address thing to work, and I also can't seem to find much info on it in the API docs. Here's my code so far.
$config = array (
'mode' => 'sandbox' ,
'acct1.UserName' => '****removed*****',
'acct1.Password' => '******removed*******',
'acct1.Signature' => '*********removed***********'
);
$paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
$paymentDetails= new PayPal\EBLBaseComponents\PaymentDetailsType();
// Dummy shipping address
// Obviously, in the final version, this would be passed in from a form
$shipping_address = new PayPal\EBLBaseComponents\AddressType();
$shipping_address->Name = "John Smith";
$shipping_address->Street1 = "123 Market Street";
$shipping_address->Street2 = "";
$shipping_address->CityName = "Columbus";
$shipping_address->StateOrProvince = "OH";
$shipping_address->PostalCode = "43017";
$shipping_address->Country = "US";
// A dummy item
// Once again, in a final version this would be passed in
$itemDetails = new PayPal\EBLBaseComponents\PaymentDetailsItemType();
$itemDetails->Name = 'Electro Lettuce Feeders';
$itemAmount = 1250.00;
$itemDetails->Amount = $itemAmount;
$itemQuantity = 1;
$itemDetails->Quantity = $itemQuantity;
// Add all items to the list
$paymentDetails->PaymentDetailsItem[0] = $itemDetails;
// The company is in NYS, so in the final version the
// sales tax rate will be passed in (NYS is destination-based)
$sales_tax_rate = 0.07;
// Order sub-total
$itemTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$itemTotal->currencyID = 'USD';
$itemTotal->value = ($itemAmount * $itemQuantity);
// Shipping total
$shippingTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$shippingTotal->currencyID = 'USD';
$shippingTotal->value = 2.00;
// Tax total
$taxTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$taxTotal->currencyID = 'USD';
$taxTotal->value = $itemTotal->value * $sales_tax_rate;
// Order total
$orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$orderTotal->currencyID = 'USD';
$orderTotal->value = $itemTotal->value + $taxTotal->value + $shippingTotal->value;
$paymentDetails->TaxTotal = $taxTotal;
$paymentDetails->ItemTotal = $itemTotal;
$paymentDetails->ShippingTotal = $shippingTotal;
$paymentDetails->OrderTotal = $orderTotal;
$paymentDetails->PaymentAction = 'Sale';
// ***** Is the address from this object passed to Paypal?
$paymentDetails->ShipToAddress = $shipping_address;
$setECReqDetails = new PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $paymentDetails;
$setECReqDetails->CancelURL = 'https://devtools-paypal.com/guide/expresscheckout/php?cancel=true';
$setECReqDetails->ReturnURL = 'https://devtools-paypal.com/guide/expresscheckout/php?success=true';
// ***** Or is this the address that will be passed to Paypal?
$setECReqDetails->Address = $shipping_address;
// ***** And can you choose to not pass in the billing address? Or is it required? *****
$setECReqDetails->BillingAddress = $shipping_address;
// ***** If this is set to 0, will the previously provided shipping address be shown
// ***** at all? Or will it just be "modify-able" unless you set this to 1?
$setECReqDetails->AddressOverride = 1;
$setECReqType = new PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
//var_dump($setECResponse);
$redirect_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=".$setECResponse->Token;
return $app->redirect($redirect_url);
Summed up...
You'll see my questions distributed throughout the code, but here they are all summed up.
Both PaymentDetailsType() and SetExpressCheckoutRequestType() have address-ish properties. Which one will be passed on to Paypal?
Does the API require that you pass in a billing address if you pass in a shipping address?
If you don't set AddressOverride to 1, should it show the address that you passed in at all?
But in the end, I most importantly just want to know how to get address passing to work. =). Right now I can't seem to get any address to pass to Paypal no matter what I try.
It would help more to see the raw API requests getting generated as opposed to the code generating the requests. The library you're using should give you some way to see that. Then you just need to make sure the address parameters are getting passed correctly in DoExpressCheckoutPayment.
If you like, you might want to take a look at my PHP class library for PayPal. Might kinda suck to start over with another library, but it makes it very quick and easy. It has files prepared with all the parameters and everything ready to go so all you need to do is fill in the values and it'll work every time. :)
After some furious research, I was able to figure out the problem using Paypal's API explorer. As it turns out, setting ->Address on the SetExpressCheckoutRequestType() object is deprecated. The correct method is to set ->ShipToAddress for your PaymentDetailsType() object.
In my case, however, the reason that nothing was working was because I had my address wrong [slaps palm into forehead]. My zip, while in the region of Columbus, OH is technically in Dublin, OH. So, Paypal was generating an error.
Paypal wasn't showing me error information, however, so I had no way to know what in particular was causing the error. This is where the API explorer came in handy; I filled in the API explorer and tried my request--and it gave me detailed error information.
Since then, I've also found out that I can see detailed error information simply by using:
var_dump($setECResponse);

PHP - Syncing MySQL Contacts with Exchange

As part of a PHP webapp I have MySQL contacts table. It is integrated throughout the app, allowing you add a contact, edit a contact or add a contact as a relation to another table. However, currently it is self-contained. The company would like it to sync with Exchange, so that contacts added to Exchange will show up on the webapp and contacts added on the webapp will show up through Exchange.
So I have two problems: 1) communicating with Exchange 2) syncing with Exchange.
As far as the basic communication goes, it looks like this library will be able to manage it https://github.com/jamesiarmes/php-ews. However, I am quite lost as to how to manage syncing and don't where to start.
The build-in way to sync items is via function called SyncFolderItems. Basically to Exchange everything, including contacts is a folder, so you'll just pass CONTACTS as DistinguishedFolderId in your sync request.
The sync works by donloading all the items for given account in batches of max 512 elements and after each batch it gives you SyncState as a refernce point for Exchange to know where you left off. So it gives you ability to do incremental sync.
Now, that's one way of course, meaning Exchange -> Your DB. The other way it aeound you should preform atomic updates/request - the moment you change/add/delete item form your db you should issue adequate request to Exchange server to keep data in sync, elese it'll be overwritten on your next SyncFolderItems.
You can read up more on SyncFolderItems # MSDN
If you'd like to see example of SyncFolderItems you can take a look # python version of EWSWrapper, it's been added in recently. Although it's python, you can still get the basic idea how to construct the request / handle response.
Hope this helps :)
I am aware that this topic is pretty old. However, for future reference find a solution below. It is using the above-mentioned library php-ews.
I have also just added this to the official php-ews wiki: https://github.com/jamesiarmes/php-ews/wiki/Calendar:-Synchronization
// Define EWS
$ews = new ExchangeWebServices($host, $username, $password, $version);
// fill with string from last sync
$sync_state = null;
$request = new EWSType_SyncFolderItemsType;
$request->SyncState = $sync_state;
$request->MaxChangesReturned = 512;
$request->ItemShape = new EWSType_ItemResponseShapeType;
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ALL_PROPERTIES;
$request->SyncFolderId = new EWSType_NonEmptyArrayOfBaseFolderIdsType;
$request->SyncFolderId->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType;
$request->SyncFolderId->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$response = $ews->SyncFolderItems($request);
$sync_state = $response->ResponseMessages->SyncFolderItemsResponseMessage->SyncState;
$changes = $response->ResponseMessages->SyncFolderItemsResponseMessage->Changes;
// created events
if(property_exists($changes, 'Create')) {
foreach($changes->Create as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// updated events
if(property_exists($changes, 'Update')) {
foreach($changes->Update as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}
// deleted events
if(property_exists($changes, 'Delete')) {
foreach($changes->Delete as $event) {
$id = $event->CalendarItem->ItemId->Id;
$change_key = $event->CalendarItem->ItemId->ChangeKey;
$start = $event->CalendarItem->Start;
$end = $event->CalendarItem->End;
$subject = $event->CalendarItem->Subject;
}
}

Create a private event using the Zend Google Calendar API PHP framework

I am trying to use the Zend_Gdata_Calendar library to create a new event on the Google Calendar API and am struggling to work out how to set the visibility - has anyone any ideas how to actually do it?
The construct of my class has
$this->calendar_client = Zend_Gdata_ClientLogin::getHttpClient($this->user_name, $this->password, Zend_Gdata_Calendar::AUTH_SERVICE_NAME);
Where the user_name and pass_word are the login details for an account which is able to write to the calendar. The following works
$gdataCal = new Zend_Gdata_Calendar($this->calendar_client);
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$newEvent->where = array($gdataCal->newWhere($where));
$newEvent->content = $gdataCal->newContent($content);
$newEvent->visibility = 'private';
$when = $gdataCal->newWhen();
$when->startTime = $start_time;
$when->endTime = $end_time;
$newEvent->when = array($when);
$createdEvent = $gdataCal->insertEvent($newEvent,"https://www.google.com/calendar/feeds/{$email}/private/full");
($title, $where, and $content are text strings passed into the function)
However the visibility doesn't seam to get used.
I have tried the visibility shown above and also each of the following,
$newEvent->setVisibility($gdataCal->newVisibility('private'));
$newEvent->setVisibility($gdataCal->newVisibility(true));
$newEvent->setVisibility($gdataCal->newVisibility(false));
And while these all work (i.e. an event is created at the correct time) the private flag is never set!
Answering my own question you need to use a URI for it!
$newEvent->visibility = $gdataCal->newVisibility("http://schemas.google.com/g/2005#event.public");
$newEvent->visibility = $gdataCal->newVisibility("http://schemas.google.com/g/2005#event.private");

Categories