potelo / multi-payment
Fornece uma interface para controlar pagamentos de múltiplos gateways
Installs: 5 446
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 3
Open Issues: 1
Requires
- php: >=7.4.0
- illuminate/config: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
- iugu/iugu: dev-master
- nesbot/carbon: 2.65.*
Requires (Dev)
- orchestra/testbench: ~7.0
- phpunit/phpunit: ^9.5
- dev-main
- v2.1.1
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.4.0
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-charge-with-credit-card
- dev-ultimos-digitos-sandbox
- dev-search-card
- dev-fix-credit-card-data
- dev-fix-pix-info
- dev-revert-v1.1.1
- dev-gateway-options
- dev-iugu-due-at
- dev-iugu-expires_in
- dev-order-id
- dev-fix-fatura-duplicada
- dev-custom-variable
- dev-cpfcnpj-valid
- dev-remove-moip
- dev-charge-exception
- dev-reset-v1.1.0
- dev-gabrielpeixoto-patch-1
- dev-create-many
This package is auto-updated.
Last update: 2024-11-14 23:12:07 UTC
README
MultiPayment permite gerenciar pagamentos de diversos gateways de pagamento. Atualmente suporta o Iugu.
Requisitos
- PHP 7.4+
- Laravel 8.0+
Instalação
Instale esse pacote pelo composer:
composer require potelo/multi-payment "dev-main"
Configuração
Após instalar o pacote rode o comando abaixo para publicar as configurações no projeto Laravel
php artisan vendor:publish --provider="Potelo\MultiPayment\Providers\MultiPaymentServiceProvider"
Verifique se o arquivo multi-payment.php
foi criado no diretório config/
.
Agora configure as variáveis de ambiente no arquivo .env:
APP_ENV=local MULTIPAYMENT_DEFAULT=iugu #iugu IUGU_ID= IUGU_APIKEY=
Opcionalmente você pode configurar o Trait, para facilitar o uso do método charge
junto a um usuário.
use Potelo\MultiPayment\MultiPaymentTrait; class User extends Authenticatable { use MultiPaymentTrait; }
Usando o Trait:
$usuario = User::find(1); $usuario->charge($options, 'iugu', 10000);
Também é possível utilizar o Facade:
\Potelo\MultiPayment\Facades\MultiPayment::charge($options);
Utilizando
MultiPayment:
Usando a classe MultiPayment
:
$payment = new \Potelo\MultiPayment\MultiPayment(); // gateway default será usado // ou $payment = new \Potelo\MultiPayment\MultiPayment('iugu'); // ou $payment = new \Potelo\MultiPayment\MultiPayment(); $payment->setGateway('iugu');
InvoiceBuilder
$multiPayment = new \Potelo\MultiPayment\MultiPayment('iugu'); $invoiceBuilder = $multiPayment->newInvoice(); $invoice = $invoiceBuilder->setPaymentMethod('payment_method') ->addCustomer('name', 'email', 'tax_document', 'phone_area', 'phone_number') ->addCustomerAddress('zip_code', 'street', 'number') ->addItem('description', 'quantity', 'price') ->create();
Confira src/MultiPayment/Builders/InvoiceBuilder.php
para saber quais métodos estão disponíveis.
CustomerBuilder
$multiPayment = new \Potelo\MultiPayment\MultiPayment('iugu'); $customerBuilder = $multiPayment->newCustomer(); $customer = $customerBuilder->setName('Nome') ->setEmail('email') ->setTaxDocument('01234567891') ->setPhone('999999999', '71') ->addAddress('45400000', 'Rua', 'S/N') ->create();
Confira src/MultiPayment/Builders/CustomerBuilder.php
para saber quais métodos estão disponíveis.
getInvoice
$invoiceId = '312ASDHGZXSGRTET312ASDHGZXSGRTET'; $payment = new \Potelo\MultiPayment\MultiPayment('iugu'); $foundInvoice = $payment->getInvoice($invoiceId);
charge
$options = [ 'amount' => 10000, 'customer' => [ 'name' => 'Nome do cliente', 'email' => 'email@example.com', 'tax_document' => '12345678901', 'phone_area' => '71', 'phone_number' => '999999999', 'address' => [ 'street' => 'Rua do cliente', 'number' => '123', 'complement' => 'Apto. 123', 'district' => 'Bairro do cliente', 'city' => 'Cidade do cliente', 'state' => 'SP', 'zip_code' => '12345678', ], ], 'items' => [ [ 'description' => 'Produto 1', 'quantity' => 1, 'price' => 10000, ], [ 'description' => 'Produto 2', 'quantity' => 2, 'price' => 5000, ], ], 'payment_method' => 'credit_card', 'credit_card' => [ 'number' => '1234567890123456', 'month' => '12', 'year' => '2022', 'cvv' => '123', 'first_name' => 'João', 'last_name' => 'Maria' ], ]; $payment = new \Potelo\MultiPayment\MultiPayment(); $payment->setGateway('iugu')->charge($options);
Models
Customer
$customer = new Customer(); $customer->name = 'Teste'; $customer->email = 'teste@email.com'; $customer->taxDocument = '12345678901'; $customer->save('iugu'); echo $customer->id; // 7D96C7C932F2427CAF54F042345A13C60CD7
Invoice
$invoice = new Invoice(); $invoice->customer = $customer; $item = new InvoiceItem(); $item->description = 'Teste'; $item->price = 10000; $item->quantity = 1; $invoice->items[] = $item; $invoice->paymentMethod = Invoice::PAYMENT_METHOD_CREDIT_CARD; $invoice->creditCard = new CreditCard(); $invoice->creditCard->number = '4111111111111111'; $invoice->creditCard->firstName = 'João'; $invoice->creditCard->lastName = 'Silva'; $invoice->creditCard->month = '11'; $invoice->creditCard->year = '2022'; $invoice->creditCard->cvv = '123'; $invoice->creditCard->customer = $customer; $invoice->save('iugu'); echo $invoice->id; // CB1FA9B5BD1C42B287F4AC7F6259E45D