PHP code example of zabaala / moip

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

    

zabaala / moip example snippets


    'providers' => [
        ...
        Zabaala\Moip\MoipServiceProvider::class,
        ...
    ],

    'aliases' => [
        ...
        'Moip' => Zabaala\Moip\MoipFacade::class,
        ...
    ],

php artisan vendor:publish --tag=moip

$moip  = Moip::plans()->all();

$moip  = Moip::plans()->find($code);

$plans = Moip::plans();
$plans->setCode('PLAN-123-7789');
$plans->setName("PLANO 01");
$plans->setDescription("Plano básico de assinatura");
$plans->setAmount("3000"); // Corresponde à R$ 30,00
$plans->setInterval('MONTH', 1); // Recorrência da cobrança
$plans->setPaymentMethod(\Zabaala\Moip\Resource\Payment::METHOD_CREDIT_CARD);

try {
    $plans->create();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$plans = Moip::plans();
$plans->setCode('PLAN-UNIQ-CODE');
$plans->setName("PLANO 01");
$plans->setDescription("Plano básico de assinatura");
$plans->setAmount("3000"); // Corresponde à R$ 30,00
$plans->setInterval('MONTH', 1); // Recorrência da cobrança
$plans->setPaymentMethod(\Zabaala\Moip\Resource\Payment::METHOD_CREDIT_CARD);

try {
    $plans->update();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$moip  = Moip::plans();
$plans->setCode('PLAN-UNIQ-CODE');

try {
    $plans->activate();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$plans  = Moip::plans();
$plans->setCode('PLAN-UNIQ-CODE');

try {
    $plans->inactivate();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$coupons = Moip::coupons()->all();

$coupons = Moip::coupons();
$coupons->setCode('ABCD-1234');
$coupons->setName('Coupon de teste de integração');
$coupons->setDescription('Utilizado para testar a integração com o Moip');
$coupons->setDiscount('20', 'percent');
$coupons->setStatus('active');
$coupons->setDuration('once'); // once|repeating|forever
$coupons->setMaxRedemptions('100');
$coupons->setExpirationDate('31', '12', '2016');

try {
    $coupons->create();
} catch (\Exception $e) {
    throw new \Exception($e);
}

$coupons = Moip::coupons();
$coupons->setCode('ABCD-1234');
$coupons->activate();

$coupons = Moip::coupons();
$coupons->setCode('ABCD-1234');
$coupons->inactivate();

$subscriber  = Moip::subscribers();
$subscriber->all();

$moip  = Moip::subscribers();
$subscriber->get('CLIENT-CODE');

$subscriber  = Moip::subscribers();
$subscriber->setCode('CLIENT-CODE');
$subscriber->setEmail('[email protected]');
$subscriber->setFullName("FULANO DE TAL");
$subscriber->setCpf("00000000000"); // Sem mascara.
$subscriber->setPhone(/* code area */ '11', /* phone number */ '999999999'); // Sem mascara.
$subscriber->setBirthDate(/* Day */ '31', /* Month */ '12', /* Year */ '1990');
$subscriber->setAddress(
    'AVENIDA CORONEL LINHARES', // street.
    '4565',                     // number.
    'AP 304',                   // complement. Can be null.
    'CENTRO',                   // District.
    'SAO PAULO',                // City.
    'SP',                       // State.
    '01000000'                  // Zipcode.
);

try {
    $subscriber->create();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$subscriber  = Moip::subscribers();
$subscriber->setCode('CLIENT-CODE');
$subscriber->setEmail('[email protected]');
$subscriber->setFullName("FULANO DE TAL");
$subscriber->setCpf("00000000000"); // Sem mascara.
$subscriber->setPhone(/* code area */ '11', /* phone number */ '999999999'); // Sem mascara.
$subscriber->setBirthDate(/* Day */ '31', /* Month */ '12', /* Year */ '1990');
$subscriber->setAddress(
    'AVENIDA CORONEL LINHARES', // street.
    '4565',                     // number.
    'AP 304',                   // complement. Can be null.
    'CENTRO',                   // District.
    'SAO PAULO',                // City.
    'SP',                       // State.
    '01000000'                  // Zipcode.
);

try {
    $subscriber->update();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$billingInfo  = Moip::billingInfos();
$billingInfo->setSubscriberCode('CLIENT-CODE');
$billingInfo->setCreditCard(
    '0000000000000000', // credit card number.
    '08',               // expiration day.
    '20',               // expiration year with two digits.
    'FULANO C DE TAL'   // holder name.
);

try {
    $billingInfo->update();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$subscription  = Moip::subscriptions();
$subscription->get('SUBSCRIPTION-CODE');

$moip  = Moip::subscriptions();
$subscription->get('SUBSCRIPTION-CODE');

$subscription  = Moip::subscriptions();
$subscription->setCode(uniqid());
$subscription->setAmount('3000');
$subscription->setPaymentMethod(\MoipAssinaturas\Resource\Payment::METHOD_CREDIT_CARD);
$subscription->setPlanCode('PLAN-CODE');
$subscription->setSubscriberCode('02');

try {
    $subscription->create();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$subscription  = Moip::subscriptions();
$subscription->setCode('SUBSCRIPTION-CODE');
$subscription->setPlanCode('PLAN-CODE');
$subscription->setNextInvoiceDate(/* day */ '05', /* month */ '03', /* year with 4 digits */ '2016');

try {
    $subscription->update();
} catch (RuntimeException $e) {
    echo $e->getMessage();
}

$invoice = Moip::invoices();
$invoice->setSubscriptionCode('SUBSCRIPTION-CODE');
$invoice->all();

$invoice = Moip::invoices();
$invoice->get('INVOICE-CODE');

$payments = Moip::payments();
$payments->setInvoiceCode('INVOICE-CODE');
$payments->all();

$payments = Moip::payments();
$payments->get('PAYMENT-ID');