-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcard.go
More file actions
2032 lines (1864 loc) · 93.2 KB
/
card.go
File metadata and controls
2032 lines (1864 loc) · 93.2 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.
package lithic
import (
"context"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"slices"
"time"
"github.com/lithic-com/lithic-go/internal/apijson"
"github.com/lithic-com/lithic-go/internal/apiquery"
"github.com/lithic-com/lithic-go/internal/param"
"github.com/lithic-com/lithic-go/internal/requestconfig"
"github.com/lithic-com/lithic-go/option"
"github.com/lithic-com/lithic-go/packages/pagination"
"github.com/lithic-com/lithic-go/shared"
"github.com/tidwall/gjson"
)
// CardService contains methods and other services that help with interacting with
// the lithic API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCardService] method instead.
type CardService struct {
Options []option.RequestOption
Balances *CardBalanceService
FinancialTransactions *CardFinancialTransactionService
}
// NewCardService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewCardService(opts ...option.RequestOption) (r *CardService) {
r = &CardService{}
r.Options = opts
r.Balances = NewCardBalanceService(opts...)
r.FinancialTransactions = NewCardFinancialTransactionService(opts...)
return
}
// Create a new virtual or physical card. Parameters `shipping_address` and
// `product_id` only apply to physical cards.
func (r *CardService) New(ctx context.Context, params CardNewParams, opts ...option.RequestOption) (res *Card, err error) {
if params.IdempotencyKey.Present {
opts = append(opts, option.WithHeader("Idempotency-Key", fmt.Sprintf("%v", params.IdempotencyKey)))
}
opts = slices.Concat(r.Options, opts)
path := "v1/cards"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
}
// Get card configuration such as spend limit and state.
func (r *CardService) Get(ctx context.Context, cardToken string, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// 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._
func (r *CardService) Update(ctx context.Context, cardToken string, body CardUpdateParams, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List cards.
func (r *CardService) List(ctx context.Context, query CardListParams, opts ...option.RequestOption) (res *pagination.CursorPage[NonPCICard], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/cards"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List cards.
func (r *CardService) ListAutoPaging(ctx context.Context, query CardListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[NonPCICard] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// 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`).
func (r *CardService) ConvertPhysical(ctx context.Context, cardToken string, body CardConvertPhysicalParams, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/convert_physical", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// 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**.
func (r *CardService) Embed(ctx context.Context, query CardEmbedParams, opts ...option.RequestOption) (res *string, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "text/html")}, opts...)
path := "v1/embed/card"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
func (r *CardService) GetEmbedHTML(ctx context.Context, params CardGetEmbedHTMLParams, opts ...option.RequestOption) (res []byte, err error) {
opts = append(r.Options, opts...)
buf, err := params.MarshalJSON()
if err != nil {
return nil, err
}
cfg, err := requestconfig.NewRequestConfig(ctx, "GET", "v1/embed/card", nil, &res, opts...)
if err != nil {
return nil, err
}
mac := hmac.New(sha256.New, []byte(cfg.APIKey))
mac.Write(buf)
sign := mac.Sum(nil)
err = cfg.Apply(
option.WithHeader("Accept", "text/html"),
option.WithQuery("hmac", base64.StdEncoding.EncodeToString(sign)),
option.WithQuery("embed_request", base64.StdEncoding.EncodeToString(buf)),
)
if err != nil {
return nil, err
}
err = cfg.Execute()
return
}
// 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**.
func (r *CardService) GetEmbedURL(ctx context.Context, params CardGetEmbedURLParams, opts ...option.RequestOption) (res *url.URL, err error) {
opts = slices.Concat(r.Options, opts)
buf, err := params.MarshalJSON()
if err != nil {
return nil, err
}
cfg, err := requestconfig.NewRequestConfig(ctx, "GET", "v1/embed/card", nil, &res, opts...)
if err != nil {
return nil, err
}
mac := hmac.New(sha256.New, []byte(cfg.APIKey))
mac.Write(buf)
sign := mac.Sum(nil)
err = cfg.Apply(
option.WithQuery("hmac", base64.StdEncoding.EncodeToString(sign)),
option.WithQuery("embed_request", base64.StdEncoding.EncodeToString(buf)),
)
if err != nil {
return nil, err
}
baseURL := cfg.BaseURL
if baseURL == nil {
baseURL = cfg.DefaultBaseURL
}
if baseURL == nil {
return nil, errors.New("base url is not set")
}
return baseURL.Parse(cfg.Request.URL.String())
}
// 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.
func (r *CardService) Provision(ctx context.Context, cardToken string, body CardProvisionParams, opts ...option.RequestOption) (res *CardProvisionResponse, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/provision", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// 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.
func (r *CardService) Reissue(ctx context.Context, cardToken string, body CardReissueParams, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/reissue", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Applies to card types `PHYSICAL` and `VIRTUAL`. For `PHYSICAL`, creates a new
// card with the same card token and PAN, but updated expiry and CVC2 code. The
// original card will keep working for card-present transactions until the new card
// is activated. For card-not-present transactions, the original card details
// (expiry, CVC2) will also keep working until the new card is activated. A
// `PHYSICAL` card can be reissued or renewed a total of 8 times. For `VIRTUAL`,
// the card will retain the same card token and PAN and receive an updated expiry
// and CVC2 code. `product_id`, `shipping_method`, `shipping_address`, `carrier`
// are only relevant for renewing `PHYSICAL` cards.
func (r *CardService) Renew(ctx context.Context, cardToken string, body CardRenewParams, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/renew", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get a Card's available spend limit, which is based on the spend limit configured
// on the Card and the amount already spent over the spend limit's duration. For
// example, if the Card has a monthly spend limit of $1000 configured, and has
// spent $600 in the last month, the available spend limit returned would be $400.
func (r *CardService) GetSpendLimits(ctx context.Context, cardToken string, opts ...option.RequestOption) (res *CardSpendLimits, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/spend_limits", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Get card configuration such as spend limit and state. Customers must be PCI
// compliant to use this endpoint. Please contact
// [support@lithic.com](mailto:support@lithic.com) for questions. _Note: this is a
// `POST` endpoint because it is more secure to send sensitive data in a request
// body than in a URL._
func (r *CardService) SearchByPan(ctx context.Context, body CardSearchByPanParams, opts ...option.RequestOption) (res *Card, err error) {
opts = slices.Concat(r.Options, opts)
path := "v1/cards/search_by_pan"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Allow your cardholders to directly add payment cards to the device's digital
// wallet from a browser on the web.
//
// This requires some additional setup and configuration. Please
// [Contact Us](https://lithic.com/contact) or your Customer Success representative
// for more information.
func (r *CardService) WebProvision(ctx context.Context, cardToken string, body CardWebProvisionParams, opts ...option.RequestOption) (res *CardWebProvisionResponse, err error) {
opts = slices.Concat(r.Options, opts)
if cardToken == "" {
err = errors.New("missing required card_token parameter")
return
}
path := fmt.Sprintf("v1/cards/%s/web_provision", cardToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Card details with potentially PCI sensitive information for Enterprise customers
type Card struct {
// Three digit cvv printed on the back of the card.
Cvv string `json:"cvv"`
// Primary Account Number (PAN) (i.e. the card number). Customers must be PCI
// compliant to have PAN returned as a field in production. Please contact
// support@lithic.com for questions.
Pan string `json:"pan"`
JSON cardJSON `json:"-"`
NonPCICard
}
// cardJSON contains the JSON metadata for the struct [Card]
type cardJSON struct {
Cvv apijson.Field
Pan apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Card) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardJSON) RawJSON() string {
return r.raw
}
type CardSpendLimits struct {
AvailableSpendLimit CardSpendLimitsAvailableSpendLimit `json:"available_spend_limit" api:"required"`
SpendLimit CardSpendLimitsSpendLimit `json:"spend_limit"`
SpendVelocity CardSpendLimitsSpendVelocity `json:"spend_velocity"`
JSON cardSpendLimitsJSON `json:"-"`
}
// cardSpendLimitsJSON contains the JSON metadata for the struct [CardSpendLimits]
type cardSpendLimitsJSON struct {
AvailableSpendLimit apijson.Field
SpendLimit apijson.Field
SpendVelocity apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardSpendLimits) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardSpendLimitsJSON) RawJSON() string {
return r.raw
}
type CardSpendLimitsAvailableSpendLimit struct {
// The available spend limit (in cents) relative to the annual limit configured on
// the Card (e.g. 100000 would be a $1,000 limit).
Annually int64 `json:"annually"`
// The available spend limit (in cents) relative to the forever limit configured on
// the Card.
Forever int64 `json:"forever"`
// The available spend limit (in cents) relative to the monthly limit configured on
// the Card.
Monthly int64 `json:"monthly"`
JSON cardSpendLimitsAvailableSpendLimitJSON `json:"-"`
}
// cardSpendLimitsAvailableSpendLimitJSON contains the JSON metadata for the struct
// [CardSpendLimitsAvailableSpendLimit]
type cardSpendLimitsAvailableSpendLimitJSON struct {
Annually apijson.Field
Forever apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardSpendLimitsAvailableSpendLimit) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardSpendLimitsAvailableSpendLimitJSON) RawJSON() string {
return r.raw
}
type CardSpendLimitsSpendLimit struct {
// The configured annual spend limit (in cents) on the Card.
Annually int64 `json:"annually"`
// The configured forever spend limit (in cents) on the Card.
Forever int64 `json:"forever"`
// The configured monthly spend limit (in cents) on the Card.
Monthly int64 `json:"monthly"`
JSON cardSpendLimitsSpendLimitJSON `json:"-"`
}
// cardSpendLimitsSpendLimitJSON contains the JSON metadata for the struct
// [CardSpendLimitsSpendLimit]
type cardSpendLimitsSpendLimitJSON struct {
Annually apijson.Field
Forever apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardSpendLimitsSpendLimit) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardSpendLimitsSpendLimitJSON) RawJSON() string {
return r.raw
}
type CardSpendLimitsSpendVelocity struct {
// Current annual spend velocity (in cents) on the Card. Present if annual spend
// limit is set.
Annually int64 `json:"annually"`
// Current forever spend velocity (in cents) on the Card. Present if forever spend
// limit is set.
Forever int64 `json:"forever"`
// Current monthly spend velocity (in cents) on the Card. Present if monthly spend
// limit is set.
Monthly int64 `json:"monthly"`
JSON cardSpendLimitsSpendVelocityJSON `json:"-"`
}
// cardSpendLimitsSpendVelocityJSON contains the JSON metadata for the struct
// [CardSpendLimitsSpendVelocity]
type cardSpendLimitsSpendVelocityJSON struct {
Annually apijson.Field
Forever apijson.Field
Monthly apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardSpendLimitsSpendVelocity) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardSpendLimitsSpendVelocityJSON) RawJSON() string {
return r.raw
}
// Card details without PCI information
type NonPCICard struct {
// Globally unique identifier.
Token string `json:"token" api:"required"`
// Globally unique identifier for the account to which the card belongs.
AccountToken string `json:"account_token" api:"required"`
// Globally unique identifier for the card program on which the card exists.
CardProgramToken string `json:"card_program_token" api:"required"`
// An RFC 3339 timestamp for when the card was created. UTC time zone.
Created time.Time `json:"created" api:"required" format:"date-time"`
// Deprecated: Funding account for the card.
Funding NonPCICardFunding `json:"funding" api:"required"`
// Last four digits of the card number.
LastFour string `json:"last_four" api:"required"`
// Indicates if a card is blocked due a PIN status issue (e.g. excessive incorrect
// attempts).
PinStatus NonPCICardPinStatus `json:"pin_status" api:"required"`
// 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.
SpendLimit int64 `json:"spend_limit" api:"required"`
// 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.
SpendLimitDuration SpendLimitDuration `json:"spend_limit_duration" api:"required"`
// 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. _ `PENDING_FULFILLMENT` -
// The initial state for cards of type `PHYSICAL`. The card is provisioned pending
// manufacturing and fulfillment. Cards in this state can accept authorizations for
// e-commerce purchases, but not for "Card Present" purchases where the physical
// card itself is present. \* `PENDING_ACTIVATION` - At regular intervals, cards of
// type `PHYSICAL` in state `PENDING_FULFILLMENT` are sent to the card production
// warehouse and updated to state `PENDING_ACTIVATION`. Similar to
// `PENDING_FULFILLMENT`, cards in this state can be used for e-commerce
// transactions or can be added to mobile wallets. API clients should update the
// card's state to `OPEN` only after the cardholder confirms receipt of the card.
// In sandbox, the same daily batch fulfillment occurs, but no cards are actually
// manufactured.
State NonPCICardState `json:"state" api:"required"`
// 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. _ `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.
Type NonPCICardType `json:"type" api:"required"`
// List of identifiers for the Auth Rule(s) that are applied on the card. This
// field is deprecated and will no longer be populated in the `Card` object. The
// key will be removed from the schema in a future release. Use the `/auth_rules`
// endpoints to fetch Auth Rule information instead.
//
// Deprecated: deprecated
AuthRuleTokens []string `json:"auth_rule_tokens"`
// Globally unique identifier for the bulk order associated with this card. Only
// applicable to physical cards that are part of a bulk shipment
BulkOrderToken string `json:"bulk_order_token" api:"nullable" format:"uuid"`
// 3-character alphabetic ISO 4217 code for the currency of the cardholder.
CardholderCurrency string `json:"cardholder_currency"`
// Additional context or information related to the card.
Comment string `json:"comment"`
// 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.
DigitalCardArtToken string `json:"digital_card_art_token"`
// Two digit (MM) expiry month.
ExpMonth string `json:"exp_month"`
// Four digit (yyyy) expiry year.
ExpYear string `json:"exp_year"`
// Hostname of card's locked merchant (will be empty if not applicable).
Hostname string `json:"hostname"`
// Friendly name to identify the card.
Memo string `json:"memo"`
// Globally unique identifier for the card's network program. Null if the card is
// not associated with a network program. Currently applicable to Visa cards
// participating in Account Level Management only
NetworkProgramToken string `json:"network_program_token" api:"nullable"`
// Indicates if there are offline PIN changes pending card interaction with an
// offline PIN terminal. Possible commands are: CHANGE_PIN, UNBLOCK_PIN. Applicable
// only to cards issued in markets supporting offline PINs.
PendingCommands []string `json:"pending_commands"`
// 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.
ProductID string `json:"product_id"`
// If the card is a replacement for another card, the globally unique identifier
// for the card that was replaced.
ReplacementFor string `json:"replacement_for" api:"nullable"`
// 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 can be provided to specify the reason.
Substatus NonPCICardSubstatus `json:"substatus"`
JSON nonPCICardJSON `json:"-"`
}
// nonPCICardJSON contains the JSON metadata for the struct [NonPCICard]
type nonPCICardJSON struct {
Token apijson.Field
AccountToken apijson.Field
CardProgramToken apijson.Field
Created apijson.Field
Funding apijson.Field
LastFour apijson.Field
PinStatus apijson.Field
SpendLimit apijson.Field
SpendLimitDuration apijson.Field
State apijson.Field
Type apijson.Field
AuthRuleTokens apijson.Field
BulkOrderToken apijson.Field
CardholderCurrency apijson.Field
Comment apijson.Field
DigitalCardArtToken apijson.Field
ExpMonth apijson.Field
ExpYear apijson.Field
Hostname apijson.Field
Memo apijson.Field
NetworkProgramToken apijson.Field
PendingCommands apijson.Field
ProductID apijson.Field
ReplacementFor apijson.Field
Substatus apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *NonPCICard) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r nonPCICardJSON) RawJSON() string {
return r.raw
}
// Deprecated: Funding account for the card.
type NonPCICardFunding struct {
// A globally unique identifier for this FundingAccount.
Token string `json:"token" api:"required" format:"uuid"`
// An RFC 3339 string representing when this funding source was added to the Lithic
// account. This may be `null`. UTC time zone.
Created time.Time `json:"created" api:"required" format:"date-time"`
// The last 4 digits of the account (e.g. bank account, debit card) associated with
// this FundingAccount. This may be null.
LastFour string `json:"last_four" api:"required"`
// State of funding source. Funding source states: _ `ENABLED` - The funding
// account is available to use for card creation and transactions. _ `PENDING` -
// The funding account is still being verified e.g. bank micro-deposits
// verification. \* `DELETED` - The founding account has been deleted.
State NonPCICardFundingState `json:"state" api:"required"`
// Types of funding source: _ `DEPOSITORY_CHECKING` - Bank checking account. _
// `DEPOSITORY_SAVINGS` - Bank savings account.
Type NonPCICardFundingType `json:"type" api:"required"`
// Account name identifying the funding source. This may be `null`.
AccountName string `json:"account_name"`
// The nickname given to the `FundingAccount` or `null` if it has no nickname.
Nickname string `json:"nickname"`
JSON nonPCICardFundingJSON `json:"-"`
}
// nonPCICardFundingJSON contains the JSON metadata for the struct
// [NonPCICardFunding]
type nonPCICardFundingJSON struct {
Token apijson.Field
Created apijson.Field
LastFour apijson.Field
State apijson.Field
Type apijson.Field
AccountName apijson.Field
Nickname apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *NonPCICardFunding) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r nonPCICardFundingJSON) RawJSON() string {
return r.raw
}
// State of funding source. Funding source states: _ `ENABLED` - The funding
// account is available to use for card creation and transactions. _ `PENDING` -
// The funding account is still being verified e.g. bank micro-deposits
// verification. \* `DELETED` - The founding account has been deleted.
type NonPCICardFundingState string
const (
NonPCICardFundingStateDeleted NonPCICardFundingState = "DELETED"
NonPCICardFundingStateEnabled NonPCICardFundingState = "ENABLED"
NonPCICardFundingStatePending NonPCICardFundingState = "PENDING"
)
func (r NonPCICardFundingState) IsKnown() bool {
switch r {
case NonPCICardFundingStateDeleted, NonPCICardFundingStateEnabled, NonPCICardFundingStatePending:
return true
}
return false
}
// Types of funding source: _ `DEPOSITORY_CHECKING` - Bank checking account. _
// `DEPOSITORY_SAVINGS` - Bank savings account.
type NonPCICardFundingType string
const (
NonPCICardFundingTypeDepositoryChecking NonPCICardFundingType = "DEPOSITORY_CHECKING"
NonPCICardFundingTypeDepositorySavings NonPCICardFundingType = "DEPOSITORY_SAVINGS"
)
func (r NonPCICardFundingType) IsKnown() bool {
switch r {
case NonPCICardFundingTypeDepositoryChecking, NonPCICardFundingTypeDepositorySavings:
return true
}
return false
}
// Indicates if a card is blocked due a PIN status issue (e.g. excessive incorrect
// attempts).
type NonPCICardPinStatus string
const (
NonPCICardPinStatusOk NonPCICardPinStatus = "OK"
NonPCICardPinStatusBlocked NonPCICardPinStatus = "BLOCKED"
NonPCICardPinStatusNotSet NonPCICardPinStatus = "NOT_SET"
)
func (r NonPCICardPinStatus) IsKnown() bool {
switch r {
case NonPCICardPinStatusOk, NonPCICardPinStatusBlocked, NonPCICardPinStatusNotSet:
return true
}
return false
}
// 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. _ `PENDING_FULFILLMENT` -
// The initial state for cards of type `PHYSICAL`. The card is provisioned pending
// manufacturing and fulfillment. Cards in this state can accept authorizations for
// e-commerce purchases, but not for "Card Present" purchases where the physical
// card itself is present. \* `PENDING_ACTIVATION` - At regular intervals, cards of
// type `PHYSICAL` in state `PENDING_FULFILLMENT` are sent to the card production
// warehouse and updated to state `PENDING_ACTIVATION`. Similar to
// `PENDING_FULFILLMENT`, cards in this state can be used for e-commerce
// transactions or can be added to mobile wallets. API clients should update the
// card's state to `OPEN` only after the cardholder confirms receipt of the card.
// In sandbox, the same daily batch fulfillment occurs, but no cards are actually
// manufactured.
type NonPCICardState string
const (
NonPCICardStateClosed NonPCICardState = "CLOSED"
NonPCICardStateOpen NonPCICardState = "OPEN"
NonPCICardStatePaused NonPCICardState = "PAUSED"
NonPCICardStatePendingActivation NonPCICardState = "PENDING_ACTIVATION"
NonPCICardStatePendingFulfillment NonPCICardState = "PENDING_FULFILLMENT"
)
func (r NonPCICardState) IsKnown() bool {
switch r {
case NonPCICardStateClosed, NonPCICardStateOpen, NonPCICardStatePaused, NonPCICardStatePendingActivation, NonPCICardStatePendingFulfillment:
return true
}
return false
}
// 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. _ `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.
type NonPCICardType string
const (
NonPCICardTypeMerchantLocked NonPCICardType = "MERCHANT_LOCKED"
NonPCICardTypePhysical NonPCICardType = "PHYSICAL"
NonPCICardTypeSingleUse NonPCICardType = "SINGLE_USE"
NonPCICardTypeVirtual NonPCICardType = "VIRTUAL"
NonPCICardTypeUnlocked NonPCICardType = "UNLOCKED"
NonPCICardTypeDigitalWallet NonPCICardType = "DIGITAL_WALLET"
)
func (r NonPCICardType) IsKnown() bool {
switch r {
case NonPCICardTypeMerchantLocked, NonPCICardTypePhysical, NonPCICardTypeSingleUse, NonPCICardTypeVirtual, NonPCICardTypeUnlocked, NonPCICardTypeDigitalWallet:
return true
}
return false
}
// 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 can be provided to specify the reason.
type NonPCICardSubstatus string
const (
NonPCICardSubstatusLost NonPCICardSubstatus = "LOST"
NonPCICardSubstatusCompromised NonPCICardSubstatus = "COMPROMISED"
NonPCICardSubstatusDamaged NonPCICardSubstatus = "DAMAGED"
NonPCICardSubstatusEndUserRequest NonPCICardSubstatus = "END_USER_REQUEST"
NonPCICardSubstatusIssuerRequest NonPCICardSubstatus = "ISSUER_REQUEST"
NonPCICardSubstatusNotActive NonPCICardSubstatus = "NOT_ACTIVE"
NonPCICardSubstatusSuspiciousActivity NonPCICardSubstatus = "SUSPICIOUS_ACTIVITY"
NonPCICardSubstatusInternalReview NonPCICardSubstatus = "INTERNAL_REVIEW"
NonPCICardSubstatusExpired NonPCICardSubstatus = "EXPIRED"
NonPCICardSubstatusUndeliverable NonPCICardSubstatus = "UNDELIVERABLE"
NonPCICardSubstatusOther NonPCICardSubstatus = "OTHER"
)
func (r NonPCICardSubstatus) IsKnown() bool {
switch r {
case NonPCICardSubstatusLost, NonPCICardSubstatusCompromised, NonPCICardSubstatusDamaged, NonPCICardSubstatusEndUserRequest, NonPCICardSubstatusIssuerRequest, NonPCICardSubstatusNotActive, NonPCICardSubstatusSuspiciousActivity, NonPCICardSubstatusInternalReview, NonPCICardSubstatusExpired, NonPCICardSubstatusUndeliverable, NonPCICardSubstatusOther:
return true
}
return false
}
// Object containing the fields required to add a card to Apple Pay. Applies only
// to Apple Pay wallet.
type ProvisionResponse struct {
ActivationData string `json:"activationData"`
EncryptedData string `json:"encryptedData"`
EphemeralPublicKey string `json:"ephemeralPublicKey"`
JSON provisionResponseJSON `json:"-"`
}
// provisionResponseJSON contains the JSON metadata for the struct
// [ProvisionResponse]
type provisionResponseJSON struct {
ActivationData apijson.Field
EncryptedData apijson.Field
EphemeralPublicKey apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ProvisionResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r provisionResponseJSON) RawJSON() string {
return r.raw
}
func (r ProvisionResponse) ImplementsCardProvisionResponseProvisioningPayloadUnion() {}
// 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.
type SpendLimitDuration string
const (
SpendLimitDurationAnnually SpendLimitDuration = "ANNUALLY"
SpendLimitDurationForever SpendLimitDuration = "FOREVER"
SpendLimitDurationMonthly SpendLimitDuration = "MONTHLY"
SpendLimitDurationTransaction SpendLimitDuration = "TRANSACTION"
)
func (r SpendLimitDuration) IsKnown() bool {
switch r {
case SpendLimitDurationAnnually, SpendLimitDurationForever, SpendLimitDurationMonthly, SpendLimitDurationTransaction:
return true
}
return false
}
type CardProvisionResponse struct {
// Base64 encoded JSON payload representing a payment card that can be passed to a
// device's digital wallet. Applies to Google and Samsung Pay wallets.
ProvisioningPayload CardProvisionResponseProvisioningPayloadUnion `json:"provisioning_payload"`
JSON cardProvisionResponseJSON `json:"-"`
}
// cardProvisionResponseJSON contains the JSON metadata for the struct
// [CardProvisionResponse]
type cardProvisionResponseJSON struct {
ProvisioningPayload apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CardProvisionResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r cardProvisionResponseJSON) RawJSON() string {
return r.raw
}
// Base64 encoded JSON payload representing a payment card that can be passed to a
// device's digital wallet. Applies to Google and Samsung Pay wallets.
//
// Union satisfied by [shared.UnionString] or [ProvisionResponse].
type CardProvisionResponseProvisioningPayloadUnion interface {
ImplementsCardProvisionResponseProvisioningPayloadUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*CardProvisionResponseProvisioningPayloadUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ProvisionResponse{}),
},
)
}
type CardWebProvisionResponse struct {
// A base64 encoded and encrypted payload representing card data for the Google Pay
// UWPP FPAN flow.
GoogleOpc string `json:"google_opc"`
// This field can have the runtime type of
// [CardWebProvisionResponseAppleWebPushProvisioningResponseJws].
Jws interface{} `json:"jws"`
// A unique identifier for the JWS object.
State string `json:"state"`
// A base64 encoded and encrypted payload representing card data for the Google Pay
// UWPP tokenization flow.
TspOpc string `json:"tsp_opc"`
JSON cardWebProvisionResponseJSON `json:"-"`
union CardWebProvisionResponseUnion
}
// cardWebProvisionResponseJSON contains the JSON metadata for the struct
// [CardWebProvisionResponse]
type cardWebProvisionResponseJSON struct {
GoogleOpc apijson.Field
Jws apijson.Field
State apijson.Field
TspOpc apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r cardWebProvisionResponseJSON) RawJSON() string {
return r.raw
}
func (r *CardWebProvisionResponse) UnmarshalJSON(data []byte) (err error) {
*r = CardWebProvisionResponse{}