Implement a parseResponseObject() method that correctly maps the data from the TransactionResponse to the internal class properties.
Diff:
1 diff --git a/api/paymentmethods/response.php b/api/paymentmethods/response.php
2 --- a/api/paymentmethods/response.php
3 +++ b/api/paymentmethods/response.php
4 @@ -63,16 +63,54 @@
5 if ($response) {
6 $this->response = $response;
7 $this->logger->logInfo('Response object provided directly');
8 + $this->parseResponseObject();
9 } else {
10 // ...
11 }
12 }
13 +
14 + private function parseResponseObject()
15 + {
16 + $data = $this->response->data();
17 + $tx = isset($data['Transaction']) ? $data['Transaction'] : $data;
18 +
19 + $this->invoicenumber = $tx['Invoice'] ?? $tx['Order'] ?? null;
20 + $this->invoice = $this->invoicenumber;
21 + $this->transactions = $tx['Key'] ?? null;
22 + $this->amount = $tx['AmountDebit'] ?? null;
23 + $this->currency = $tx['Currency'] ?? null;
24 +
25 + if (isset($tx['Status']['Code']['Code'])) {
26 + $this->statuscode = $tx['Status']['Code']['Code'];
27 + $this->statusmessage = $tx['Status']['Code']['Description'] ?? null;
28 + } else {
29 + $this->statuscode = $tx['Statuscode'] ?? null;
30 + $this->statusmessage = $tx['Statusmessage'] ?? null;
31 + }
32 +
33 + if (isset($tx['ServiceCode'])) {
34 + $this->payment_method = $this->getPaymentCode($tx['ServiceCode']);
35 + }
36 +
37 + if (!empty($this->statuscode)) {
38 + $responseArray = $this->responseCodes[(int)$this->statuscode] ?? null;
39 + if ($responseArray) {
40 + $this->status = $responseArray['status'];
41 + $this->message = $responseArray['message'];
42 + }
43 + }
44 + }
Implement a parseResponseObject() method that correctly maps the data from the TransactionResponse to the internal class properties.
Diff:
10 // ...
11 }
12 }
13 +
14 + private function parseResponseObject()
15 + {
16 + $data = $this->response->data();
17 + $tx = isset($data['Transaction']) ? $data['Transaction'] : $data;
18 +
19 + $this->invoicenumber = $tx['Invoice'] ?? $tx['Order'] ?? null;
20 + $this->invoice = $this->invoicenumber;
21 + $this->transactions = $tx['Key'] ?? null;
22 + $this->amount = $tx['AmountDebit'] ?? null;
23 + $this->currency = $tx['Currency'] ?? null;
24 +
25 + if (isset($tx['Status']['Code']['Code'])) {
26 + $this->statuscode = $tx['Status']['Code']['Code'];
27 + $this->statusmessage = $tx['Status']['Code']['Description'] ?? null;
28 + } else {
29 + $this->statuscode = $tx['Statuscode'] ?? null;
30 + $this->statusmessage = $tx['Statusmessage'] ?? null;
31 + }
32 +
33 + if (isset($tx['ServiceCode'])) {
34 + $this->payment_method = $this->getPaymentCode($tx['ServiceCode']);
35 + }
36 +
37 + if (!empty($this->statuscode)) {
38 + $responseArray = $this->responseCodes[(int)$this->statuscode] ?? null;
39 + if ($responseArray) {
40 + $this->status = $responseArray['status'];
41 + $this->message = $responseArray['message'];
42 + }
43 + }
44 + }