Skip to content

Commit

Permalink
Add support for CreditNote preview
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Nov 26, 2019
1 parent a7084b6 commit 3431f7d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cache:
env:
global:
# If changing this number, please also change it in `testing/testing.go`.
- STRIPE_MOCK_VERSION=0.74.0
- STRIPE_MOCK_VERSION=0.76.0

go:
- "1.9.x"
Expand Down
14 changes: 14 additions & 0 deletions creditnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ type CreditNoteListParams struct {
Invoice *string `form:"invoice"`
}

// CreditNotePreviewParams is the set of parameters that can be used when previewing a credit note.
// For more details see https://stripe.com/docs/api/credit_notes/create, https://stripe.com/docs/api/credit_notes/update.
type CreditNotePreviewParams struct {
Params `form:"*"`
Amount *int64 `form:"amount"`
CreditAmount *int64 `form:"credit_amount"`
Invoice *string `form:"invoice"`
Memo *string `form:"memo"`
OutOfBankdAmount *int64 `form:"out_of_band_amount"`
Reason *string `form:"reason"`
Refund *string `form:"refund"`
RefundAmount *int64 `form:"refund_amount"`
}

// CreditNoteVoidParams is the set of parameters that can be used when voiding invoices.
type CreditNoteVoidParams struct {
Params `form:"*"`
Expand Down
12 changes: 12 additions & 0 deletions creditnote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ func (c Client) List(listParams *stripe.CreditNoteListParams) *Iter {
})}
}

// Preview previews a credit note.
func Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
return getC().Preview(params)
}

// Preview previews a credit note.
func (c Client) Preview(params *stripe.CreditNotePreviewParams) (*stripe.CreditNote, error) {
cn := &stripe.CreditNote{}
err := c.B.Call(http.MethodGet, "/v1/credit_notes/preview", c.Key, params, cn)
return cn, err
}

// VoidCreditNote voids a credit note.
func VoidCreditNote(id string, params *stripe.CreditNoteVoidParams) (*stripe.CreditNote, error) {
return getC().VoidCreditNote(id, params)
Expand Down
10 changes: 10 additions & 0 deletions creditnote/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func TestCreditNoteUpdate(t *testing.T) {
assert.NotNil(t, cn)
}

func TestCreditNotePreview(t *testing.T) {
params := &stripe.CreditNotePreviewParams{
Amount: stripe.Int64(100),
Invoice: stripe.String("in_123"),
}
cn, err := Preview(params)
assert.Nil(t, err)
assert.NotNil(t, cn)
}

func TestCreditNoteVoidCreditNote(t *testing.T) {
params := &stripe.CreditNoteVoidParams{}
cn, err := VoidCreditNote("cn_123", params)
Expand Down
2 changes: 1 addition & 1 deletion testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// added in a more recent version of stripe-mock, we can show people a
// better error message instead of the test suite crashing with a bunch of
// confusing 404 errors or the like.
MockMinimumVersion = "0.74.0"
MockMinimumVersion = "0.76.0"

// TestMerchantID is a token that can be used to represent a merchant ID in
// simple tests.
Expand Down

0 comments on commit 3431f7d

Please sign in to comment.