Skip to content

Commit 51321d8

Browse files
feat(api): Add idempotency key to cards POST and PATCH endpoints
1 parent fdb9960 commit 51321d8

File tree

9 files changed

+111
-71
lines changed

9 files changed

+111
-71
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

lib/lithic/models/card_create_params.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ class CardCreateParams < Lithic::Internal::Type::BaseModel
226226
# @return [Symbol, Lithic::Models::CardCreateParams::State, nil]
227227
optional :state, enum: -> { Lithic::CardCreateParams::State }
228228

229-
# @!method initialize(type:, account_token: nil, bulk_order_token: nil, card_program_token: nil, carrier: nil, digital_card_art_token: nil, exp_month: nil, exp_year: nil, memo: nil, pin: nil, product_id: nil, replacement_account_token: nil, replacement_comment: nil, replacement_for: nil, replacement_substatus: nil, shipping_address: nil, shipping_method: nil, spend_limit: nil, spend_limit_duration: nil, state: nil, request_options: {})
229+
# @!attribute idempotency_key
230+
#
231+
# @return [String, nil]
232+
optional :idempotency_key, String
233+
234+
# @!method initialize(type:, account_token: nil, bulk_order_token: nil, card_program_token: nil, carrier: nil, digital_card_art_token: nil, exp_month: nil, exp_year: nil, memo: nil, pin: nil, product_id: nil, replacement_account_token: nil, replacement_comment: nil, replacement_for: nil, replacement_substatus: nil, shipping_address: nil, shipping_method: nil, spend_limit: nil, spend_limit_duration: nil, state: nil, idempotency_key: nil, request_options: {})
230235
# Some parameter documentations has been truncated, see
231236
# {Lithic::Models::CardCreateParams} for more details.
232237
#
@@ -270,6 +275,8 @@ class CardCreateParams < Lithic::Internal::Type::BaseModel
270275
#
271276
# @param state [Symbol, Lithic::Models::CardCreateParams::State] Card state values:
272277
#
278+
# @param idempotency_key [String]
279+
#
273280
# @param request_options [Lithic::RequestOptions, Hash{Symbol=>Object}]
274281

275282
# Card types:

