Failed Conditions
Push — develop ( 84789b...288de2 )
by Reüel
06:59
created

src/XML/DirectTransactionRequestMessage.php (1 issue)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML;
4
5
use Pronamic\WordPress\Pay\Core\XML\Util as XML_Util;
6
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Customer;
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\GatewayInfo;
8
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Merchant;
9
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Transaction;
10
11
/**
12
 * Title: MultiSafepay Connect XML direct transaction request message
13
 * Description:
14
 * Copyright: 2005-2020 Pronamic
15
 * Company: Pronamic
16
 *
17
 * @author  Remco Tolsma
18
 * @version 2.0.2
19
 * @since   1.2.0
20
 */
21
class DirectTransactionRequestMessage extends RequestMessage {
22
	/**
23
	 * The document element name
24
	 *
25
	 * @var string
26
	 */
27
	const NAME = 'directtransaction';
28
29
	/**
30
	 * Gateway info.
31
	 *
32
	 * @var GatewayInfo
33
	 */
34
	private $gateway_info;
35
36
	/**
37
	 * Constructs and initialize an directory response message
38
	 *
39
	 * @param Merchant    $merchant     Merchant.
40
	 * @param Customer    $customer     Customer.
41
	 * @param Transaction $transaction  Transaction.
42
	 * @param GatewayInfo $gateway_info Gateway info.
43
	 */
44 1
	public function __construct( Merchant $merchant, Customer $customer, Transaction $transaction, GatewayInfo $gateway_info = null ) {
45 1
		parent::__construct( self::NAME );
46
47 1
		$this->merchant     = $merchant;
48 1
		$this->customer     = $customer;
49 1
		$this->transaction  = $transaction;
50 1
		$this->gateway_info = $gateway_info;
51 1
	}
52
53
	/**
54
	 * Get document
55
	 *
56
	 * @see Pronamic_Gateways_IDealAdvancedV3_XML_RequestMessage::get_document()
57
	 */
58 1
	public function get_document() {
59 1
		$document = parent::get_document();
60
61
		// Merchant.
62 1
		$merchant = XML_Util::add_element( $document, $document->documentElement, 'merchant' );
63
64 1
		XML_Util::add_elements(
65 1
			$document,
66
			$merchant,
67
			array(
68 1
				'account'          => $this->merchant->account,
69 1
				'site_id'          => $this->merchant->site_id,
70 1
				'site_secure_code' => $this->merchant->site_secure_code,
71 1
				'notification_url' => $this->merchant->notification_url,
72 1
				'redirect_url'     => $this->merchant->redirect_url,
73 1
				'cancel_url'       => $this->merchant->cancel_url,
74 1
				'close_window'     => $this->merchant->close_window,
75
			)
76
		);
77
78
		// Customer.
79 1
		$customer = XML_Util::add_element( $document, $document->documentElement, 'customer' );
80
81 1
		XML_Util::add_elements(
82 1
			$document,
83
			$customer,
84
			array(
85 1
				'locale'      => $this->customer->locale,
86 1
				'ipaddress'   => $this->customer->ip_address,
87 1
				'forwardedip' => $this->customer->forwarded_ip,
88 1
				'firstname'   => $this->customer->first_name,
89 1
				'lastname'    => $this->customer->last_name,
90 1
				'address1'    => $this->customer->address_1,
91 1
				'address2'    => $this->customer->address_2,
92 1
				'housenumber' => $this->customer->house_number,
93 1
				'zipcode'     => $this->customer->zip_code,
94 1
				'city'        => $this->customer->city,
95 1
				'country'     => $this->customer->country,
96 1
				'phone'       => $this->customer->phone,
97 1
				'email'       => $this->customer->email,
98
			)
99
		);
100
101
		// Transaction.
102 1
		$transaction = XML_Util::add_element( $document, $document->documentElement, 'transaction' );
103
104 1
		XML_Util::add_elements(
105 1
			$document,
106
			$transaction,
107
			array(
108 1
				'id'          => $this->transaction->id,
109 1
				'currency'    => $this->transaction->currency,
110 1
				'amount'      => $this->transaction->amount,
111 1
				'description' => $this->transaction->description,
112 1
				'var1'        => $this->transaction->var1,
113 1
				'var2'        => $this->transaction->var2,
114 1
				'var3'        => $this->transaction->var3,
115 1
				'items'       => $this->transaction->items,
116 1
				'manual'      => $this->transaction->manual,
117 1
				'gateway'     => $this->transaction->gateway,
118 1
				'daysactive'  => $this->transaction->days_active,
119
			)
120
		);
121
122
		// Gateway info.
123 1
		if ( $this->gateway_info ) {
124 1
			$gateway_info = XML_Util::add_element( $document, $document->documentElement, 'gatewayinfo' );
125
126 1
			XML_Util::add_elements(
127 1
				$document,
128
				$gateway_info,
129
				array(
130 1
					'issuerid' => $this->gateway_info->issuer_id,
131
				)
132
			);
133
		}
134
135
		// Signature.
136 1
		XML_Util::add_element( $document, $document->documentElement, 'signature', $this->signature );
0 ignored issues
show
Bug Best Practice introduced by
The property signature does not exist on Pronamic\WordPress\Pay\G...ansactionRequestMessage. Did you maybe forget to declare it?
Loading history...
137
138 1
		return $document;
139
	}
140
}
141