Failed Conditions
Push — develop ( 109ee7...3a2185 )
by Reüel
04:37
created

src/XML/RequestMessage.php (1 issue)

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