PaymentSqlDao.sql.stg

99 lines | 2.79 kB Blame History Raw Download
group PaymentSqlDao;

paymentAttemptFields(prefix) ::= <<
    <prefix>payment_attempt_id,
    <prefix>invoice_id,
    <prefix>account_id,
    <prefix>amount,
    <prefix>currency,
    <prefix>payment_id,
    <prefix>payment_attempt_dt,
    <prefix>invoice_dt,
    <prefix>retry_count,
    <prefix>next_retry_dt,
    <prefix>created_dt,
    <prefix>updated_dt
>>

paymentInfoFields(prefix) ::= <<
    <prefix>payment_id,
    <prefix>amount,
    <prefix>refund_amount,
    <prefix>bank_identification_number,
    <prefix>payment_number,
    <prefix>payment_type,
    <prefix>status,
    <prefix>reference_id,
    <prefix>payment_method_id,
    <prefix>payment_method,
    <prefix>card_type,
    <prefix>card_country,
    <prefix>effective_dt,
    <prefix>created_dt,
    <prefix>updated_dt
>>

insertPaymentAttempt() ::= <<
    INSERT INTO payment_attempts (<paymentAttemptFields()>)
    VALUES (:payment_attempt_id, :invoice_id, :account_id, :amount, :currency, :payment_id, :payment_attempt_dt, :invoice_dt, :retry_count, :next_retry_dt, :created_dt, :updated_dt);
>>

getPaymentAttemptForPaymentId() ::= <<
    SELECT <paymentAttemptFields()>
      FROM payment_attempts
     WHERE payment_id = :payment_id
>>

getPaymentAttemptById() ::= <<
    SELECT <paymentAttemptFields()>
      FROM payment_attempts
     WHERE payment_attempt_id = :payment_attempt_id
>>

getPaymentAttemptsForInvoiceIds(invoiceIds) ::= <<
    SELECT <paymentAttemptFields()>
      FROM payment_attempts
     WHERE invoice_id in (<invoiceIds>)
>>

getPaymentAttemptForInvoiceId() ::= <<
    SELECT <paymentAttemptFields()>
      FROM payment_attempts
     WHERE invoice_id = :invoice_id
>>

updatePaymentAttemptWithPaymentId() ::= <<
    UPDATE payment_attempts
       SET payment_id = :payment_id,
           updated_dt = NOW()
     WHERE payment_attempt_id = :payment_attempt_id
>>

insertPaymentInfo() ::= <<
    INSERT INTO payments (<paymentInfoFields()>)
    VALUES (:payment_id, :amount, :refund_amount, :bank_identification_number, :payment_number, :payment_type, :status, :reference_id, :payment_method_id, :payment_method, :card_type, :card_country, :effective_dt, :created_dt, :updated_dt);
>>

updatePaymentInfo() ::= <<
    UPDATE payments
       SET payment_method = :payment_method,
           card_type = :card_type,
           card_country = :card_country,
           updated_dt = NOW()
     WHERE payment_id = :payment_id
>>

updatePaymentAttemptWithRetryInfo() ::= <<
    UPDATE payment_attempts
       SET retry_count = :retry_count,
           next_retry_dt = :next_retry_dt,
           updated_dt = NOW()
     WHERE payment_attempt_id = :payment_attempt_id
>>

getPaymentInfos(invoiceIds) ::= <<
    SELECT <paymentInfoFields("p.")>
      FROM payments p, payment_attempts pa
     WHERE pa.invoice_id in (<invoiceIds>)
       AND pa.payment_id = p.payment_id
>>