shieldforce / checkout-payment
This is my package checkout-payment
Fund package maintenance!
Shieldforce
Requires
- php: ^8.1
- filament/filament: ^3.0
- mercadopago/dx-php: 3.5.1
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.1
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
Este plugin implementa checkout de pagamento interno e externo para o filament!
Instalação
Instalar Via Composer:
composer require shieldforce/checkout-payment
Você precisa publicar as migrações:
php artisan checkout-payment:install
php artisan vendor:publish --tag="checkout-payment-migrations"
php artisan migrate
Caso se arrependa (CUIDADO, TENHA CERTEZA QUE OS MIGRATIONS DO CHECKOUT FORAM OS ÚLTIMOS A SEREM RODADOS):
php artisan migrate:rollback --step=6
Você precisa publicar as configurações:
php artisan vendor:publish --tag="checkout-payment-config"
Opcionalmente você pode publicar as views:
php artisan vendor:publish --tag="checkout-payment-views"
Conteúdo do arquivo de configuração ao publicar será parecido com este:
return [ 'sidebar_group' => 'Checkout Payment', 'type_gateway' => \Shieldforce\CheckoutPayment\Enums\TypeGatewayEnum::mercado_pago, ];
Usage
$checkoutPayment = new Shieldforce\CheckoutPayment(); echo $checkoutPayment->echoPhrase('Hello, Shieldforce!');
Exemplo de implementação completa:
/* * Neste exemplo você irá passar todos os dados do checkout já prontos, * com exceção do passo Pagamentos, que é de escolha exclusiva do cliente! */ // Dados que irão alimentar o checkout --- $client = $model->order->client; $partName = explode(" ", trim($client->name)); $fullPhone = $client?->contacts()?->first()?->prefix . $client?->contacts()?->first()?->number; $address = $client?->addresses()->where("main", 1)?->first(); $typePeople = isset($client->document) && strlen($client->document) > 11 ? TypePeopleEnum::J : TypePeopleEnum::F; // Criando Checkout --- $mountCheckout = new MountCheckoutStepsService( model: $model, requiredMethods: [ MethodPaymentEnum::credit_card->value, MethodPaymentEnum::pix->value, MethodPaymentEnum::billet->value, ] ); $mountCheckout->handle() // Configurando botão que finaliza o wizard --- ->configureButtonSubmit( text: "Dashboard", color: "info", urlRedirect: route("filament.admin.pages.dashboard"), ) // Cadastrando step 1 --- ->step1( items: array_map(callback: function ($product) { return (new DtoStep1( name: $product["name"], price: $product["pivot"]["price"], price_2: $product["pivot"]["price"], price_3: $product["pivot"]["price"], description: "Venda de produto: " . $product["name"], img: $product["picture"], quantity: $product["pivot"]["quantity"], ))->toArray(); }, array: $model->order->products->toArray()), visible: true, ) // Cadastrando step 2 --- ->step2( data: new DtoStep2( people_type: $typePeople, first_name: $partName[0], last_name: $partName[1] ?? "Não Informado", email: $client->email, phone_number: $fullPhone, document: $client->document, visible: true, ) ) // Cadastrando step 3 --- ->step3( data: new DtoStep3( zipcode: $address->zipcode, street: $address->street, district: $address->district, city: $address->city, state: $address->state, number: $address->number, complement: $address->complement, visible: true, ) );
Exemplo de implementação simples:
/* * Neste exemplo você irá passar somente os itens do carrinho, * e o cliente irá informar todos os passos. */ // Criando Checkout --- $mountCheckout = new MountCheckoutStepsService( model: $model, requiredMethods: [ MethodPaymentEnum::credit_card->value, MethodPaymentEnum::pix->value, MethodPaymentEnum::billet->value, ] ); $mountCheckout->handle() // Configurando botão que finaliza o wizard --- ->configureButtonSubmit( text: "Dashboard", color: "info", urlRedirect: route("filament.admin.pages.dashboard"), ) // Cadastrando step 1 --- ->step1( items: array_map(callback: function ($product) { return (new DtoStep1( name: $product["name"], price: $product["pivot"]["price"], price_2: $product["pivot"]["price"], price_3: $product["pivot"]["price"], description: "Venda de produto: " . $product["name"], img: $product["picture"], quantity: $product["pivot"]["quantity"], ))->toArray(); }, array: $model->order->products->toArray()), visible: true, );
Exemplo de implementação simples:
/* * A cada hora roda um job para atualizar os pagamentos de um checkout * no campo checkout->return_gateway. * Para os jobs do plugin acontecer você precisa ter o horizon ou os works * rodando com supervisor, ou crontab. */ // Chamada no provider --- class CheckoutPaymentServiceProvider extends ServiceProvider { public function boot(): void { $this->loadViewsFrom(__DIR__ . '/../resources/views', 'checkout-payment'); $this->app->booted(function () { $schedule = $this->app->make(Schedule::class); $schedule->job(new AllCheckoutsUpdatesPaymentsJob())->hourly(); }); } } // Chamada no Job que executa os checkouts class AllCheckoutsUpdatesPaymentsJob implements ShouldQueue { use Dispatchable, Queueable, Batchable; public MercadoPagoService $mp; public function __construct() { $this->mp = new MercadoPagoService(); } public function handle(): void { logger("AllCheckoutsUpdatesPaymentsJob" . date("Y-m-d H:i:s")); $checkouts = CppCheckout::where("status", StatusCheckoutEnum::pendente->value)->get(); foreach ($checkouts as $checkout) { ProcessCheckoutUpdatePaymentsJob::dispatch($checkout); } } } // Chamada do ‘update’ do checkout individual class ProcessCheckoutUpdatePaymentsJob implements ShouldQueue { use Dispatchable, Queueable, Batchable; public MercadoPagoService $mp; public function __construct(public CppCheckout $checkout) { $this->mp = new MercadoPagoService(); } public function handle(): void { logger("ProcessCheckoutUpdatePaymentsJob, checkout id: {$this->checkout->id} - " . date("Y-m-d H:i:s")); $payments = $this->mp->buscarPagamentoPorExternalId($this->checkout->id); $this->checkout->update([ "return_gateway" => $payments, ]); } }
Testing
composer test
Changelog
Consulte CHANGELOG para obter mais informações sobre o que mudou recentemente.
Contributing
Consulte CONTRIBUTING para obter detalhes.
Security Vulnerabilities
Revise nossa política de segurança sobre como relatar vulnerabilidades de segurança.
Credits
License
A Licença do MIT (MIT). Consulte Arquivo de Licença para obter mais informações.