Skip to content

Commit

Permalink
Merge pull request #998 from stripe/remi-creditnote-preview
Browse files Browse the repository at this point in the history
Add support for `CreditNote` preview
  • Loading branch information
remi-stripe authored Nov 27, 2019
2 parents a7084b6 + 57bc028 commit 2d46c68
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 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
35 changes: 26 additions & 9 deletions creditnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ const (
// CreditNoteParams is the set of parameters that can be used when creating or updating a credit note.
// For more details see https://stripe.com/docs/api/credit_notes/create, https://stripe.com/docs/api/credit_notes/update.
type CreditNoteParams 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"`
Params `form:"*"`
Amount *int64 `form:"amount"`
CreditAmount *int64 `form:"credit_amount"`
Invoice *string `form:"invoice"`
Memo *string `form:"memo"`
OutOfBandAmount *int64 `form:"out_of_band_amount"`
Reason *string `form:"reason"`
Refund *string `form:"refund"`
RefundAmount *int64 `form:"refund_amount"`

// TODO: Remove in the next major version as the name is incorrect.
OutOfBankdAmount *int64 `form:"out_of_band_amount"`
}

// CreditNoteListParams is the set of parameters that can be used when listing credit notes.
Expand All @@ -53,6 +56,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/preview.
type CreditNotePreviewParams struct {
Params `form:"*"`
Amount *int64 `form:"amount"`
CreditAmount *int64 `form:"credit_amount"`
Invoice *string `form:"invoice"`
Memo *string `form:"memo"`
OutOfBandAmount *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 2d46c68

Please sign in to comment.