|
| 1 | +from dataclasses import dataclass |
| 2 | +from typing import Optional |
| 3 | + |
| 4 | + |
| 5 | +@dataclass |
| 6 | +class CCavenueWebhookData: |
| 7 | + """ |
| 8 | + Represents the data received from a CCAvenue webhook/notification. |
| 9 | +
|
| 10 | + Covers fields for: |
| 11 | + - Order Status (including Reconcilation and Echo) |
| 12 | + - Order Risk Status |
| 13 | + - Payment Type Status |
| 14 | + """ |
| 15 | + |
| 16 | + # Core Fields (Order Status / generic) |
| 17 | + order_id: Optional[str] = None |
| 18 | + tracking_id: Optional[str] = None |
| 19 | + bank_ref_no: Optional[str] = None |
| 20 | + order_status: Optional[str] = None # Success, Failure, Aborted, Invalid |
| 21 | + failure_message: Optional[str] = None |
| 22 | + payment_mode: Optional[str] = None |
| 23 | + |
| 24 | + # Card & Bank Details |
| 25 | + card_name: Optional[str] = None |
| 26 | + status_code: Optional[str] = None |
| 27 | + status_message: Optional[str] = None |
| 28 | + |
| 29 | + # Transaction Details |
| 30 | + currency: Optional[str] = None |
| 31 | + amount: Optional[str] = None |
| 32 | + |
| 33 | + # Billing Details |
| 34 | + billing_name: Optional[str] = None |
| 35 | + billing_address: Optional[str] = None |
| 36 | + billing_city: Optional[str] = None |
| 37 | + billing_state: Optional[str] = None |
| 38 | + billing_zip: Optional[str] = None |
| 39 | + billing_country: Optional[str] = None |
| 40 | + billing_tel: Optional[str] = None |
| 41 | + billing_email: Optional[str] = None |
| 42 | + |
| 43 | + # Delivery Details |
| 44 | + delivery_name: Optional[str] = None |
| 45 | + delivery_address: Optional[str] = None |
| 46 | + delivery_city: Optional[str] = None |
| 47 | + delivery_state: Optional[str] = None |
| 48 | + delivery_zip: Optional[str] = None |
| 49 | + delivery_country: Optional[str] = None |
| 50 | + delivery_tel: Optional[str] = None |
| 51 | + |
| 52 | + # Merchant Custom Fields |
| 53 | + merchant_param1: Optional[str] = None |
| 54 | + merchant_param2: Optional[str] = None |
| 55 | + merchant_param3: Optional[str] = None |
| 56 | + merchant_param4: Optional[str] = None |
| 57 | + merchant_param5: Optional[str] = None |
| 58 | + |
| 59 | + # Offers & Vault |
| 60 | + vault: Optional[str] = None |
| 61 | + offer_type: Optional[str] = None |
| 62 | + offer_code: Optional[str] = None |
| 63 | + discount_value: Optional[str] = None |
| 64 | + |
| 65 | + # Risk Status Specific |
| 66 | + risk_status: Optional[str] = None # High, Low, NR, GA |
| 67 | + risk_reason: Optional[str] = None |
| 68 | + |
| 69 | + # Payment Type Status Specific |
| 70 | + payment_option: Optional[str] = None |
| 71 | + current_status: Optional[str] = None # ACTI, FLCT, INAC, DOWN, NEW |
| 72 | + |
| 73 | + @classmethod |
| 74 | + def from_dict(cls, data: dict) -> "CCavenueWebhookData": |
| 75 | + """ |
| 76 | + Create a CCavenueWebhookData instance from a dictionary. |
| 77 | + Keys in the dictionary that don't match fields are ignored. |
| 78 | + """ |
| 79 | + # Filter data to only include keys that match field names |
| 80 | + known_fields = set(cls.__annotations__.keys()) |
| 81 | + filtered_data = {k: v for k, v in data.items() if k in known_fields} |
| 82 | + return cls(**filtered_data) |
0 commit comments