200 lines
5.0 KiB
Go
200 lines
5.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: payments.sql
|
|
|
|
package billing
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createPayment = `-- name: CreatePayment :one
|
|
INSERT INTO billing.payments (
|
|
invoice_id, billing_account_id, payment_method_id,
|
|
amount, currency, status, failed_at
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at
|
|
`
|
|
|
|
type CreatePaymentParams struct {
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
PaymentMethodID uuid.NullUUID `json:"payment_method_id"`
|
|
Amount int32 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
FailedAt sql.NullTime `json:"failed_at"`
|
|
}
|
|
|
|
func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, createPayment,
|
|
arg.InvoiceID,
|
|
arg.BillingAccountID,
|
|
arg.PaymentMethodID,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.Status,
|
|
arg.FailedAt,
|
|
)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentByID = `-- name: GetPaymentByID :one
|
|
SELECT payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at FROM billing.payments
|
|
WHERE payment_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPaymentByID(ctx context.Context, paymentID string) (Payment, error) {
|
|
row := q.db.QueryRowContext(ctx, getPaymentByID, paymentID)
|
|
var i Payment
|
|
err := row.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPaymentsByInvoiceID = `-- name: GetPaymentsByInvoiceID :many
|
|
SELECT payment_id, invoice_id, billing_account_id, payment_method_id, amount, currency, status, failed_at, created_at, updated_at FROM billing.payments
|
|
WHERE invoice_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) GetPaymentsByInvoiceID(ctx context.Context, invoiceID string) ([]Payment, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPaymentsByInvoiceID, invoiceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Payment{}
|
|
for rows.Next() {
|
|
var i Payment
|
|
if err := rows.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listPayments = `-- name: ListPayments :many
|
|
SELECT
|
|
p.payment_id,
|
|
p.invoice_id,
|
|
p.billing_account_id,
|
|
p.payment_method_id,
|
|
p.amount,
|
|
p.currency,
|
|
p.status,
|
|
p.failed_at,
|
|
p.created_at,
|
|
p.updated_at,
|
|
ba.name as billing_account_name,
|
|
pm.pm_type as payment_method_type,
|
|
pm.card_brand,
|
|
pm.card_last4
|
|
FROM billing.payments p
|
|
JOIN billing.accounts ba ON p.billing_account_id = ba.billing_account_id
|
|
LEFT JOIN billing.payment_methods pm ON p.payment_method_id = pm.payment_method_id
|
|
ORDER BY p.created_at DESC
|
|
`
|
|
|
|
type ListPaymentsRow struct {
|
|
PaymentID string `json:"payment_id"`
|
|
InvoiceID string `json:"invoice_id"`
|
|
BillingAccountID string `json:"billing_account_id"`
|
|
PaymentMethodID uuid.NullUUID `json:"payment_method_id"`
|
|
Amount int32 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
FailedAt sql.NullTime `json:"failed_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
BillingAccountName string `json:"billing_account_name"`
|
|
PaymentMethodType sql.NullString `json:"payment_method_type"`
|
|
CardBrand sql.NullString `json:"card_brand"`
|
|
CardLast4 sql.NullString `json:"card_last4"`
|
|
}
|
|
|
|
func (q *Queries) ListPayments(ctx context.Context) ([]ListPaymentsRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPayments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListPaymentsRow{}
|
|
for rows.Next() {
|
|
var i ListPaymentsRow
|
|
if err := rows.Scan(
|
|
&i.PaymentID,
|
|
&i.InvoiceID,
|
|
&i.BillingAccountID,
|
|
&i.PaymentMethodID,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.FailedAt,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.BillingAccountName,
|
|
&i.PaymentMethodType,
|
|
&i.CardBrand,
|
|
&i.CardLast4,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|