Skip to content

Commit 4c16ffa

Browse files
akshayDev17Akshay Prabhakant
and
Akshay Prabhakant
authored
#177 feature/Invoice: init, added Invoice related structs, implemented met… (#249)
* feature/Invoice: init, added Invoice related structs, implemented methods:GenerateInvoiceNumber,GetInvoiceDetails(by ID) * feature/Invoice: added implemented endpoints to README along with Usage Co-authored-by: Akshay Prabhakant <akshayprabhakant@Akshays-MacBook-Pro.local>
1 parent 1bb626d commit 4c16ffa

File tree

4 files changed

+728
-0
lines changed

4 files changed

+728
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@
101101
* POST /v1/billing/subscriptions/:id/capture
102102
* POST /v1/billing/subscriptions/:id/suspend
103103
* GET /v1/billing/subscriptions/:id/transactions
104+
105+
### Invoicing
106+
107+
* POST /v2/invoicing/generate-next-invoice-number
108+
* GET /v2/invoicing/invoices/:id
104109

105110
## Missing endpoints
106111

@@ -371,6 +376,27 @@ c.DeleteWebhook("WebhookID")
371376
c.ListWebhooks(paypal.AncorTypeApplication)
372377
```
373378

379+
### Generate Next Invoice Number
380+
```go
381+
// GenerateInvoiceNumber: generates the next invoice number that is available to the merchant.
382+
c.GenerateInvoiceNumber(ctx) // might return something like "0001" or "0010".
383+
```
384+
385+
### Get Invoice Details by ID
386+
```go
387+
// the second argument is an ID, it should be valid
388+
invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33")
389+
```
390+
* for now, we are yet to implement the ShowAllInvoices endpoint, so use the following cURL request for the same(this gives you the list of invoice-IDs for this customer)
391+
```bash
392+
curl -v -X GET https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true \
393+
-H "Content-Type: application/json" \
394+
-H "Authorization: Bearer <Token>"
395+
```
396+
397+
* refer to the beginning of this Usage section for obtaining a Token.
398+
399+
374400
## How to Contribute
375401

376402
* Fork a repository

invoicing.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package paypal
2+
3+
import (
4+
"context"
5+
"fmt"
6+
)
7+
8+
// GenerateInvoiceNumber: generates the next invoice number that is available to the merchant.
9+
// Endpoint: POST /v2/invoicing/generate-next-invoice-number
10+
func (c *Client) GenerateInvoiceNumber(ctx context.Context) (*InvoiceNumber, error) {
11+
12+
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/invoicing/generate-next-invoice-number"), nil)
13+
nextInvoiceNumber := &InvoiceNumber{}
14+
if err != nil {
15+
return nextInvoiceNumber, err
16+
}
17+
18+
if err = c.SendWithAuth(req, nextInvoiceNumber); err != nil {
19+
return nextInvoiceNumber, err
20+
}
21+
22+
return nextInvoiceNumber, nil
23+
}
24+
25+
// GetInvoiceDetails: show invoice details for a particular invoice by ID.
26+
// Endpoint: GET /v2/invoicing/invoices/{invoice_id}
27+
func (c *Client) GetInvoiceDetails(ctx context.Context, invoiceID string) (*Invoice, error) {
28+
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/invoicing/invoices/", invoiceID), nil)
29+
invoice := &Invoice{}
30+
if err != nil {
31+
return invoice, err
32+
}
33+
34+
if err = c.SendWithAuth(req, invoice); err != nil {
35+
return invoice, err
36+
}
37+
return invoice, nil
38+
}

0 commit comments

Comments
 (0)