potelo / multi-payment
提供控制多个网关支付接口
v2.1.0
2024-09-12 15:45 UTC
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.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-09-12 17:56:49 UTC
README
MultiPayment 允许管理多个支付网关的支付。目前支持 Iugu。
要求
- PHP 7.4+
- Laravel 8.0+
安装
使用 composer 安装此包
composer require potelo/multi-payment "dev-main"
配置
安装包后,运行以下命令以在 Laravel 项目中发布配置
php artisan vendor:publish --provider="Potelo\MultiPayment\Providers\MultiPaymentServiceProvider"
请检查 config/
目录中是否创建了 multi-payment.php
文件。
现在在 .env 文件中配置环境变量
APP_ENV=local MULTIPAYMENT_DEFAULT=iugu #iugu IUGU_ID= IUGU_APIKEY=
可选地,您可以配置 Trait,以便于与用户一起使用 charge
方法。
use Potelo\MultiPayment\MultiPaymentTrait; class User extends Authenticatable { use MultiPaymentTrait; }
使用 Trait
$usuario = User::find(1); $usuario->charge($options, 'iugu', 10000);
也可以使用 Facade
\Potelo\MultiPayment\Facades\MultiPayment::charge($options);
使用
MultiPayment
使用 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');
InvoceBuilder
$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();
查看 src/MultiPayment/Builders/InvoiceBuilder.php
以了解可用的方法。
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();
查看 src/MultiPayment/Builders/CustomerBuilder.php
以了解可用的方法。
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);
模型
Customer
$customer = new Customer(); $customer->name = 'Teste'; $customer->email = 'teste@email.com'; $customer->taxDocument = '12345678901'; $customer->save('iugu'); echo $customer->id; // 7D96C7C932F2427CAF54F042345A13C60CD7
Invoce
$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