How to insert an order into Infusionsoft via API - infusionsoft

I have the code to insert the items into to an order as follows,
$ordId = 1;
$prodId = 221;
$type = '';
$price = 1000;
$qty = 5;
$desc = DESC;
$notes = "test notes";
$test = $app->addOrderItem($ordId, $prodId, $type, $price, $qty, $desc, $notes);
Is there any functions/methods available for inserting the orders directly into Infusionsoft?

If you're using the InfusionSoft PHP SDK, you have a couple of options. (1) Use the OrderService API's placeOrder() function, (2) Use the InvoiceService API to create a blank invoice, add line items to that invoice, and charge it. The OrderService API is a good one-off option; but the InvoiceService allows much more flexibility.
Using OrderService.placeOrder
$order = $app->placeOrder(
(int)$contactId,
(int)$creditCardId,
(int)$payPlanId,
(array(int))$productIds,
(array(int))$subscriptionIds,
(bool)$processSpecials,
(array(str))$promoCodes
)
NOTE: The OrderService API requires you to have already added a Contact via the ContactService API, and a Credit Card via the DataService API (by adding it to the CreditCard table).

You can use the order service. Details can be found here http://help.infusionsoft.com/api-docs/orderservice

check the complete code here
$app = new iSDK();
// perform authorization tasks
$carray = array(
$app->key,
$contactId,
$creditCardId,
$payPlanId,
array($productId1, $productId2),
array($subscriptionPlanId1, $subscriptionPlanId2),
$processSpecials,
array($promoCode1, $promoCode2)) // array of strings
);
$app->placeOrder($carray);

Related

Token cannot be null on the instantiation of the Product Query Builder. / Query Akeneo 2

I would like to create a command akeneo into my bundle who query my products like this.
So, after multiple test, i have always this error:
In ProductQueryBuilderFactory.php line 68:
Token cannot be null on the instantiation of the Product Query
Builder.
Here is my code :
$pqbFactory = $this->getApplication()->getKernel()->getContainer()->get('pim_catalog.query.product_query_builder_factory');
$pqb = $pqbFactory->create(['default_locale' => 'fr_FR', 'default_scope' => 'ecommerce']); // error
To complete Julien's answer, note that this error comes only if you are using the Enterprise Edition (EE). Indeed, in the EE, we decorate the normal product_query_builder_factory to apply permission.
If you don't want to apply permission (and don't use any token), you can use the pim_catalog.query.product_query_builder_factory_without_permission:
<?php
require __DIR__.'/vendor/autoload.php';
$kernel = new AppKernel('dev', true);
$kernel->boot();
$pqbFactory = $kernel->getContainer()->get('pim_catalog.query.product_query_builder_factory_without_permission');
$pqb = $pqbFactory->create(['default_locale' => 'fr_FR', 'default_scope' => 'ecommerce']); // you won't have any error
The PQB needs to have an authenticated user to be able to apply right filters on the results. To authenticate a user in your command you can take inspiration from the get product command. We simply take a --username argument and manually add it to the token storage.
$userManager = $this->getContainer()->get('pim_user.manager');
$user = $userManager->findUserByUsername($username);
if (null === $user) {
$output->writeln(sprintf('<error>Username "%s" is unknown<error>', $username));
return false;
}
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->getTokenStorage()->setToken($token);

How is slug being created in Sylius?

I want to create new product in Sylius. I just tested:
$user = $this->getUser();
$repository = $this->container->get('sylius.repository.product');
$manager = $this->container->get('sylius.manager.product'); // Alias for appropriate doctrine manager service.
$product = $repository->createNew();
$product
->setName('Test product')
->setDescription('Des Product 2')
->setPrice(90)
->setUser($user)
;
$manager->persist($product);
$manager->flush(); // Save changes in database.
But it trigger an exception of slug. When I try $product->getSlug(), that returns empty. I don't know how does slug created in Sylius and where is the code for that?
It's a gedmo:slug, check ProductBundle\Resources\config\doctrine\model\ProductTranslation.orm.xml
Make sure you have a default locale configured and add this to your code:
$product->setCurrentLocale($locale);
$product->setFallbackLocale($locale);
Products are translatable, and I think this is what you're missing.
Check how a product is created in Sylius\Bundle\FixturesBundle\DataFixtures\ORM\LoadProductsData line 404.

Using Dancer2::Plugin::DBIC to pull values from database

