Xero SDK Writing Line Item AccountCode to Invoices - xero-api

I am successfully writing invoices to Xero, including line item information, thus:
$products_list[] = array(
'Description' => $product_description,
'Quantity' => (float) $row['Quantity'],
'UnitAmount' => (float) $row['List Price'],
'DiscountRate' => $discountPercentage,
'TaxType' => 'OUTPUT2', //20% vat
'TaxAmount' => $calculatedTaxRate, //20% vat
'Name' => $xeroProductName['itemName'],
'ItemCode' => $xeroProductName['itemCode'],
'AccountCode' => $accountCode
);
All is fine except the AccountCode - no matter what I do it simply doesn't get written (neither I think does TaxAmount). I notice in Xero that 'Account' is a dropdown and when an account is selected, the tax amount is calculated.
Any help greatly appreciated.
Andy

Related

Prestashop order::getProducts: What is the price without tax and without discount?

In an element of Order::getProducts(), there are several prices:
[total_price_tax_incl] => 1900.800000 [total_price_tax_excl] =>
1584.000000 [unit_price_tax_incl] => 1900.800000 [unit_price_tax_excl] => 1584.000000 [total_shipping_price_tax_incl] => 0.000000 [total_shipping_price_tax_excl] => 0.000000 [purchase_supplier_price]
=> 923.000000 [original_product_price] => 2112.000000 [original_wholesale_price] => 923.000000 [price] => 1846.000000
[wholesale_price] => 923.000000
I'd want to pick up the one that is without tax, and without reduction.
What is it?
original_product_price is a field you're looking for :)

Shopify Order API - Passing Discount

I'm getting some very strange results from Shopify API and I'm hoping someone can help me out.
I'm trying to create an order, with a discount. Its actually saving the order, with the discount information... however the amount is ALWAYS wrong
order_params = {
:browser_ip => webhook[:browser_ip],
:buyer_accepts_marketing => webhook[:buyer_accepts_marketing],
:currency => webhook[:currency],
:email => webhook[:email],
:financial_status => webhook[:financial_status],
:landing_site => webhook[:landing_site],
:note => webhook[:note],
:referring_site => webhook[:referring_site],
:line_items => line_items,
:tag => tags,
:transactions => transactions,
:discount_codes => webhook[:discount_codes],
:total_discounts => webhook[:total_discounts],
:shipping_address => webhook[:shipping_address],
:shipping_lines => webhook[:shipping_lines],
:customer_id => #options[:customer_id],
:billing_address => webhook[:billing_address]
}
#shopify_order = ShopifyAPI::Order.create(order_params)
As you can see its created from webhook data. This is giving me back...(truncated)
"reference"=>nil,
"user_id"=>nil,
"subtotal_price"=>"55.00",
"total_discounts"=>"55.00",
"location_id"=>nil,
"source_identifier"=>nil,
"source_url"=>nil,
"processed_at"=>"2017-05-31T15:53:03-04:00",
"device_id"=>nil,
"phone"=>nil,
"browser_ip"=>nil,
"landing_site_ref"=>nil,
"order_number"=>1140,
"discount_codes"=>
[#<ShopifyAPI::Order::DiscountCode:0x007ffbec42ccb0
#attributes={"code"=>"50% OFF", "amount"=>"55.00", "type"=>""},
#persisted=true,
#prefix_options={}>]
So far, so good all data is correct.. then I save and this happens.. the amount discounted is incorrect... it should be £55.
I haven't dug too deep into this, but I'm pretty sure the code needs to be unique.
i.e. you probably already have a Discount Code with the same code 50% OFF with amount: 60.50 defined somewhere else on that shop.
Try using a new, unique discount code and testing with that.
I would suggest creating a new discount code like 50OFF that has amount: 50 with type: percentage, then you can re-use that for orders with a 50% discount.
See the Price Rules reference for more information >

Bigcommerce API Tracking Number Create PHP

I am trying to update the tracking number of an order in Bigcommerce using the API. This is the code I am using:
//update BC of order status
$filter = array('status_id' => 2);
$order_status_update = BigCommerce::updateResource('/orders/' . 105, $filter);
$order = Bigcommerce::getOrder(105);
foreach($order->products as $shipment)
{
$filter = array(
'order_address_id' => $shipment->order_address_id,
'items'=> array(
'order_product_id' => $shipment->product_id,
'quantity' => $shipment->quantity
),
'tracking_number' => 'tracking number'
);
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);
}
I have followed the instructions from here:
https://developer.bigcommerce.com/api/stores/v2/orders/shipments#list-shipments
BigCommerce Uploading Tracking Numbers
But I can't seem to get it to work. Can someone help?
In advance, thanks for your help!
Akshay
The payload for creating a shipment is invalid due to the items field needing to be formatted as an object array and the use of the product_id as opposed to the ID of the product within the order.
The code provided is attempting to create one shipment per product in the order, is this intended? Ideally you would ship all items in one shipment, which is why the items field is meant to be an array of product objects.
Additionally, by creating a shipment for an order the order status will automatically change to "Shipped", so the first PUT request is unnecessary.
If you were trying to create a single shipment per order and are assuming no orders will have multiple addresses then this code should work.
$order = Bigcommerce::getOrder(105);
$filter = array(
'order_address_id' => $order->shipping_addresses[0]->id,
'tracking_number' => '123456'
);
foreach($order->products as $product) {
$items[] = array(
'order_product_id' => $product->id,
'quantity' => $product->quantity
);
}
$filter['items'] => $items;
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);