lib/lithic/resources/cards.rb

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,49 @@ class Cards
1515
# Create a new virtual or physical card. Parameters `shipping_address` and
1616
# `product_id` only apply to physical cards.
1717
#
18-
# @overload create(type:, account_token: nil, bulk_order_token: nil, card_program_token: nil, carrier: nil, digital_card_art_token: nil, exp_month: nil, exp_year: nil, memo: nil, pin: nil, product_id: nil, replacement_account_token: nil, replacement_comment: nil, replacement_for: nil, replacement_substatus: nil, shipping_address: nil, shipping_method: nil, spend_limit: nil, spend_limit_duration: nil, state: nil, request_options: {})
18+
# @overload create(type:, account_token: nil, bulk_order_token: nil, card_program_token: nil, carrier: nil, digital_card_art_token: nil, exp_month: nil, exp_year: nil, memo: nil, pin: nil, product_id: nil, replacement_account_token: nil, replacement_comment: nil, replacement_for: nil, replacement_substatus: nil, shipping_address: nil, shipping_method: nil, spend_limit: nil, spend_limit_duration: nil, state: nil, idempotency_key: nil, request_options: {})
1919
#
20-
# @param type [Symbol, Lithic::Models::CardCreateParams::Type] Card types:
20+
# @param type [Symbol, Lithic::Models::CardCreateParams::Type] Body param: Card types:
2121
#
22-
# @param account_token [String] Globally unique identifier for the account that the card will be associated with
22+
# @param account_token [String] Body param: Globally unique identifier for the account that the card will be ass
2323
#
24-
# @param bulk_order_token [String] Globally unique identifier for an existing bulk order to associate this card wit
24+
# @param bulk_order_token [String] Body param: Globally unique identifier for an existing bulk order to associate t
2525
#
26-
# @param card_program_token [String] For card programs with more than one BIN range. This must be configured with Lit
26+
# @param card_program_token [String] Body param: For card programs with more than one BIN range. This must be configu
2727
#
28-
# @param carrier [Lithic::Models::Carrier]
28+
# @param carrier [Lithic::Models::Carrier] Body param
2929
#
30-
# @param digital_card_art_token [String] Specifies the digital card art to be displayed in the user’s digital wallet afte
30+
# @param digital_card_art_token [String] Body param: Specifies the digital card art to be displayed in the user’s digital
3131
#
32-
# @param exp_month [String] Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
32+
# @param exp_month [String] Body param: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` i
3333
#
34-
# @param exp_year [String] Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is provided
34+
# @param exp_year [String] Body param: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year`
3535
#
36-
# @param memo [String] Friendly name to identify the card.
36+
# @param memo [String] Body param: Friendly name to identify the card.
3737
#
38-
# @param pin [String] Encrypted PIN block (in base64). Applies to cards of type `PHYSICAL` and `VIRTUA
38+
# @param pin [String] Body param: Encrypted PIN block (in base64). Applies to cards of type `PHYSICAL`
3939
#
40-
# @param product_id [String] Only applicable to cards of type `PHYSICAL`. This must be configured with Lithic
40+
# @param product_id [String] Body param: Only applicable to cards of type `PHYSICAL`. This must be configured
4141
#
42-
# @param replacement_account_token [String] Restricted field limited to select use cases. Lithic will reach out directly if
42+
# @param replacement_account_token [String] Body param: Restricted field limited to select use cases. Lithic will reach out
4343
#
44-
# @param replacement_comment [String] Additional context or information related to the card that this card will replac
44+
# @param replacement_comment [String] Body param: Additional context or information related to the card that this card
4545
#
46-
# @param replacement_for [String] Globally unique identifier for the card that this card will replace. If the card
46+
# @param replacement_for [String] Body param: Globally unique identifier for the card that this card will replace.
4747
#
48-
# @param replacement_substatus [Symbol, Lithic::Models::CardCreateParams::ReplacementSubstatus] Card state substatus values for the card that this card will replace:
48+
# @param replacement_substatus [Symbol, Lithic::Models::CardCreateParams::ReplacementSubstatus] Body param: Card state substatus values for the card that this card will replace
4949
#
50-
# @param shipping_address [Lithic::Models::ShippingAddress]
50+
# @param shipping_address [Lithic::Models::ShippingAddress] Body param
5151
#
52-
# @param shipping_method [Symbol, Lithic::Models::CardCreateParams::ShippingMethod] Shipping method for the card. Only applies to cards of type PHYSICAL.
52+
# @param shipping_method [Symbol, Lithic::Models::CardCreateParams::ShippingMethod] Body param: Shipping method for the card. Only applies to cards of type PHYSICAL
5353
#
54-
# @param spend_limit [Integer] Amount (in cents) to limit approved authorizations (e.g. 100000 would be a $1,00
54+
# @param spend_limit [Integer] Body param: Amount (in cents) to limit approved authorizations (e.g. 100000 woul
5555
#
56-
# @param spend_limit_duration [Symbol, Lithic::Models::SpendLimitDuration] Spend limit duration values:
56+
# @param spend_limit_duration [Symbol, Lithic::Models::SpendLimitDuration] Body param: Spend limit duration values:
57+
#
58+
# @param state [Symbol, Lithic::Models::CardCreateParams::State] Body param: Card state values:
5759
#
58-
# @param state [Symbol, Lithic::Models::CardCreateParams::State] Card state values:
60+
# @param idempotency_key [String] Header param: Idempotency key for the request
5961
#
6062
# @param request_options [Lithic::RequestOptions, Hash{Symbol=>Object}, nil]
6163
#
@@ -64,7 +66,15 @@ class Cards
6466
# @see Lithic::Models::CardCreateParams
6567
def create(params)
6668
parsed, options = Lithic::CardCreateParams.dump_request(params)
67-
@client.request(method: :post, path: "v1/cards", body: parsed, model: Lithic::Card, options: options)
69+
header_params = {idempotency_key: "idempotency-key"}
70+
@client.request(
71+
method: :post,
72+
path: "v1/cards",
73+
headers: parsed.slice(*header_params.keys).transform_keys(header_params),
74+
body: parsed.except(*header_params.keys),
75+
model: Lithic::Card,
76+
options: options
77+
)
6878
end
6979

7080
# Get card configuration such as spend limit and state.

lib/lithic/resources/financial_accounts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FinancialAccounts
3030
#
3131
# @param is_for_benefit_of [Boolean] Body param
3232
#
33-
# @param idempotency_key [String] Header param
33+
# @param idempotency_key [String] Header param: Idempotency key for the request
3434
#
3535
# @param request_options [Lithic::RequestOptions, Hash{Symbol=>Object}, nil]
3636
#

rbi/lithic/models/card_create_params.rbi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ module Lithic
264264
sig { params(state: Lithic::CardCreateParams::State::OrSymbol).void }
265265
attr_writer :state
266266

