1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Request message. |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2021 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3\XML; |
12
|
|
|
|
13
|
|
|
use DOMDocument; |
14
|
|
|
use Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3\Merchant; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Title: iDEAL request XML message |
18
|
|
|
* Description: |
19
|
|
|
* Copyright: 2005-2021 Pronamic |
20
|
|
|
* Company: Pronamic |
21
|
|
|
* |
22
|
|
|
* @author Remco Tolsma |
23
|
|
|
* @version 2.0.0 |
24
|
|
|
*/ |
25
|
|
|
abstract class RequestMessage extends Message { |
26
|
|
|
/** |
27
|
|
|
* Merchant |
28
|
|
|
* |
29
|
|
|
* @var Merchant |
30
|
|
|
*/ |
31
|
|
|
private $merchant; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructs and initialize an request message |
35
|
|
|
* |
36
|
|
|
* @param string $name Name. |
37
|
|
|
*/ |
38
|
|
|
public function __construct( $name ) { |
39
|
|
|
parent::__construct( $name ); |
40
|
|
|
|
41
|
|
|
$this->merchant = new Merchant(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the merchant |
46
|
|
|
* |
47
|
|
|
* @return Merchant |
48
|
|
|
*/ |
49
|
|
|
public function get_merchant() { |
50
|
|
|
return $this->merchant; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the DOM document |
55
|
|
|
* |
56
|
|
|
* @return DOMDocument |
57
|
|
|
*/ |
58
|
|
|
public function get_document() { |
59
|
|
|
$document = new DOMDocument( parent::XML_VERSION, parent::XML_ENCODING ); |
60
|
|
|
|
61
|
|
|
/* |
62
|
|
|
* We can't disable preserve white space and format the output |
63
|
|
|
* this is causing 'Invalid electronic signature' errors. |
64
|
|
|
* |
65
|
|
|
* $document->preserveWhiteSpace = true; |
66
|
|
|
* $document->formatOutput = true; |
67
|
|
|
*/ |
68
|
|
|
|
69
|
|
|
// Root. |
70
|
|
|
$root = $document->createElementNS( parent::XML_NAMESPACE, $this->get_name() ); |
71
|
|
|
$root->setAttribute( 'version', parent::VERSION ); |
72
|
|
|
|
73
|
|
|
$document->appendChild( $root ); |
74
|
|
|
|
75
|
|
|
// Create date timestamp. |
76
|
|
|
// Using DateTime::ISO8601 won't work, this is giving an error. |
77
|
|
|
$timestamp = $this->get_create_date()->format( 'Y-m-d\TH:i:s.000\Z' ); |
78
|
|
|
|
79
|
|
|
$element = $document->createElement( 'createDateTimestamp', $timestamp ); |
80
|
|
|
|
81
|
|
|
$root->appendChild( $element ); |
82
|
|
|
|
83
|
|
|
return $document; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Create a string representation |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function __toString() { |
92
|
|
|
$document = $this->get_document(); |
93
|
|
|
|
94
|
|
|
return (string) $document->saveXML(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|