1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\BillPay\Message\ResponseData; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use SimpleXMLElement; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Access invoice bank account in the response |
10
|
|
|
* |
11
|
|
|
* @author Andreas Lange <[email protected]> |
12
|
|
|
* @copyright 2016, Connox GmbH |
13
|
|
|
* @license MIT |
14
|
|
|
*/ |
15
|
|
|
trait InvoiceBankAccountTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @return SimpleXMLElement |
19
|
|
|
* |
20
|
|
|
* @codeCoverageIgnore |
21
|
|
|
*/ |
22
|
|
|
abstract public function getData(); |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Extracts the invoice bank account data if it exists |
26
|
|
|
* |
27
|
|
|
* @return array|null |
28
|
|
|
*/ |
29
|
5 |
|
public function getInvoiceBankAccount() |
30
|
|
|
{ |
31
|
5 |
|
if (!$this->hasInvoiceBankAccount()) { |
32
|
2 |
|
return null; |
33
|
|
|
} |
34
|
|
|
|
35
|
3 |
|
$data = $this->getData(); |
36
|
|
|
|
37
|
|
|
return [ |
38
|
3 |
|
'account_holder' => (string)$data->invoice_bank_account['account_holder'], |
39
|
3 |
|
'account_number' => (string)$data->invoice_bank_account['account_number'], |
40
|
3 |
|
'bank_code' => (string)$data->invoice_bank_account['bank_code'], |
41
|
3 |
|
'bank_name' => (string)$data->invoice_bank_account['bank_name'], |
42
|
3 |
|
'invoice_reference' => (string)$data->invoice_bank_account['invoice_reference'], |
43
|
3 |
|
'invoice_duedate' => $this->formatDate((string)$data->invoice_bank_account['invoice_duedate']), |
44
|
3 |
|
'activation_performed' => (string)$data->invoice_bank_account['activation_performed'] === '1', |
45
|
3 |
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Checks if the node has an invoice bank account node |
50
|
|
|
* |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
5 |
|
public function hasInvoiceBankAccount() |
54
|
|
|
{ |
55
|
5 |
|
$data = $this->getData(); |
56
|
|
|
|
57
|
5 |
|
return isset($data->invoice_bank_account) && (string)$data->invoice_bank_account['account_holder'] !== ''; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $date Date with format 'Ymd' |
62
|
|
|
* |
63
|
|
|
* @return null|string Y-m-d or null |
64
|
|
|
*/ |
65
|
3 |
|
private function formatDate($date) |
66
|
|
|
{ |
67
|
3 |
|
if (!$date) { |
68
|
2 |
|
return null; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
return DateTime::createFromFormat('Ymd', $date)->format('Y-m-d'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|