Add multiple products to paypal express checkout

For a few hours i'm trying to list into paypal express checkout multiple products. This has to be done in order to increase the customers trust for what they buy.
How i can create the bellow array in order to be reconized by paypal as multiple products?
Listing of 1 product is not a problem. Here is the code:
$requestParams = array(
'RETURNURL' => '***',
'CANCELURL' => '***'
);
$item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ',
'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item',
'L_PAYMENTREQUEST_0_AMT0' => '0.01',
'L_PAYMENTREQUEST_0_QTY0' => '1'
);
$orderParams = array(
'PAYMENTREQUEST_0_AMT' => '0.01',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'PAYMENTREQUEST_0_ITEMAMT' => '0.01',
'PAYMENTREQUEST_0_SHIPPINGAMT' => '0'
);
$response = $core->paypal->request('SetExpressCheckout',$requestParams + $item + $orderParams);
I have tried lots of combinations like adding keys and values into $item array like that in order to add more products to be listed:
I tried also to add in a similar way keys to $orderParams array but without success.
Either i got errors from paypal api, either the paypal listed only the first product.
$item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ',
'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item',
'L_PAYMENTREQUEST_0_AMT0' => '0.01',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'L_PAYMENTREQUEST_1_NAME1' => 'Test product 1',
'L_PAYMENTREQUEST_1_DESC1' => 'Description of my next item',
'L_PAYMENTREQUEST_1_AMT1' => '0.01',
'L_PAYMENTREQUEST_1_QTY1' => '1'
);
This is my first integration, i understand the paypal flow but i can't go over this.
Thanks.
Ok, it was a simple trick to do. For those who might need it:
L_PAYMENTREQUEST_n_NAMEm - "n" is the number of transaction, 0 for 1 single transaction - "m" is the number of the product
$item = array('L_PAYMENTREQUEST_0_NAME0' => 'Test product ', //title of the first product
'L_PAYMENTREQUEST_0_DESC0' => 'Description of my item', //description of the forst product
'L_PAYMENTREQUEST_0_AMT0' => '0.01', //amount first product
'L_PAYMENTREQUEST_0_QTY0' => '1', //qty first product
'L_PAYMENTREQUEST_0_NAME1' => 'Test ', // title of the second product
'L_PAYMENTREQUEST_0_DESC1' => 'Description item',//description of the second product
'L_PAYMENTREQUEST_0_AMT1' => '0.01',//amount second product
'L_PAYMENTREQUEST_0_QTY1' => '1'//qty second product
);
$orderParams = array(
'PAYMENTREQUEST_0_PAYMENTACTION'=>'Sale', //becouse we want to sale something
'PAYMENTREQUEST_0_AMT' => '0.02', //total amount (items amount+shipping..etc)
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', //curency code
'PAYMENTREQUEST_0_ITEMAMT' => '0.02', //total amount items, without shipping and other taxes
'PAYMENTREQUEST_0_SHIPPINGAMT' => '0' //the shipping amount, will be 0 coz we sell digital products
);
Above you can see an example for two products.
These keys and values will be send to express checkout api in order to deliver the token.
The vars will be sent with GET.

Restricting a category for a certain country in Prestashop 1.5

I need to restrict a category to a set of countries in Prestashop 1.5.
This restriction would prevent the shipping of a product belonging to such a category; as such, the users would still be able to see the products but they would not be able to buy them.
Ideally, I wanted to develop a module that would insert a list of countries (checkbox style, as in the Modules -> Payment page (AdminPayment)) inside a category's edit page, but I haven't been able to do so.
Why can't i simply paste the following code inside the renderForm() function?
Only the description is visible if i do so...
array(
'items' =>Country::getCountries(Context::getContext()->language->id),
'title' => $this->l('Country restrictions'),
'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want to block the shipping.'),
'name_id' => 'country',
'identifier' => 'id_country',
'icon' => 'world',
),
EDIT:
I managed to get the list of countries working:
array(
'type' => 'checkbox',
'label' => $this->l('Restricted Countries').':',
'class' => 'sel_country',
'name' => 'restricted_countries',
'values' => array(
'query' => Country::getCountries(Context::getContext()->language->id),
'id' => 'id_country',
'name' => 'name'
),
'desc' => $this->l('Mark all the countries you want to block the selling to. The restrictions will always be applied to every subcategory as well')
),
Now, I can save these values by checking if the value "submitAddcategory" is being submitted in the postProcess function and by running an insert query there. Similarly, I can also load the IDs of the blocked countries from the database, but how can I tick the respective select boxes in the list of countries?
My initial "quick and dirty" idea was to use jQuery selectors inside a document.ready(), but the code gets inserted before everything else and, as such, it won't work because jQuery isn't even loaded yet.
How can this be done?
Cheers
I solved it by using the following code right before the end of the renderForm() function.
The Pièce de résistance was $this->fields_value, as sadly I didn't known of its existence.
public function getRestrictedCountries($obj)
{
// Loading blacklisted countries
$country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT id_country
FROM `'._DB_PREFIX_.'category_country_restriction`
WHERE id_category = ' . (int)Tools::getValue('id_category') . ';');
$blacklisted_countries = array();
if (is_array($country))
foreach ($country as $cnt)
$blacklisted_countries[] = $cnt['id_country'];
// Global country list
$c_todos = Country::getCountries(Context::getContext()->language->id);
// Crossmatching everything
foreach ($c_todos as $c)
$this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries)));
}
PS: The table I am reading from is basically an associative table between 'category' and 'country'