From 3431f7d2c27aa450d74f0094bb88c91636a43b07 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 26 Nov 2019 14:01:52 -0800 Subject: [PATCH] Add support for `CreditNote` preview --- .travis.yml | 2 +- creditnote.go | 14 ++++++++++++++ creditnote/client.go | 12 ++++++++++++ creditnote/client_test.go | 10 ++++++++++ testing/testing.go | 2 +- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a73a58226..f114414f84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/creditnote.go b/creditnote.go index 08ecb6fa30..776549d7ac 100644 --- a/creditnote.go +++ b/creditnote.go @@ -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:"*"` diff --git a/creditnote/client.go b/creditnote/client.go index 1ccf9c4b43..7950629e30 100644 --- a/creditnote/client.go +++ b/creditnote/client.go @@ -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) diff --git a/creditnote/client_test.go b/creditnote/client_test.go index cfa30d0822..09bc635404 100644 --- a/creditnote/client_test.go +++ b/creditnote/client_test.go @@ -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) diff --git a/testing/testing.go b/testing/testing.go index 1a6fb686fe..7ba7b5c9c1 100644 --- a/testing/testing.go +++ b/testing/testing.go @@ -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.