public function view() { $pkg = Package::getByHandle('vivid_store'); $customer = new Customer(); $this->set('customer', $customer); $guestCheckout = Config::get('vividstore.guestCheckout'); $this->set('guestCheckout', $guestCheckout ? $guestCheckout : 'off'); $this->set('requiresLogin', VividCart::requiresLogin()); if (VividCart::getTotalItemsInCart() == 0) { $this->redirect("/cart/"); } $this->set('form', Core::make("helper/form")); $allcountries = Core::make('helper/lists/countries')->getCountries(); $db = Loader::db(); $ak = UserAttributeKey::getByHandle('billing_address'); $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID())); $defaultBillingCountry = $row['akDefaultCountry']; if ($row['akHasCustomCountries'] == 1) { $availableBillingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID())); $billingCountries = array(); foreach ($availableBillingCountries as $countrycode) { $billingCountries[$countrycode] = $allcountries[$countrycode]; } } else { $billingCountries = $allcountries; } $ak = UserAttributeKey::getByHandle('shipping_address'); $row = $db->GetRow('select akHasCustomCountries, akDefaultCountry from atAddressSettings where akID = ?', array($ak->getAttributeKeyID())); $defaultShippingCountry = $row['akDefaultCountry']; if ($row['akHasCustomCountries'] == 1) { $availableShippingCountries = $db->GetCol('select country from atAddressCustomCountries where akID = ?', array($ak->getAttributeKeyID())); $shippingCountries = array(); foreach ($availableShippingCountries as $countrycode) { $shippingCountries[$countrycode] = $allcountries[$countrycode]; } } else { $shippingCountries = $allcountries; } $this->set("billingCountries", $billingCountries); $this->set("shippingCountries", $shippingCountries); $this->set("defaultBillingCountry", $defaultBillingCountry); $this->set("defaultShippingCountry", $defaultShippingCountry); $this->set("states", Core::make('helper/lists/states_provinces')->getStates()); $totals = VividCart::getTotals(); $this->set('subtotal', $totals['subTotal']); $this->set('taxes', $totals['taxes']); $taxBased = Config::get('vividstore.taxBased'); $taxlabel = Config::get('vividstore.taxName'); $this->set('taxtotal', $totals['taxTotal']); $this->set('shippingtotal', $totals['shippingTotal']); $this->set('total', $totals['total']); $this->set('shippingEnabled', VividCart::isShippable()); $this->addHeaderItem("\n <script type=\"text/javascript\">\n var PRODUCTMODAL = '" . View::url('/productmodal') . "';\n var CARTURL = '" . View::url('/cart') . "';\n var CHECKOUTURL = '" . View::url('/checkout') . "';\n </script>\n "); $packagePath = $pkg->getRelativePath(); $this->addFooterItem(Core::make('helper/html')->javascript($packagePath . '/js/vivid-store.js', 'vivid-store')); $this->addHeaderItem(Core::make('helper/html')->css($packagePath . '/css/vivid-store.css', 'vivid-store')); $this->addFooterItem("\n <script type=\"text/javascript\">\n vividStore.loadViaHash();\n </script>\n "); $this->set("enabledPaymentMethods", PaymentMethod::getEnabledMethods()); }
public function submitPayment() { $crypt = Loader::helper('encryption'); $paypal = new \Concrete\Package\PaypalExpressVividStore\Src\VividStore\Payment\Methods\PaypalExpress\Helpers\PaypalExpressHelper(); $totals = VividCart::getTotals(); if (Config::get('vividstore.paypalExpressMode') == 'test') { $type = 'sandbox'; } else { $type = 'live'; } $invoice = Invoice::get(); $conf = ['type' => $type, 'username' => Config::get('vividstore.paypalExpressUsername'), 'password' => Config::get('vividstore.paypalExpressPassword'), 'signature' => Config::get('vividstore.paypalExpressSignature'), 'notify_url' => (string) URL::to('/paypal_express_vivid_store/notify'), 'cancel_url' => (string) URL::to('/paypal_express_vivid_store/cancel'), 'return_url' => (string) URL::to('/paypal_express_vivid_store/return'), 'cart_total' => $totals['total'], 'cart_subtotal' => $totals['subTotal'], 'cart_tax' => $totals['taxTotal'], 'cart_shipping' => $totals['shippingTotal'], 'invoice' => $crypt->encrypt($invoice), 'description' => t(SITE), 'currency_code' => Config::get('vividstore.paypalExpressCurrencyCode'), 'payment_action' => Config::get('vividstore.paypalExpressTransactionType')]; $paypal->setConfig($conf); if (isset($_GET['token']) && isset($_GET['PayerID'])) { $token = urldecode($_GET['token']); $payer_id = urldecode($_GET['PayerID']); $data_get = $paypal->getExpressCheckout($token, $payer_id); $response = $paypal->makeRequest($data_get, $type); if ($response['ACK'] == 'Success') { $data_do = $paypal->doExpressCheckout($token, $payer_id); $response = $paypal->makeRequest($data_do, $type); if ($response['ACK'] == 'Success') { return true; } } } else { $items = []; $cart = Session::get('cart'); if ($cart) { foreach ($cart as $cartItem) { $pID = $cartItem['product']['pID']; $qty = $cartItem['product']['qty']; $product = VividProduct::getByID($pID); if (is_object($product)) { $tempItem = []; $tempItem['name'] = $product->getProductName(); $tempItem['desc'] = strip_tags($product->getProductDesc()); $tempItem['price'] = $product->getFormattedPrice(); $tempItem['qty'] = $qty; $items[] = $tempItem; } } } $configData = []; $configData['items'] = $items; $configData['item_sum'] = $totals['total']; $data = $paypal->setExpressCheckout($configData); $response = $paypal->makeRequest($data, $type); if ($response['ACK'] == 'Success') { //Redirect to paypal payment page header('Location: ' . $paypal->getPaypalUrl($response['TOKEN'])); exit; } else { return ['error' => 1, 'errorMessage' => print_r($response, true)]; } } }
public function redirectForm() { $customer = new Customer(); $totals = VividCart::getTotals(); $paypalEmail = Config::get('vividstore.paypalEmail'); $order = VividOrder::getByID(Session::get('orderID')); $this->set('paypalEmail', $paypalEmail); $this->set('siteName', Config::get('concrete.site')); $this->set('customer', $customer); $this->set('total', $order->getTotal()); $this->set('notifyURL', URL::to('/checkout/paypalresponse')); $this->set('orderID', $order->getOrderID()); $this->set('returnURL', URL::to('/checkout/complete')); }
public function add($data, $pm, $status = null) { $db = Database::get(); //get who ordered it $customer = new Customer(); //what time is it? $dt = Core::make('helper/date'); $now = $dt->getLocalDateTime(); //get the price details $smID = \Session::get('smID'); if ($smID > 0) { $sm = ShippingMethod::getByID($smID); $shippingMethodTypeName = $sm->getShippingMethodType()->getShippingMethodTypeName(); $shippingMethodName = $sm->getName(); $smName = $shippingMethodTypeName . ": " . $shippingMethodName; } else { $smName = "No Shipping Method"; } $shipping = VividCart::getShippingTotal(); $taxes = Tax::getTaxes(); $totals = VividCart::getTotals(); $total = $totals['total']; $taxCalc = Config::get('vividstore.calculation'); $taxTotal = array(); $taxIncludedTotal = array(); $taxLabels = array(); foreach ($taxes as $tax) { if ($taxCalc == 'extract') { $taxIncludedTotal[] = $tax['taxamount']; } else { $taxTotal[] = $tax['taxamount']; } $taxLabels[] = $tax['name']; } $taxTotal = implode(',', $taxTotal); $taxIncludedTotal = implode(',', $taxIncludedTotal); $taxLabels = implode(',', $taxLabels); //get payment method $pmName = $pm->getPaymentMethodName(); //add the order $vals = array($customer->getUserID(), $now, $pmName, $smName, $shipping, $taxTotal, $taxIncludedTotal, $taxLabels, $total); $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmName,smName,oShippingTotal,oTax,oTaxIncluded,oTaxName,oTotal) VALUES (?,?,?,?,?,?,?,?,?)", $vals); $oID = $db->lastInsertId(); $order = Order::getByID($oID); if ($status) { $order->updateStatus($status); } else { $order->updateStatus(OrderStatus::getStartingStatus()->getHandle()); } $email = $customer->getEmail(); $billing_first_name = $customer->getValue("billing_first_name"); $billing_last_name = $customer->getValue("billing_last_name"); $billing_address = $customer->getValueArray("billing_address"); $billing_phone = $customer->getValue("billing_phone"); $shipping_first_name = $customer->getValue("shipping_first_name"); $shipping_last_name = $customer->getValue("shipping_last_name"); $shipping_address = $customer->getValueArray("shipping_address"); $order->setAttribute("email", $email); $order->setAttribute("billing_first_name", $billing_first_name); $order->setAttribute("billing_last_name", $billing_last_name); $order->setAttribute("billing_address", $billing_address); $order->setAttribute("billing_phone", $billing_phone); if ($smID) { $order->setAttribute("shipping_first_name", $shipping_first_name); $order->setAttribute("shipping_last_name", $shipping_last_name); $order->setAttribute("shipping_address", $shipping_address); } $customer->setLastOrderID($oID); //add the order items $cart = VividCart::getCart(); foreach ($cart as $cartItem) { $taxes = Tax::getTaxForProduct($cartItem); $taxProductTotal = array(); $taxProductIncludedTotal = array(); $taxProductLabels = array(); foreach ($taxes as $tax) { if ($taxCalc == 'extract') { $taxProductIncludedTotal[] = $tax['taxamount']; } else { $taxProductTotal[] = $tax['taxamount']; } $taxProductLabels[] = $tax['name']; } $taxProductTotal = implode(',', $taxProductTotal); $taxProductIncludedTotal = implode(',', $taxProductIncludedTotal); $taxProductLabels = implode(',', $taxProductLabels); OrderItem::add($cartItem, $oID, $taxProductTotal, $taxProductIncludedTotal, $taxProductLabels); } $discounts = VividCart::getDiscounts(); if ($discounts) { foreach ($discounts as $discount) { $order->addDiscount($discount, VividCart::getCode()); } } //if the payment method is not external, go ahead and complete the order. if (!$pm->external) { $order->completeOrder(); } return $order; }