Creating An Invoice from an Order over the SOAP API - magento

Im running into an issue when using the soap api to talk to magento that prevents me from creating an invoice from an order. The issue is in the sales_order_invoice.create call from my tool. When i call this one of the arguments passed in that call is the product id and the quantity to invoice, formatted in a nested array. For some reason no matter how i send this data to magento, magento will create the invoice with the amount as seen on the order but it dosent add any of the products to the invoice page. Its like its completely ignoring the itemQtys array. Also i cant figure out if i can change the quantity i want to invoice.
This is the call im using:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/sales_order_invoice#sales_order_invoice.create
As an example imagine that customer places an order for some number of products but we only have a certain number on hand. I would like to invoice the number that we have on hand and ship that invoice then invoice the rest of the order at a later date. This of course needs to be done all "programmatically". Is this possible to do over the SOAP api? or in magento period?
Thanks.

if(!$order->getId()){
return;
}
try {
if(!$order->canInvoice())
{
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
}
catch (Mage_Core_Exception $e) {
}
you can have some idea from the above code.

Related

Why is my stripe invoice showing 0 as total?

I am trying to create a one time charge with a pdf invoice with Laravel Cashier for stripe.
The form submit successfuly, however, the invoice total is 0 and there is no payment in the Stripe page of payment list.
I have created one product with multiple price.
I saved the price ids in a table with the product name.
public function purchase(Request $request, SubscriptionPlan $subscriptionPlan)
{
try {
auth()->user()->createOrGetStripeCustomer();
auth()->user()->updateStripeCustomer(['address' => ['country' => 'CA'],'preferred_locales' => ['fr-CA']]);
auth()->user()->updateDefaultPaymentMethod($request->paymentMethod);
auth()->user()->invoicePrice($subscriptionPlan->stripe_price_id, 1); // Product ID from stripe
} catch (\Exception $exception) {
\Log::debug($exception->getMessage());
return back()->with('error', $exception->getMessage());
}
return back()->with('success', 'Paiement effectué avec succès!');
}
Edit:
I found that there are as many "pending invoice items" as $0 invoices.
Pending invoice items
it sound likes a subscription with a trial period, where the first invoice is $0.
Did you specify a trial_period_days or trial_end when creating this subscription? If not, you can reach out to Stripe Support and give them the subscription ID to investigate further.

Magento dmin Checkboxes Save magento categories to custom database table

I'm currently developing a custom module for Magento and theres one thing I´m not able to get working.
I have a front-end display of employees and an backend so I can add employees.
I save the employees in a regular mysql table(so not EAV). Just to add employees to the database is no problem but now I want to add a different table so that the employees can be part of more than one category. I want to display the magento categories, and that I get working, but next I want to save that value along with the id of my employee in my own table in the database. Thats the problem i'm having.
I've tried using the magento admin grid and have a tab for adding and editing. I´ve tried to add a new tab and adding checkboxes there to check and save but can get it to work
Maybe I'm completely of, if that so youre free to suggest a different approach.
add this to save action
if (isset($data['categories'])) {
$data['categories'] = explode(',', $data['categories']);
if (is_array($data['categories'])) {
$data['categories'] = array_unique($data['categories']);
}
}
and this to collection
$this->getSelect()->join(
array('category_table' => $this->getTable('qbanner/qbanner_category')), 'main_table.qbanner_id = category_table.qbanner_id', array()
)
->where('category_table.category_id = ?', $categoryId);
return $this;
hope this will help you

Retrieve original Customer object from sales_order_invoice_pay event

I'm building a small module for my Magento 1.7 installation.
My function is called when the sales_order_payment_pay event is triggered.
Basically, it looks into the customer's order to check for the presence of a specific magic product.
// Retrieve the order
$order = $observer->getPayment()->getOrder();
// Look for product ID 999, whatever that is
try {
$magic_product = $order->getItemById(999);
if ($magic_product){
// The order contains our magic product; let's find our customer object and do something with it.
//**$customer = $order->getCustomer();**
$customer->setData( "foo", "bar" );
$customer->save();
}
} catch ( Exception $e ) {
// Fail silently, I don't care...
}
I'm trying here to find a way to go up the object hierarchy to retrieve the customer (if any!) who made the order.
With getCustomerName() I could get it's name, but I can't find any way to find the object itself without resorting to some kind of hack. And I don't like hacks. Anyone can help me?
If you're trying to get the customer object that is related to the order, you have to load it and the order has the customers id:
$customerId = $order->getCustomerId();
$customer = Mage::getModel('customer/customer')->load($customerId);
// customer stuff
$event = $observer->getEvent();
$invoice = $event->getInvoice();
$order = $invoice->getOrder();
echo $order->getCustomerId();
Try using this in case you get a Null for Customer ID

Magento coupon code applied, can I update order status to "Processing"?

When a customer pays, partially or fully, by coupon code the order status is set to "Pending Payment". We use a third party order management application which only pulls in orders with the status "Processing".
Normal orders are automatically set to "Processing", so it's only when a coupon code is used that we have a problem.
Is there a way of automatically updating the order status to "Processing" when a customers applies a coupon code?
Thanks for your help
(Magento Community 1.7)
I think this is possible, but you might have to combine it with creating an invoice - since the coupon amount covers the order value and the order is technically paid. I would create an observer to catch sales_order_place_after and use it for the following:
$order = $observer->getOrder();
/**
add code to check if the coupon amount covers the order value
*/
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
$invoice->register();
$invoice->getOrder()->setIsInProcess(true);
$invoice->getOrder()->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, '', false);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$invoice->getOrder()->save();

Magento: Retrieve payment information with Authorize.net gateway

I am using Authorize.net payment gateway in my magento based shopping cart. It is Authorize Only, which means I first authorize the card, an after shipping product to customer I captures the amount.
Authorize paygate stores information like cc_exp_month, cc_exp_year inside "additional_information" field in table sales_flat_order_payment in serialize form.
Is there any method in magento to simply retrieve these values (cc_exp_month, cc_exp_year) from additional_information column?
I believe the next 2 lines will do the trick:
$ccExpMonth = $order->getPayment()->getAdditionalInformation('cc_exp_month');
$ccExpYear = $order->getPayment()->getAdditionalInformation('cc_exp_year');
Of course $order is instance of Mage_Sales_Model_Order.
For reference you also can check: how to get payment information on Magento?
Is there any method in magento to simply retrieve these values (cc_exp_month, cc_exp_year) from additional_information column?
No, there isn't. You need to drill into the additional_information array. Here's a method I added to retrieve the cc_type value. It can easily be adjusted to return all the data or just another piece:
public function getCcType(Mage_Sales_Model_Order_Payment $payment)
{
if(count($payment->getAdditionalInformation()))
{
foreach($payment->getAdditionalInformation() as $auth_cards)
{
foreach($auth_cards as $ac_id)
{
if(isset($ac_id['cc_type']))
{
return $ac_id['cc_type'];
}
}
}
}
return false;
}
Try
$order_id = 113
$order = Mage::getModel('sales/order')->load($order_id);
If info is stored cc_exp_month and cc_exp_year
$ccExpMonth = $order->getPayment()->getCcExpMonth();
$ccExpYear = $order->getPayment()->getCcExpYear();
If info is stored in Additional Info
$ccExpMonth = $order->getPayment()->getAdditionalInformation('cc_exp_month');
$ccExpYear = $order->getPayment()->getAdditionalInformation('cc_exp_year');

Resources