|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink; |
|
4
|
|
|
|
|
5
|
|
|
use Pronamic\WordPress\Pay\Core\Util; |
|
6
|
|
|
use Pronamic\WordPress\Pay\Core\XML\Security; |
|
7
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink; |
|
8
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\Error; |
|
9
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\XML\OrderResponseParser; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Title: Ingenico DirectLink client |
|
13
|
|
|
* Description: |
|
14
|
|
|
* Copyright: 2005-2021 Pronamic |
|
15
|
|
|
* Company: Pronamic |
|
16
|
|
|
* |
|
17
|
|
|
* @author Remco Tolsma |
|
18
|
|
|
* @version 2.0.4 |
|
19
|
|
|
* @since 1.0.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class Client { |
|
22
|
|
|
/** |
|
23
|
|
|
* API URL. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
public $api_url; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* PSP ID. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
public $psp_id; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* SHA IN. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
public $sha_in; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* User ID. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
public $user_id; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Password. |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
public $password; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Constructs and initializes an Ogone DirectLink client |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct() { |
|
61
|
|
|
$this->api_url = DirectLink::API_PRODUCTION_URL; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Order direct |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $data Data. |
|
68
|
|
|
* |
|
69
|
|
|
* @return bool|OrderResponse |
|
70
|
|
|
* @throws \Exception Throws exception if DirectLink request fails. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function order_direct( array $data = array() ) { |
|
73
|
|
|
$result = Util::remote_get_body( |
|
74
|
|
|
$this->api_url, |
|
75
|
|
|
200, |
|
76
|
|
|
array( |
|
77
|
|
|
'method' => 'POST', |
|
78
|
|
|
'sslverify' => false, |
|
79
|
|
|
'body' => $data, |
|
80
|
|
|
) |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
if ( $result instanceof \WP_Error ) { |
|
84
|
|
|
throw new \Exception( |
|
85
|
|
|
\sprintf( |
|
86
|
|
|
'Ogone DirectLink HTTP request failed: %s.', |
|
87
|
|
|
$result->get_error_message() |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$xml = Util::simplexml_load_string( $result ); |
|
93
|
|
|
|
|
94
|
|
|
$order_response = OrderResponseParser::parse( $xml ); |
|
95
|
|
|
|
|
96
|
|
|
if ( ! empty( $order_response->nc_error ) ) { |
|
97
|
|
|
$ogone_error = new Error( |
|
98
|
|
|
Security::filter( $order_response->nc_error ), |
|
99
|
|
|
Security::filter( $order_response->nc_error_plus ) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
throw new \Exception( (string) $ogone_error ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $order_response; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|