Код: Выделить всё
require 'vendor/autoload.php';
class QuadernoService
{
private $apiKey;
private $apiUrl;
public function __construct()
{
$this->apiKey = QUADERNO_KEY;
$this->apiUrl = QUADERNO_URL;
QuadernoBase::init($this->apiKey, $this->apiUrl);
}
public function createInvoice($transactionDetails, $items = [])
{
$transaction = new QuadernoTransaction($transactionDetails);
$transaction->items = $items; // Assign items to the transaction
$transaction_data = $transaction->save();
$response = [
"invoice_number" => null,
"invoice_url" => null
];
if ($transaction_data) {
$response = [
"invoice_url" => str_replace('http://', 'https://', $transaction->pdf),
"invoice_number" => $transaction->number
];
}
return $response;
}
public function handleInvoiceCreation($transaction_data)
{
global $core;
$Customer = $core->get_row('customers', '*', "WHERE CID = " . $transaction_data['customer_id']);
$items = [
[
'description' => 'Linkingpress credits for guest posts and/or press releases',
'quantity' => 1,
'amount' => floatval($transaction_data['amount'])
]
];
$transactionDetails = [
'type' => 'sale',
'payment' => [
'method' => 'credit_card',
'processor' => $transaction_data['payment_method'],
'processor_id' => $transaction_data['transaction_id']
],
'currency' => 'USD',
'notes' => 'Description or notes here',
'company_name' => 'Your Business Name' // Company name
];
if ($Customer) {
$transactionDetails['customer'] = [
'first_name' => $Customer->firstname,
'last_name' => $Customer->lastname,
'email' => $Customer->email,
'billing_address' => [
'address1' => 'Street Name',
'city' => 'City Name',
'postal_code' => 'Postal Code',
'country' => 'Country Code'
]
];
}
// Create the invoice
$response = $this->createInvoice($transactionDetails, $items);
$transaction_data['invoice_url'] = $response['invoice_url'];
$transaction_data['invoice_number'] = $response['invoice_number'];
return $transaction_data;
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... no-invoice