-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcards.py
More file actions
2635 lines (2286 loc) · 118 KB
/
cards.py
File metadata and controls
2635 lines (2286 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import hmac
import json
import base64
import hashlib
from typing import Any, Union, cast
from datetime import datetime, timezone, timedelta
from typing_extensions import Literal
import httpx
from httpx import URL
from ... import _legacy_response
from ...types import (
SpendLimitDuration,
card_list_params,
card_embed_params,
card_renew_params,
card_create_params,
card_update_params,
card_reissue_params,
card_provision_params,
card_get_embed_url_params,
card_search_by_pan_params,
card_web_provision_params,
card_convert_physical_params,
)
from ..._types import NOT_GIVEN, Body, Omit, Query, Headers, NotGiven, Base64FileInput, omit, not_given
from ..._utils import path_template, maybe_transform, strip_not_given, async_maybe_transform
from .balances import (
Balances,
AsyncBalances,
BalancesWithRawResponse,
AsyncBalancesWithRawResponse,
BalancesWithStreamingResponse,
AsyncBalancesWithStreamingResponse,
)
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from ...pagination import SyncCursorPage, AsyncCursorPage
from ...types.card import Card
from ..._base_client import AsyncPaginator, _merge_mappings, make_request_options
from ...types.non_pci_card import NonPCICard
from .financial_transactions import (
FinancialTransactions,
AsyncFinancialTransactions,
FinancialTransactionsWithRawResponse,
AsyncFinancialTransactionsWithRawResponse,
FinancialTransactionsWithStreamingResponse,
AsyncFinancialTransactionsWithStreamingResponse,
)
from ...types.card_spend_limits import CardSpendLimits
from ...types.spend_limit_duration import SpendLimitDuration
from ...types.shared_params.carrier import Carrier
from ...types.card_provision_response import CardProvisionResponse
from ...types.card_web_provision_response import CardWebProvisionResponse
from ...types.shared_params.shipping_address import ShippingAddress
__all__ = ["Cards", "AsyncCards"]
class Cards(SyncAPIResource):
@cached_property
def balances(self) -> Balances:
return Balances(self._client)
@cached_property
def financial_transactions(self) -> FinancialTransactions:
return FinancialTransactions(self._client)
@cached_property
def with_raw_response(self) -> CardsWithRawResponse:
"""
This property can be used as a prefix for any HTTP method call to return
the raw response object instead of the parsed content.
For more information, see https://www.github.com/lithic-com/lithic-python#accessing-raw-response-data-eg-headers
"""
return CardsWithRawResponse(self)
@cached_property
def with_streaming_response(self) -> CardsWithStreamingResponse:
"""
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
For more information, see https://www.github.com/lithic-com/lithic-python#with_streaming_response
"""
return CardsWithStreamingResponse(self)
def create(
self,
*,
type: Literal["MERCHANT_LOCKED", "PHYSICAL", "SINGLE_USE", "VIRTUAL", "UNLOCKED", "DIGITAL_WALLET"],
account_token: str | Omit = omit,
bulk_order_token: str | Omit = omit,
card_program_token: str | Omit = omit,
carrier: Carrier | Omit = omit,
digital_card_art_token: str | Omit = omit,
exp_month: str | Omit = omit,
exp_year: str | Omit = omit,
memo: str | Omit = omit,
pin: str | Omit = omit,
product_id: str | Omit = omit,
replacement_account_token: str | Omit = omit,
replacement_comment: str | Omit = omit,
replacement_for: str | Omit = omit,
replacement_substatus: Literal[
"LOST",
"COMPROMISED",
"DAMAGED",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"SUSPICIOUS_ACTIVITY",
"INTERNAL_REVIEW",
"EXPIRED",
"UNDELIVERABLE",
"OTHER",
]
| Omit = omit,
shipping_address: ShippingAddress | Omit = omit,
shipping_method: Literal[
"2_DAY", "BULK", "EXPEDITED", "EXPRESS", "PRIORITY", "STANDARD", "STANDARD_WITH_TRACKING"
]
| Omit = omit,
spend_limit: int | Omit = omit,
spend_limit_duration: SpendLimitDuration | Omit = omit,
state: Literal["OPEN", "PAUSED"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Card:
"""Create a new virtual or physical card.
Parameters `shipping_address` and
`product_id` only apply to physical cards.
Args:
type:
Card types:
- `VIRTUAL` - Card will authorize at any merchant and can be added to a digital
wallet like Apple Pay or Google Pay (if the card program is digital
wallet-enabled).
- `PHYSICAL` - Manufactured and sent to the cardholder. We offer white label
branding, credit, ATM, PIN debit, chip/EMV, NFC and magstripe functionality.
Reach out at [lithic.com/contact](https://lithic.com/contact) for more
information.
- `SINGLE_USE` - Card is closed upon first successful authorization.
- `MERCHANT_LOCKED` - Card is locked to the first merchant that successfully
authorizes the card.
- `UNLOCKED` - _[Deprecated]_ Similar behavior to VIRTUAL cards, please use
VIRTUAL instead.
- `DIGITAL_WALLET` - _[Deprecated]_ Similar behavior to VIRTUAL cards, please
use VIRTUAL instead.
account_token: Globally unique identifier for the account that the card will be associated
with. Required for programs enrolling users using the
[/account_holders endpoint](https://docs.lithic.com/docs/account-holders-kyc).
See [Managing Your Program](doc:managing-your-program) for more information.
bulk_order_token: Globally unique identifier for an existing bulk order to associate this card
with. When specified, the card will be added to the bulk order for batch
shipment. Only applicable to cards of type PHYSICAL
card_program_token: For card programs with more than one BIN range. This must be configured with
Lithic before use. Identifies the card program/BIN range under which to create
the card. If omitted, will utilize the program's default `card_program_token`.
In Sandbox, use 00000000-0000-0000-1000-000000000000 and
00000000-0000-0000-2000-000000000000 to test creating cards on specific card
programs.
digital_card_art_token: Specifies the digital card art to be displayed in the user’s digital wallet
after tokenization. This artwork must be approved by Mastercard and configured
by Lithic to use. See
[Flexible Card Art Guide](https://docs.lithic.com/docs/about-digital-wallets#flexible-card-art).
exp_month: Two digit (MM) expiry month. If neither `exp_month` nor `exp_year` is provided,
an expiration date will be generated.
exp_year: Four digit (yyyy) expiry year. If neither `exp_month` nor `exp_year` is
provided, an expiration date will be generated.
memo: Friendly name to identify the card.
pin: Encrypted PIN block (in base64). Applies to cards of type `PHYSICAL` and
`VIRTUAL`. See
[Encrypted PIN Block](https://docs.lithic.com/docs/cards#encrypted-pin-block).
product_id: Only applicable to cards of type `PHYSICAL`. This must be configured with Lithic
before use. Specifies the configuration (i.e., physical card art) that the card
should be manufactured with.
replacement_account_token: Restricted field limited to select use cases. Lithic will reach out directly if
this field should be used. Globally unique identifier for the replacement card's
account. If this field is specified, `replacement_for` must also be specified.
If `replacement_for` is specified and this field is omitted, the replacement
card's account will be inferred from the card being replaced.
replacement_comment: Additional context or information related to the card that this card will
replace.
replacement_for: Globally unique identifier for the card that this card will replace. If the card
type is `PHYSICAL` it will be replaced by a `PHYSICAL` card. If the card type is
`VIRTUAL` it will be replaced by a `VIRTUAL` card.
replacement_substatus:
Card state substatus values for the card that this card will replace:
- `LOST` - The physical card is no longer in the cardholder's possession due to
being lost or never received by the cardholder.
- `COMPROMISED` - Card information has been exposed, potentially leading to
unauthorized access. This may involve physical card theft, cloning, or online
data breaches.
- `DAMAGED` - The physical card is not functioning properly, such as having chip
failures or a demagnetized magnetic stripe.
- `END_USER_REQUEST` - The cardholder requested the closure of the card for
reasons unrelated to fraud or damage, such as switching to a different product
or closing the account.
- `ISSUER_REQUEST` - The issuer closed the card for reasons unrelated to fraud
or damage, such as account inactivity, product or policy changes, or
technology upgrades.
- `NOT_ACTIVE` - The card hasn’t had any transaction activity for a specified
period, applicable to statuses like `PAUSED` or `CLOSED`.
- `SUSPICIOUS_ACTIVITY` - The card has one or more suspicious transactions or
activities that require review. This can involve prompting the cardholder to
confirm legitimate use or report confirmed fraud.
- `INTERNAL_REVIEW` - The card is temporarily paused pending further internal
review.
- `EXPIRED` - The card has expired and has been closed without being reissued.
- `UNDELIVERABLE` - The card cannot be delivered to the cardholder and has been
returned.
- `OTHER` - The reason for the status does not fall into any of the above
categories. A comment should be provided to specify the reason.
shipping_method: Shipping method for the card. Only applies to cards of type PHYSICAL. Use of
options besides `STANDARD` require additional permissions.
- `STANDARD` - USPS regular mail or similar international option, with no
tracking
- `STANDARD_WITH_TRACKING` - USPS regular mail or similar international option,
with tracking
- `PRIORITY` - USPS Priority, 1-3 day shipping, with tracking
- `EXPRESS` - FedEx or UPS depending on card manufacturer, Express, 3-day
shipping, with tracking
- `2_DAY` - FedEx or UPS depending on card manufacturer, 2-day shipping, with
tracking
- `EXPEDITED` - FedEx or UPS depending on card manufacturer, Standard Overnight
or similar international option, with tracking
- `BULK` - Card will be shipped as part of a bulk fulfillment order. The
shipping method and timeline are inherited from the parent bulk order.
spend_limit: Amount (in cents) to limit approved authorizations (e.g. 100000 would be a
$1,000 limit). Transaction requests above the spend limit will be declined. Note
that a spend limit of 0 is effectively no limit, and should only be used to
reset or remove a prior limit. Only a limit of 1 or above will result in
declined transactions due to checks against the card limit.
spend_limit_duration:
Spend limit duration values:
- `ANNUALLY` - Card will authorize transactions up to spend limit for the
trailing year.
- `FOREVER` - Card will authorize only up to spend limit for the entire lifetime
of the card.
- `MONTHLY` - Card will authorize transactions up to spend limit for the
trailing month. To support recurring monthly payments, which can occur on
different day every month, the time window we consider for monthly velocity
starts 6 days after the current calendar date one month prior.
- `TRANSACTION` - Card will authorize multiple transactions if each individual
transaction is under the spend limit.
state:
Card state values:
- `OPEN` - Card will approve authorizations (if they match card and account
parameters).
- `PAUSED` - Card will decline authorizations, but can be resumed at a later
time.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._post(
"/v1/cards",
body=maybe_transform(
{
"type": type,
"account_token": account_token,
"bulk_order_token": bulk_order_token,
"card_program_token": card_program_token,
"carrier": carrier,
"digital_card_art_token": digital_card_art_token,
"exp_month": exp_month,
"exp_year": exp_year,
"memo": memo,
"pin": pin,
"product_id": product_id,
"replacement_account_token": replacement_account_token,
"replacement_comment": replacement_comment,
"replacement_for": replacement_for,
"replacement_substatus": replacement_substatus,
"shipping_address": shipping_address,
"shipping_method": shipping_method,
"spend_limit": spend_limit,
"spend_limit_duration": spend_limit_duration,
"state": state,
},
card_create_params.CardCreateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Card,
)
def retrieve(
self,
card_token: str,
*,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Card:
"""
Get card configuration such as spend limit and state.
Args:
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not card_token:
raise ValueError(f"Expected a non-empty value for `card_token` but received {card_token!r}")
return self._get(
path_template("/v1/cards/{card_token}", card_token=card_token),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Card,
)
def update(
self,
card_token: str,
*,
comment: str | Omit = omit,
digital_card_art_token: str | Omit = omit,
memo: str | Omit = omit,
network_program_token: str | Omit = omit,
pin: str | Omit = omit,
pin_status: Literal["OK"] | Omit = omit,
spend_limit: int | Omit = omit,
spend_limit_duration: SpendLimitDuration | Omit = omit,
state: Literal["CLOSED", "OPEN", "PAUSED"] | Omit = omit,
substatus: Literal[
"LOST",
"COMPROMISED",
"DAMAGED",
"END_USER_REQUEST",
"ISSUER_REQUEST",
"NOT_ACTIVE",
"SUSPICIOUS_ACTIVITY",
"INTERNAL_REVIEW",
"EXPIRED",
"UNDELIVERABLE",
"OTHER",
]
| Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Card:
"""Update the specified properties of the card.
Unsupplied properties will remain
unchanged.
_Note: setting a card to a `CLOSED` state is a final action that cannot be
undone._
Args:
comment: Additional context or information related to the card.
digital_card_art_token: Specifies the digital card art to be displayed in the user’s digital wallet
after tokenization. This artwork must be approved by Mastercard and configured
by Lithic to use. See
[Flexible Card Art Guide](https://docs.lithic.com/docs/about-digital-wallets#flexible-card-art).
memo: Friendly name to identify the card.
network_program_token: Globally unique identifier for the card's network program. Currently applicable
to Visa cards participating in Account Level Management only.
pin: Encrypted PIN block (in base64). Only applies to cards of type `PHYSICAL` and
`VIRTUAL`. Changing PIN also resets PIN status to `OK`. See
[Encrypted PIN Block](https://docs.lithic.com/docs/cards#encrypted-pin-block).
pin_status: Indicates if a card is blocked due a PIN status issue (e.g. excessive incorrect
attempts). Can only be set to `OK` to unblock a card.
spend_limit: Amount (in cents) to limit approved authorizations (e.g. 100000 would be a
$1,000 limit). Transaction requests above the spend limit will be declined. Note
that a spend limit of 0 is effectively no limit, and should only be used to
reset or remove a prior limit. Only a limit of 1 or above will result in
declined transactions due to checks against the card limit.
spend_limit_duration:
Spend limit duration values:
- `ANNUALLY` - Card will authorize transactions up to spend limit for the
trailing year.
- `FOREVER` - Card will authorize only up to spend limit for the entire lifetime
of the card.
- `MONTHLY` - Card will authorize transactions up to spend limit for the
trailing month. To support recurring monthly payments, which can occur on
different day every month, the time window we consider for monthly velocity
starts 6 days after the current calendar date one month prior.
- `TRANSACTION` - Card will authorize multiple transactions if each individual
transaction is under the spend limit.
state:
Card state values:
- `CLOSED` - Card will no longer approve authorizations. Closing a card cannot
be undone.
- `OPEN` - Card will approve authorizations (if they match card and account
parameters).
- `PAUSED` - Card will decline authorizations, but can be resumed at a later
time.
substatus:
Card state substatus values:
- `LOST` - The physical card is no longer in the cardholder's possession due to
being lost or never received by the cardholder.
- `COMPROMISED` - Card information has been exposed, potentially leading to
unauthorized access. This may involve physical card theft, cloning, or online
data breaches.
- `DAMAGED` - The physical card is not functioning properly, such as having chip
failures or a demagnetized magnetic stripe.
- `END_USER_REQUEST` - The cardholder requested the closure of the card for
reasons unrelated to fraud or damage, such as switching to a different product
or closing the account.
- `ISSUER_REQUEST` - The issuer closed the card for reasons unrelated to fraud
or damage, such as account inactivity, product or policy changes, or
technology upgrades.
- `NOT_ACTIVE` - The card hasn’t had any transaction activity for a specified
period, applicable to statuses like `PAUSED` or `CLOSED`.
- `SUSPICIOUS_ACTIVITY` - The card has one or more suspicious transactions or
activities that require review. This can involve prompting the cardholder to
confirm legitimate use or report confirmed fraud.
- `INTERNAL_REVIEW` - The card is temporarily paused pending further internal
review.
- `EXPIRED` - The card has expired and has been closed without being reissued.
- `UNDELIVERABLE` - The card cannot be delivered to the cardholder and has been
returned.
- `OTHER` - The reason for the status does not fall into any of the above
categories. A comment should be provided to specify the reason.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not card_token:
raise ValueError(f"Expected a non-empty value for `card_token` but received {card_token!r}")
return self._patch(
path_template("/v1/cards/{card_token}", card_token=card_token),
body=maybe_transform(
{
"comment": comment,
"digital_card_art_token": digital_card_art_token,
"memo": memo,
"network_program_token": network_program_token,
"pin": pin,
"pin_status": pin_status,
"spend_limit": spend_limit,
"spend_limit_duration": spend_limit_duration,
"state": state,
"substatus": substatus,
},
card_update_params.CardUpdateParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Card,
)
def list(
self,
*,
account_token: str | Omit = omit,
begin: Union[str, datetime] | Omit = omit,
end: Union[str, datetime] | Omit = omit,
ending_before: str | Omit = omit,
memo: str | Omit = omit,
page_size: int | Omit = omit,
starting_after: str | Omit = omit,
state: Literal["CLOSED", "OPEN", "PAUSED", "PENDING_ACTIVATION", "PENDING_FULFILLMENT"] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> SyncCursorPage[NonPCICard]:
"""
List cards.
Args:
account_token: Returns cards associated with the specified account.
begin: Date string in RFC 3339 format. Only entries created after the specified time
will be included. UTC time zone.
end: Date string in RFC 3339 format. Only entries created before the specified time
will be included. UTC time zone.
ending_before: A cursor representing an item's token before which a page of results should end.
Used to retrieve the previous page of results before this item.
memo: Returns cards containing the specified partial or full memo text.
page_size: Page size (for pagination).
starting_after: A cursor representing an item's token after which a page of results should
begin. Used to retrieve the next page of results after this item.
state: Returns cards with the specified state.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get_api_list(
"/v1/cards",
page=SyncCursorPage[NonPCICard],
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"account_token": account_token,
"begin": begin,
"end": end,
"ending_before": ending_before,
"memo": memo,
"page_size": page_size,
"starting_after": starting_after,
"state": state,
},
card_list_params.CardListParams,
),
),
model=NonPCICard,
)
def convert_physical(
self,
card_token: str,
*,
shipping_address: ShippingAddress,
carrier: Carrier | Omit = omit,
product_id: str | Omit = omit,
shipping_method: Literal[
"2_DAY", "BULK", "EXPEDITED", "EXPRESS", "PRIORITY", "STANDARD", "STANDARD_WITH_TRACKING"
]
| Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Card:
"""Convert a virtual card into a physical card and manufacture it.
Customer must
supply relevant fields for physical card creation including `product_id`,
`carrier`, `shipping_method`, and `shipping_address`. The card token will be
unchanged. The card's type will be altered to `PHYSICAL`. The card will be set
to state `PENDING_FULFILLMENT` and fulfilled at next fulfillment cycle. Virtual
cards created on card programs which do not support physical cards cannot be
converted. The card program cannot be changed as part of the conversion. Cards
must be in an `OPEN` state to be converted. Only applies to cards of type
`VIRTUAL` (or existing cards with deprecated types of `DIGITAL_WALLET` and
`UNLOCKED`).
Args:
shipping_address: The shipping address this card will be sent to.
carrier: If omitted, the previous carrier will be used.
product_id: Specifies the configuration (e.g. physical card art) that the card should be
manufactured with, and only applies to cards of type `PHYSICAL`. This must be
configured with Lithic before use.
shipping_method: Shipping method for the card. Only applies to cards of type PHYSICAL. Use of
options besides `STANDARD` require additional permissions.
- `STANDARD` - USPS regular mail or similar international option, with no
tracking
- `STANDARD_WITH_TRACKING` - USPS regular mail or similar international option,
with tracking
- `PRIORITY` - USPS Priority, 1-3 day shipping, with tracking
- `EXPRESS` - FedEx or UPS depending on card manufacturer, Express, 3-day
shipping, with tracking
- `2_DAY` - FedEx or UPS depending on card manufacturer, 2-day shipping, with
tracking
- `EXPEDITED` - FedEx or UPS depending on card manufacturer, Standard Overnight
or similar international option, with tracking
- `BULK` - Card will be shipped as part of a bulk fulfillment order. The
shipping method and timeline are inherited from the parent bulk order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not card_token:
raise ValueError(f"Expected a non-empty value for `card_token` but received {card_token!r}")
return self._post(
path_template("/v1/cards/{card_token}/convert_physical", card_token=card_token),
body=maybe_transform(
{
"shipping_address": shipping_address,
"carrier": carrier,
"product_id": product_id,
"shipping_method": shipping_method,
},
card_convert_physical_params.CardConvertPhysicalParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Card,
)
def embed(
self,
*,
embed_request: str,
hmac: str,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> str:
"""
Handling full card PANs and CVV codes requires that you comply with the Payment
Card Industry Data Security Standards (PCI DSS). Some clients choose to reduce
their compliance obligations by leveraging our embedded card UI solution
documented below.
In this setup, PANs and CVV codes are presented to the end-user via a card UI
that we provide, optionally styled in the customer's branding using a specified
css stylesheet. A user's browser makes the request directly to api.lithic.com,
so card PANs and CVVs never touch the API customer's servers while full card
data is displayed to their end-users. The response contains an HTML document
(see Embedded Card UI or Changelog for upcoming changes in January). This means
that the url for the request can be inserted straight into the `src` attribute
of an iframe.
```html
<iframe
id="card-iframe"
src="https://sandbox.lithic.com/v1/embed/card?embed_request=eyJjc3MiO...;hmac=r8tx1..."
allow="clipboard-write"
class="content"
></iframe>
```
You should compute the request payload on the server side. You can render it (or
the whole iframe) on the server or make an ajax call from your front end code,
but **do not ever embed your API key into front end code, as doing so introduces
a serious security vulnerability**.
Args:
embed_request: A base64 encoded JSON string of an EmbedRequest to specify which card to load.
hmac: SHA256 HMAC of the embed_request JSON string with base64 digest.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {"Accept": "text/html", **(extra_headers or {})}
return self._get(
"/v1/embed/card",
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
query=maybe_transform(
{
"embed_request": embed_request,
"hmac": hmac,
},
card_embed_params.CardEmbedParams,
),
),
cast_to=str,
)
def get_embed_html(
self,
*,
token: str,
css: str | Omit = omit,
expiration: Union[str, datetime] | Omit = omit,
target_origin: str | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> str:
"""
Generates and executes an embed request, returning html you can serve to the
user.
Be aware that this html contains sensitive data whose presence on your server
could trigger PCI DSS.
If your company is not certified PCI compliant, we recommend using
`get_embed_url()` instead. You would then pass that returned URL to the
frontend, where you can load it via an iframe.
"""
headers = _merge_mappings({"Accept": "text/html"}, extra_headers or {})
url = self.get_embed_url(
css=css,
token=token,
expiration=expiration,
target_origin=target_origin,
)
return self._get(
str(url),
cast_to=str,
options=make_request_options(
extra_headers=headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
),
)
def get_embed_url(
self,
*,
token: str,
css: str | Omit = omit,
expiration: Union[str, datetime] | Omit = omit,
target_origin: str | Omit = omit,
) -> URL:
"""
Handling full card PANs and CVV codes requires that you comply with the Payment
Card Industry Data Security Standards (PCI DSS). Some clients choose to reduce
their compliance obligations by leveraging our embedded card UI solution
documented below.
In this setup, PANs and CVV codes are presented to the end-user via a card UI
that we provide, optionally styled in the customer's branding using a specified
css stylesheet. A user's browser makes the request directly to api.lithic.com,
so card PANs and CVVs never touch the API customer's servers while full card
data is displayed to their end-users. The response contains an HTML document.
This means that the url for the request can be inserted straight into the `src`
attribute of an iframe.
```html
<iframe
id="card-iframe"
src="https://sandbox.lithic.com/v1/embed/card?embed_request=eyJjc3MiO...;hmac=r8tx1..."
allow="clipboard-write"
class="content"
></iframe>
```
You should compute the request payload on the server side. You can render it (or
the whole iframe) on the server or make an ajax call from your front end code,
but **do not ever embed your API key into front end code, as doing so introduces
a serious security vulnerability**.
"""
# Default expiration of 1 minute from now.
if isinstance(expiration, NotGiven):
expiration = datetime.now(timezone.utc) + timedelta(minutes=1)
query = maybe_transform(
strip_not_given(
{
"css": css,
"token": token,
"expiration": expiration,
"target_origin": target_origin,
}
),
card_get_embed_url_params.CardGetEmbedURLParams,
)
serialized = json.dumps(query, sort_keys=True, separators=(",", ":"))
params = {
"embed_request": base64.b64encode(bytes(serialized, "utf-8")).decode("utf-8"),
"hmac": base64.b64encode(
hmac.new(
key=bytes(self._client.api_key, "utf-8"),
msg=bytes(serialized, "utf-8"),
digestmod=hashlib.sha256,
).digest()
).decode("utf-8"),
}
# Copied nearly directly from httpx.BaseClient._merge_url
base_url = self._client.base_url
raw_path = base_url.raw_path + URL("v1/embed/card").raw_path
return base_url.copy_with(raw_path=raw_path).copy_merge_params(params)
def provision(
self,
card_token: str,
*,
certificate: Union[str, Base64FileInput] | Omit = omit,
client_device_id: str | Omit = omit,
client_wallet_account_id: str | Omit = omit,
digital_wallet: Literal["APPLE_PAY", "GOOGLE_PAY", "SAMSUNG_PAY"] | Omit = omit,
nonce: Union[str, Base64FileInput] | Omit = omit,
nonce_signature: Union[str, Base64FileInput] | Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> CardProvisionResponse:
"""
Allow your cardholders to directly add payment cards to the device's digital
wallet (e.g. Apple Pay) with one touch from your app.
This requires some additional setup and configuration. Please
[Contact Us](https://lithic.com/contact) or your Customer Success representative
for more information.
Args:
certificate: Only applicable if `digital_wallet` is `APPLE_PAY`. Omit to receive only
`activationData` in the response. Apple's public leaf certificate. Base64
encoded in PEM format with headers `(-----BEGIN CERTIFICATE-----)` and trailers
omitted. Provided by the device's wallet.
client_device_id: Only applicable if `digital_wallet` is `GOOGLE_PAY` or `SAMSUNG_PAY` and the
card is on the Visa network. Stable device identification set by the wallet
provider.
client_wallet_account_id: Only applicable if `digital_wallet` is `GOOGLE_PAY` or `SAMSUNG_PAY` and the
card is on the Visa network. Consumer ID that identifies the wallet account
holder entity.
digital_wallet: Name of digital wallet provider.
nonce: Only applicable if `digital_wallet` is `APPLE_PAY`. Omit to receive only
`activationData` in the response. Base64 cryptographic nonce provided by the
device's wallet.
nonce_signature: Only applicable if `digital_wallet` is `APPLE_PAY`. Omit to receive only
`activationData` in the response. Base64 cryptographic nonce provided by the
device's wallet.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not card_token:
raise ValueError(f"Expected a non-empty value for `card_token` but received {card_token!r}")
return self._post(
path_template("/v1/cards/{card_token}/provision", card_token=card_token),
body=maybe_transform(
{
"certificate": certificate,
"client_device_id": client_device_id,
"client_wallet_account_id": client_wallet_account_id,
"digital_wallet": digital_wallet,
"nonce": nonce,
"nonce_signature": nonce_signature,
},
card_provision_params.CardProvisionParams,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=CardProvisionResponse,
)
def reissue(
self,
card_token: str,
*,
carrier: Carrier | Omit = omit,
product_id: str | Omit = omit,
shipping_address: ShippingAddress | Omit = omit,
shipping_method: Literal[
"2_DAY", "BULK", "EXPEDITED", "EXPRESS", "PRIORITY", "STANDARD", "STANDARD_WITH_TRACKING"
]
| Omit = omit,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = not_given,
) -> Card:
"""Initiate print and shipment of a duplicate physical card (e.g.
card is
physically damaged). The PAN, expiry, and CVC2 will remain the same and the
original card can continue to be used until the new card is activated. Only
applies to cards of type `PHYSICAL`. A card can be reissued or renewed a total
of 8 times.
Args:
carrier: If omitted, the previous carrier will be used.
product_id: Specifies the configuration (e.g. physical card art) that the card should be
manufactured with, and only applies to cards of type `PHYSICAL`. This must be
configured with Lithic before use.
shipping_address: If omitted, the previous shipping address will be used.
shipping_method: Shipping method for the card. Only applies to cards of type PHYSICAL. Use of
options besides `STANDARD` require additional permissions.
- `STANDARD` - USPS regular mail or similar international option, with no
tracking
- `STANDARD_WITH_TRACKING` - USPS regular mail or similar international option,
with tracking
- `PRIORITY` - USPS Priority, 1-3 day shipping, with tracking
- `EXPRESS` - FedEx or UPS depending on card manufacturer, Express, 3-day
shipping, with tracking
- `2_DAY` - FedEx or UPS depending on card manufacturer, 2-day shipping, with
tracking
- `EXPEDITED` - FedEx or UPS depending on card manufacturer, Standard Overnight
or similar international option, with tracking
- `BULK` - Card will be shipped as part of a bulk fulfillment order. The
shipping method and timeline are inherited from the parent bulk order.
extra_headers: Send extra headers
extra_query: Add additional query parameters to the request
extra_body: Add additional JSON properties to the request
timeout: Override the client-level default timeout for this request, in seconds
"""
if not card_token:
raise ValueError(f"Expected a non-empty value for `card_token` but received {card_token!r}")
return self._post(
path_template("/v1/cards/{card_token}/reissue", card_token=card_token),