-
Notifications
You must be signed in to change notification settings - Fork 8
/
CreditTransfer.php
83 lines (71 loc) · 1.75 KB
/
CreditTransfer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Sepa;
use Sepa\Builder\CreditTransfer as Builder;
use Sepa\CreditTransfer\GroupHeader;
use Sepa\CreditTransfer\PaymentInformation;
/**
* CreditTransfer
*
* @author Perry Faro 2015
* @license MIT
*/
class CreditTransfer {
/**
*
* @var Sepa\CreditTransfer\GroupHeader
*/
protected $groupHeader = null;
/**
*
* @var Sepa\CreditTransfer\PaymentInformation
*/
protected $paymentInformation = null;
/**
*
* @param GroupHeader $groupHeader
* @return CreditTransfer
*/
public function setGroupHeader(GroupHeader $groupHeader) {
$this->groupHeader = $groupHeader;
return $this;
}
/**
*
* @param $paymentInformation
* @return CreditTransfer
*/
public function setPaymentInformation(PaymentInformation $paymentInformation) {
$this->paymentInformation = $paymentInformation;
return $this;
}
/**
*
* @param string $xml
* @param string $painformat
* @return boolean
*/
public function validate($xml, $painformat = 'pain.001.001.03') {
$reader = new \DOMDocument;
$reader->loadXML($xml);
if ($reader->schemaValidate(__DIR__ . '/xsd/' . $painformat . '.xsd')) {
return true;
}
return false;
}
/**
*
* @throws Exception
*/
public function xml() {
if ($this->groupHeader === null) {
throw new Exception;
}
if ($this->paymentInformation === null) {
throw new Exception;
}
$build = new Builder;
$build->appendGroupHeader($this->groupHeader);
$build->appendPaymentInformation($this->paymentInformation);
return $build->xml();
}
}