|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Ingenico\OrderStandardEasy; |
|
4
|
|
|
|
|
5
|
|
|
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
|
6
|
|
|
use Pronamic\WordPress\Pay\Core\PaymentMethods; |
|
7
|
|
|
use Pronamic\WordPress\Pay\Core\Statuses; |
|
8
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\DataCustomerHelper; |
|
9
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\DataGeneralHelper; |
|
10
|
|
|
use Pronamic\WordPress\Pay\Gateways\Ingenico\DataUrlHelper; |
|
11
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Title: Easy |
|
15
|
|
|
* Description: |
|
16
|
|
|
* Copyright: 2005-2019 Pronamic |
|
17
|
|
|
* Company: Pronamic |
|
18
|
|
|
* |
|
19
|
|
|
* @author Remco Tolsma |
|
20
|
|
|
* @version 2.0.1 |
|
21
|
|
|
* @since 1.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Gateway extends Core_Gateway { |
|
24
|
|
|
/** |
|
25
|
|
|
* Client. |
|
26
|
|
|
* |
|
27
|
|
|
* @var Client |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $client; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Construct and intialize an iDEAL Easy gateway |
|
33
|
|
|
* |
|
34
|
|
|
* @param Config $config Config. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( Config $config ) { |
|
37
|
|
|
parent::__construct( $config ); |
|
38
|
|
|
|
|
39
|
|
|
$this->set_method( self::METHOD_HTML_FORM ); |
|
40
|
|
|
|
|
41
|
|
|
$this->client = new Client( $config->psp_id ); |
|
42
|
|
|
$this->client->set_payment_server_url( $config->get_form_action_url() ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get supported payment methods |
|
47
|
|
|
* |
|
48
|
|
|
* @see Core_Gateway::get_supported_payment_methods() |
|
49
|
|
|
*/ |
|
50
|
|
|
public function get_supported_payment_methods() { |
|
51
|
|
|
return array( |
|
52
|
|
|
PaymentMethods::IDEAL, |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get output fields |
|
58
|
|
|
* |
|
59
|
|
|
* @since 1.2.1 |
|
60
|
|
|
* @see Core_Gateway::get_output_html() |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
|
|
public function get_output_fields() { |
|
64
|
|
|
return $this->client->get_fields(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Start transaction with the specified data |
|
69
|
|
|
* |
|
70
|
|
|
* @see Core_Gateway::start() |
|
71
|
|
|
* |
|
72
|
|
|
* @param Payment $payment Payment. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function start( Payment $payment ) { |
|
75
|
|
|
$payment->set_action_url( $this->client->get_payment_server_url() ); |
|
76
|
|
|
|
|
77
|
|
|
$ogone_data = $this->client->get_data(); |
|
78
|
|
|
|
|
79
|
|
|
// General. |
|
80
|
|
|
$ogone_data_general = new DataGeneralHelper( $ogone_data ); |
|
81
|
|
|
|
|
82
|
|
|
$ogone_data_general |
|
83
|
|
|
->set_order_id( $payment->format_string( $this->config->order_id ) ) |
|
84
|
|
|
->set_order_description( $payment->get_description() ) |
|
85
|
|
|
->set_param_plus( 'payment_id=' . $payment->get_id() ) |
|
86
|
|
|
->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ) |
|
87
|
|
|
->set_amount( $payment->get_total_amount()->get_cents() ); |
|
88
|
|
|
|
|
89
|
|
|
$customer = $payment->get_customer(); |
|
90
|
|
|
|
|
91
|
|
|
if ( null !== $customer ) { |
|
92
|
|
|
// Localised language. |
|
93
|
|
|
$ogone_data_general->set_language( $customer->get_locale() ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// Customer. |
|
97
|
|
|
$ogone_data_customer = new DataCustomerHelper( $ogone_data ); |
|
98
|
|
|
|
|
99
|
|
|
if ( null !== $customer ) { |
|
100
|
|
|
$name = $customer->get_name(); |
|
101
|
|
|
|
|
102
|
|
|
if ( null !== $name ) { |
|
103
|
|
|
$ogone_data_customer->set_name( strval( $name ) ); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
$ogone_data_customer->set_email( $customer->get_email() ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$billing_address = $payment->get_billing_address(); |
|
110
|
|
|
|
|
111
|
|
|
if ( null !== $billing_address ) { |
|
112
|
|
|
$ogone_data_customer |
|
113
|
|
|
->set_address( $billing_address->get_line_1() ) |
|
114
|
|
|
->set_zip( $billing_address->get_postal_code() ) |
|
115
|
|
|
->set_town( $billing_address->get_city() ) |
|
116
|
|
|
->set_country( $billing_address->get_country_code() ) |
|
117
|
|
|
->set_telephone_number( $billing_address->get_phone() ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
// URLs. |
|
121
|
|
|
$ogone_url_helper = new DataUrlHelper( $ogone_data ); |
|
122
|
|
|
|
|
123
|
|
|
$ogone_url_helper |
|
124
|
|
|
->set_accept_url( add_query_arg( 'status', Statuses::SUCCESS, $payment->get_return_url() ) ) |
|
|
|
|
|
|
125
|
|
|
->set_cancel_url( add_query_arg( 'status', Statuses::CANCELLED, $payment->get_return_url() ) ) |
|
126
|
|
|
->set_decline_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) ) |
|
127
|
|
|
->set_exception_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) ) |
|
128
|
|
|
->set_back_url( home_url( '/' ) ) |
|
|
|
|
|
|
129
|
|
|
->set_home_url( home_url( '/' ) ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Update status of the specified payment |
|
134
|
|
|
* |
|
135
|
|
|
* @param Payment $payment Payment. |
|
136
|
|
|
*/ |
|
137
|
|
|
public function update_status( Payment $payment ) { |
|
138
|
|
|
if ( ! filter_has_var( INPUT_GET, 'status' ) ) { |
|
139
|
|
|
return; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
$status = filter_input( INPUT_GET, 'status', FILTER_SANITIZE_STRING ); |
|
143
|
|
|
|
|
144
|
|
|
$payment->set_status( $status ); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|