1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resova\Endpoints; |
4
|
|
|
|
5
|
|
|
use Resova\Client; |
6
|
|
|
use Resova\Models\Transaction; |
7
|
|
|
use Resova\Models\TransactionRequest; |
8
|
|
|
use Resova\Models\TransactionUpdate; |
9
|
|
|
use Resova\Models\Webhook; |
10
|
|
|
use Resova\Models\WebhookDelete; |
11
|
|
|
use Resova\Models\WebhookList; |
12
|
|
|
|
13
|
|
|
class Transactions extends Client |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $namespace = __CLASS__; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a transaction |
22
|
|
|
* Retrieves the details of a transaction. Provide the unique id for the transaction. |
23
|
|
|
* |
24
|
|
|
* @param TransactionRequest $transaction |
25
|
|
|
* |
26
|
|
|
* @return $this |
27
|
|
|
*/ |
28
|
|
|
public function create(TransactionRequest $transaction): self |
29
|
|
|
{ |
30
|
|
|
$transaction->setRequired([ |
31
|
|
|
'basket_id', |
32
|
|
|
'payment', |
33
|
|
|
]); |
34
|
|
|
|
35
|
|
|
// Set HTTP params |
36
|
|
|
$this->type = 'post'; |
37
|
|
|
$this->endpoint = '/transactions'; |
38
|
|
|
$this->params = $transaction; |
39
|
|
|
$this->response = Transaction::class; |
|
|
|
|
40
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Retrieve a transaction |
46
|
|
|
* Retrieves the details of a transaction. Provide the unique id for the transaction. |
47
|
|
|
* |
48
|
|
|
* @param int $transaction_id The transaction id |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
*/ |
52
|
|
|
public function __invoke(int $transaction_id): self |
53
|
|
|
{ |
54
|
|
|
$this->transaction_id = $transaction_id; |
|
|
|
|
55
|
|
|
|
56
|
|
|
// Set HTTP params |
57
|
|
|
$this->type = 'get'; |
58
|
|
|
$this->endpoint = '/transactions/' . $transaction_id; |
59
|
|
|
$this->response = Transaction::class; |
|
|
|
|
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Update a transaction |
66
|
|
|
* Updates the specified transaction by setting the values of the parameters passed. |
67
|
|
|
* Any parameters not provided will be left unchanged. |
68
|
|
|
* This request accepts mostly the same arguments as the transaction creation call. |
69
|
|
|
* |
70
|
|
|
* @param TransactionUpdate $transaction |
71
|
|
|
* |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function update(TransactionUpdate $transaction): self |
75
|
|
|
{ |
76
|
|
|
// Set HTTP params |
77
|
|
|
$this->type = 'put'; |
78
|
|
|
$this->endpoint = '/transactions/' . $this->transaction_id; |
79
|
|
|
$this->params = $transaction; |
80
|
|
|
$this->response = Transaction::class; |
|
|
|
|
81
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|