Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dunning): Add create payment requests endpoint #202

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions payment_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@ type PaymentRequestListInput struct {
}

type PaymentRequest struct {
LagoID uuid.UUID `json:"lago_id,omitempty"`
Email string `json:"email,omitempty"`
Currency Currency `json:"currency,omitempty"`
AmountCents int `json:"amount_cents,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`

Customer *Customer `json:"customer,omitempty"`
Invoices []Invoice `json:"fees,omitempty"`
LagoID uuid.UUID `json:"lago_id,omitempty"`
Email string `json:"email,omitempty"`
AmountCurrency Currency `json:"amount_currency,omitempty"`
AmountCents int `json:"amount_cents,omitempty"`
PaymentStatus string `json:"payment_status,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`

Customer *Customer `json:"customer,omitempty"`
Invoices []Invoice `json:"fees,omitempty"`
}

type PaymentRequestParams struct {
PaymentRequest *PaymentRequestInput `json:"payment_request"`
}

type PaymentRequestInput struct {
Email string `json:"email,omitempty"`
CustomerExternalId string `json:"customer_external_id,omitempty"`
LagoInvoiceIds []string `json:"lago_invoice_ids,omitempty"`
}

func (c *Client) PaymentRequest() *PaymentRequestRequest {
Expand Down Expand Up @@ -70,3 +81,27 @@ func (ir *PaymentRequestRequest) GetList(ctx context.Context, paymentRequestList

return paymentRequestResult, nil
}

func (cr *PaymentRequestRequest) Create(ctx context.Context, paymentRequestInput *PaymentRequestInput) (*PaymentRequest, *Error) {
paymentRequestParams := &PaymentRequestParams{
PaymentRequest: paymentRequestInput,
}

clientRequest := &ClientRequest{
Path: "payment_requests",
Result: &PaymentRequestResult{},
Body: paymentRequestParams,
}

result, err := cr.client.Post(ctx, clientRequest)
if err != nil {
return nil, err
}

paymentRequestResult, ok := result.(*PaymentRequestResult)
if !ok {
return nil, &ErrorTypeAssert
}

return paymentRequestResult.PaymentRequest, nil
}
Loading