267+
sig { returns(T.nilable(String)) }
268+
attr_reader :idempotency_key
269+
270+
sig { params(idempotency_key: String).void }
271+
attr_writer :idempotency_key
272+
267273
sig do
268274
params(
269275
type: Lithic::CardCreateParams::Type::OrSymbol,
@@ -287,6 +293,7 @@ module Lithic
287293
spend_limit: Integer,
288294
spend_limit_duration: Lithic::SpendLimitDuration::OrSymbol,
289295
state: Lithic::CardCreateParams::State::OrSymbol,
296+
idempotency_key: String,
290297
request_options: Lithic::RequestOptions::OrHash
291298
).returns(T.attached_class)
292299
end
@@ -430,6 +437,7 @@ module Lithic
430437
# - `PAUSED` - Card will decline authorizations, but can be resumed at a later
431438
# time.
432439
state: nil,
440+
idempotency_key: nil,
433441
request_options: {}
434442
)
435443
end
@@ -458,6 +466,7 @@ module Lithic
458466
spend_limit: Integer,
459467
spend_limit_duration: Lithic::SpendLimitDuration::OrSymbol,
460468
state: Lithic::CardCreateParams::State::OrSymbol,
469+
idempotency_key: String,
461470
request_options: Lithic::RequestOptions
462471
}
463472
)

