/** * Return true if the order should be taxed * * @return boolean */ public function isTaxed($isShippingTaxed = null) { $s = $this->getShipping(); if (count($s)) { $taxRate = new Cart66TaxRate(); $isTaxed = $taxRate->loadByZip($s['zip']); if ($isTaxed == false) { $isTaxed = $taxRate->loadByState($s['state']); } $this->_taxRate = $taxRate; $taxShipping = $taxRate->tax_shipping; return $isShippingTaxed == null ? $isTaxed : $taxShipping; } else { throw new Exception(__('Unable to determine tax rate because shipping data is unavailable', 'cart66')); } }
// Calculate IPN URL $ipnPage = get_page_by_path('store/ipn'); $ipnUrl = get_permalink($ipnPage->ID); // Set shipping as an item if the item total is $0.00, otherwise PayPal will fail if ($itemTotal == 0 && $shipping > 0) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Setting shipping to be an item because the item total would otherwise be \$0.00"); $itemTotal = $shipping; $itemData = array('NAME' => 'Shipping', 'AMT' => $shipping, 'NUMBER' => 'SHIPPING', 'QTY' => 1); //$pp->addItem($itemData); $shipping = 0; } else { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Not making shipping part of the item list. Item Total: {$itemTotal}"); } // calculate taxes on all sales $tax = 0; $isTaxed = $taxRate->loadByState('All Sales'); if ($isTaxed) { $taxable = Cart66Session::get('Cart66Cart')->getTaxableAmount($taxRate->tax_shipping); $tax = number_format($taxable * ($taxRate->rate / 100), 2, '.', ''); if ($tax == 0) { $tax = Cart66Session::get('Cart66Cart')->getTax('All Sales'); } if ($tax > 0) { $total = $total + $tax; } } // Set payment information $payment = array('AMT' => $total, 'TAXAMT' => $tax, 'CURRENCYCODE' => CURRENCY_CODE, 'ITEMAMT' => $itemTotal, 'SHIPPINGAMT' => $shipping, 'NOTIFYURL' => $ipnUrl); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Setting Payment Details:\n" . print_r($payment, true)); $pp->setPaymentDetails($payment); // Add cart items to PayPal
public function getTax($state = 'All Sales', $zip = null) { $tax = 0; $taxRate = new Cart66TaxRate(); $isTaxed = $taxRate->loadByZip($zip); if ($isTaxed == false) { $isTaxed = $taxRate->loadByState($state); if ($state == 'All Sales' && $isTaxed) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] so i guess it's all sales? rate: " . $taxRate->rate); Cart66Session::set('Cart66TaxRate', Cart66Common::tax($taxRate->rate)); } } if ($isTaxed) { $taxable = $this->getTaxableAmount($taxRate->tax_shipping); $tax = number_format($taxable * ($taxRate->rate / 100), 2, '.', ''); } return $tax; }