PHP code example of lucasamauri / moip-subscriptions-php

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

    

lucasamauri / moip-subscriptions-php example snippets




use Moip\Moip;

$token = '01010101010101010101010101010101';
$key = 'ABABABABABABABABABABABABABABABABABABABAB';

$moip = new Moip($token, $key, Moip::ENDPOINT_SANDBOX);

// Create a plan
$plan = $moip->plan()
    ->setCode("P99")
    ->setName("R$99")
    ->setDescription("Plano R$99")
    ->setAmount(99.00)
    ->create();

// List Plans
$moip->plan()->getList();

// Create a subscription
$customer = $moip->customer()
        ->setCode("01")
        ->setFullname("Your Awesome Name")
        ->setTaxDocument("999.999.999-99")
        ->setEmail("[email protected]")
        ->setPhone(31, 99999999)
        ->setBirthDate("1980-06-02")
        ->addAddress("AV", "Larga", null, "Vila Cristina", "Belo Horizonte", "MG", "33333-333")
        ->setBillingInfo("Your Awesome Name", "5209 9026 0329 5762", 12, 21, 522)
        ;
try {
    $subscription = $moip->subscription()
        ->setCode("01")
        ->setCustomer($customer)
        ->setPlan("P99")
        ->setPaymentMethod("CREDIT_CARD")
        ->create();
}
catch (Exception $e) {
    var_dump($e->getMessage());
}