rbi/lithic/resources/cards.rbi

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ module Lithic
3434
spend_limit: Integer,
3535
spend_limit_duration: Lithic::SpendLimitDuration::OrSymbol,
3636
state: Lithic::CardCreateParams::State::OrSymbol,
37+
idempotency_key: String,
3738
request_options: Lithic::RequestOptions::OrHash
3839
).returns(Lithic::Card)
3940
end
4041
def create(
41-
# Card types:
42+
# Body param: Card types:
4243
#
4344
# - `VIRTUAL` - Card will authorize at any merchant and can be added to a digital
4445
# wallet like Apple Pay or Google Pay (if the card program is digital
@@ -55,58 +56,60 @@ module Lithic
5556
# - `DIGITAL_WALLET` - _[Deprecated]_ Similar behavior to VIRTUAL cards, please
5657
# use VIRTUAL instead.
5758
type:,
58-
# Globally unique identifier for the account that the card will be associated
59-
# with. Required for programs enrolling users using the
59+
# Body param: Globally unique identifier for the account that the card will be
60+
# associated with. Required for programs enrolling users using the
6061
# [/account_holders endpoint](https://docs.lithic.com/docs/account-holders-kyc).
6162
# See [Managing Your Program](doc:managing-your-program) for more information.
6263
account_token: nil,
63-
# Globally unique identifier for an existing bulk order to associate this card
64-
# with. When specified, the card will be added to the bulk order for batch
65-
# shipment. Only applicable to cards of type PHYSICAL
64+
# Body param: Globally unique identifier for an existing bulk order to associate
65+
# this card with. When specified, the card will be added to the bulk order for
66+
# batch shipment. Only applicable to cards of type PHYSICAL
6667
bulk_order_token: nil,
67-
# For card programs with more than one BIN range. This must be configured with
68-
# Lithic before use. Identifies the card program/BIN range under which to create
69-
# the card. If omitted, will utilize the program's default `card_program_token`.
70-
# In Sandbox, use 00000000-0000-0000-1000-000000000000 and
68+
# Body param: For card programs with more than one BIN range. This must be
69+
# configured with Lithic before use. Identifies the card program/BIN range under
70+
# which to create the card. If omitted, will utilize the program's default
71+
# `card_program_token`. In Sandbox, use 00000000-0000-0000-1000-000000000000 and
7172
# 00000000-0000-0000-2000-000000000000 to test creating cards on specific card
7273
# programs.
7374
card_program_token: nil,
75+
# Body param
7476
carrier: nil,
75-
# Specifies the digital card art to be displayed in the user’s digital wallet
76-
# after tokenization. This artwork must be approved by Mastercard and configured
77-
# by Lithic to use. See
77+
# Body param: Specifies the digital card art to be displayed in the user’s digital
78+
# wallet after tokenization. This artwork must be approved by Mastercard and
79+
# configured by Lithic to use. See
7880
# [Flexible Card Art Guide](https://docs.lithic.com/docs/about-digital-wallets#flexible-card-art).
7981
digital_card_art_token: nil,
80-
# Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
81-
# an expiration date will be generated.
82+
# Body param: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year`
83+
# is provided, an expiration date will be generated.
8284
exp_month: nil,
83-
# Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
84-
# provided, an expiration date will be generated.
85+
# Body param: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year`
86+
# is provided, an expiration date will be generated.
8587
exp_year: nil,
86-
# Friendly name to identify the card.
88+
# Body param: Friendly name to identify the card.
8789
memo: nil,
88-
# Encrypted PIN block (in base64). Applies to cards of type `PHYSICAL` and
89-
# `VIRTUAL`. See
90+
# Body param: Encrypted PIN block (in base64). Applies to cards of type `PHYSICAL`
91+
# and `VIRTUAL`. See
9092
# [Encrypted PIN Block](https://docs.lithic.com/docs/cards#encrypted-pin-block).
9193
pin: nil,
92-
# Only applicable to cards of type `PHYSICAL`. This must be configured with Lithic
93-
# before use. Specifies the configuration (i.e., physical card art) that the card
94-
# should be manufactured with.
94+
# Body param: Only applicable to cards of type `PHYSICAL`. This must be configured
95+
# with Lithic before use. Specifies the configuration (i.e., physical card art)
96+
# that the card should be manufactured with.
9597
product_id: nil,
96-
# Restricted field limited to select use cases. Lithic will reach out directly if
97-
# this field should be used. Globally unique identifier for the replacement card's
98-
# account. If this field is specified, `replacement_for` must also be specified.
99-
# If `replacement_for` is specified and this field is omitted, the replacement
100-
# card's account will be inferred from the card being replaced.
98+
# Body param: Restricted field limited to select use cases. Lithic will reach out
99+
# directly if this field should be used. Globally unique identifier for the
100+
# replacement card's account. If this field is specified, `replacement_for` must
101+
# also be specified. If `replacement_for` is specified and this field is omitted,
102+
# the replacement card's account will be inferred from the card being replaced.
101103
replacement_account_token: nil,
102-
# Additional context or information related to the card that this card will
103-
# replace.
104+
# Body param: Additional context or information related to the card that this card
105+
# will replace.
104106
replacement_comment: nil,
105-
# Globally unique identifier for the card that this card will replace. If the card
106-
# type is `PHYSICAL` it will be replaced by a `PHYSICAL` card. If the card type is
107-
# `VIRTUAL` it will be replaced by a `VIRTUAL` card.
107+
# Body param: Globally unique identifier for the card that this card will replace.
108+
# If the card type is `PHYSICAL` it will be replaced by a `PHYSICAL` card. If the
109+
# card type is `VIRTUAL` it will be replaced by a `VIRTUAL` card.
108110
replacement_for: nil,
109-
# Card state substatus values for the card that this card will replace:
111+
# Body param: Card state substatus values for the card that this card will
112+
# replace:
110113
#
111114
# - `LOST` - The physical card is no longer in the cardholder's possession due to
112115
# being lost or never received by the cardholder.
@@ -134,9 +137,10 @@ module Lithic
134137
# - `OTHER` - The reason for the status does not fall into any of the above
135138
# categories. A comment should be provided to specify the reason.
136139
replacement_substatus: nil,
140+
# Body param
137141
shipping_address: nil,
138-
# Shipping method for the card. Only applies to cards of type PHYSICAL. Use of
139-
# options besides `STANDARD` require additional permissions.
142+
# Body param: Shipping method for the card. Only applies to cards of type
143+
# PHYSICAL. Use of options besides `STANDARD` require additional permissions.
140144
#
141145
# - `STANDARD` - USPS regular mail or similar international option, with no
142146
# tracking
@@ -151,13 +155,13 @@ module Lithic
151155
# or similar international option, with tracking
152156
# - `BULK_EXPEDITED` - Bulk shipment with Expedited shipping
153157
shipping_method: nil,
154-
# Amount (in cents) to limit approved authorizations (e.g. 100000 would be a
155-
# $1,000 limit). Transaction requests above the spend limit will be declined. Note
156-
# that a spend limit of 0 is effectively no limit, and should only be used to
157-
# reset or remove a prior limit. Only a limit of 1 or above will result in
158-
# declined transactions due to checks against the card limit.
158+
# Body param: Amount (in cents) to limit approved authorizations (e.g. 100000
159+
# would be a $1,000 limit). Transaction requests above the spend limit will be
160+
# declined. Note that a spend limit of 0 is effectively no limit, and should only
161+
# be used to reset or remove a prior limit. Only a limit of 1 or above will result
162+
# in declined transactions due to checks against the card limit.
159163
spend_limit: nil,
160-
# Spend limit duration values:
164+
# Body param: Spend limit duration values:
161165
#
162166
# - `ANNUALLY` - Card will authorize transactions up to spend limit for the
163167
# trailing year.
@@ -170,13 +174,15 @@ module Lithic
170174
# - `TRANSACTION` - Card will authorize multiple transactions if each individual
171175
# transaction is under the spend limit.
172176
spend_limit_duration: nil,
173-
# Card state values:
177+
# Body param: Card state values:
174178
#
175179
# - `OPEN` - Card will approve authorizations (if they match card and account
176180
# parameters).
177181
# - `PAUSED` - Card will decline authorizations, but can be resumed at a later
178182
# time.
179183
state: nil,
184+
# Header param: Idempotency key for the request
185+
idempotency_key: nil,
180186
request_options: {}
181187
)
182188
end

0 commit comments

Comments
 (0)