Test Failed
Push — develop ( fd928b...40893b )
by Remco
04:14
created

StatusResponseMessage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 50
dl 0
loc 110
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 67 5
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML;
4
5
use Pronamic\WordPress\Pay\Core\XML\Security;
6
use SimpleXMLElement;
7
use stdClass;
8
9
/**
10
 * Title: MultiSafepay Connect XML status response message
11
 * Description:
12
 * Copyright: 2005-2019 Pronamic
13
 * Company: Pronamic
14
 *
15
 * @author  Remco Tolsma
16
 * @version 2.0.2
17
 * @since   1.0.0
18
 */
19
class StatusResponseMessage {
20
	/**
21
	 * Result
22
	 *
23
	 * @var string
24
	 */
25
	public $result;
26
27
	/**
28
	 * E-wallet
29
	 *
30
	 * @var object
31
	 */
32
	public $ewallet;
33
34
	/**
35
	 * Customer
36
	 *
37
	 * @var object
38
	 */
39
	public $customer;
40
41
	/**
42
	 * Transaction
43
	 *
44
	 * @var object
45
	 */
46
	public $transaction;
47
48
	/**
49
	 * Payment details.
50
	 *
51
	 * @var object
52
	 */
53
	public $payment_details;
54
55
	/**
56
	 * Parse the specified XML element into an iDEAL transaction object
57
	 *
58
	 * @param SimpleXMLElement $xml
59
	 *
60
	 * @return StatusResponseMessage
61
	 */
62
	public static function parse( SimpleXMLElement $xml ) {
63
		$message = new StatusResponseMessage();
64
65
		$message->result = Security::filter( $xml['result'] );
66
67
		// E-wallet
68
		if ( $xml->ewallet ) {
69
			$ewallet = new stdClass();
70
71
			$ewallet->id          = Security::filter( $xml->ewallet->id );
72
			$ewallet->status      = Security::filter( $xml->ewallet->status );
73
			$ewallet->created     = Security::filter( $xml->ewallet->created );
74
			$ewallet->modified    = Security::filter( $xml->ewallet->modified );
75
			$ewallet->reason_code = Security::filter( $xml->ewallet->reasoncode );
76
			$ewallet->reason      = Security::filter( $xml->ewallet->reason );
77
78
			$message->ewallet = $ewallet;
79
		}
80
81
		// Customer
82
		if ( $xml->customer ) {
83
			$customer = new stdClass();
84
85
			$customer->currency      = Security::filter( $xml->customer->currency );
86
			$customer->amount        = Security::filter( $xml->customer->amount );
87
			$customer->exchange_rate = Security::filter( $xml->customer->exchange_rate );
88
			$customer->first_name    = Security::filter( $xml->customer->firstname );
89
			$customer->last_name     = Security::filter( $xml->customer->lastname );
90
			$customer->last_name     = Security::filter( $xml->customer->lastname );
91
			$customer->city          = Security::filter( $xml->customer->city );
92
			$customer->state         = Security::filter( $xml->customer->state );
93
			$customer->country       = Security::filter( $xml->customer->country );
94
95
			$message->customer = $customer;
96
		}
97
98
		// Transaction
99
		if ( $xml->transaction ) {
100
			$transaction = new stdClass();
101
102
			$transaction->id          = Security::filter( $xml->transaction->id );
103
			$transaction->currency    = Security::filter( $xml->transaction->currency );
104
			$transaction->amount      = Security::filter( $xml->transaction->amount );
105
			$transaction->description = Security::filter( $xml->transaction->description );
106
			$transaction->var1        = Security::filter( $xml->transaction->var1 );
107
			$transaction->var2        = Security::filter( $xml->transaction->var2 );
108
			$transaction->var3        = Security::filter( $xml->transaction->var3 );
109
			$transaction->items       = Security::filter( $xml->transaction->items );
110
111
			$message->transaction = $transaction;
112
		}
113
114
		// Payment details
115
		if ( $xml->paymentdetails ) {
116
			$payment_details = new stdClass();
117
118
			$payment_details->type                    = Security::filter( $xml->paymentdetails->type );
119
			$payment_details->account_iban            = Security::filter( $xml->paymentdetails->accountiban );
120
			$payment_details->account_bic             = Security::filter( $xml->paymentdetails->accountbic );
121
			$payment_details->account_id              = Security::filter( $xml->paymentdetails->accountid );
122
			$payment_details->account_holder_name     = Security::filter( $xml->paymentdetails->accountholdername );
123
			$payment_details->external_transaction_id = Security::filter( $xml->paymentdetails->externaltransactionid );
124
125
			$message->payment_details = $payment_details;
126
		}
127
128
		return $message;
129
	}
130
}
131