|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace CasParser\InboundEmail; |
| 6 | + |
| 7 | +use CasParser\Core\Attributes\Optional; |
| 8 | +use CasParser\Core\Attributes\Required; |
| 9 | +use CasParser\Core\Concerns\SdkModel; |
| 10 | +use CasParser\Core\Concerns\SdkParams; |
| 11 | +use CasParser\Core\Contracts\BaseModel; |
| 12 | +use CasParser\InboundEmail\InboundEmailCreateParams\AllowedSource; |
| 13 | + |
| 14 | +/** |
| 15 | + * Create a dedicated inbound email address for collecting CAS statements via email forwarding. |
| 16 | + * |
| 17 | + * **How it works:** |
| 18 | + * 1. Create an inbound email with your webhook URL |
| 19 | + * 2. Display the email address to your user (e.g., "Forward your CAS to ie_xxx@import.casparser.in") |
| 20 | + * 3. When an investor forwards a CAS email, we verify the sender and deliver to your webhook |
| 21 | + * |
| 22 | + * **Webhook Delivery:** |
| 23 | + * - We POST to your `callback_url` with JSON body containing files (matching EmailCASFile schema) |
| 24 | + * - Failed deliveries are retried automatically with exponential backoff |
| 25 | + * |
| 26 | + * **Inactivity:** |
| 27 | + * - Inbound emails with no activity in 30 days are marked inactive |
| 28 | + * - Active inbound emails remain operational indefinitely |
| 29 | + * |
| 30 | + * @see CasParser\Services\InboundEmailService::create() |
| 31 | + * |
| 32 | + * @phpstan-type InboundEmailCreateParamsShape = array{ |
| 33 | + * callbackURL: string, |
| 34 | + * alias?: string|null, |
| 35 | + * allowedSources?: list<AllowedSource|value-of<AllowedSource>>|null, |
| 36 | + * metadata?: array<string,string>|null, |
| 37 | + * reference?: string|null, |
| 38 | + * } |
| 39 | + */ |
| 40 | +final class InboundEmailCreateParams implements BaseModel |
| 41 | +{ |
| 42 | + /** @use SdkModel<InboundEmailCreateParamsShape> */ |
| 43 | + use SdkModel; |
| 44 | + use SdkParams; |
| 45 | + |
| 46 | + /** |
| 47 | + * Webhook URL where we POST email notifications. |
| 48 | + * Must be HTTPS in production (HTTP allowed for localhost during development). |
| 49 | + */ |
| 50 | + #[Required('callback_url')] |
| 51 | + public string $callbackURL; |
| 52 | + |
| 53 | + /** |
| 54 | + * Optional custom email prefix for user-friendly addresses. |
| 55 | + * - Must be 3-32 characters |
| 56 | + * - Alphanumeric + hyphens only |
| 57 | + * - Must start and end with letter/number |
| 58 | + * - Example: `john-portfolio@import.casparser.in` |
| 59 | + * - If omitted, generates random ID like `ie_abc123xyz@import.casparser.in`. |
| 60 | + */ |
| 61 | + #[Optional] |
| 62 | + public ?string $alias; |
| 63 | + |
| 64 | + /** |
| 65 | + * Filter emails by CAS provider. If omitted, accepts all providers. |
| 66 | + * - `cdsl` → eCAS@cdslstatement.com |
| 67 | + * - `nsdl` → NSDL-CAS@nsdl.co.in |
| 68 | + * - `cams` → donotreply@camsonline.com |
| 69 | + * - `kfintech` → samfS@kfintech.com. |
| 70 | + * |
| 71 | + * @var list<value-of<AllowedSource>>|null $allowedSources |
| 72 | + */ |
| 73 | + #[Optional('allowed_sources', list: AllowedSource::class)] |
| 74 | + public ?array $allowedSources; |
| 75 | + |
| 76 | + /** |
| 77 | + * Optional key-value pairs (max 10) to include in webhook payload. |
| 78 | + * Useful for passing context like plan_type, campaign_id, etc. |
| 79 | + * |
| 80 | + * @var array<string,string>|null $metadata |
| 81 | + */ |
| 82 | + #[Optional(map: 'string')] |
| 83 | + public ?array $metadata; |
| 84 | + |
| 85 | + /** |
| 86 | + * Your internal identifier (e.g., user_id, account_id). |
| 87 | + * Returned in webhook payload for correlation. |
| 88 | + */ |
| 89 | + #[Optional] |
| 90 | + public ?string $reference; |
| 91 | + |
| 92 | + /** |
| 93 | + * `new InboundEmailCreateParams()` is missing required properties by the API. |
| 94 | + * |
| 95 | + * To enforce required parameters use |
| 96 | + * ``` |
| 97 | + * InboundEmailCreateParams::with(callbackURL: ...) |
| 98 | + * ``` |
| 99 | + * |
| 100 | + * Otherwise ensure the following setters are called |
| 101 | + * |
| 102 | + * ``` |
| 103 | + * (new InboundEmailCreateParams)->withCallbackURL(...) |
| 104 | + * ``` |
| 105 | + */ |
| 106 | + public function __construct() |
| 107 | + { |
| 108 | + $this->initialize(); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Construct an instance from the required parameters. |
| 113 | + * |
| 114 | + * You must use named parameters to construct any parameters with a default value. |
| 115 | + * |
| 116 | + * @param list<AllowedSource|value-of<AllowedSource>>|null $allowedSources |
| 117 | + * @param array<string,string>|null $metadata |
| 118 | + */ |
| 119 | + public static function with( |
| 120 | + string $callbackURL, |
| 121 | + ?string $alias = null, |
| 122 | + ?array $allowedSources = null, |
| 123 | + ?array $metadata = null, |
| 124 | + ?string $reference = null, |
| 125 | + ): self { |
| 126 | + $self = new self; |
| 127 | + |
| 128 | + $self['callbackURL'] = $callbackURL; |
| 129 | + |
| 130 | + null !== $alias && $self['alias'] = $alias; |
| 131 | + null !== $allowedSources && $self['allowedSources'] = $allowedSources; |
| 132 | + null !== $metadata && $self['metadata'] = $metadata; |
| 133 | + null !== $reference && $self['reference'] = $reference; |
| 134 | + |
| 135 | + return $self; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Webhook URL where we POST email notifications. |
| 140 | + * Must be HTTPS in production (HTTP allowed for localhost during development). |
| 141 | + */ |
| 142 | + public function withCallbackURL(string $callbackURL): self |
| 143 | + { |
| 144 | + $self = clone $this; |
| 145 | + $self['callbackURL'] = $callbackURL; |
| 146 | + |
| 147 | + return $self; |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Optional custom email prefix for user-friendly addresses. |
| 152 | + * - Must be 3-32 characters |
| 153 | + * - Alphanumeric + hyphens only |
| 154 | + * - Must start and end with letter/number |
| 155 | + * - Example: `john-portfolio@import.casparser.in` |
| 156 | + * - If omitted, generates random ID like `ie_abc123xyz@import.casparser.in`. |
| 157 | + */ |
| 158 | + public function withAlias(string $alias): self |
| 159 | + { |
| 160 | + $self = clone $this; |
| 161 | + $self['alias'] = $alias; |
| 162 | + |
| 163 | + return $self; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Filter emails by CAS provider. If omitted, accepts all providers. |
| 168 | + * - `cdsl` → eCAS@cdslstatement.com |
| 169 | + * - `nsdl` → NSDL-CAS@nsdl.co.in |
| 170 | + * - `cams` → donotreply@camsonline.com |
| 171 | + * - `kfintech` → samfS@kfintech.com. |
| 172 | + * |
| 173 | + * @param list<AllowedSource|value-of<AllowedSource>> $allowedSources |
| 174 | + */ |
| 175 | + public function withAllowedSources(array $allowedSources): self |
| 176 | + { |
| 177 | + $self = clone $this; |
| 178 | + $self['allowedSources'] = $allowedSources; |
| 179 | + |
| 180 | + return $self; |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Optional key-value pairs (max 10) to include in webhook payload. |
| 185 | + * Useful for passing context like plan_type, campaign_id, etc. |
| 186 | + * |
| 187 | + * @param array<string,string> $metadata |
| 188 | + */ |
| 189 | + public function withMetadata(array $metadata): self |
| 190 | + { |
| 191 | + $self = clone $this; |
| 192 | + $self['metadata'] = $metadata; |
| 193 | + |
| 194 | + return $self; |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Your internal identifier (e.g., user_id, account_id). |
| 199 | + * Returned in webhook payload for correlation. |
| 200 | + */ |
| 201 | + public function withReference(string $reference): self |
| 202 | + { |
| 203 | + $self = clone $this; |
| 204 | + $self['reference'] = $reference; |
| 205 | + |
| 206 | + return $self; |
| 207 | + } |
| 208 | +} |
0 commit comments