| 1 | <?php |
||
| 8 | class StripeWebhookCall extends Model |
||
| 9 | { |
||
| 10 | public $guarded = []; |
||
| 11 | |||
| 12 | protected $casts = [ |
||
| 13 | 'payload' => 'array', |
||
| 14 | 'exception' => 'array', |
||
| 15 | ]; |
||
| 16 | |||
| 17 | public function process() |
||
| 18 | { |
||
| 19 | $jobClass = $this->determineJobClass($this->type); |
||
| 20 | |||
| 21 | if (! class_exists($jobClass) { |
||
|
|
|||
| 22 | return; |
||
| 23 | } |
||
| 24 | |||
| 25 | dispatch(new $jobClass($this)); |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function determineJobClass(string $eventType): string |
||
| 29 | { |
||
| 30 | $jobConfigKey = str_replace('.', '_', $eventType); |
||
| 31 | |||
| 32 | return config("stripe-webhooks.jobs.{$jobConfigKey}", ''); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function saveException(Exception $exception) |
||
| 36 | { |
||
| 37 | $this->exception = [ |
||
| 38 | 'code' => $exception->getCode(), |
||
| 39 | 'message' => $exception->getMessage(), |
||
| 40 | 'exception' => $exception->getTraceAsString(), |
||
| 41 | ]; |
||
| 42 | |||
| 43 | $this->save(); |
||
| 44 | |||
| 45 | return $this; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |