| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace LauLamanApps\eCurring\Resource; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DateTimeImmutable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use LauLamanApps\eCurring\Http\Resource\Creatable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use LauLamanApps\eCurring\Resource\Transaction\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use LauLamanApps\eCurring\Resource\Transaction\PaymentMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use LauLamanApps\eCurring\Resource\Transaction\Status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Money\Money; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Ramsey\Uuid\UuidInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | final class Transaction implements TransactionInterface, Creatable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var UuidInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var Status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * The current status of the transaction. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private $status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @var DateTimeImmutable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * The date on which this transaction was scheduled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Generally this is the date on which the subscription was activated. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private $scheduledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var DateTimeImmutable|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * The date on which the transaction will be, or was, executed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * Usually a transaction will be fulfilled within 3 days of this date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * If a transaction was rescheduled after a charge back, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * this attribute will reflect the date of the next attempt. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     private $dueDate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @var Money | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * The amount of the transaction. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     private $amount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @var DateTimeImmutable|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * The date on which the transaction was cancelled. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * Only filled if $status is 'cancelled' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     private $canceledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @var string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * The webhook URL we will call when the status of this transaction changes, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * inherited from the subscription. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     private $webhookUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @var PaymentMethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * The payment method used for this transaction. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * For fullfilled transactions this is the actual method used, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * for future transactions this will be payment method used for the first attempt. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * However, the method may change if the attempt fails and the transaction is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * fulfilled through other means (a payment reminder, for example). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     private $paymentMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @var Event[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * Collection of events with the full life cycle history of the transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     private $history; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @var Subscription|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     private $subscription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     private function __construct(Money $amount) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 1 |  |         $this->amount = $amount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 1 |  |         $this->history = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public static function new( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         Subscription $subscription, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         Money $amount, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         ?DateTimeImmutable $dueDate = null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $self = new self($amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $self->dueDate = $dueDate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $self->subscription = $subscription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return $self; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public static function fromData( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         UuidInterface $id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         Status $status, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         DateTimeImmutable $scheduledOn, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         Money $amount, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         PaymentMethod $paymentMethod, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         ?DateTimeImmutable $dueDate = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         ?DateTimeImmutable $canceledOn = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         ?string $webhookUrl = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         ?Event ...$history | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 1 |  |     ): self { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 1 |  |         $self = new self($amount); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 1 |  |         $self->id = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 1 |  |         $self->status = $status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 1 |  |         $self->scheduledOn = $scheduledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |         $self->dueDate = $dueDate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 1 |  |         $self->amount = $amount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 1 |  |         $self->canceledOn = $canceledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 1 |  |         $self->webhookUrl = $webhookUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 1 |  |         $self->paymentMethod = $paymentMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $self->history = $history; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         return $self; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     public function getId(): ?UuidInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         return $this->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     public function getStatus(): ?Status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         return $this->status; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     public function getScheduledOn(): ?DateTimeImmutable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         return $this->scheduledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     public function getDueDate(): ?DateTimeImmutable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         return $this->dueDate; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     public function getAmount(): Money | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         return $this->amount; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     public function getCanceledOn(): ?DateTimeImmutable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         return $this->canceledOn; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     public function getWebhookUrl(): ?string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         return $this->webhookUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     public function getPaymentMethod(): PaymentMethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         return $this->paymentMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     public function getHistory(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         return $this->history; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 181 |  |  |     public function getSubscription(): ?Subscription | 
            
                                                                        
                            
            
                                    
            
            
                | 182 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 183 |  |  |         return $this->subscription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 185 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 186 |  |  |  |