group InvoicePayment;

invoicePaymentFields(prefix) ::= <<
  <prefix>id,
  <prefix>invoice_id,
  <prefix>payment_attempt_id,
  <prefix>payment_attempt_date,
  <prefix>amount,
  <prefix>currency,
  <prefix>created_by,
  <prefix>created_date
>>

create() ::= <<
  INSERT INTO invoice_payments(<invoicePaymentFields()>)
  VALUES(:id, :invoiceId, :paymentAttemptId, :paymentAttemptDate, :amount, :currency, :userName, :createdDate);
>>

batchCreateFromTransaction() ::= <<
  INSERT INTO invoice_payments(<invoicePaymentFields()>)
  VALUES(:id, :invoiceId, :paymentAttemptId, :paymentAttemptDate, :amount, :currency, :userName, :createdDate);
>>

getByPaymentAttemptId() ::= <<
  SELECT <invoicePaymentFields()>
  FROM invoice_payments
  WHERE payment_id = :paymentAttemptId;
>>

get() ::= <<
  SELECT <invoicePaymentFields()>
  FROM invoice_payments;
>>

getPaymentsForInvoice() ::= <<
  SELECT <invoicePaymentFields()>
  FROM invoice_payments
  WHERE invoice_id = :invoiceId;
>>

notifyOfPaymentAttempt() ::= <<
  INSERT INTO invoice_payments(<invoicePaymentFields()>)
  VALUES(:id, :invoiceId, :paymentAttemptId, :paymentAttemptDate, :amount, :currency, :userName, :createdDate);
>>

getInvoicePayment() ::= <<
    SELECT <invoicePaymentFields()>
    FROM invoice_payments
    WHERE payment_id = :payment_id;
>>

test() ::= <<
  SELECT 1 FROM invoice_payments;
>>
;