<?php
namespace Maatwebsite\Excel;
use Illuminate\Support\Arr;
use Maatwebsite\Excel\Concerns\WithBackgroundColor;
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
use Maatwebsite\Excel\Concerns\WithDefaultStyles;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\WithProperties;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Factories\WriterFactory;
use Maatwebsite\Excel\Files\RemoteTemporaryFile;
use Maatwebsite\Excel\Files\TemporaryFile;
use Maatwebsite\Excel\Files\TemporaryFileFactory;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Fill;
/** @mixin Spreadsheet */
class Writer
{
use DelegatedMacroable, HasEventBus;
/**
* @var Spreadsheet
*/
protected $spreadsheet;
/**
* @var object
*/
protected $exportable;
/**
* @var TemporaryFileFactory
*/
protected $temporaryFileFactory;
/**
* @param TemporaryFileFactory $temporaryFileFactory
*/
public function __construct(TemporaryFileFactory $temporaryFileFactory)
{
$this->temporaryFileFactory = $temporaryFileFactory;
$this->setDefaultValueBinder();
}
/**
* @param object $export
* @param string $writerType
* @return TemporaryFile
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
public function export($export, string $writerType): TemporaryFile
{
$this->open($export);
$sheetExports = [$export];
if ($export instanceof WithMultipleSheets) {
$sheetExports = $export->sheets();
}
foreach ($sheetExports as $sheetExport) {
$this->addNewSheet()->export($sheetExport);
}
return $this->write($export, $this->temporaryFileFactory->makeLocal(null, strtolower($writerType)), $writerType);
}
/**
* @param object $export
* @return $this
*/
public function open($export)
{
$this->exportable = $export;
if ($export instanceof WithEvents) {
$this->registerListeners($export->registerEvents());
}
$this->exportable = $export;
$this->spreadsheet = new Spreadsheet;
$this->spreadsheet->disconnectWorksheets();
if ($export instanceof WithCustomValueBinder) {
Cell::setValueBinder($export);
}
$this->handleDocumentProperties($export);
if ($export instanceof WithBackgroundColor) {
$defaultStyle = $this->spreadsheet->getDefaultStyle();
$backgroundColor = $export->backgroundColor();
if (is_string($backgroundColor)) {
$defaultStyle->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setRGB($backgroundColor);
}
if (is_array($backgroundColor)) {
$defaultStyle->applyFromArray(['fill' => $backgroundColor]);
}
if ($backgroundColor instanceof Color) {
$defaultStyle->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor($backgroundColor);
}
}
if ($export instanceof WithDefaultStyles) {
$defaultStyle = $this->spreadsheet->getDefaultStyle();
$styles = $export->defaultStyles($defaultStyle);
if (is_array($styles)) {
$defaultStyle->applyFromArray($styles);
}
}
$this->raise(new BeforeExport($this, $this->exportable));
return $this;
}
/**
* @param TemporaryFile $tempFile
* @param string $writerType
* @return Writer
*
* @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
*/
public function reopen(TemporaryFile $tempFile, string $writerType)
{
$reader = IOFactory::createReader($writerType);
$this->spreadsheet = $reader->load($tempFile->sync()->getLocalPath());
return $this;
}
/**
* @param object $export
* @param TemporaryFile $temporaryFile
* @param string $writerType
* @return TemporaryFile
*
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
public function write($export, TemporaryFile $temporaryFile, string $writerType): TemporaryFile
{
$this->exportable = $export;
$this->spreadsheet->setActiveSheetIndex(0);
$this->raise(new BeforeWriting($this, $this->exportable));
$writer = WriterFactory::make(
$writerType,
$this->spreadsheet,
$export
);
if ($temporaryFile instanceof RemoteTemporaryFile && !$temporaryFile->existsLocally()) {
$temporaryFile = resolve(TemporaryFileFactory::class)
->makeLocal(Arr::last(explode('/', $temporaryFile->getLocalPath())));
}
$writer->save(
$temporaryFile->getLocalPath()
);
if ($temporaryFile instanceof RemoteTemporaryFile) {
$temporaryFile->updateRemote();
$temporaryFile->deleteLocalCopy();
}
$this->clearListeners();
$this->spreadsheet->disconnectWorksheets();
unset($this->spreadsheet);
return $temporaryFile;
}
/**
* @param int|null $sheetIndex
* @return Sheet
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
public function addNewSheet(int $sheetIndex = null)
{
return new Sheet($this->spreadsheet->createSheet($sheetIndex));
}
/**
* @return Spreadsheet
*/
public function getDelegate()
{
return $this->spreadsheet;
}
/**
* @return $this
*/
public function setDefaultValueBinder()
{
Cell::setValueBinder(
app(config('excel.value_binder.default', DefaultValueBinder::class))
);
return $this;
}
/**
* @param int $sheetIndex
* @return Sheet
*
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
public function getSheetByIndex(int $sheetIndex)
{
return new Sheet($this->getDelegate()->getSheet($sheetIndex));
}
/**
* @param string $concern
* @return bool
*/
public function hasConcern($concern): bool
{
return $this->exportable instanceof $concern;
}
/**
* @param object $export
*/
protected function handleDocumentProperties($export)
{
$properties = config('excel.exports.properties', []);
if ($export instanceof WithProperties) {
$properties = array_merge($properties, $export->properties());
}
if ($export instanceof WithTitle) {
$properties = array_merge($properties, ['title' => $export->title()]);
}
$props = $this->spreadsheet->getProperties();
foreach (array_filter($properties) as $property => $value) {
switch ($property) {
case 'title':
$props->setTitle($value);
break;
case 'description':
$props->setDescription($value);
break;
case 'creator':
$props->setCreator($value);
break;
case 'lastModifiedBy':
$props->setLastModifiedBy($value);
break;
case 'subject':
$props->setSubject($value);
break;
case 'keywords':
$props->setKeywords($value);
break;
case 'category':
$props->setCategory($value);
break;
case 'manager':
$props->setManager($value);
break;
case 'company':
$props->setCompany($value);
break;
}
}
}
}
The Kueue Pay Payment Gateway is an innovative technology that facilitates seamless and secure transactions between merchants and their customers. It enables businesses to accept debit and credit card payments both online and in physical stores.
The Kueue Pay Payment Gateway acts as a bridge between a merchant’s website or point-of-sale system and the payment processing network. It securely transmits payment information, authorizes transactions, and provides real-time status updates.
The Kueue Pay Developer API empowers developers and entrepreneurs to integrate the Kueue Pay Payment Gateway directly into their websites or applications. This streamlines the payment process for customers and provides businesses with a customizable and efficient payment solution.
To access the Kueue Pay Developer API, you need to sign up for a developer account on our platform. Once registered, you’ll receive an API key that you can use to authenticate your API requests.
The Kueue Pay Developer API allows you to initiate payments, check the status of payments, and process refunds. You can create a seamless payment experience for your customers while maintaining control over transaction management.
Yes, the Kueue Pay Developer API is designed to accommodate businesses of varying sizes and industries. Whether you’re a small online store or a large enterprise, our API can be tailored to fit your specific payment needs.
The Kueue Pay Developer API is designed with simplicity and ease of use in mind. Our comprehensive documentation, code samples, and developer support resources ensure a smooth integration process for any web platform.
We offer competitive pricing plans for using the Kueue Pay Payment Gateway and Developer API. Details about fees and pricing tiers can be found on our developer portal.
Absolutely, the Kueue Pay Developer API offers customization options that allow you to tailor the payment experience to match your brand and user interface. You can create a seamless and cohesive payment journey for your customers.
We provide dedicated developer support to assist you with any issues or questions you may have during the API integration process. Reach out to our support team at developersupport@NFCPay.com for prompt assistance.
Remember, our goal is to empower your business with a robust and efficient payment solution. If you have any additional questions or concerns, feel free to explore our developer portal or contact our support team.