Official PHP client for the Quipu API
PHP classes that connect to the Quipu API see documentation, (*1)
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., (*2)
$api_connection = Quipu_Api_Connection::get_instance('YOUR_APP_KEY', 'YOUR_APP_SECRET');
Pass the connection class to the numeration class, then call "create_series". The series will either be created or loaded if it already exists., (*3)
$quipu_num = new Quipu_Api_Numeration($api_connection);
$quipu_num->create_series('YOUR_PREFIX');
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), (*4)
$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., (*5)
$quipu_contact = new Quipu_Api_Contact($api_connection);
$quipu_contact->create_contact($contact);
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, (*6)
$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:, (*7)
$quipu_invoice = new Quipu_Api_Invoice($api_connection);
You can first set the Numbering Series if one exists:, (*8)
$quipu_invoice->set_numeration($quipu_num);
A contact is required or the invoice cannot be created:, (*9)
$quipu_invoice->set_contact($quipu_contact);
Once the contact is passed to the class you can create an invoice, (*10)
$quipu_invoice->create_invoice($order);
To get the internal Quipu Invoice id. Store locall to use for refunds., (*11)
$quipu_invoice->get_id()
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), (*12)
$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:, (*13)
$quipu_invoice = new Quipu_Api_Invoice($api_connection);
You can first set the Refund Numbering Series if one exists:, (*14)
$quipu_invoice->set_numeration($refund_num_series);
Call the 'refund_invoice' function to refund an invoice, (*15)
$quipu_invoice->refund_invoice($order);