/** * 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(); $transaction = $payment->transaction(); $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); 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; } if ($payment->status() !== $this->_pay_model->approved_status()) { $this->log(array('url' => $this->_process_response_url(), 'message' => __('We shouldn\'t update transactions taxes or shipping data from non-approved payments', 'event_espresso'), 'payment' => $payment->model_field_array()), $payment); return; } $grand_total_needs_resaving = false; //might paypal have changed the taxes? if ($this->_paypal_taxes && $payment_was_itemized) { //note that we're doing this BEFORE adding shipping; we actually want PayPal's shipping to remain non-taxable $this->_line_item->set_line_items_taxable($transaction->total_line_item(), true, 'paypal_shipping'); $this->_line_item->set_total_tax_to($transaction->total_line_item(), floatval($update_info['tax']), __('Taxes', 'event_espresso'), __('Calculated by Paypal', 'event_espresso'), 'paypal_tax'); $grand_total_needs_resaving = TRUE; } $shipping_amount = floatval($update_info['mc_shipping']); //might paypal have added shipping? if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { $this->_line_item->add_unrelated_item($transaction->total_line_item(), sprintf(__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), $shipping_amount, __('Shipping charges calculated by Paypal', 'event_espresso'), 1, false, 'paypal_shipping_' . $transaction->ID()); $grand_total_needs_resaving = true; } if ($grand_total_needs_resaving) { $transaction->total_line_item()->save_this_and_descendants_to_txn($transaction->ID()); $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); $registration_processor->update_registration_final_prices($transaction); } $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); }
/** * 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); }