setTable('stripe_module_orders'); } /** * Add a payment link to the database * @param int $order_id * @param string $email * @param string $payment_link_id * @param string $url The URL of the payment link * @return void * @throws Exception If the object was not created successfully */ public function add(int $order_id, string $email, string $payment_link_id, string $url): void { $tmp_id = self::add_object([ 'id' => $order_id, 'email' => $email, 'payment_link_id' => $payment_link_id, 'url' => $url, ]); $this->id = $tmp_id; self::getObjectProperties(); self::objectChanged(); } public function getObjectProperties(): void { $this->payment_link_id = new object_property($this->table, $this->id, 'payment_link_id', 'string', false); $this->email = new object_property($this->table, $this->id, 'email', 'string', false); $this->email_sent = new object_property($this->table, $this->id, 'email_sent', 'timestamp', false); $this->url = new object_property($this->table, $this->id, 'url', 'string', false); $this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false); } public function objectChanged(): void { //TODO: Add cache invalidation } /** * @throws ApiErrorException */ public function asArray(): array { return [ 'id' => (int)$this->id, 'payment_link_id' => (string)$this->payment_link_id->value(), 'email' => (string)$this->email->value(), 'email_sent' => $this->email_sent->value() ? (string)$this->email_sent->value() : null, 'url' => (string)$this->url->value(), 'created_at' => (string)$this->created_at->value(), 'object' => self::retrievePaymentLink() ]; } /** * @throws ApiErrorException * @throws Exception */ public function retrievePaymentLink(): object { // Validate the object self::requireSelected(); // Return the payment link return (new stripe())->payment_link->retrieve($this->payment_link_id->value()); } }