/** * like test_REG_final_price_matches_total_of_filtering_line_item_tree, * but makes sure the tickets have sub-prices, because that has shown to have some * bugs with calculations so far */ function test_REG_final_price_matches_total_of_filtering_line_item_tree__with_sub_line_items() { $transaction = $this->new_typical_transaction(array('ticket_types' => 2, 'fixed_ticket_price_modifiers' => 2)); //add another ticket purchase for one of the same events $event1 = EEM_Event::instance()->get_one(array(array('Registration.TXN_ID' => $transaction->ID()))); $event_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'OBJ_type' => 'Event', 'OBJ_ID' => $event1->ID()))); $discount = $this->new_model_obj_with_dependencies('Line_Item', array('LIN_type' => EEM_Line_Item::type_line_item, 'LIN_name' => 'event discount', 'LIN_total' => -8, 'LIN_unit_price' => -8, 'LIN_percent' => 0, 'LIN_quantity' => 1, 'LIN_parent' => $event_line_item->ID(), 'LIN_percent' => null, 'LIN_order' => count($event_line_item->children()))); $transaction->total_line_item()->recalculate_pre_tax_total(); //and add an unrelated purchase EEH_Line_Item::add_unrelated_item($transaction->total_line_item(), 'Transaction-Wide Discount', -5); $totals = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item()); // honestly the easiest way to confirm the total was right is to visualize the tree // var_dump( $totals ); // EEH_Line_Item::visualize( $transaction->total_line_item() ); //for each registration on the tranasction, verify the REG_final_price //indicated by EEH_Line_Item::calculate_reg_final_prices_per_line_item matches //what the line item filters would have returned EEH_Autoloader::register_line_item_filter_autoloaders(); foreach ($transaction->registrations() as $registration) { $ticket_line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); $reg_final_price_from_line_item_helper = $totals[$ticket_line_item->ID()]; //now get the line item filter's final price $filters = new EE_Line_Item_Filter_Collection(); $filters->add(new EE_Single_Registration_Line_Item_Filter($registration)); $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, $transaction->total_line_item()); $filtered_line_item_tree = $line_item_filter_processor->process(); $reg_final_price_from_line_item_filter = $filtered_line_item_tree->total(); $this->assertLessThan(0.2, abs($reg_final_price_from_line_item_filter - $reg_final_price_from_line_item_helper)); } }
/** * @group current */ public function test_set_redirection_info__with_paypal_taxes_and_shipping() { //make sure paypal gateway is included $ppm = $this->new_model_obj_with_dependencies('Payment_Method', array('PMD_type' => 'Paypal_Standard')); $ppg = $ppm->type_obj()->get_gateway(); $ppg->set_settings(array('paypal_id' => $this->_paypal_id, 'paypal_taxes' => TRUE, 'paypal_shipping' => TRUE)); $t = $this->new_typical_transaction(array('ticket_types' => 2, 'taxable_tickets' => 1)); $original_txn_total = $t->total(); //pretend we previous used paypal to make a payment. EEH_Line_Item::add_unrelated_item($t->total_line_item(), 'Shipping', 8, 'some shipping', 1, false, 'paypal_shipping_' . $t->ID()); EEH_Line_Item::set_total_tax_to($t->total_line_item(), 4, 'paypal taxes', 'paypal did thi', 'paypal_tax', false); $t->total_line_item()->save_this_and_descendants_to_txn($t->ID()); $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); $registration_processor->update_registration_final_prices($t); $p = $this->new_model_obj_with_dependencies('Payment', array('TXN_ID' => $t->ID(), 'PMD_ID' => $ppm->ID(), 'PAY_amount' => $t->total())); $this->assertEmpty($p->redirect_url()); //set redirection info; we should ignore previously-added paypal tax and shipping //(so paypal can add calculate them again when we send them) $p = $ppg->set_redirection_info($p, NULL, self::return_url, self::notify_url, self::cancel_url); $this->assertNotEmpty($p->redirect_url()); $this->assertEquals(self::paypal_url, $p->redirect_url()); $this->assertNotEmpty($p->redirect_args()); $rargs = $p->redirect_args(); $items_purchased = $t->items_purchased(); $first_item = array_shift($items_purchased); $second_item = array_shift($items_purchased); $this->assertEquals(sprintf('%s for %s', $first_item->ticket()->name(), $first_item->ticket_event_name()), $rargs['item_name_1']); $this->assertEquals($first_item->ticket()->price(), $rargs['amount_1']); $this->assertEquals(sprintf('%s for %s', $second_item->ticket()->name(), $second_item->ticket_event_name()), $rargs['item_name_2']); $this->assertEquals($second_item->ticket()->price(), $rargs['amount_2']); $this->assertEquals(1, $rargs['quantity_1']); //we shouldn't have told paypal how much tax to add. Let paypal decide. $this->assertFalse(isset($rargs['tax_cart'])); //there should be no 3rd item for shipping $this->assertFalse(isset($rargs['amount_3'])); }
/** * @group current * @group 4710 */ function test_set_line_items_taxable() { $t = $this->new_typical_transaction(array('taxable_tickets' => 0)); EEH_Line_Item::add_unrelated_item($t->total_line_item(), 'Excempt Line Item', 1, 'Description', 1, false, 'exemptme'); $reg_line_items = EEH_Line_Item::get_descendants_of_type($t->total_line_item(), EEM_Line_Item::type_line_item); foreach ($reg_line_items as $line_item) { $this->assertFalse($line_item->is_taxable(), print_r($line_item->model_field_array(), true)); } EEH_Line_Item::set_line_items_taxable($t->total_line_item(), true, 'exemptme'); foreach ($reg_line_items as $line_item) { if ($line_item->code() == 'exemptme') { $this->assertFalse($line_item->is_taxable(), print_r($line_item->model_field_array(), true)); } else { $this->assertTrue($line_item->is_taxable(), print_r($line_item->model_field_array(), true)); } } }
/** * @group 8193 */ public function test_calculate_reg_final_prices_per_line_item__3_taxable_tickets_with_an_event_wide_discount() { $transaction = $this->new_typical_transaction(array('ticket_types' => 2)); //add another ticket purchase for one of the same events $event1 = EEM_Event::instance()->get_one(array(array('Registration.TXN_ID' => $transaction->ID()))); $event_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'OBJ_type' => 'Event', 'OBJ_ID' => $event1->ID()))); $discount = $this->new_model_obj_with_dependencies('Line_Item', array('LIN_type' => EEM_Line_Item::type_line_item, 'LIN_name' => 'event discount', 'LIN_total' => -8, 'LIN_unit_price' => -8, 'LIN_percent' => 0, 'LIN_quantity' => 1, 'LIN_parent' => $event_line_item->ID(), 'LIN_percent' => null, 'LIN_order' => count($event_line_item->children()))); $transaction->total_line_item()->recalculate_pre_tax_total(); //and add an unrelated purchase EEH_Line_Item::add_unrelated_item($transaction->total_line_item(), 'Transaction-Wide Discount', -5); $totals = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item()); // honestly the easiest way to confirm the total was right is to visualize the tree // var_dump( $totals ); // EEH_Line_Item::visualize( $transaction->total_line_item() ); //verify that if we added the REG_final_prices onto the regs as derived from $totals, //that it would equal the grand total $sum_of_regs_final_prices = 0; foreach ($transaction->registrations() as $reg) { $ticket_line_item = EEM_Line_Item::instance()->get_line_item_for_registration($reg); $sum_of_regs_final_prices += $totals[$ticket_line_item->ID()]; } $this->assertEquals($totals['total'], $sum_of_regs_final_prices); //ok now let's verify the 'REG_final_price' for each ticket's line item is what we expect it to be //so there should be 3 ticket line items right? $ticket_line_items = EEM_Line_Item::instance()->get_all(array(array('TXN_ID' => $transaction->ID(), 'OBJ_type' => 'Ticket'))); //one ticket should be 10 pre-tax $ten_dollar_ticket = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'LIN_unit_price' => 10, 'LIN_type' => EEM_Line_Item::type_line_item))); $this->assertEquals(3.05, round($totals[$ten_dollar_ticket->ID()], 2)); //one ticket should be 20 pre-tax $twenty_dollar_ticket = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'LIN_unit_price' => 20, 'LIN_type' => EEM_Line_Item::type_line_item))); $this->assertEquals(18.45, round($totals[$twenty_dollar_ticket->ID()], 2)); }