tiloweb/matpe-bundle

There is no license information available for the latest version (dev-master) of this package.

Add automated API integration as a Symfony Service

Installs: 5 127

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 3

Forks: 1

Open Issues: 1

Type:symfony-bundle

dev-master 2018-02-16 13:06 UTC

This package is auto-updated.

Last update: 2024-04-16 01:19:12 UTC


README

This Bundle integrate the MaTPE API v1 as a Symfony Service.

Requirments

  • cURL
  • Symfony >= 3.1

Intallation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require tiloweb/matpe-bundle "dev-master"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Tiloweb\MaTPEBundle\MaTPEBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure Symfony

# app/config/config.yml

ma_tpe:
    login: "yourLoginAPI"
    key: "yourAPIkey"
    firm: "yourFirmID"

Step 4: Enjoy !

The API is now reachable from the matpe service in your Controller or anywhere in Symfony.

Documentation

List all the customers

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->listCustomers());
}

Create a customer

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->createCustomer(array(
        'last_name' => 'Doe', // Required
        'first_name' => 'John', // Required
        'email' => 'fakemail@test.com',
        'country' => 'fr' // Required
    )));
}

Get a customer

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->getCustomer(13423);
}

Update a customer

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->updateCustomer(13423, array(
        'name' => 'New name',
        'email' => 'anotheremail@test.com'
    )));
}

List all the invoices

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->listInvoices());
}

List all the invoices of a customer

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->listInvoices(12345));
}

Create an invoice

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    $customerId = 12345;
    $datetime = new \DateTime();
    
    $invoice = array(
        'kind' => 'income', // Required 
        'issue_date' => $datetime->format('Y-m-d') // Required
    );
    
    $items = array(
        array(
            'concept' => 'Product 1',
            'unitary_amount' => "10",
            'quantity' => 30,
            'vat_percent' => 20,
            'retention_percent' => 0
        ),
        array(
            'concept' => 'Product 2',
            'unitary_amount' => "5",
            'quantity' => 10,
            'vat_percent' => 20,
            'retention_percent' => 0
        )
    );
    
    dump($matpe->createInvoice($customerId, $invoice, $items));
}

Get an invoice

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    dump($matpe->getInvoice(13423);
}

Update an invoice

<?php
// src/AppBundle/Controller/DefaultController.php

public function MaTPEAction() {
    $matpe = $this->get("matpe");
    
    $datetime = new DateTime();
    
    dump($matpe->updateInvoice(13423, array(
        'paid_at' => $datetime->format('Y-m-d')
    )));
}