Add Organisation & Contact to Insightly and automatically link them - php

I am using a PHP library (https://github.com/Insightly/insightly-php) with great success for the Insightly API. More information on the Insightly API can be found here: https://api.insight.ly/v2.2/Help
My goal is to have an organisation and a contact added to Insightly on a form submission and to then link the two together. I can add the organisation and the contact without any issues but I am having troubles linking the two afterwards. When I add in the code to link the two it is only adding the organisation and not the contact.
Please view my code below:
$organization = $i->addOrganization($newOrganization);
$getOrganizationID = $i->getOrganization($company);
$id = json_decode($getOrganizationID, true);
$newContact = (object)array(
"FIRST_NAME" => $first_name,
"LAST_NAME" => $last_name,
"CONTACTINFOS" => array(
(object)array(
"TYPE" => "EMAIL",
"LABEL" => "WORK",
"DETAIL" => $email,
),
(object)array(
"TYPE" => "PHONE",
"LABEL" => "WORK",
"DETAIL" => $phone,
)
),
"LINKS" => array(
(object)array(
"ORGANISATION_ID" => $id[0]['ORGANISATION_ID'],
)
),
);
$contact = $i->addContact($newContact);

I had a faulty link in the getOrganization() function and have since fixed it.

Related

DocuSign REST API (PHP) - pre-fill custom tags

I am working on project in which I need to use DocuSign API (PHP). This is my first experience with DocuSign and I successfully made template in DocuSign Console with roleName = signer. There I also made Custom Text Tags: address, city, state and phone and drag them to the desired location in my template. I want there to put my customer (signer) information from project database.
From my project I successfully made connection with DocuSign via PHP API and receive Embedded Singing View URL which opens my template where the user can sign document without problem.
But... all my custom text tags are empty and signer can type into them. I need to pre-fill them with signer personal data which is coming from database. I triple check custom tag label spelling, upper/lower case in my DocuSign Console and in my code as well as roleName->tagLabel relation. My PHP code is below.
Can someone, please, tell me what I am doing wrong?
I lost two days on it.
$data = array(
"accountId" => $accountId,
"emailSubject" => $this->_emailSubject,
"templateId" => $templateId,
"templateRoles" => array(
array(
"email" => $email,
"name" => $recipientName,
"clientUserId" => $clientUserId,
"roleName" => "signer",
"customFields" => array(
"textCustomFields" => array (
array (
"name" => "address",
"value" => "Address from DB",
"show" => "true",
),
array (
"name" => "city",
"value" => "City from DB",
"show" => "true",
),
array (
"name" => "state",
"value" => "State from DB",
"show" => "true",
),
array (
"name" => "phone",
"value" => "Phone from DB",
"show" => "true",
),
),
),
),
),
"status" => "sent"
);
You need to use the textTabs type in your JSON, not customFields which is used for something else. For instance, if you drag a Data Field from the UI onto the document and give it name address, to pre-fill that field you would need to reference it's tabLabel and value fields like this:
"roleName" => "signer",
"tabs" => array(
"textTabs" => array(
array(
"tabLabel"=> "address",
"value" => "123 Main St."
)
)
)

Podio - Relationship app field implementation

A great thanks to #Andreas for answering my question at Podio : Troubles assigning reference for a Relationship app field, it helped me finding the special settings for all podio app fields.
Anyway, I still can't assign referenced apps to relationship app fields.
I've tried to create app with all the fields the following way :
$attributes = array(
"space_id" => $ws->space_id,
"config" => array(
"icon" => DEFAULT_APP_ICON,
"item_name" => "Test App",
"name" => "TestApp"
),
"fields" => array(
array (
"type" => "app",
"external_id" => "test-reference-field",
"config" => array (
"label" => "Test field",
"settings" => array(
"referenced_apps" => array(array("app_id" => 10048654))
)
)
)
)
);
$app = new PodioApp($attributes);
But it does not create the app at all in the given workspace, so I created the app by calling static create() method instead:
$app = PodioApp::create($attributes);
Indeed, the app is created in the right workspace but the referenced app is not linked at all.
So, would it be an API bug or anything else I skipped in my code? Any help would be appreciated
Thanks
The documentation is wrong and you should be using referenceable_types for your settings key and the value should just be an array of app_ids.
$attributes = array(
"space_id" => $ws->space_id,
"config" => array(
"icon" => DEFAULT_APP_ICON,
"item_name" => "Test App",
"name" => "TestApp"
),
"fields" => array(
array (
"type" => "app",
"external_id" => "test-reference-field",
"config" => array (
"label" => "Test field",
"settings" => array(
"referenceable_types" => array(233461, 233464)
)
)
)
)
);
$app = PodioApp::create($attributes);

Having problems with Mailchimp API Editing Member of a list

Its not working for some odd reason.
http://apidocs.mailchimp.com/api/2.0/lists/update-member.php
I want to update the Notes section on a member.
Its acting like it posts fine.
returning a valid response no error code.
but its not adding a new note to the member.
$results = $MailChimp->call("lists/update-member",
array(
"id"=> "xxxxxxx",
"email" => array(
"email" => "someemail#gmail.com",
"euid" => "xxxxxxx"
),
"merge_vars" => array(
"mc_notes" => array(
"note" => "THIS IS MY NEW NOTE"
)
),
"update_existing"=> true,
));
var_dump($results);

Magento Credit card number mismatch with credit card type exception

I am working with the magento api and I have run into a bit of an issue with creating an order. I have been able to get everything up to creating the order to work correctly. The issue that I am seeing is when I call the method to create the order I always get the exception: Credit card number mismatch with credit card type.
I am running Magento ver. 1.6.2.0
I have verified that the card I am testing with works via the magento frontend.
Any help with this is greatly appreciated.
This is the test code that I am using:
<?php
$proxy = new SoapClient('http://localhost/index.php/api/soap/?wsdl');
$sessionId = $proxy->login('shopapi', 'test123');
// Create a quote, get quote identifier
$shoppingCartId = $proxy->call( $sessionId, 'cart.create');
// Set customer, for example guest
$customerAsGuest = array(
"firstname" => "testFirstname",
"lastname" => "testLastName",
"email" => "test#test.com",
//"website_id" => "0",
//"store_id" => "0",
"mode" => "guest"
);
$resultCustomerSet = $proxy->call($sessionId, 'cart_customer.set', array( $shoppingCartId, $customerAsGuest) );
// Set customer addresses, for example guest's addresses
$arrAddresses = array(
array(
"mode" => "shipping",
"firstname" => "testFirstname",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "testCity",
"region" => "CA",
"postcode" => "90049",
"country_id" => "US",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
),
array(
"mode" => "billing",
"firstname" => "testFirstname",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "testCity",
"region" => "CA",
"postcode" => "90049",
"country_id" => "US",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
)
);
$resultCustomerAddresses = $proxy->call($sessionId, "cart_customer.addresses", array($shoppingCartId, $arrAddresses));
// add products into shopping cart
$arrProducts = array(
array(
"product_id" => "1",
"qty" => 1
)
);
$resultCartProductAdd = $proxy->call($sessionId, "cart_product.add", array($shoppingCartId, $arrProducts));
// get list of products
$shoppingCartProducts = $proxy->call($sessionId, "cart_product.list", array($shoppingCartId));
// set payment method
$paymentMethod = array(
"method" => "authorizenet",
"cc_type" => 'MC',
"cc_number" =>'5555555555554444' ,
"cc_exp_month" => 9,
"cc_exp_year" => 2014,
"cc_cid" => 123
);
$resultPaymentMethod = $proxy->call($sessionId, "cart_payment.method", array($shoppingCartId, $paymentMethod));
// create order
$resultOrderCreation = $proxy->call($sessionId,"cart.order",array($shoppingCartId));
var_dump($resultOrderCreation);
?>
Your call to cart_payment.method is succeeding, according to your post, so the CC number is validating to be a MC card, as expected.
The problem is that Magento, due to PCI concerns, does NOT save the CC number in the database (in most cases).
So, as you are sending payment details, along with CC number and CID, in one request and then creating the order in another, the state is lost and the CC number and CID are blanked out.
When the order is created, the payment data is validated a second time and when that happens, it has an empty CC number with a type of MC, causing the fault you see.
Unfortunately, I do not see a way to make cart.order accept payment data as a work around.
You could write a module to extend the checkout APIs with a new method that does both steps in a single call and that would likely solve the problem.
I ran into this issue as well. My solution was to create a custom SOAP endpoint which handled all of the order creation and submission logic at once without multiple API calls.
Even this way, I was getting card type mismatch exceptions.
The trick was once I set the payment info, collect totals, and save quote, with the getPayment->importData method, it seems to forget the card info. Probably for (not the best way to handle) PCI-DSS compliance.
To solve it, I added another getPayment->importData line after saving the quote, before submitting the order.
This is achieved without changing any of the core files.
See example:
public function customCheckout($checkoutData=false)
{
if(!$checkoutData){
Mage::throwException("No checkout data received.");
}
if(!json_decode($checkoutData)){
Mage::throwException("Bad checkout data received.");
}
$data = json_decode($checkoutData);
$email = 'email#email.cc';
// get the basic store info to associate with order
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
// begin checkout with a quote
$quote = Mage::getModel('sales/quote')->setStoreId($store->getId());
// set customer by email
$customer = Mage::getModel('customer/customer')
->setWebsiteId($websiteId)
->loadByEmail($email);
// handle customer not exists by creating a new customer
if($customer->getId() == ''){
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstName("Bob")
->setLastName("Loblaw")
->setEmail($email)
->setPassword('password');
$customer->save();
}
// assign customer to SO quote
$quote->assignCustomer($customer);
// do we want to send a confirmation email to the customer?
// my guess is we would handle that in a separate service.
$quote->setSendConfirmation(0);
// add products to quote
foreach($data->products as $item){
$product = Mage::getModel('catalog/product')->load($item->id);
$quote->addProduct($product,new Varien_Object(array('qty'=>$item->qty)));
}
// set SO billing address
$billingAddress = $quote->getBillingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => $data->customer->firstName,
'middlename' => '',
'lastname' => $data->customer->lastName,
'suffix' => '',
'company' => '',
'street' => array(
'0' => 'street1',
'1' => 'street2'
),
'city'=>'city',
'country_id'=>'US',
'region'=>'WA',
'postcode'=>'98101',
'telephone' => '425-425-4254',
'fax' => '789-789-7897',
'vat_id' => '',
'save_in_address_book' => 0
));
// set SO shipping address, this will probably be the location of sale, on-site
$shippingAddress = $quote->getShippingAddress()->addData(array(
'customer_address_id' => '',
'prefix' => '',
'firstname' => $data->customer->firstName,
'middlename' => 'middle',
'lastname' => $data->customer->lastName,
'suffix' => '',
'company' => '',
'street' => array(
'0' => 'street1',
'1' => 'street2'
),
'city'=>'city',
'country_id'=>'US',
'region'=>'WA',
'postcode'=>'98201',
'telephone' => '425-425-4254',
'fax' => '789-789-7897',
'vat_id' => '',
'save_in_address_book' => 0
));
// set shipping method, if it's sold on site we aren't charging for delivery
$shipMethod='freeshipping_freeshipping';
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($shipMethod)
->setPaymentMethod($data->payment->method);
// set payment method
$quote->getPayment()->importData(array(
'method' =>$data->payment->method,
'cc_type' =>$data->payment->type,
'cc_number' =>$data->payment->number,
'cc_exp_year' =>$data->payment->expYear,
'cc_exp_month'=>$data->payment->expMonth,
));
// collect totals, save quote
$quote->collectTotals()->save();
// turn the quote into an order
$service = Mage::getModel('sales/service_quote',$quote);
// set payment method A SECOND TIME!!!!!!!!!!!!!
$quote->getPayment()->importData(array(
'method' =>$data->payment->method,
'cc_type' =>$data->payment->type,
'cc_number' =>$data->payment->number,
'cc_exp_year' =>$data->payment->expYear,
'cc_exp_month'=>$data->payment->expMonth,
));
$service->submitAll();
$increment_id = $service->getOrder()->getRealOrderId();
$quote = $customer = $service = null;
$retval = new stdClass;
$retval->orderId = $increment_id;
return json_encode($retval);
}
I have never done successful API transactions to the payment method code authorizenet. This only always succeeds via frontend, not sure why.. nor have I had time to investigate why. Although what I have always done instead is to use authorizenet_direct post instead. My reasoning behind this / how I stumbled upon this is that the same also applies to the Paypal payment methods. API seems to only work with paypal_direct or paypaluk_direct. Try it! it should work. At the very least, this works for me.
$paymentMethod = array(
"method" => "authorizenet_directpost",
"cc_type" => 'MC',
"cc_number" =>'5555555555554444' ,
"cc_exp_month" => 9,
"cc_exp_year" => 2014,
"cc_cid" => 123
);
Actually I just discovered a way to take authorize.net payments via the API.
First in /app/code/core/Mage/Payment/Model/Method/Cc.php, uncomment the line about saving the cid, so the function look like this on line 65
public function prepareSave()
{
$info = $this->getInfoInstance();
if ($this->_canSaveCc) {
$info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
}
$info->setCcCidEnc($info->encrypt($info->getCcCid()));
$info->setCcNumber(null)
->setCcCid(null);
return $this;
}
And then in the main model file of your payment method, make sure the variable is set to:
protected $_canSaveCc = true;
I've tested 2 payment methods using this and both work fine via API now.
this is my solution:
goto /app/code/core/Mage/Payment/Model/Method/Cc.php
and see function :
public function prepareSave()
{
$info = $this->getInfoInstance();
if ($this->_canSaveCc) {
$info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
}
//$info->setCcCidEnc($info->encrypt($info->getCcCid()));
$info->setCcNumber(null)
->setCcCid(null);
return $this;
}
only comment line :
$info->setCcNumber(null)
->setCcCid(null);

Sugar SOAP set_entry

I am trying to add entries to a Sugar Contacts database with the following SOAP code in PHP.
$set_entry_params = array(
'session' => $result_array->id,
'module_name' => 'Contacts',
'name_value_list'=>array(
array('name'=>'Name','value'=>'Brian')
)
);
$result = $soapClient->__soapCall('set_entry', $set_entry_params);
An entry is made in the sugar db, but the name field is left blank and the Role field is labelled: Pre Sugar Roll Out
does anyone know what is wrong here?
The issue is probably due to using "Name" as your "name" in teh "name_value_list". The "Name" field is just a concactonation of the "first_name" and "last_name" fields. Try:
$set_entry_params = array(
'session' => $result_array->id,
'module_name' => 'Contacts',
'name_value_list'=>array(
array('name'=>'first_name','value'=>'Brian')
)
);
$result = $soapClient->__soapCall('set_entry', $set_entry_params);

Categories