I have a webapp where a user can log in and see a dashboard with some data. I'm using APIary for mock data and in my Postgres Database each of my users have an ID. These ID's are also used in the APIary JSON file with relevant information.
I'm using REST::Client and JSON to connect so for example the url for the user's dashboard is: "/user/dashboard/12345" (in Apiary)
and in the database there is a user with the ID "12345".
How can I make it so when the user logs in, their ID is used to pull the data that is relevant to them? (/user/dashboard/{id})? Any documentation or advice would be much appreciated!
The docs of Dancer2::Plugin::Auth::Extensible are showing one part of what you need to do already. In short, save the user ID in the session. I took part of code in the doc and added the session.
post '/login' => sub {
my ($success, $realm) = authenticate_user(
params->{username}, params->{password}
);
if ($success) {
# we are saving your user ID to the session here
session logged_in_user => params->{username};
session logged_in_user_realm => $realm;
} else {
# authentication failed
}
};
get '/dashboard' => sub {
my $client = REST::Client->new();
# ... and now we use the user ID from the session to get the
# from the webservice
$client->GET( $apiary . '/user/dashboard/' . session('logged_in_user') );
my $data = $client->responseContent();
# do stuff with $data
};
For those who want to know what I ended up doing:
Dancer2::Plugin::Auth::Extensible has
$user = logged_in_user();
When I printed this it showed me a hash of all the values that user had in the database including the additional ID I had. So I accessed the id with
my $user_id = $user->{user_id};
And appended $user_id to the end of the url!

Retrieve session data Codeigniter

I'm working on a messaging system and want the user's userid to be posted to the database along with the message. Right now, the message is posting to the database, but with a user ID of 0.
How can I get the user ID from the session data to post to the database along with the message? Sidenote: I'm using Tank Auth for authentication. (From the mysql side, user_id in the message table is a foreign key referencing id in the users table).
Controller
function index() {
if ($this->input->post('submit')) {
$id = $this->input->post('user_id');
$message = $this->input->post('message');
$this->load->model('message_model');
$this->message_model->addPost($id, $message);
}
}
Model
function addMessage($id, $message) {
$data = array(
'user_id' => $id,
'message' => $message
);
$this->db->insert('message', $data);
}
For tank_auth, get the user_id using the following, and then assign that to your sessions
$user_id = $this->tank_auth->get_user_id();
Taken directly from CI's documentation:
Retrieving Session Data
Any piece of information from the session array is available using the
following function:
$this->session->userdata('item');
Where item is the array index
corresponding to the item you wish to fetch. For example, to fetch the
session ID you will do this:
$session_id = $this->session->userdata('session_id');
Note: The
function returns FALSE (boolean) if the item you are trying to access
does not exist.
So, if you have a piece of session data named user_id, you would access it like this:
$user_id = $this->session->userdata('user_id');

How to convert zipcode to longitude and latitude?

I want to find the longitude and latitude of place with a the help to a zipcode.
Can anyone tell me how to do that?
An example in actionscript what be very much helpful for me. Because i am making a project in Flex.
Regards
Zee
Do you have access to a long/lat database? if not, i believe you can use the google maps API to do that lookup.
Oh .. I just noticed Chris' answer. I am not familiar with geonames. You might also want to get familiar with "http://freegeographytools.com/" which has a ton of geocoding, gps, etc. resources for a whole range of projects.
Ahhh ... I just visited Eric's blog post. That is excellent! I will definitely hook up with google for more details in a future project.
If you are looking for on demand geocoding, use Google. They provide a simple pox web service version.
I wrote a blog about this a while back. Check out this link for step by step instructions for using this simple geocoding.
Cheers,
Eric
I got my solve you can also
function getLatLong($code) {
$mapsApiKey = 'ABQIAAAAsV7S85DtCo0H9T4zv19FoRTdT40ApbWAnDYRE0-JyP5I6Ha9-xT9G5hCQO5UtOKSH5M3qhp5OXiWaA';
$query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;
$data = file_get_contents($query);
// if data returned
if($data) {
// convert into readable format
$data = json_decode($data);
$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];
return array('Latitude'=>$lat, 'Longitude'=>$long);
} else {
return false;
}
}
There are several places to get zip code databases, in several formats. Load it into your favorite RDBMS, and query away.
Alternatively, you can use someone else's web service to look up the value for you. Other answers have posted possible web services; also, geocoder.us appears to have support for ZIP code lookup now as well.
There is now a better solution for this using the most recent Google Maps API (v3). The following is a slightly modified example from multiple sources. I have to give most of the credit to them. It's PHP, using cURL to retrieve the data from Google, but you could also use Ajax.
function address_lookup($string){
$string = str_replace (" ", "+", urlencode($string));
$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if ($response['status'] != 'OK') {
return null;
}
$geometry = $response['results'][0]['geometry']['location'];
$array = array(
'lat' => $geometry['lat'],
'lng' => $geometry['lng'],
'state' => $response['results'][0]['address_components'][3]['short_name'],
'address' => $response['results'][0]['formatted_address']
);
return $array;
}
$zip= '01742';
$array = address_lookup($zip);
print_r($array);
The easiest way out is using GoogleMap Api. Say you have a zipcode in a varible $zipcode.
$latlongUrl = 'http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:'.$zipcode;
$data = file_get_contents($latlongUrl); // you will get string data
$data = (json_decode($data)); // convert it into object with json_decode
$location = ($data->results[0]->geometry->location); // get location object
$location is the object with Latitude and Longitude value.