PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Repository / Payment / OrderRepository.php

OrderRepository.php in The Innovative Form Builder – IvyForms 1.5.1, at backend/src/Repository/Payment/OrderRepository.php

95 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Repository\Payment;
4
5 use IvyForms\Common\Exceptions\QueryExecutionException;
6 use IvyForms\Entity\Payment\Order;
7 use IvyForms\Factory\Payment\OrderFactory;
8 use IvyForms\Repository\AbstractRepository;
9 use IvyForms\Services\Translations\BackendStrings;
10
11 class OrderRepository extends AbstractRepository implements OrderRepositoryInterface
12 {
13 public const FACTORY = OrderFactory::class;
14
15 /**
16 * @param Order $entity
17 * @return int
18 * @throws QueryExecutionException
19 */
20 public function add($entity): int
21 {
22 $data = $entity->toArray();
23
24 $result = $this->wpdb->insert(
25 $this->table,
26 [
27 'entryId' => $data['entryId'],
28 'squareOrderId' => $data['squareOrderId'],
29 'status' => $data['status'],
30 'squareCustomerId' => $data['squareCustomerId'],
31 'amount' => $data['amount'],
32 'currency' => $data['currency'],
33 'dateCreated' => current_time('mysql'),
34 ],
35 ['%d', '%s', '%s', '%s', '%d', '%s', '%s']
36 );
37
38 if ($result === false) {
39 throw new QueryExecutionException(
40 BackendStrings::getExceptionStrings()['unable_to_add_data'] . __CLASS__
41 );
42 }
43
44 return (int) $this->wpdb->insert_id;
45 }
46
47 public function getBySquareOrderId(string $squareOrderId): ?Order
48 {
49 $row = $this->wpdb->get_row(
50 $this->wpdb->prepare(
51 $this->selectQuery() . " WHERE {$this->table}.squareOrderId = %s LIMIT 1",
52 $squareOrderId
53 ),
54 ARRAY_A
55 );
56
57 if (!$row) {
58 return null;
59 }
60
61 return OrderFactory::create($row);
62 }
63
64 public function updateStatus(string $squareOrderId, string $status): bool
65 {
66 $result = $this->wpdb->update(
67 $this->table,
68 ['status' => $status],
69 ['squareOrderId' => $squareOrderId],
70 ['%s'],
71 ['%s']
72 );
73
74 return $result !== false;
75 }
76
77 public function selectQuery(): string
78 {
79 return "SELECT {$this->table}.* FROM {$this->table}";
80 }
81
82 /**
83 * @return string[]
84 */
85 protected function getAllowedForeignColumns(): array
86 {
87 return ['entryId'];
88 }
89
90 protected function getDateColumn(): string
91 {
92 return 'dateCreated';
93 }
94 }
95