Skip to content

Commit c53307f

Browse files
feat(api): Add idempotency key to cards POST and PATCH endpoints
1 parent a9a3198 commit c53307f

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 176
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-6e800837b020104545778d65b7b16bae277e6667d98044e83f3bfeacebdb489b.yml
3-
openapi_spec_hash: 94788968e119e8665a1b0d4742565984
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lithic%2Flithic-eeeb62a4869ba1436c9252f9630006a829695178e86305aea232f6be0d1e3d81.yml
3+
openapi_spec_hash: 25bf9c499cd22240949862e622c534f2
44
config_hash: 2af43c32faa12490c9c9caa2ce62bccb

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Response Types:
196196

197197
Methods:
198198

199-
- <code title="post /v1/cards">client.Cards.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, body <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardNewParams">CardNewParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Card">Card</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
199+
- <code title="post /v1/cards">client.Cards.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardService.New">New</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardNewParams">CardNewParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Card">Card</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
200200
- <code title="get /v1/cards/{card_token}">client.Cards.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, cardToken <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Card">Card</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
201201
- <code title="patch /v1/cards/{card_token}">client.Cards.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardService.Update">Update</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, cardToken <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardUpdateParams">CardUpdateParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#Card">Card</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
202202
- <code title="get /v1/cards">client.Cards.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#CardListParams">CardListParams</a>) (<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go/packages/pagination#CursorPage">CursorPage</a>[<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go">lithic</a>.<a href="https://pkg.go.dev/github.com/lithic-com/lithic-go#NonPCICard">NonPCICard</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

card.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ func NewCardService(opts ...option.RequestOption) (r *CardService) {
5050

5151
// Create a new virtual or physical card. Parameters `shipping_address` and
5252
// `product_id` only apply to physical cards.
53-
func (r *CardService) New(ctx context.Context, body CardNewParams, opts ...option.RequestOption) (res *Card, err error) {
53+
func (r *CardService) New(ctx context.Context, params CardNewParams, opts ...option.RequestOption) (res *Card, err error) {
54+
if params.IdempotencyKey.Present {
55+
opts = append(opts, option.WithHeader("Idempotency-Key", fmt.Sprintf("%s", params.IdempotencyKey)))
56+
}
5457
opts = slices.Concat(r.Options, opts)
5558
path := "v1/cards"
56-
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
59+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
5760
return
5861
}
5962

@@ -1294,7 +1297,8 @@ type CardNewParams struct {
12941297
// parameters).
12951298
// - `PAUSED` - Card will decline authorizations, but can be resumed at a later
12961299
// time.
1297-
State param.Field[CardNewParamsState] `json:"state"`
1300+
State param.Field[CardNewParamsState] `json:"state"`
1301+
IdempotencyKey param.Field[string] `header:"Idempotency-Key" format:"uuid"`
12981302
}
12991303

13001304
func (r CardNewParams) MarshalJSON() (data []byte, err error) {

card_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func TestCardNewWithOptionalParams(t *testing.T) {
6262
SpendLimit: lithic.F(int64(1000)),
6363
SpendLimitDuration: lithic.F(lithic.SpendLimitDurationTransaction),
6464
State: lithic.F(lithic.CardNewParamsStateOpen),
65+
IdempotencyKey: lithic.F("65a9dad4-1b60-4686-83fd-65b25078a4b4"),
6566
})
6667
if err != nil {
6768
var apierr *lithic.Error

financialaccount_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestFinancialAccountNewWithOptionalParams(t *testing.T) {
3030
Type: lithic.F(lithic.FinancialAccountNewParamsTypeOperating),
3131
AccountToken: lithic.F("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
3232
IsForBenefitOf: lithic.F(true),
33-
IdempotencyKey: lithic.F("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
33+
IdempotencyKey: lithic.F("65a9dad4-1b60-4686-83fd-65b25078a4b4"),
3434
})
3535
if err != nil {
3636
var apierr *lithic.Error

0 commit comments

Comments
 (0)