PHP code example of potelo / multi-payment
1. Go to this page and download the library: Download potelo/multi-payment library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
potelo / multi-payment example snippets
use Potelo\MultiPayment\MultiPaymentTrait;
class User extends Authenticatable
{
use MultiPaymentTrait;
}
$usuario = User::find(1);
$usuario->charge($options, 'iugu', 10000);
\Potelo\MultiPayment\Facades\MultiPayment::charge($options);
$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');
$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();
$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();
$invoiceId = '312ASDHGZXSGRTET312ASDHGZXSGRTET';
$payment = new \Potelo\MultiPayment\MultiPayment('iugu');
$foundInvoice = $payment->getInvoice($invoiceId);
$options = [
'amount' => 10000,
'customer' => [
'name' => 'Nome do cliente',
'email' => '[email protected] ',
'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 = new Customer();
$customer->name = 'Teste';
$customer->email = '[email protected] ';
$customer->taxDocument = '12345678901';
$customer->save('iugu');
echo $customer->id; // 7D96C7C932F2427CAF54F042345A13C60CD7
$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
php artisan vendor:publish --provider="Potelo\MultiPayment\Providers\MultiPaymentServiceProvider"