PHP code example of tear / moip-bundle

1. Go to this page and download the library: Download tear/moip-bundle 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/ */

    

tear / moip-bundle example snippets


 // app/AppKernel.php
 public function registerBundles()
 {
     return [
         // ...            
         new LeonnLeite\MoipBundle\MoipBundle(),
         // ...
     ];
 }
 

//...
class AcmeController extends Controller
{
    public function indexAction()
    {
        try {
            $customer = $this->get('moip')
                ->customers()->setOwnId(uniqid())
                ->setFullname('Fulano de Tal')
                ->setEmail('[email protected]')
                ->setBirthDate('1988-12-30')
                ->setTaxDocument('22222222222')
                ->setPhone(11, 66778899)
                ->addAddress('BILLING',
                    'Rua de teste', 123,
                    'Bairro', 'Sao Paulo', 'SP',
                    '01234567', 8)
                ->addAddress('SHIPPING',
                          'Rua de teste do SHIPPING', 123,
                          'Bairro do SHIPPING', 'Sao Paulo', 'SP',
                          '01234567', 8)
                ->create();
            print_r($customer);
        } catch (Exception $e) {
            printf($e->__toString());
        }
//...

try {
    $order = $this->get('moip')->orders()->setOwnId(uniqid())
        ->addItem("bicicleta 1",1, "sku1", 10000)
        ->addItem("bicicleta 2",1, "sku2", 11000)
        ->addItem("bicicleta 3",1, "sku3", 12000)
        ->addItem("bicicleta 4",1, "sku4", 13000)
        ->addItem("bicicleta 5",1, "sku5", 14000)
        ->addItem("bicicleta 6",1, "sku6", 15000)
        ->addItem("bicicleta 7",1, "sku7", 16000)
        ->addItem("bicicleta 8",1, "sku8", 17000)
        ->addItem("bicicleta 9",1, "sku9", 18000)
        ->addItem("bicicleta 10",1, "sku10", 19000)
        ->setShippingAmount(3000)->setAddition(1000)->setDiscount(5000)
        ->setCustomer($customer)
        ->create();

    print_r($order);
} catch (Exception $e) {
    printf($e->__toString());
}

try {
    $payment = $order->payments()->setCreditCard(12, 21, '4073020000000002', '123', $customer)
        ->execute();

    print_r($payment);
} catch (Exception $e) {
    printf($e->__toString());
}