/**
  * Updates the transaction and line items based on the payment IPN data from PayPal,
  * like the taxes or shipping
  * @param EEI_Payment $payment
  */
 public function update_txn_based_on_payment($payment)
 {
     $update_info = $payment->details();
     $redirect_args = $payment->redirect_args();
     $transaction = $payment->transaction();
     if (!$transaction) {
         $this->log(__('Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', 'event_espresso'), $payment);
         return;
     }
     if (!is_array($update_info) || !isset($update_info['mc_shipping']) || !isset($update_info['tax'])) {
         $this->log(array('url' => $this->_process_response_url(), 'message' => __('Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', 'event_espresso'), 'payment' => $payment->model_field_array()), $payment);
         return;
     }
     //take note of whether or not we COULD have allowed PayPal to add taxes and shipping
     //when we sent the customer to PayPal (because if we couldn't itemize the transaction, we
     //wouldn't have known what parts were taxable, meaning we would have had to tell PayPal
     //NONE of it was taxable otherwise it would re-add taxes each time a payment attempt occurred)
     //		$could_allow_paypal_to_add_taxes_and_shipping = $this->_can_easily_itemize_transaction_for( $payment );
     $grand_total_needs_resaving = FALSE;
     //might PayPal have added shipping?
     if ($this->_paypal_shipping && floatval($update_info['mc_shipping']) != 0) {
         $this->_line_item->add_unrelated_item($transaction->total_line_item(), __('Shipping', 'event_espresso'), floatval($update_info['mc_shipping']), __('Shipping charges calculated by Paypal', 'event_espresso'), 1, FALSE, 'paypal_shipping');
         $grand_total_needs_resaving = TRUE;
     }
     //might PayPal have changed the taxes?
     if ($this->_paypal_taxes && floatval($update_info['tax']) != $redirect_args['tax_cart']) {
         $this->_line_item->set_total_tax_to($transaction->total_line_item(), floatval($update_info['tax']), __('Taxes', 'event_espresso'), __('Calculated by Paypal', 'event_espresso'));
         $grand_total_needs_resaving = TRUE;
     }
     if ($grand_total_needs_resaving) {
         $transaction->total_line_item()->save_this_and_descendants_to_txn($transaction->ID());
     }
     $this->log(array('url' => $this->_process_response_url(), 'message' => __('Updated transaction related to payment', 'event_espresso'), 'transaction (updated)' => $transaction->model_field_array(), 'payment (updated)' => $payment->model_field_array(), 'use_paypal_shipping' => $this->_paypal_shipping, 'use_paypal_tax' => $this->_paypal_taxes, 'grand_total_needed_resaving' => $grand_total_needs_resaving), $payment);
 }