PHP code example of devsitarget / sdk-vindi-php

1. Go to this page and download the library: Download devsitarget/sdk-vindi-php 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/ */

    

devsitarget / sdk-vindi-php example snippets



use VindiSdk\Environment;
use VindiSdk\Store;
use VindiSdk\Vindi;

$env = Environment::sandbox(); // ou Environment::production()
$store = new Store('PUBLIC_KEY', 'PRIVATE_KEY', $env);

// ID do produto configurado no painel Vindi
$productId = 363801;

$vindi = new Vindi($store, $productId);


use VindiSdk\Customer;
use VindiSdk\Address;
use VindiSdk\Pix\PixRequest;

$customer = new Customer(
  id: '123', name: 'Cliente', email: '[email protected]',
  document: '12345678900', phone: '11999999999',
  address: new Address('Rua A', '100', '01234-567', 'Centro', 'São Paulo', 'SP')
);

$req = new PixRequest(amount: 100.0, currency: 'BRL', customer: $customer, description: 'PIX Pedido 123');
$res = $vindi->createPixCharge($req);

// $res->qrCode contém SVG, $res->pixCopyPaste contém payload COPIA E COLA


use VindiSdk\CreditCard\CreditCard;
use VindiSdk\CreditCard\CreditCardRequest;

$card = new CreditCard(
  number: '4111111111111111', holderName: 'Cliente', expirationMonth: '12', expirationYear: '2028', securityCode: '123', brand: 'visa'
);

$ccReq = new CreditCardRequest(
  amount: 150.0,
  currency: 'BRL',
  customer: $customer,
  creditCard: $card,
  installments: 1,
  description: 'Pedido 456'
);

$ccRes = $vindi->createCreditCardPayment($ccReq);


use DateTime;
use VindiSdk\Bank\BankRequest;

$due = new DateTime('+3 days');
$bankReq = new BankRequest(
  amount: 200.0,
  currency: 'BRL',
  customer: $customer,
  description: 'Pedido 789',
  dueDate: $due,
  number: 'BOL789'
);

$bankRes = $vindi->generateBank($bankReq);
// $bankRes->digitableLine, $bankRes->barCode, $bankRes->url


$status = $vindi->checkPaymentStatus($res->tid);


$parsed = Vindi::parseSettlementWebhook($payload);
// ['tid', 'transactionId', 'paymentMethodCode', 'statusCode', 'lowDate', 'occurrenceDate']


use VindiSdk\BillAffiliate;

$affiliates = [
    new BillAffiliate(affiliateId: 2425, amount: 50.0, amountType: 2), // 50%
    new BillAffiliate(affiliateId: 3000, amount: 10.0, amountType: 1), // R$ 10,00
];

// PIX
$pixReq = new \VindiSdk\Pix\PixRequest(
    amount: 100.0,
    currency: 'BRL',
    customer: $customer,
    description: 'PIX com split',
    affiliates: $affiliates
);
$pixRes = $vindi->createPixCharge($pixReq);

// Cartão
$ccReq = new \VindiSdk\CreditCard\CreditCardRequest(
    amount: 150.0,
    currency: 'BRL',
    customer: $customer,
    creditCard: $card,
    installments: 1,
    description: 'Cartão com split',
    affiliates: $affiliates
);
$ccRes = $vindi->createCreditCardPayment($ccReq);

// Boleto
$bankReq = new \VindiSdk\Bank\BankRequest(
    amount: 200.0,
    currency: 'BRL',
    customer: $customer,
    description: 'Boleto com split',
    dueDate: new DateTime('+3 days'),
    number: 'BOL123',
    affiliates: $affiliates
);
$bankRes = $vindi->generateBank($bankReq);
bash
composer 

vindi-sdk/
├── src/
│   └── Vindi/
│       ├── Environment.php
│       ├── Store.php
│       ├── PaymentStatus.php
│       ├── VindiBaseClient.php
│       ├── Vindi.php
│       ├── Pix/
│       ├── CreditCard/
│       └── Bank/
├── tests/
│   └── Unit/
├── composer.json
├── phpunit.xml
├── env.example
└── README.md