starling_webhooks/
schema.rs

1//! Type definitions for dealing with Starling webhook payloads.
2
3use chrono::{DateTime, NaiveDate, Utc};
4use uuid::Uuid;
5
6/// Webhook payload dispatched in response to an event occurring
7#[derive(Clone, Debug, Deserialize, PartialEq)]
8#[serde(rename_all = "camelCase")]
9pub struct WebhookDispatchFeedItem {
10    /// Unique identifier representing an event occurring for an account holder
11    pub webhook_event_uid: Uuid,
12    /// Timestamp indicating when the webhook event occurred
13    pub event_timestamp: DateTime<Utc>,
14    /// An account holder for which an event has occurred
15    pub account_holder_uid: Uuid,
16    /// An item from the account holders' transaction feed
17    pub content: FeedItem,
18}
19
20/// Webhook payload dispatched in response to an event occurring
21#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
22#[serde(rename_all = "camelCase")]
23pub struct WebhookDispatchPaymentOrderWebhookEventPayload {
24    /// Unique identifier representing an event occurring for an account holder
25    pub webhook_event_uid: Uuid,
26    /// Timestamp indicating when the webhook event occurred
27    pub event_timestamp: DateTime<Utc>,
28    /// An account holder for which an event has occurred
29    pub account_holder_uid: Uuid,
30    /// Webhook event payload indicating operation success or failure
31    pub content: PaymentOrderWebhookEventPayload,
32}
33
34/// Webhook payload dispatched in response to an event occurring
35#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
36#[serde(rename_all = "camelCase")]
37pub struct WebhookDispatchPaymentOrder {
38    /// Unique identifier representing an event occurring for an account holder
39    pub webhook_event_uid: Uuid,
40    /// Timestamp indicating when the webhook event occurred
41    pub event_timestamp: DateTime<Utc>,
42    /// An account holder for which an event has occurred
43    pub account_holder_uid: Uuid,
44    /// A payment instruction to be carried out at a specific point in time
45    pub content: PaymentOrder,
46}
47
48/// An item from the account holders' transaction feed
49#[derive(Clone, Debug, Deserialize, PartialEq)]
50#[serde(rename_all = "camelCase")]
51pub struct FeedItem {
52    /// Unique identifier for this item
53    pub feed_item_uid: Uuid,
54    /// The category on which the transaction happened
55    pub category_uid: Uuid,
56    /// The account for which the transaction happened
57    pub account_uid: Uuid,
58    /// Representation of money
59    pub amount: CurrencyAndAmount,
60    /// Representation of money
61    pub source_amount: CurrencyAndAmount,
62    /// Was this an inbound or outbound transaction
63    pub direction: Direction,
64    /// The time the transaction was last updated at
65    pub updated_at: DateTime<Utc>,
66    /// The time of the transaction
67    pub transaction_time: DateTime<Utc>,
68    /// The time the transaction settled
69    pub settlement_time: DateTime<Utc>,
70    /// The source of the transaction
71    pub source: Source,
72    /// The source subtype of the transaction
73    pub source_sub_type: SourceSubtype,
74    /// The status of the transaction
75    pub status: Status,
76    /// The application user that made the transaction
77    pub transacting_application_user_uid: Uuid,
78    /// The type of counter party for this transaction
79    pub counter_party_type: CounterPartyType,
80    /// The unique identifier for the counter party
81    pub counter_party_uid: Uuid,
82    /// The name of the counter party
83    pub counter_party_name: String,
84    /// An identifier for the counter party sub entity
85    pub counter_party_sub_entity_uid: Uuid,
86    /// A name for the counter party sub entity
87    pub counter_party_sub_entity_name: String,
88    /// An external identifier for the sub entity
89    pub counter_party_sub_entity_identifier: String,
90    /// An external sub identifier for the sub entity
91    pub counter_party_sub_entity_sub_identifier: String,
92    /// The exchange rate applied between different currencies
93    pub exchange_rate: f64,
94    /// Representation of money
95    pub total_fee_amount: CurrencyAndAmount,
96    /// The reference for the transaction
97    pub reference: String,
98    /// The country in which the transaction took place
99    pub country: Country,
100    /// The category of the transaction
101    pub spending_category: SpendingCategory,
102    /// The user-provided transaction note
103    pub user_note: String,
104    /// Round up details associated with a feed item
105    pub round_up: AssociatedFeedRoundUp,
106    /// Indicates whether an attachment exists for the feed item
107    pub has_attachment: bool,
108    /// Indicates if a copy of the receipt is present
109    pub receipt_present: bool,
110    /// Provides the failure reason for a failed transaction
111    pub feed_item_failure_reason: FeedItemFailureReason,
112    /// The MasterCard feed item details
113    pub master_card_feed_details: MasterCardFeedItemData,
114}
115
116/// Webhook event payload indicating operation success or failure
117#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
118#[serde(rename_all = "camelCase")]
119pub struct PaymentOrderWebhookEventPayload {
120    /// A payment instruction to be carried out at a specific point in time
121    pub payment_order: PaymentOrder,
122    /// Indicates if the payment was successful
123    pub success: bool,
124    /// Provides the reported success or failure reason code
125    pub reason: String,
126    /// Provides the payment uuid of the successful payment
127    pub payment_uid: Uuid,
128}
129
130/// A payment instruction to be carried out at a specific point in time
131#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
132#[serde(rename_all = "camelCase")]
133pub struct PaymentOrder {
134    /// Unique identifier of this payment order
135    pub payment_order_uid: Uuid,
136    /// Unique identifier of the category associated with this payment order
137    pub category_uid: Uuid,
138    /// Representation of money
139    pub amount: CurrencyAndAmount,
140    /// The reference set by the payer
141    pub reference: String,
142    /// The ID of the payee receiving the payments
143    pub payee_uid: Uuid,
144    /// The account ID of the payee account receiving the payments
145    pub payee_account_uid: Uuid,
146    /// Recurrence rules of a standing order
147    pub payment_order_recurrance: Option<StandingOrderRecurrance>,
148    /// Indicates if the payment order should process immediately or if this is a future dated
149    /// payment
150    pub processed_immediately: bool,
151    /// Date on which the next standing order payment will be made
152    pub next_date: NaiveDate,
153    /// The time the payment order is cancelled at
154    pub cancelled_at: DateTime<Utc>,
155    /// The time the payment order is updated at
156    pub updated_at: DateTime<Utc>,
157    /// Optional spending category for the payment order
158    pub spending_category: Option<SpendingCategory>,
159    /// Recurrence rules of a standing order
160    pub standing_order_recurrance: Option<StandingOrderRecurrance>,
161}
162
163/// Recurrence rules of a standing order
164#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
165#[serde(rename_all = "camelCase")]
166pub struct StandingOrderRecurrance {
167    /// Date that the first standing order payment should be made
168    pub start_date: NaiveDate,
169    /// Frequency of which payments should be made
170    pub frequency: Option<Frequency>,
171    /// Interval of specified frequency on which payments should be made
172    pub interval: Option<i32>,
173    /// Number of payments that should be made before standing order is stopped
174    pub count: Option<i32>,
175    /// Date on which to stop standing order
176    pub until_date: NaiveDate,
177}
178
179/// Representation of money
180#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
181#[serde(rename_all = "camelCase")]
182pub struct CurrencyAndAmount {
183    /// ISO-4217 3 character currency code
184    pub currency: Currency,
185    /// Amount in the minor units of the given currency
186    pub minor_units: i64,
187}
188
189/// Round up details associated with a feed item
190#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
191#[serde(rename_all = "camelCase")]
192pub struct AssociatedFeedRoundUp {
193    /// Unique identifier of associated category
194    pub goal_category_uid: Uuid,
195    /// Representation of money
196    pub amount: CurrencyAndAmount,
197}
198
199/// The MasterCard feed item details
200#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
201#[serde(rename_all = "camelCase")]
202pub struct MasterCardFeedItemData {
203    /// The identifier for the merchant
204    pub merchant_identifier: String,
205    /// The category given by the merchant
206    pub mcc: i32,
207    /// The point of sale timestamp
208    pub pos_timestamp: LocalTime,
209    /// The authorisation code for the feed item
210    pub authorisation_code: String,
211    /// The last 4 digits on the card
212    pub card_last_4: String,
213}
214
215/// The point of sale timestamp
216#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
217#[serde(rename_all = "camelCase")]
218pub struct LocalTime {
219    pub hour: i32,
220    pub minute: i32,
221    pub second: i32,
222    pub nano: i32,
223}
224
225/// ISO-4217 3 character currency code
226#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
227pub enum Currency {
228    NDEFINED,
229    AED,
230    AFN,
231    ALL,
232    AMD,
233    ANG,
234    AOA,
235    ARS,
236    AUD,
237    AWG,
238    AZN,
239    BAM,
240    BBD,
241    BDT,
242    BGN,
243    BHD,
244    BIF,
245    BMD,
246    BND,
247    BOB,
248    BOV,
249    BRL,
250    BSD,
251    BTN,
252    BWP,
253    BYN,
254    BYR,
255    BZD,
256    CAD,
257    CDF,
258    CHE,
259    CHF,
260    CHW,
261    CLF,
262    CLP,
263    CNY,
264    COP,
265    COU,
266    CRC,
267    CUC,
268    CUP,
269    CVE,
270    CZK,
271    DJF,
272    DKK,
273    DOP,
274    DZD,
275    EGP,
276    ERN,
277    ETB,
278    EUR,
279    FJD,
280    FKP,
281    GBP,
282    GEL,
283    GHS,
284    GIP,
285    GMD,
286    GNF,
287    GTQ,
288    GYD,
289    HKD,
290    HNL,
291    HRK,
292    HTG,
293    HUF,
294    IDR,
295    ILS,
296    INR,
297    IQD,
298    IRR,
299    ISK,
300    JMD,
301    JOD,
302    JPY,
303    KES,
304    KGS,
305    KHR,
306    KMF,
307    KPW,
308    KRW,
309    KWD,
310    KYD,
311    KZT,
312    LAK,
313    LBP,
314    LKR,
315    LRD,
316    LSL,
317    LTL,
318    LYD,
319    MAD,
320    MDL,
321    MGA,
322    MKD,
323    MMK,
324    MNT,
325    MOP,
326    MRO,
327    MRU,
328    MUR,
329    MVR,
330    MWK,
331    MXN,
332    MXV,
333    MYR,
334    MZN,
335    NAD,
336    NGN,
337    NIO,
338    NOK,
339    NPR,
340    NZD,
341    OMR,
342    PAB,
343    PEN,
344    PGK,
345    PHP,
346    PKR,
347    PLN,
348    PYG,
349    QAR,
350    RON,
351    RSD,
352    RUB,
353    RUR,
354    RWF,
355    SAR,
356    SBD,
357    SCR,
358    SDG,
359    SEK,
360    SGD,
361    SHP,
362    SLL,
363    SOS,
364    SRD,
365    SSP,
366    STD,
367    STN,
368    SVC,
369    SYP,
370    SZL,
371    THB,
372    TJS,
373    TMT,
374    TND,
375    TOP,
376    TRY,
377    TTD,
378    TWD,
379    TZS,
380    UAH,
381    UGX,
382    USD,
383    USN,
384    USS,
385    UYI,
386    UYU,
387    UZS,
388    VEF,
389    VES,
390    VND,
391    VUV,
392    WST,
393    XAF,
394    XAG,
395    XAU,
396    XBA,
397    XBB,
398    XBC,
399    XBD,
400    XCD,
401    XDR,
402    XOF,
403    XPD,
404    XPF,
405    XPT,
406    XSU,
407    XTS,
408    XUA,
409    XXX,
410    YER,
411    ZAR,
412    ZMW,
413    ZWL,
414}
415
416/// Was this an inbound or outbound transaction
417#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
418#[serde(rename_all = "UPPERCASE")]
419pub enum Direction {
420    In,
421    Out,
422}
423
424/// The source of the transaction
425#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
426#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
427pub enum Source {
428    BritishBusinessBankFees,
429    CashDeposit,
430    CashDepositCharge,
431    CashWithdrawal,
432    CashWithdrawalCharge,
433    Chaps,
434    Cheque,
435    CicsCheque,
436    CurrencyCloud,
437    DirectCredit,
438    DirectDebit,
439    DirectDebitDispute,
440    InternalTransfer,
441    MasterCard,
442    MastercardMoneysend,
443    MastercardChargeback,
444    FasterPaymentsIn,
445    FasterPaymentsOut,
446    FasterPaymentsReversal,
447    StripeFunding,
448    InterestPayment,
449    NostroDeposit,
450    Overdraft,
451    OverdraftInterestWaived,
452    FasterPaymentsRefund,
453    StarlingPayStripe,
454    OnUsPayMe,
455    LoanPrincipalPayment,
456    LoanRepayment,
457    LoanOverpayment,
458    LoanLatePayment,
459    LoanFeePayment,
460    SepaCreditTransfer,
461    SepaDirectDebit,
462    Target2CustomerPayment,
463    FxTransfer,
464    IssPayment,
465    StarlingPayment,
466    SubscriptionCharge,
467    OverdraftFee,
468}
469
470/// The source subtype of the transaction
471#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
472#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
473pub enum SourceSubtype {
474    Contactless,
475    MagneticStrip,
476    ManualKeyEntry,
477    ChipAndPin,
478    Online,
479    Atm,
480    CreditAuth,
481    ApplePay,
482    AndroidPay,
483    FitbitPay,
484    GarminPay,
485    SamsungPay,
486    OtherWallet,
487    NotApplicable,
488    Unknown,
489    Deposit,
490    Overdraft,
491    SettleUp,
492    Nearby,
493    TransferSameCurrency,
494    SctPayment,
495    SctRejection,
496    SctReturn,
497    SctRecall,
498    SddPending,
499    SddPayment,
500    SddReturn,
501    CcExchange,
502    CcDomestic,
503    FxTransferSameAccountHolder,
504    FxTransferBetweenAccountHolders,
505}
506
507/// The status of the transaction
508#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
509#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
510pub enum Status {
511    Upcoming,
512    Pending,
513    Retrying,
514    Reversed,
515    Settled,
516    Declined,
517    Refunded,
518    AccountCheck,
519}
520
521/// The type of counter party for this transaction
522#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
523#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
524pub enum CounterPartyType {
525    Category,
526    Cheque,
527    Customer,
528    Payee,
529    Merchant,
530    Sender,
531    Starling,
532    Loan,
533}
534
535/// The country in which the transaction took place
536#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
537pub enum Country {
538    UNDEFINED,
539    AC,
540    AD,
541    AE,
542    AF,
543    AG,
544    AI,
545    AL,
546    AM,
547    AN,
548    AO,
549    AQ,
550    AR,
551    AS,
552    AT,
553    AU,
554    AW,
555    AX,
556    AZ,
557    BA,
558    BB,
559    BD,
560    BE,
561    BF,
562    BG,
563    BH,
564    BI,
565    BJ,
566    BL,
567    BM,
568    BN,
569    BO,
570    BQ,
571    BR,
572    BS,
573    BT,
574    BU,
575    BV,
576    BW,
577    BY,
578    BZ,
579    CA,
580    CC,
581    CD,
582    CF,
583    CG,
584    CH,
585    CI,
586    CK,
587    CL,
588    CM,
589    CN,
590    CO,
591    CP,
592    CR,
593    CS,
594    CU,
595    CV,
596    CW,
597    CX,
598    CY,
599    CZ,
600    DE,
601    DG,
602    DJ,
603    DK,
604    DM,
605    DO,
606    DZ,
607    EA,
608    EC,
609    EE,
610    EG,
611    EH,
612    ER,
613    ES,
614    ET,
615    EU,
616    EZ,
617    FI,
618    FJ,
619    FK,
620    FM,
621    FO,
622    FR,
623    FX,
624    GA,
625    GB,
626    GD,
627    GE,
628    GF,
629    GG,
630    GH,
631    GI,
632    GL,
633    GM,
634    GN,
635    GP,
636    GQ,
637    GR,
638    GS,
639    GT,
640    GU,
641    GW,
642    GY,
643    HK,
644    HM,
645    HN,
646    HR,
647    HT,
648    HU,
649    IC,
650    ID,
651    IE,
652    IL,
653    IM,
654    IN,
655    IO,
656    IQ,
657    IR,
658    IS,
659    IT,
660    JE,
661    JM,
662    JO,
663    JP,
664    KE,
665    KG,
666    KH,
667    KI,
668    KM,
669    KN,
670    KP,
671    KR,
672    KW,
673    KY,
674    KZ,
675    LA,
676    LB,
677    LC,
678    LI,
679    LK,
680    LR,
681    LS,
682    LT,
683    LU,
684    LV,
685    LY,
686    MA,
687    MC,
688    MD,
689    ME,
690    MF,
691    MG,
692    MH,
693    MK,
694    ML,
695    MM,
696    MN,
697    MO,
698    MP,
699    MQ,
700    MR,
701    MS,
702    MT,
703    MU,
704    MV,
705    MW,
706    MX,
707    MY,
708    MZ,
709    NA,
710    NC,
711    NE,
712    NF,
713    NG,
714    NI,
715    NL,
716    NO,
717    NP,
718    NR,
719    NT,
720    NU,
721    NZ,
722    OM,
723    PA,
724    PE,
725    PF,
726    PG,
727    PH,
728    PK,
729    PL,
730    PM,
731    PN,
732    PR,
733    PS,
734    PT,
735    PW,
736    PY,
737    QA,
738    RE,
739    RO,
740    RS,
741    RU,
742    RW,
743    SA,
744    SB,
745    SC,
746    SD,
747    SE,
748    SF,
749    SG,
750    SH,
751    SI,
752    SJ,
753    SK,
754    SL,
755    SM,
756    SN,
757    SO,
758    SR,
759    SS,
760    ST,
761    SU,
762    SV,
763    SX,
764    SY,
765    SZ,
766    TA,
767    TC,
768    TD,
769    TF,
770    TG,
771    TH,
772    TJ,
773    TK,
774    TL,
775    TM,
776    TN,
777    TO,
778    TP,
779    TR,
780    TT,
781    TV,
782    TW,
783    TZ,
784    UA,
785    UG,
786    UK,
787    UM,
788    US,
789    UY,
790    UZ,
791    VA,
792    VC,
793    VE,
794    VG,
795    VI,
796    VN,
797    VU,
798    WF,
799    WS,
800    XK,
801    YE,
802    YT,
803    YU,
804    ZA,
805    ZM,
806    ZR,
807    ZW,
808}
809
810/// The category of the transaction
811#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
812#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
813pub enum SpendingCategory {
814    BillsAndServices,
815    Charity,
816    EatingOut,
817    Entertainment,
818    Expenses,
819    Family,
820    Gambling,
821    General,
822    Gifts,
823    Groceries,
824    Holidays,
825    Home,
826    Income,
827    Lifestyle,
828    Payments,
829    Pets,
830    Saving,
831    Shopping,
832    Transport,
833    None,
834    Revenue,
835    OtherIncome,
836    ClientRefunds,
837    Inventory,
838    Staff,
839    Travel,
840    Workplace,
841    RepairsAndMaintenance,
842    Admin,
843    Marketing,
844    BusinessEntertainment,
845    InterestPayments,
846    BankCharges,
847    Other,
848    FoodAndDrink,
849    Equipment,
850    ProfessionalServices,
851    PhoneAndInternet,
852    Vehicles,
853    DirectorsWages,
854    Vat,
855    CorporationTax,
856    SelfAssessmentTax,
857    InvestmentCapital,
858    Transfers,
859    LoanPrincipal,
860    Personal,
861    Dividends,
862}
863
864/// Provides the failure reason for a failed transaction
865#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
866#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
867pub enum FeedItemFailureReason {
868    CardWalletLimit,
869    CardApplePayLimit,
870    CardPosDisabled,
871    CardAtmDisabled,
872    CardMobileWalletDisabled,
873    CardOnlineDisabled,
874    CardGamblingDisabled,
875    CardDisabled,
876    CardCancelled,
877    CardNotActivated,
878    CardMagneticStripDisabled,
879    CardManualKeyEntryDisabled,
880    CardPayAtPumpDeclined,
881    CardInsufficientFunds,
882    ChildCardMerchantDisabled,
883    DestinationAccountInvalid,
884    ReferenceInformationIncorrect,
885    DestinationAccountCurrencyIncorrect,
886    DestinationAccountNameMismatch,
887    DestinationAccountUnavailable,
888    IncorrectPin,
889    IncorrectCvv2,
890    InsufficientFunds,
891    MandateCancelled,
892    MandateNotFound,
893    ChequeBeingRepresented,
894    ChequeIssuerAccountClosed,
895    ChequeNotSignedInAccordanceWithMandate,
896    ChequeStopped,
897    ChequeDeclinedReferToIssuer,
898    LastBillItemCancelled,
899    ScaRequired,
900    PinTriesExceeded,
901    CvcTriesExceeded,
902    SuspiciousCardTransaction,
903}
904
905/// Frequency of which payments should be made
906#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
907pub enum Frequency {
908    Daily,
909    Weekly,
910    Monthly,
911    Yearly,
912}