-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauthrulev2.go
More file actions
6254 lines (5557 loc) · 397 KB
/
authrulev2.go
File metadata and controls
6254 lines (5557 loc) · 397 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"
"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"
)
// AuthRuleV2Service 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 [NewAuthRuleV2Service] method instead.
type AuthRuleV2Service struct {
Options []option.RequestOption
Backtests *AuthRuleV2BacktestService
}
// NewAuthRuleV2Service 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 NewAuthRuleV2Service(opts ...option.RequestOption) (r *AuthRuleV2Service) {
r = &AuthRuleV2Service{}
r.Options = opts
r.Backtests = NewAuthRuleV2BacktestService(opts...)
return
}
// Creates a new V2 Auth rule in draft mode
func (r *AuthRuleV2Service) New(ctx context.Context, body AuthRuleV2NewParams, opts ...option.RequestOption) (res *AuthRule, err error) {
opts = slices.Concat(r.Options, opts)
path := "v2/auth_rules"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Fetches a V2 Auth rule by its token
func (r *AuthRuleV2Service) Get(ctx context.Context, authRuleToken string, opts ...option.RequestOption) (res *AuthRule, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Updates a V2 Auth rule's properties
//
// If `account_tokens`, `card_tokens`, `program_level`, or `excluded_card_tokens`
// is provided, this will replace existing associations with the provided list of
// entities.
func (r *AuthRuleV2Service) Update(ctx context.Context, authRuleToken string, body AuthRuleV2UpdateParams, opts ...option.RequestOption) (res *AuthRule, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// Lists V2 Auth rules
func (r *AuthRuleV2Service) List(ctx context.Context, query AuthRuleV2ListParams, opts ...option.RequestOption) (res *pagination.CursorPage[AuthRule], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v2/auth_rules"
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
}
// Lists V2 Auth rules
func (r *AuthRuleV2Service) ListAutoPaging(ctx context.Context, query AuthRuleV2ListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[AuthRule] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Deletes a V2 Auth rule
func (r *AuthRuleV2Service) Delete(ctx context.Context, authRuleToken string, opts ...option.RequestOption) (err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "*/*")}, opts...)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
return
}
// Creates a new draft version of a rule that will be ran in shadow mode.
//
// This can also be utilized to reset the draft parameters, causing a draft version
// to no longer be ran in shadow mode.
func (r *AuthRuleV2Service) Draft(ctx context.Context, authRuleToken string, body AuthRuleV2DraftParams, opts ...option.RequestOption) (res *AuthRule, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s/draft", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Lists Auth Rule evaluation results.
//
// **Limitations:**
//
// - Results are available for the past 3 months only
// - At least one filter (`event_token` or `auth_rule_token`) must be provided
// - When filtering by `event_token`, pagination is not supported
func (r *AuthRuleV2Service) ListResults(ctx context.Context, query AuthRuleV2ListResultsParams, opts ...option.RequestOption) (res *pagination.CursorPage[AuthRuleV2ListResultsResponse], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v2/auth_rules/results"
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
}
// Lists Auth Rule evaluation results.
//
// **Limitations:**
//
// - Results are available for the past 3 months only
// - At least one filter (`event_token` or `auth_rule_token`) must be provided
// - When filtering by `event_token`, pagination is not supported
func (r *AuthRuleV2Service) ListResultsAutoPaging(ctx context.Context, query AuthRuleV2ListResultsParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[AuthRuleV2ListResultsResponse] {
return pagination.NewCursorPageAutoPager(r.ListResults(ctx, query, opts...))
}
// Promotes the draft version of an Auth rule to the currently active version such
// that it is enforced in the respective stream.
func (r *AuthRuleV2Service) Promote(ctx context.Context, authRuleToken string, opts ...option.RequestOption) (res *AuthRule, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s/promote", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Fetches the current calculated Feature values for the given Auth Rule
//
// This only calculates the features for the active version.
//
// - VelocityLimit Rules calculates the current Velocity Feature data. This
// requires a `card_token` or `account_token` matching what the rule is Scoped
// to.
// - ConditionalBlock Rules calculates the CARD*TRANSACTION_COUNT*\* attributes on
// the rule. This requires a `card_token`
func (r *AuthRuleV2Service) GetFeatures(ctx context.Context, authRuleToken string, query AuthRuleV2GetFeaturesParams, opts ...option.RequestOption) (res *AuthRuleV2GetFeaturesResponse, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s/features", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
// Retrieves a performance report for an Auth rule containing daily statistics and
// evaluation outcomes.
//
// **Time Range Limitations:**
//
// - Reports are supported for the past 3 months only
// - Maximum interval length is 1 month
// - Report data is available only through the previous day in UTC (current day
// data is not available)
//
// The report provides daily statistics for both current and draft versions of the
// Auth rule, including approval, decline, and challenge counts along with sample
// events.
func (r *AuthRuleV2Service) GetReport(ctx context.Context, authRuleToken string, query AuthRuleV2GetReportParams, opts ...option.RequestOption) (res *AuthRuleV2GetReportResponse, err error) {
opts = slices.Concat(r.Options, opts)
if authRuleToken == "" {
err = errors.New("missing required auth_rule_token parameter")
return
}
path := fmt.Sprintf("v2/auth_rules/%s/report", authRuleToken)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
type AuthRule struct {
// Auth Rule Token
Token string `json:"token" api:"required" format:"uuid"`
// Account tokens to which the Auth Rule applies.
AccountTokens []string `json:"account_tokens" api:"required" format:"uuid"`
// Business Account tokens to which the Auth Rule applies.
BusinessAccountTokens []string `json:"business_account_tokens" api:"required" format:"uuid"`
// Card tokens to which the Auth Rule applies.
CardTokens []string `json:"card_tokens" api:"required" format:"uuid"`
CurrentVersion AuthRuleCurrentVersion `json:"current_version" api:"required,nullable"`
DraftVersion AuthRuleDraftVersion `json:"draft_version" api:"required,nullable"`
// The event stream during which the rule will be evaluated.
EventStream EventStream `json:"event_stream" api:"required"`
// Indicates whether this auth rule is managed by Lithic. If true, the rule cannot
// be modified or deleted by the user
LithicManaged bool `json:"lithic_managed" api:"required"`
// Auth Rule Name
Name string `json:"name" api:"required,nullable"`
// Whether the Auth Rule applies to all authorizations on the card program.
ProgramLevel bool `json:"program_level" api:"required"`
// The state of the Auth Rule
State AuthRuleState `json:"state" api:"required"`
// The type of Auth Rule. For certain rule types, this determines the event stream
// during which it will be evaluated. For rules that can be applied to one of
// several event streams, the effective one is defined by the separate
// `event_stream` field.
//
// - `CONDITIONAL_BLOCK`: Deprecated. Use `CONDITIONAL_ACTION` instead.
// AUTHORIZATION event stream.
// - `VELOCITY_LIMIT`: AUTHORIZATION event stream.
// - `MERCHANT_LOCK`: AUTHORIZATION event stream.
// - `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
// ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
Type AuthRuleType `json:"type" api:"required"`
// Card tokens to which the Auth Rule does not apply.
ExcludedCardTokens []string `json:"excluded_card_tokens" format:"uuid"`
JSON authRuleJSON `json:"-"`
}
// authRuleJSON contains the JSON metadata for the struct [AuthRule]
type authRuleJSON struct {
Token apijson.Field
AccountTokens apijson.Field
BusinessAccountTokens apijson.Field
CardTokens apijson.Field
CurrentVersion apijson.Field
DraftVersion apijson.Field
EventStream apijson.Field
LithicManaged apijson.Field
Name apijson.Field
ProgramLevel apijson.Field
State apijson.Field
Type apijson.Field
ExcludedCardTokens apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AuthRule) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r authRuleJSON) RawJSON() string {
return r.raw
}
type AuthRuleCurrentVersion struct {
// Parameters for the Auth Rule
Parameters AuthRuleCurrentVersionParameters `json:"parameters" api:"required"`
// The version of the rule, this is incremented whenever the rule's parameters
// change.
Version int64 `json:"version" api:"required"`
JSON authRuleCurrentVersionJSON `json:"-"`
}
// authRuleCurrentVersionJSON contains the JSON metadata for the struct
// [AuthRuleCurrentVersion]
type authRuleCurrentVersionJSON struct {
Parameters apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AuthRuleCurrentVersion) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r authRuleCurrentVersionJSON) RawJSON() string {
return r.raw
}
// Parameters for the Auth Rule
type AuthRuleCurrentVersionParameters struct {
// This field can have the runtime type of [Conditional3DSActionParametersAction],
// [ConditionalAuthorizationActionParametersAction],
// [ConditionalACHActionParametersAction],
// [ConditionalTokenizationActionParametersAction].
Action interface{} `json:"action"`
// This field can have the runtime type of [[]AuthRuleCondition],
// [[]Conditional3DsActionParametersCondition],
// [[]ConditionalAuthorizationActionParametersCondition],
// [[]ConditionalACHActionParametersCondition],
// [[]ConditionalTokenizationActionParametersCondition].
Conditions interface{} `json:"conditions"`
// This field can have the runtime type of [VelocityLimitParamsFilters].
Filters interface{} `json:"filters"`
// The maximum amount of spend velocity allowed in the period in minor units (the
// smallest unit of a currency, e.g. cents for USD). Transactions exceeding this
// limit will be declined.
LimitAmount int64 `json:"limit_amount" api:"nullable"`
// The number of spend velocity impacting transactions may not exceed this limit in
// the period. Transactions exceeding this limit will be declined. A spend velocity
// impacting transaction is a transaction that has been authorized, and optionally
// settled, or a force post (a transaction that settled without prior
// authorization).
LimitCount int64 `json:"limit_count" api:"nullable"`
// This field can have the runtime type of [[]MerchantLockParametersMerchant].
Merchants interface{} `json:"merchants"`
// Velocity over the current day since 00:00 / 12 AM in Eastern Time
Period VelocityLimitPeriod `json:"period"`
// The scope the velocity is calculated for
Scope AuthRuleCurrentVersionParametersScope `json:"scope"`
JSON authRuleCurrentVersionParametersJSON `json:"-"`
union AuthRuleCurrentVersionParametersUnion
}
// authRuleCurrentVersionParametersJSON contains the JSON metadata for the struct
// [AuthRuleCurrentVersionParameters]
type authRuleCurrentVersionParametersJSON struct {
Action apijson.Field
Conditions apijson.Field
Filters apijson.Field
LimitAmount apijson.Field
LimitCount apijson.Field
Merchants apijson.Field
Period apijson.Field
Scope apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r authRuleCurrentVersionParametersJSON) RawJSON() string {
return r.raw
}
func (r *AuthRuleCurrentVersionParameters) UnmarshalJSON(data []byte) (err error) {
*r = AuthRuleCurrentVersionParameters{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [AuthRuleCurrentVersionParametersUnion] interface which you
// can cast to the specific types for more type safety.
//
// Possible runtime types of the union are [ConditionalBlockParameters],
// [VelocityLimitParams], [MerchantLockParameters],
// [Conditional3DSActionParameters], [ConditionalAuthorizationActionParameters],
// [ConditionalACHActionParameters], [ConditionalTokenizationActionParameters].
func (r AuthRuleCurrentVersionParameters) AsUnion() AuthRuleCurrentVersionParametersUnion {
return r.union
}
// Parameters for the Auth Rule
//
// Union satisfied by [ConditionalBlockParameters], [VelocityLimitParams],
// [MerchantLockParameters], [Conditional3DSActionParameters],
// [ConditionalAuthorizationActionParameters], [ConditionalACHActionParameters] or
// [ConditionalTokenizationActionParameters].
type AuthRuleCurrentVersionParametersUnion interface {
implementsAuthRuleCurrentVersionParameters()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AuthRuleCurrentVersionParametersUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalBlockParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(VelocityLimitParams{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(MerchantLockParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(Conditional3DSActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalAuthorizationActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalACHActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalTokenizationActionParameters{}),
},
)
}
// The scope the velocity is calculated for
type AuthRuleCurrentVersionParametersScope string
const (
AuthRuleCurrentVersionParametersScopeCard AuthRuleCurrentVersionParametersScope = "CARD"
AuthRuleCurrentVersionParametersScopeAccount AuthRuleCurrentVersionParametersScope = "ACCOUNT"
)
func (r AuthRuleCurrentVersionParametersScope) IsKnown() bool {
switch r {
case AuthRuleCurrentVersionParametersScopeCard, AuthRuleCurrentVersionParametersScopeAccount:
return true
}
return false
}
type AuthRuleDraftVersion struct {
// Parameters for the Auth Rule
Parameters AuthRuleDraftVersionParameters `json:"parameters" api:"required"`
// The version of the rule, this is incremented whenever the rule's parameters
// change.
Version int64 `json:"version" api:"required"`
JSON authRuleDraftVersionJSON `json:"-"`
}
// authRuleDraftVersionJSON contains the JSON metadata for the struct
// [AuthRuleDraftVersion]
type authRuleDraftVersionJSON struct {
Parameters apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AuthRuleDraftVersion) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r authRuleDraftVersionJSON) RawJSON() string {
return r.raw
}
// Parameters for the Auth Rule
type AuthRuleDraftVersionParameters struct {
// This field can have the runtime type of [Conditional3DSActionParametersAction],
// [ConditionalAuthorizationActionParametersAction],
// [ConditionalACHActionParametersAction],
// [ConditionalTokenizationActionParametersAction].
Action interface{} `json:"action"`
// This field can have the runtime type of [[]AuthRuleCondition],
// [[]Conditional3DsActionParametersCondition],
// [[]ConditionalAuthorizationActionParametersCondition],
// [[]ConditionalACHActionParametersCondition],
// [[]ConditionalTokenizationActionParametersCondition].
Conditions interface{} `json:"conditions"`
// This field can have the runtime type of [VelocityLimitParamsFilters].
Filters interface{} `json:"filters"`
// The maximum amount of spend velocity allowed in the period in minor units (the
// smallest unit of a currency, e.g. cents for USD). Transactions exceeding this
// limit will be declined.
LimitAmount int64 `json:"limit_amount" api:"nullable"`
// The number of spend velocity impacting transactions may not exceed this limit in
// the period. Transactions exceeding this limit will be declined. A spend velocity
// impacting transaction is a transaction that has been authorized, and optionally
// settled, or a force post (a transaction that settled without prior
// authorization).
LimitCount int64 `json:"limit_count" api:"nullable"`
// This field can have the runtime type of [[]MerchantLockParametersMerchant].
Merchants interface{} `json:"merchants"`
// Velocity over the current day since 00:00 / 12 AM in Eastern Time
Period VelocityLimitPeriod `json:"period"`
// The scope the velocity is calculated for
Scope AuthRuleDraftVersionParametersScope `json:"scope"`
JSON authRuleDraftVersionParametersJSON `json:"-"`
union AuthRuleDraftVersionParametersUnion
}
// authRuleDraftVersionParametersJSON contains the JSON metadata for the struct
// [AuthRuleDraftVersionParameters]
type authRuleDraftVersionParametersJSON struct {
Action apijson.Field
Conditions apijson.Field
Filters apijson.Field
LimitAmount apijson.Field
LimitCount apijson.Field
Merchants apijson.Field
Period apijson.Field
Scope apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r authRuleDraftVersionParametersJSON) RawJSON() string {
return r.raw
}
func (r *AuthRuleDraftVersionParameters) UnmarshalJSON(data []byte) (err error) {
*r = AuthRuleDraftVersionParameters{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [AuthRuleDraftVersionParametersUnion] interface which you can
// cast to the specific types for more type safety.
//
// Possible runtime types of the union are [ConditionalBlockParameters],
// [VelocityLimitParams], [MerchantLockParameters],
// [Conditional3DSActionParameters], [ConditionalAuthorizationActionParameters],
// [ConditionalACHActionParameters], [ConditionalTokenizationActionParameters].
func (r AuthRuleDraftVersionParameters) AsUnion() AuthRuleDraftVersionParametersUnion {
return r.union
}
// Parameters for the Auth Rule
//
// Union satisfied by [ConditionalBlockParameters], [VelocityLimitParams],
// [MerchantLockParameters], [Conditional3DSActionParameters],
// [ConditionalAuthorizationActionParameters], [ConditionalACHActionParameters] or
// [ConditionalTokenizationActionParameters].
type AuthRuleDraftVersionParametersUnion interface {
implementsAuthRuleDraftVersionParameters()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AuthRuleDraftVersionParametersUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalBlockParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(VelocityLimitParams{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(MerchantLockParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(Conditional3DSActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalAuthorizationActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalACHActionParameters{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ConditionalTokenizationActionParameters{}),
},
)
}
// The scope the velocity is calculated for
type AuthRuleDraftVersionParametersScope string
const (
AuthRuleDraftVersionParametersScopeCard AuthRuleDraftVersionParametersScope = "CARD"
AuthRuleDraftVersionParametersScopeAccount AuthRuleDraftVersionParametersScope = "ACCOUNT"
)
func (r AuthRuleDraftVersionParametersScope) IsKnown() bool {
switch r {
case AuthRuleDraftVersionParametersScopeCard, AuthRuleDraftVersionParametersScopeAccount:
return true
}
return false
}
// The state of the Auth Rule
type AuthRuleState string
const (
AuthRuleStateActive AuthRuleState = "ACTIVE"
AuthRuleStateInactive AuthRuleState = "INACTIVE"
)
func (r AuthRuleState) IsKnown() bool {
switch r {
case AuthRuleStateActive, AuthRuleStateInactive:
return true
}
return false
}
// The type of Auth Rule. For certain rule types, this determines the event stream
// during which it will be evaluated. For rules that can be applied to one of
// several event streams, the effective one is defined by the separate
// `event_stream` field.
//
// - `CONDITIONAL_BLOCK`: Deprecated. Use `CONDITIONAL_ACTION` instead.
// AUTHORIZATION event stream.
// - `VELOCITY_LIMIT`: AUTHORIZATION event stream.
// - `MERCHANT_LOCK`: AUTHORIZATION event stream.
// - `CONDITIONAL_ACTION`: AUTHORIZATION, THREE_DS_AUTHENTICATION, TOKENIZATION,
// ACH_CREDIT_RECEIPT, or ACH_DEBIT_RECEIPT event stream.
type AuthRuleType string
const (
AuthRuleTypeConditionalBlock AuthRuleType = "CONDITIONAL_BLOCK"
AuthRuleTypeVelocityLimit AuthRuleType = "VELOCITY_LIMIT"
AuthRuleTypeMerchantLock AuthRuleType = "MERCHANT_LOCK"
AuthRuleTypeConditionalAction AuthRuleType = "CONDITIONAL_ACTION"
)
func (r AuthRuleType) IsKnown() bool {
switch r {
case AuthRuleTypeConditionalBlock, AuthRuleTypeVelocityLimit, AuthRuleTypeMerchantLock, AuthRuleTypeConditionalAction:
return true
}
return false
}
type AuthRuleCondition struct {
// The attribute to target.
//
// The following attributes may be targeted:
//
// - `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a
// business by the types of goods or services it provides.
// - `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all
// ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for
// Netherlands Antilles.
// - `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of
// the transaction.
// - `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor
// (merchant).
// - `DESCRIPTOR`: Short description of card acceptor.
// - `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer
// applies to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or
// `TOKEN_AUTHENTICATED`.
// - `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number
// (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`,
// `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`,
// `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`,
// `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`.
// - `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer
// fee field in the settlement/cardholder billing currency. This is the amount
// the issuer should authorize against unless the issuer is paying the acquirer
// fee on behalf of the cardholder.
// - `RISK_SCORE`: Network-provided score assessing risk level associated with a
// given authorization. Scores are on a range of 0-999, with 0 representing the
// lowest risk and 999 representing the highest risk. For Visa transactions,
// where the raw score has a range of 0-99, Lithic will normalize the score by
// multiplying the raw score by 10x.
// - `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the
// trailing 15 minutes before the authorization.
// - `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the
// trailing hour up and until the authorization.
// - `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the
// trailing 24 hours up and until the authorization.
// - `CARD_STATE`: The current state of the card associated with the transaction.
// Valid values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`,
// `PENDING_FULFILLMENT`.
// - `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction.
// Valid values are `TRUE`, `FALSE`.
// - `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`,
// `OK`, `BLOCKED`.
// - `WALLET_TYPE`: For transactions using a digital wallet token, indicates the
// source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`,
// `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`.
// - `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address
// data with the cardholder KYC data if it exists. Valid values are `MATCH`,
// `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`.
Attribute ConditionalAttribute `json:"attribute" api:"required"`
// The operation to apply to the attribute
Operation ConditionalOperation `json:"operation" api:"required"`
// A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH`
Value ConditionalValueUnion `json:"value" api:"required" format:"date-time"`
JSON authRuleConditionJSON `json:"-"`
}
// authRuleConditionJSON contains the JSON metadata for the struct
// [AuthRuleCondition]
type authRuleConditionJSON struct {
Attribute apijson.Field
Operation apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AuthRuleCondition) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r authRuleConditionJSON) RawJSON() string {
return r.raw
}
type AuthRuleConditionParam struct {
// The attribute to target.
//
// The following attributes may be targeted:
//
// - `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a
// business by the types of goods or services it provides.
// - `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all
// ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for
// Netherlands Antilles.
// - `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of
// the transaction.
// - `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor
// (merchant).
// - `DESCRIPTOR`: Short description of card acceptor.
// - `LIABILITY_SHIFT`: Indicates whether chargeback liability shift to the issuer
// applies to the transaction. Valid values are `NONE`, `3DS_AUTHENTICATED`, or
// `TOKEN_AUTHENTICATED`.
// - `PAN_ENTRY_MODE`: The method by which the cardholder's primary account number
// (PAN) was entered. Valid values are `AUTO_ENTRY`, `BAR_CODE`, `CONTACTLESS`,
// `ECOMMERCE`, `ERROR_KEYED`, `ERROR_MAGNETIC_STRIPE`, `ICC`, `KEY_ENTERED`,
// `MAGNETIC_STRIPE`, `MANUAL`, `OCR`, `SECURE_CARDLESS`, `UNSPECIFIED`,
// `UNKNOWN`, `CREDENTIAL_ON_FILE`, or `ECOMMERCE`.
// - `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer
// fee field in the settlement/cardholder billing currency. This is the amount
// the issuer should authorize against unless the issuer is paying the acquirer
// fee on behalf of the cardholder.
// - `RISK_SCORE`: Network-provided score assessing risk level associated with a
// given authorization. Scores are on a range of 0-999, with 0 representing the
// lowest risk and 999 representing the highest risk. For Visa transactions,
// where the raw score has a range of 0-99, Lithic will normalize the score by
// multiplying the raw score by 10x.
// - `CARD_TRANSACTION_COUNT_15M`: The number of transactions on the card in the
// trailing 15 minutes before the authorization.
// - `CARD_TRANSACTION_COUNT_1H`: The number of transactions on the card in the
// trailing hour up and until the authorization.
// - `CARD_TRANSACTION_COUNT_24H`: The number of transactions on the card in the
// trailing 24 hours up and until the authorization.
// - `CARD_STATE`: The current state of the card associated with the transaction.
// Valid values are `CLOSED`, `OPEN`, `PAUSED`, `PENDING_ACTIVATION`,
// `PENDING_FULFILLMENT`.
// - `PIN_ENTERED`: Indicates whether a PIN was entered during the transaction.
// Valid values are `TRUE`, `FALSE`.
// - `PIN_STATUS`: The current state of card's PIN. Valid values are `NOT_SET`,
// `OK`, `BLOCKED`.
// - `WALLET_TYPE`: For transactions using a digital wallet token, indicates the
// source of the token. Valid values are `APPLE_PAY`, `GOOGLE_PAY`,
// `SAMSUNG_PAY`, `MASTERPASS`, `MERCHANT`, `OTHER`, `NONE`.
// - `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address
// data with the cardholder KYC data if it exists. Valid values are `MATCH`,
// `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`.
Attribute param.Field[ConditionalAttribute] `json:"attribute" api:"required"`
// The operation to apply to the attribute
Operation param.Field[ConditionalOperation] `json:"operation" api:"required"`
// A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH`
Value param.Field[ConditionalValueUnionParam] `json:"value" api:"required" format:"date-time"`
}
func (r AuthRuleConditionParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BacktestStats struct {
// The total number of historical transactions approved by this rule during the
// backtest period, or the number of transactions that would have been approved if
// the rule was evaluated in shadow mode.
Approved int64 `json:"approved"`
// The total number of historical transactions challenged by this rule during the
// backtest period, or the number of transactions that would have been challenged
// if the rule was evaluated in shadow mode. Currently applicable only for 3DS Auth
// Rules.
Challenged int64 `json:"challenged"`
// The total number of historical transactions declined by this rule during the
// backtest period, or the number of transactions that would have been declined if
// the rule was evaluated in shadow mode.
Declined int64 `json:"declined"`
// Example events and their outcomes.
Examples []BacktestStatsExample `json:"examples"`
// The version of the rule, this is incremented whenever the rule's parameters
// change.
Version int64 `json:"version"`
JSON backtestStatsJSON `json:"-"`
}
// backtestStatsJSON contains the JSON metadata for the struct [BacktestStats]
type backtestStatsJSON struct {
Approved apijson.Field
Challenged apijson.Field
Declined apijson.Field
Examples apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BacktestStats) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r backtestStatsJSON) RawJSON() string {
return r.raw
}
type BacktestStatsExample struct {
// The decision made by the rule for this event.
Decision BacktestStatsExamplesDecision `json:"decision"`
// The event token.
EventToken string `json:"event_token" format:"uuid"`
// The timestamp of the event.
Timestamp time.Time `json:"timestamp" format:"date-time"`
JSON backtestStatsExampleJSON `json:"-"`
}
// backtestStatsExampleJSON contains the JSON metadata for the struct
// [BacktestStatsExample]
type backtestStatsExampleJSON struct {
Decision apijson.Field
EventToken apijson.Field
Timestamp apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BacktestStatsExample) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r backtestStatsExampleJSON) RawJSON() string {
return r.raw
}
// The decision made by the rule for this event.
type BacktestStatsExamplesDecision string
const (
BacktestStatsExamplesDecisionApproved BacktestStatsExamplesDecision = "APPROVED"
BacktestStatsExamplesDecisionDeclined BacktestStatsExamplesDecision = "DECLINED"
BacktestStatsExamplesDecisionChallenged BacktestStatsExamplesDecision = "CHALLENGED"
)
func (r BacktestStatsExamplesDecision) IsKnown() bool {
switch r {
case BacktestStatsExamplesDecisionApproved, BacktestStatsExamplesDecisionDeclined, BacktestStatsExamplesDecisionChallenged:
return true
}
return false
}
type Conditional3DSActionParameters struct {
// The action to take if the conditions are met.
Action Conditional3DSActionParametersAction `json:"action" api:"required"`
Conditions []Conditional3DsActionParametersCondition `json:"conditions" api:"required"`
JSON conditional3DsActionParametersJSON `json:"-"`
}
// conditional3DsActionParametersJSON contains the JSON metadata for the struct
// [Conditional3DSActionParameters]
type conditional3DsActionParametersJSON struct {
Action apijson.Field
Conditions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Conditional3DSActionParameters) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r conditional3DsActionParametersJSON) RawJSON() string {
return r.raw
}
func (r Conditional3DSActionParameters) implementsAuthRuleCurrentVersionParameters() {}
func (r Conditional3DSActionParameters) implementsAuthRuleDraftVersionParameters() {}
// The action to take if the conditions are met.
type Conditional3DSActionParametersAction string
const (
Conditional3DSActionParametersActionDecline Conditional3DSActionParametersAction = "DECLINE"
Conditional3DSActionParametersActionChallenge Conditional3DSActionParametersAction = "CHALLENGE"
)
func (r Conditional3DSActionParametersAction) IsKnown() bool {
switch r {
case Conditional3DSActionParametersActionDecline, Conditional3DSActionParametersActionChallenge:
return true
}
return false
}
type Conditional3DsActionParametersCondition struct {
// The attribute to target.
//
// The following attributes may be targeted:
//
// - `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a
// business by the types of goods or services it provides.
// - `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all
// ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for
// Netherlands Antilles.
// - `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of
// the transaction.
// - `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor
// (merchant).
// - `DESCRIPTOR`: Short description of card acceptor.
// - `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer
// fee field in the settlement/cardholder billing currency. This is the amount
// the issuer should authorize against unless the issuer is paying the acquirer
// fee on behalf of the cardholder.
// - `RISK_SCORE`: Mastercard only: Assessment by the network of the authentication
// risk level, with a higher value indicating a higher amount of risk.
// - `MESSAGE_CATEGORY`: The category of the authentication being processed.
// - `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address
// data with the cardholder KYC data if it exists. Valid values are `MATCH`,
// `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`.
Attribute Conditional3DSActionParametersConditionsAttribute `json:"attribute" api:"required"`
// The operation to apply to the attribute
Operation ConditionalOperation `json:"operation" api:"required"`
// A regex string, to be used with `MATCHES` or `DOES_NOT_MATCH`
Value ConditionalValueUnion `json:"value" api:"required" format:"date-time"`
JSON conditional3DsActionParametersConditionJSON `json:"-"`
}
// conditional3DsActionParametersConditionJSON contains the JSON metadata for the
// struct [Conditional3DsActionParametersCondition]
type conditional3DsActionParametersConditionJSON struct {
Attribute apijson.Field
Operation apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Conditional3DsActionParametersCondition) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r conditional3DsActionParametersConditionJSON) RawJSON() string {
return r.raw
}
// The attribute to target.
//
// The following attributes may be targeted:
//
// - `MCC`: A four-digit number listed in ISO 18245. An MCC is used to classify a
// business by the types of goods or services it provides.
// - `COUNTRY`: Country of entity of card acceptor. Possible values are: (1) all
// ISO 3166-1 alpha-3 country codes, (2) QZZ for Kosovo, and (3) ANT for
// Netherlands Antilles.
// - `CURRENCY`: 3-character alphabetic ISO 4217 code for the merchant currency of
// the transaction.
// - `MERCHANT_ID`: Unique alphanumeric identifier for the payment card acceptor
// (merchant).
// - `DESCRIPTOR`: Short description of card acceptor.
// - `TRANSACTION_AMOUNT`: The base transaction amount (in cents) plus the acquirer
// fee field in the settlement/cardholder billing currency. This is the amount
// the issuer should authorize against unless the issuer is paying the acquirer
// fee on behalf of the cardholder.
// - `RISK_SCORE`: Mastercard only: Assessment by the network of the authentication
// risk level, with a higher value indicating a higher amount of risk.
// - `MESSAGE_CATEGORY`: The category of the authentication being processed.
// - `ADDRESS_MATCH`: Lithic's evaluation result comparing transaction's address
// data with the cardholder KYC data if it exists. Valid values are `MATCH`,
// `MATCH_ADDRESS_ONLY`, `MATCH_ZIP_ONLY`,`MISMATCH`,`NOT_PRESENT`.