Skip to content

Commit

Permalink
feat (payment-url): add support for generating invoice payment url (#158
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lovrocolic authored Feb 12, 2024
1 parent 679bb1d commit 93c6b2f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type InvoiceResult struct {
Meta Metadata `json:"meta,omitempty"`
}

type InvoicePaymentUrlResult struct {
InvoicePaymentUrl *InvoicePaymentUrl `json:"invoice_payment_url"`
}

type InvoiceParams struct {
Invoice *InvoiceInput `json:"invoice"`
}
Expand Down Expand Up @@ -185,6 +189,10 @@ type Invoice struct {
SubTotalVatIncludedAmountCents int `json:"sub_total_vat_included_amount_cents,omitempty"`
}

type InvoicePaymentUrl struct {
PaymentUrl string `json:"payment_url,omitempty"`
}

func (c *Client) Invoice() *InvoiceRequest {
return &InvoiceRequest{
client: c,
Expand Down Expand Up @@ -385,3 +393,28 @@ func (ir *InvoiceRequest) RetryPayment(ctx context.Context, invoiceID string) (*

return nil, nil
}

func (ir *InvoiceRequest) PaymentUrl(ctx context.Context, invoiceID string) (*InvoicePaymentUrl, *Error) {
subPath := fmt.Sprintf("%s/%s/%s", "invoices", invoiceID, "payment_url")

clientRequest := &ClientRequest{
Path: subPath,
Result: &InvoicePaymentUrlResult{},
}

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

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

return paymentUrlResult.InvoicePaymentUrl, nil
}

return nil, nil
}

0 comments on commit 93c6b2f

Please sign in to comment.