PaymentAttempt.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Webkul\BagistoApi\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Webkul\BagistoApi\Contracts\PaymentAttempt as PaymentAttemptContract;
  6. use Webkul\Sales\Models\OrderProxy;
  7. /**
  8. * Audit trail for the full payment lifecycle (initiate / replay / callback).
  9. *
  10. * This is intentionally separate from `order_transactions`, which only
  11. * records the final settled (invoiced) transaction. A payment attempt is
  12. * an intent that may fail, be replayed multiple times, or be cancelled.
  13. */
  14. class PaymentAttempt extends Model implements PaymentAttemptContract
  15. {
  16. protected $table = 'payment_attempts';
  17. /**
  18. * Lifecycle stage of the attempt.
  19. */
  20. public const ACTION_INITIATE = 'initiate';
  21. public const ACTION_REPLAY = 'replay';
  22. public const ACTION_CALLBACK = 'callback';
  23. public const ACTION_WEBHOOK = 'webhook';
  24. /**
  25. * Status of the attempt.
  26. */
  27. public const STATUS_CREATED = 'created';
  28. public const STATUS_REDIRECTED = 'redirected';
  29. public const STATUS_CAPTURED = 'captured';
  30. public const STATUS_CANCELLED = 'cancelled';
  31. public const STATUS_FAILED = 'failed';
  32. /**
  33. * The attributes that are mass assignable.
  34. *
  35. * @var array
  36. */
  37. protected $fillable = [
  38. 'order_id',
  39. 'cart_id',
  40. 'payment_method',
  41. 'gateway_order_id',
  42. 'action',
  43. 'status',
  44. 'amount',
  45. 'currency',
  46. 'express',
  47. 'request_payload',
  48. 'response_payload',
  49. 'idempotency_key',
  50. ];
  51. /**
  52. * The attributes that should be cast.
  53. *
  54. * @var array
  55. */
  56. protected $casts = [
  57. 'express' => 'boolean',
  58. 'request_payload' => 'array',
  59. 'response_payload' => 'array',
  60. 'amount' => 'float',
  61. ];
  62. /**
  63. * Get the order associated with this payment attempt.
  64. */
  65. public function order(): BelongsTo
  66. {
  67. return $this->belongsTo(OrderProxy::modelClass(), 'order_id');
  68. }
  69. }