1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Integrate Payments into API

This commit is contained in:
David Bomba 2016-01-05 23:51:27 +11:00
parent cd2599fe58
commit f66539b0da
3 changed files with 18 additions and 4 deletions

View File

@ -176,6 +176,11 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->belongsTo('App\Models\InvoiceDesign');
}
public function payments()
{
return $this->hasMany('App\Models\Payment', 'invoice_id', 'id');
}
public function recurring_invoice()
{
return $this->belongsTo('App\Models\Invoice');

View File

@ -22,6 +22,7 @@ class InvoiceTransformer extends EntityTransformer
protected $defaultIncludes = [
'invoice_items',
'payments'
];
public function includeInvoiceItems(Invoice $invoice)
@ -30,6 +31,12 @@ class InvoiceTransformer extends EntityTransformer
return $this->includeCollection($invoice->invoice_items, $transformer, ENTITY_INVOICE_ITEMS);
}
public function includePayments(Invoice $invoice)
{
$transformer = new PaymentTransformer($this->account, $this->serializer);
return $this->includeCollection($invoice->payments, $transformer, ENTITY_PAYMENT);
}
public function transform(Invoice $invoice)
{
return [

View File

@ -18,10 +18,7 @@ class PaymentTransformer extends EntityTransformer
* @SWG\Property(property="amount", type="float", example=10, readOnly=true)
* @SWG\Property(property="invoice_id", type="integer", example=1)
*/
protected $defaultIncludes = [
'invoice',
'client',
];
protected $defaultIncludes = [];
public function __construct(Account $account)
@ -50,6 +47,11 @@ class PaymentTransformer extends EntityTransformer
'account_key' => $this->account->account_key,
'user_id' => (int) $payment->user->public_id + 1,
'transaction_reference' => $payment->transaction_reference,
'payment_date' => $payment->payment_date,
'updated_at' => $this->getTimestamp($payment->updated_at),
'archived_at' => $this->getTimestamp($payment->deleted_at),
'is_deleted' => (bool) $payment->is_deleted,
'payment_type_id' => (int) $payment->payment_type_id,
];
}
}