Skip to main content

PayrixEntity

Derive Macro PayrixEntity 

Source
#[derive(PayrixEntity)]
{
    // Attributes available to this derive:
    #[payrix]
}
Expand description

Derive macro for generating Create and Update types from a Payrix entity.

§Attributes

§Struct-level

  • #[payrix(create = CreateTypeName)] - Name for the Create type
  • #[payrix(update = UpdateTypeName)] - Name for the Update type

§Field-level

  • #[payrix(readonly)] - Field is read-only, excluded from request types
  • #[payrix(create_only)] - Field only in Create type (e.g., merchant, customer)
  • #[payrix(mutable)] - Field in both Create and Update types
  • #[payrix(create_required)] - Field is required in Create type (not wrapped in Option)
  • #[payrix(create_type = "SomeType")] - Use a different type for Create requests

Fields without any payrix attribute are excluded from request types.

§Example

#[derive(PayrixEntity)]
#[payrix(create = CreateAlert, update = UpdateAlert)]
pub struct Alert {
    #[payrix(readonly)]
    pub id: PayrixId,

    #[payrix(readonly)]
    pub created: Option<String>,

    #[payrix(create_only)]
    pub forlogin: Option<PayrixId>,

    #[payrix(mutable)]
    pub name: Option<String>,
}

// For types with required create fields:
#[derive(PayrixEntity)]
#[payrix(create = CreateToken)]
pub struct Token {
    #[payrix(readonly)]
    pub id: PayrixId,

    // Required for creation, uses a different input type
    #[payrix(create_only, create_required, create_type = "PaymentInfo")]
    pub payment: Option<PaymentMethod>,

    // Required for creation
    #[payrix(create_only, create_required)]
    pub customer: Option<PayrixId>,
}