quipu / quipu-api
Official PHP client for the Quipu API
Requires
- php: ^5.3 || ^7.0
This package is not auto-updated.
Last update: 2024-11-04 16:12:49 UTC
README
PHP classes that connect to the Quipu API see documentation
Requirements
- PHP 5.3 or higher
- cURL
- Quipu Account
Getting Started
Create a connection
The Quipu_Api_Connection class is a singleton class and will keep the connection open for 2 hours. The connection instance must be passed to each class.
$api_connection = Quipu_Api_Connection::get_instance('YOUR_APP_KEY', 'YOUR_APP_SECRET');
Create a Numbering Series
Pass the connection class to the numeration class, then call "create_series". The series will either be created or loaded if it already exists.
$quipu_num = new Quipu_Api_Numeration($api_connection);
$quipu_num->create_series('YOUR_PREFIX');
Create a Contact
The following parameters can be passed to create a contact.
- The only required field is "name".
- If "tax_id" is passed the class will try to load the contact if they already exist in Quipu.
- "country_code" should use [ISO 3166-1 alpha-2] (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
$contact = array(
"name" => "CONTACT_NAME",
"tax_id" => "CONTACT_VAT_ID",
"phone" => "CONTACT_PHONE ",
"email" => "CONTACT_EMAIL",
"address" => "CONTACT_ADDRESS",
"town" => "CONTACT_CITY",
"zip_code" => "CONTACT_ZIP_CODE",
"country_code" => "CONTACT_CODE"
);
Pass the connection class to the contact class, then call "create_contact", with the array above. The contact will either be created or loaded if they already exist.
$quipu_contact = new Quipu_Api_Contact($api_connection);
$quipu_contact->create_contact($contact);
Create an Invoice
The following parameters can be passed to create an invoice.
- "issue_date" is required
- "items" are required. "items" is an array with at least one value, all its variables are required
- "product" is the item name
- "cost" is the value in Euros
- "quantity" must be at least 1
- "vat_per" is the VAT percentage (not value)
- The accepted values for "payment_method" are detailed in the Quipu API documentation
$order = array(
"payment_method" => "PAYMENT_METHOD",
"issue_date" => "YYYY-mm-dd",
"items" => array(
"product" => "PRODUCT_NAME",
"cost" => "PRODUCT_PRICE",
"quantity" => "PRODUCT_QUANTITY",
"vat_per" => "VAT_PERCENTAGE"
);
);
Pass the connection class to the invoice class:
$quipu_invoice = new Quipu_Api_Invoice($api_connection);
You can first set the Numbering Series if one exists:
$quipu_invoice->set_numeration($quipu_num);
A contact is required or the invoice cannot be created:
$quipu_invoice->set_contact($quipu_contact);
Once the contact is passed to the class you can create an invoice
$quipu_invoice->create_invoice($order);
To get the internal Quipu Invoice id. Store locall to use for refunds.
$quipu_invoice->get_id()
Create a Refund
The following parameters can be passed to create a refund.
- "refund_date" is required
- "invoice_id" is required. This is the Quipu invoice id returned after creating an invoice
- "items" are NOT required. If "items" are not passed then the assumption is the whole invoice is being refunded, otherwise the assumption is it is a partial refund:
- "product" is the item name
- "cost" is the value in Euros
- "quantity" must be at least 1
- "vat_per" is the VAT percentage (not value)
$order = array(
"invoice_id" => "QUIPU_INVOICE_ID",
"refund_date" => "YYYY-mm-dd",
"items" => array(
"product" => "PRODUCT_NAME",
"cost" => "PRODUCT_PRICE",
"quantity" => "PRODUCT_QUANTITY",
"vat_per" => "VAT_PERCENTAGE"
);
);
Pass the connection class to the invoice class:
$quipu_invoice = new Quipu_Api_Invoice($api_connection);
You can first set the Refund Numbering Series if one exists:
$quipu_invoice->set_numeration($refund_num_series);
Call the 'refund_invoice' function to refund an invoice
$quipu_invoice->refund_invoice($order);
Changelog
1.0
- First public release