diff --git a/invoice.go b/invoice.go index 0f10f8e..89f8c61 100644 --- a/invoice.go +++ b/invoice.go @@ -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"` } @@ -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, @@ -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 +}