magento update Total Paid after payment - magento

I have my own custom payment gateway which is working ok with one problem. When a transaction is successful the order gets updated and the email sent but the Total paid is still €0.
How do I update the paid status? I cannot find any articles on this.
Magento 1.7
public function responseAction() {
if($this->getRequest()->isPost()) {
if($payment_validated) {
// Payment was successful, so update the order's state, send order email and move to the success page
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'AIB has authorized the payment.');
$order->sendNewOrderEmail();
$order->setEmailSent(true);
$order->save();
Mage::getSingleton('checkout/session')->unsQuoteId();
Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
}

This answer might be little out of date but still someone might find it helpful.
I myself found this question and wanted an answer for this one.
So i found a very helpful article at atwix and specifically I used:
$orderId = 200000025; // you'll get your own Order Id
$model = Mage::getModel('sales/order');
$model->loadByIncrementId($orderId);
$invoice = $model->prepareInvoice();
$invoice->register();
Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder())
->save();
$invoice->sendEmail(true, '');
if($model->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)) {
$model->save();
}
So after this I got payment status to Paid in the backend and also changed the status to processing.
Now next step is to let customer know that he's order has been paid and I would like to do it via email.
Cheers!!

Related

No Transaction ID in Payment Invoice

I've developed a Payment Method extension for Magento. In this extension, I've added:
protected $_canRefund = true;
However, when I click an invoice and select Credit Memo, I can only see 'Refund Offline' and not 'Refund'. All tutorials I followed insist that I only have to change that value to true to activate the button (obviously I still have to implement the refund method and the actual refund procedure) but I can't see a way to do this.
If I, within a block on the order screen, execute this line $order->getPayment()->getMethodInstance()->canRefund(); it does indeed return true, but still no luck with the actual credit memo.
Edit
I've changed the title of the question to reflect my new find.
Basically, the reason it's not appearing is because my invoices aren't created with transaction IDs - I have no idea why, but this is my capture payment method that runs when generating an invoice:
public function capturePayment($order) {
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_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
$order->setState('processing', 'payment_received', "Payment has been received", false);
$order->save();
} catch (Mage_Core_Exception $e) {
Mage::throwException("Error Taking Payment, Please Try Again:\n" . $e);
}
}
Why isn't a transaction ID being assigned to my capture?
check below url
http://www.spinonesolutions.com/2009/10/magento-enable-paygate-refunds/
https://magento.stackexchange.com/questions/7846/capture-void-refund-not-showed-in-magento-admin-area
http://excellencemagentoblog.com/magento-create-custom-payment-method-api-based
hope this help you

Magento: catching a placed order, but the transaction id is empty

