/** * Empty string prefix if current locale is the primary * @param $locale * @return string */ public static function localePrefix($locale = '') { if (!$locale) { $locale = App::getLocale(); } return $locale == ClientHelper::getClientInfo()->primary_language->language_code ? '' : $locale . '.'; }
/** * Bootstrap the application services. * * @return void */ public function boot() { $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'vendirun'); // use artisan vendor:publish to copy views to standard view folder // commented out since generally we don't want to publish all the views /*$this->publishes([ __DIR__.'/../../resources/views' => base_path('resources/views/vendor/vendirun'), ]);*/ // use artisan vendor:publish to copy config $this->publishes([__DIR__ . '/../../config/vendirun.php' => config_path('vendirun.php')]); // use artisan vendor:publish to copy public assets // use artisan vendor:publish --tag=public --force to force overwrite of assets tagged as "public" $this->publishes([__DIR__ . '/../../public' => public_path('vendor/vendirun')], 'public'); // this publishes the error views $this->publishes([__DIR__ . '/../../resources/views/errors' => base_path('resources/views/errors')], 'public'); // include my package custom routes include __DIR__ . '/../../routes.php'; // load translation files $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'vendirun'); $clientInfo = ClientHelper::getClientInfo(); if ($clientInfo->business_settings->tax->price_includes_tax) { $this->app->bind(CartValuesTransformer::class, CartValuesVATIncludedTransformer::class); $this->app->bind(CartItemValuesTransformer::class, CartItemValuesVATIncludedTransformer::class); } else { $this->app->bind(CartValuesTransformer::class, CartValuesVATExcludedTransformer::class); $this->app->bind(CartItemValuesTransformer::class, CartItemValuesVATExcludedTransformer::class); } $this->app->bind(CartRepository::class, function () { $clientInfo = ClientHelper::getClientInfo(); $transformer = $clientInfo->business_settings->tax->price_includes_tax ? new CartValuesVATExcludedTransformer() : new CartValuesVATIncludedTransformer(); return new ApiCartRepository($transformer); }); }
public function __construct() { if ($this->primaryPages) { $this->setPrimaryPath(); } // set public client information to the config so we have access to it everywhere $clientInfo = ClientHelper::getClientInfo(); Config::set('clientInfo', $clientInfo); }
/** * @throws CardDeclinedException * @throws UnknownErrorException */ public function takePayment() { $settings = ClientHelper::getPaymentGatewayInfo('stripe'); $clientInfo = ClientHelper::getClientInfo(); Stripe::setApiKey($settings->sandbox_mode ? $settings->test_secret : $settings->secret); // Create the charge on Stripe's servers - this will charge the user's card try { $charge = Charge::create(array("amount" => $this->order->getTotalPrice(), "currency" => $clientInfo->currency->currency_iso, "source" => $this->stripeToken, "description" => $clientInfo->name, "metadata" => ["order_id" => $this->order->getId()])); $payment = new Payment($this->order->getTotalPrice(), date("Y-m-d"), 'stripe', $charge->getLastResponse()->body); $this->order->addPayment($payment); $this->orderRepository->save($this->order); } catch (Card $e) { throw new CardDeclinedException(); } catch (\Exception $e) { dd($e); throw new UnknownErrorException($e->getMessage()); } }
/** * @return Transaction */ private function buildTransaction() { $clientInfo = ClientHelper::getClientInfo(); $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax; $paypalItems = []; $subTotal = 0; foreach ($this->order->getItems() as $item) { /* @var $item OrderItem */ // don't add shipping row if ($item->isShipping()) { continue; } $subTotal += $item->getPrice(); $newItem = new Item(); $newItem->setName($item->getProductName())->setCurrency($clientInfo->currency->currency_iso)->setQuantity($item->getQuantity())->setSku($item->getProductSku())->setPrice($item->getPrice() / 100); $paypalItems[] = $newItem; } $shippingBeforeTax = $this->order->getShipping() / 100; $tax = $this->order->getTax() / 100; $subTotal = $subTotal / 100; $total = $this->order->getTotalPrice() / 100; $orderShippingAddress = $this->order->getShippingAddress()->getArray(); $shippingAddress = new ShippingAddress(); $shippingAddress->setCity($orderShippingAddress['city']); $shippingAddress->setCountryCode(CountryHelper::getCountryCode($orderShippingAddress['countryId'])); $shippingAddress->setPostalCode($orderShippingAddress['postcode']); $shippingAddress->setLine1($orderShippingAddress['address1']); $shippingAddress->setState($orderShippingAddress['state']); $shippingAddress->setRecipientName($this->order->getCustomer()->fullName()); $itemList = new ItemList(); if (!$priceIncludesTax) { $itemList->setItems($paypalItems); } $itemList->setShippingAddress($shippingAddress); $details = new Details(); $details->setShipping($shippingBeforeTax)->setTax($tax)->setSubtotal($subTotal); $amount = new Amount(); $amount->setCurrency($clientInfo->currency->currency_iso)->setTotal($total)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Order from " . $clientInfo->name)->setInvoiceNumber($this->order->getId()); return $transaction; }