Skip to content

VirtualCard

Dataclass representing a virtual card returned by card gateways.

paygraph.gateways.base.VirtualCard dataclass

A virtual card returned by a card gateway.

Attributes:

Name Type Description
pan str

Primary Account Number (full card number). Treat as sensitive.

cvv str

Card Verification Value.

expiry str

Expiration date in MM/YY format.

spend_limit_cents int

Maximum spend limit in cents.

gateway_ref str

Unique reference ID from the gateway.

gateway_type str

Gateway identifier (e.g. "mock", "stripe_test").

Source code in src/paygraph/gateways/base.py
@dataclass
class VirtualCard:
    """A virtual card returned by a card gateway.

    Attributes:
        pan: Primary Account Number (full card number). **Treat as sensitive.**
        cvv: Card Verification Value.
        expiry: Expiration date in ``MM/YY`` format.
        spend_limit_cents: Maximum spend limit in cents.
        gateway_ref: Unique reference ID from the gateway.
        gateway_type: Gateway identifier (e.g. ``"mock"``, ``"stripe_test"``).
    """

    pan: str
    cvv: str
    expiry: str
    spend_limit_cents: int
    gateway_ref: str
    gateway_type: str

    def redacted(self) -> "VirtualCard":
        """Return a copy with the PAN masked, showing only the last 4 digits.

        Returns:
            A new ``VirtualCard`` with ``pan`` set to ``****XXXX``.
        """
        return VirtualCard(
            pan=f"****{self.pan[-4:]}",
            cvv=self.cvv,
            expiry=self.expiry,
            spend_limit_cents=self.spend_limit_cents,
            gateway_ref=self.gateway_ref,
            gateway_type=self.gateway_type,
        )

redacted()

Return a copy with the PAN masked, showing only the last 4 digits.

Returns:

Type Description
VirtualCard

A new VirtualCard with pan set to ****XXXX.

Source code in src/paygraph/gateways/base.py
def redacted(self) -> "VirtualCard":
    """Return a copy with the PAN masked, showing only the last 4 digits.

    Returns:
        A new ``VirtualCard`` with ``pan`` set to ``****XXXX``.
    """
    return VirtualCard(
        pan=f"****{self.pan[-4:]}",
        cvv=self.cvv,
        expiry=self.expiry,
        spend_limit_cents=self.spend_limit_cents,
        gateway_ref=self.gateway_ref,
        gateway_type=self.gateway_type,
    )