I want to catch all placed order with an observer to use the data in a further process.
In my Observer I wrote:
class Custom_CrmApi_Model_Observer extends Varien_Object {
….
public function placeOrder( $observer ){
$order = $observer->getOrder();
$payment = $order->getPayment();
$transId = $order->getPayment()->getTransactionId();
//$transId = $order->getPayment()->getLastTransId();
....
But the transaction ID of all ebay orders is empty (but not in the backend). I am using the M2E extension for ebay integration. But that shouldn’t be the problem, because the observer catch any placed order, or? At this time the transaction Id supposed to be available. But for some reason it isn’t available.
Any ideas? Perhaps a work around?
Thank you so much in advanced,
Hannes
It may be too late for you but maybe works for someone else.
I used this code to get the Transaction id for my report. It is on a different place then the normal ones for m2epro orders.
$additional_data = $order->getPayment()->getData();
//print_r($additional_data['additional_data']);
$component_mode = $additional_data['additional_data'];
additional_data in payment gives you the information about the transaction.
I am getting channel, payment, channel_order_id, channel_final_fee, transaction_id, fee, sum and transaction_date from aditional_data of the order. It is possible to get the same data from the same place on placeOrder function in m2epro.
app\code\community\Ess\M2ePro\Model\Magento\Order.php -> placeOrder
if (version_compare(Mage::helper('M2ePro/Magento')->getVersion(false), '1.4.1', '>=')) {
/** #var $service Mage_Sales_Model_Service_Quote */
$service = Mage::getModel('sales/service_quote', $this->quote);
$service->submitAll();
// You can get this order before you return it and get the data maybe!
return $service->getOrder();
}
Worths to try.
Cheers

Magento Programmatically Edit Order Payment

I need to make a change of payment method to an order after it is placed. I have the order ID ($orderID), the order object ($order), a proper payment object, etc.
$service->retrievePaymentType() Returns the payment in the form of Mage_Sales_Model_Order_Payment
All of this happens in an extension of Mage_Checkout_Model_Type_Onepage
Does anybody know how I would go about doing this?
$order = Mage::getModel('sales/order')->load($orderID);
$service = Mage::getModel('sales/service_quote', $this->getQuote());
// Update Saved Order Payment Method
// $order->getPaymentsCollection()->clear();
$order->setPayment($service->retrievePaymentType());
$order->getPaymentsCollection()->save();
$order->save();
Thanks in advance!
Unfortunately, I had to do a direct SQL query, which is not Magento spec, but it gets the job done. If someone want's the code, leave me a comment, and I will dig it up.
Thanks though!
EDIT:
I managed to in fact get this working with Magento API:
// The payment type I want to change the target order to
$service = Mage::getModel('sales/service_quote', $this->getQuote());
$payment = $service->retrievePaymentType();
$paymentData = $payment->getData();
$oldPayment = $order->getAllPayments();
$oldPayment = $oldPayment[0];
foreach ($paymentData as $n => $v) {
$oldPayment->setData($n,$v);
}
It is a little bit hackish, but pretty effective.

Setting Order Status and adding custom carriers in Magento 1.5.1.0

i am trying to create a order and assign a shipping no for that order when a order is placed. But i see that when i have an invoice created and a shipment added , magento sets the order status to 'complete' automatically. I tried to change the status manually but it wouldn work.
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
$order->save();
Could some one suggest me how to over come this?
Also, how i add a custom carrier ? The default ones are DHL, FedEx , UPS.. I want to add one similar to them. This is how i am doing it:
$carrier = "dhl";
$title = "DHL";
$trackNumber = '538099';
if (1) {
$itemsQty = $order->getItemsCollection()->count();
$shipment =Mage::getModel('sales/service_order',$order)->prepareShipment($itemsQty);
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
$shipmentId = $shipment->create($orderId);
$shipment->addTrack($shipmentId,$carrier,$title,$trackNumber);
}
For the carrier and title, if i give a custom name, i get a error invalid carrier in a report. How do i go about this? Thanks.
You could use the addStatusToHistory function. This is also used for adding comments.
$order->addStatusToHistory('processing', 'Order is being processed', false);
param 1 (string): The new status
param 2 (string): Your Comment
param 3 (boolean): If you want to send the customer an email notification.

Magento 1.4 paypal bug

i try to get the paypal payment run in my magento 1.4 but there is a serious problem with the workflow. after i select paypal and get routed to the paypal account to send the money you normally come back automatically into the magento shop to finish the order, but in my case magento tells you there is aproblem with the adress field. paypal does'nt send the adress back to magento correctly:
Error: Please check shipping address information. Please enter last name.
is this a known bug or is there a patch or workaround?
please help!
thnx.
The error seems to be in /app/code/core/Mage/Paypal/Model/Api/Nvp.php. Looks like the vars aren't mapped well. Because I couldn't find the concrete error in this file, I did a bit dirty workaround in /app/code/core/Mage/Paypal/Model/Express/Checkout.php.
In 1.4.2 just replace the method returnFromPaypal() with the following code...
public function returnFromPaypal($token)
{
$this->_getApi();
$this->_api->setToken($token)
->callGetExpressCheckoutDetails();
// import billing address
$billingAddress = $this->_quote->getBillingAddress();
$exportedBillingAddress = $this->_api->getExportedBillingAddress();
// import shipping address
$exportedShippingAddress = $this->_api->getExportedShippingAddress();
if (!$this->_quote->getIsVirtual()) {
$shippingAddress = $this->_quote->getShippingAddress();
if ($shippingAddress) {
if ($exportedShippingAddress) {
foreach ($exportedShippingAddress->getExportedKeys() as $key) {
if('firstname' == $key || 'lastname' == $key){
continue;
} // if
$shippingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key));
$billingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key));
}
// Correct First- and Lastnames
list($_firstname, $_lastname) = explode(' ', $exportedShippingAddress->getData('firstname'));
$shippingAddress->setDataUsingMethod('firstname', $_firstname);
$billingAddress->setDataUsingMethod('firstname', $_firstname);
$shippingAddress->setDataUsingMethod('lastname', $_lastname);
$billingAddress->setDataUsingMethod('lastname', $_lastname);
$shippingAddress->setCollectShippingRates(true);
}
// import shipping method
$code = '';
if ($this->_api->getShippingRateCode()) {
if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) {
// possible bug of double collecting rates :-/
$shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
}
}
$this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code);
}
}
$this->_ignoreAddressValidation();
// import payment info
$payment = $this->_quote->getPayment();
$payment->setMethod($this->_methodType);
Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment);
$payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())
->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token)
;
$this->_quote->collectTotals()->save();
}
The modified code replaces the whole billing address with the shipping address and pushes the name given in $firstname into $firstname and $lastname.
not clean, but working. :-)
any luck finding a solution to this, I'm having the same issue.
--- update ---
I finally figured out what was happening on this one for me. I had the Custom Shipping Admin module installed and it was overriding the address controller that validates the order. I updated the overrided module to reflect the version of Magento I was on and it worked.. no problems. Hope this helps someone.

Resources