1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mollie settings. |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2019 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
12
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Core\GatewaySettings; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Title: Mollie gateway settings |
17
|
|
|
* Description: |
18
|
|
|
* Copyright: 2005-2019 Pronamic |
19
|
|
|
* Company: Pronamic |
20
|
|
|
* |
21
|
|
|
* @author Remco Tolsma |
22
|
|
|
* @version 2.0.5 |
23
|
|
|
* @since 1.0.0 |
24
|
|
|
*/ |
25
|
|
|
class Settings extends GatewaySettings { |
26
|
|
|
/** |
27
|
|
|
* API key meta key. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const API_KEY_META_KEY = '_pronamic_gateway_mollie_api_key'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Settings constructor. |
35
|
|
|
*/ |
36
|
3 |
|
public function __construct() { |
37
|
3 |
|
add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) ); |
38
|
3 |
|
add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) ); |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Settings sections. |
43
|
|
|
* |
44
|
|
|
* @param array $sections Sections. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
1 |
|
public function sections( array $sections ) { |
49
|
|
|
// General. |
50
|
1 |
|
$sections['mollie'] = array( |
51
|
1 |
|
'title' => __( 'Mollie', 'pronamic_ideal' ), |
52
|
|
|
'methods' => array( 'mollie' ), |
53
|
1 |
|
'description' => __( 'Account details are provided by the payment provider after registration. These settings need to match with the payment provider dashboard.', 'pronamic_ideal' ), |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
// Transaction feedback. |
57
|
1 |
|
$sections['mollie_feedback'] = array( |
58
|
1 |
|
'title' => __( 'Transaction feedback', 'pronamic_ideal' ), |
59
|
|
|
'methods' => array( 'mollie' ), |
60
|
1 |
|
'description' => __( 'Payment status updates will be processed without any additional configuration. The <em>Webhook URL</em> is being used to receive the status updates.', 'pronamic_ideal' ), |
61
|
1 |
|
'features' => Gateway::get_supported_features(), |
62
|
|
|
); |
63
|
|
|
|
64
|
1 |
|
return $sections; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Settings fields. |
69
|
|
|
* |
70
|
|
|
* @param array $fields Fields. |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
1 |
|
public function fields( array $fields ) { |
75
|
|
|
// API Key. |
76
|
1 |
|
$fields[] = array( |
77
|
1 |
|
'filter' => FILTER_SANITIZE_STRING, |
78
|
1 |
|
'section' => 'mollie', |
79
|
1 |
|
'meta_key' => self::API_KEY_META_KEY, |
80
|
1 |
|
'title' => _x( 'API Key', 'mollie', 'pronamic_ideal' ), |
81
|
1 |
|
'type' => 'text', |
82
|
|
|
'classes' => array( 'regular-text', 'code' ), |
83
|
|
|
'methods' => array( 'mollie' ), |
84
|
1 |
|
'tooltip' => __( 'API key as mentioned in the payment provider dashboard', 'pronamic_ideal' ), |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
// Transaction feedback. |
88
|
1 |
|
$fields[] = array( |
89
|
1 |
|
'section' => 'mollie', |
90
|
|
|
'methods' => array( 'mollie' ), |
91
|
1 |
|
'title' => __( 'Transaction feedback', 'pronamic_ideal' ), |
92
|
1 |
|
'type' => 'description', |
93
|
1 |
|
'html' => __( 'Payment status updates will be processed without any additional configuration.', 'pronamic_ideal' ), |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
// Webhook. |
97
|
1 |
|
$fields[] = array( |
98
|
1 |
|
'section' => 'mollie_feedback', |
99
|
1 |
|
'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
100
|
1 |
|
'type' => 'text', |
101
|
|
|
'classes' => array( 'large-text', 'code' ), |
102
|
1 |
|
'value' => add_query_arg( 'mollie_webhook', '', home_url( '/' ) ), |
103
|
|
|
'readonly' => true, |
104
|
|
|
'methods' => array( 'mollie' ), |
105
|
1 |
|
'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
// Webhook status. |
109
|
1 |
|
$fields[] = array( |
110
|
1 |
|
'section' => 'mollie_feedback', |
111
|
|
|
'methods' => array( 'mollie' ), |
112
|
1 |
|
'title' => __( 'Status', 'pronamic_ideal' ), |
113
|
1 |
|
'type' => 'description', |
114
|
|
|
'callback' => array( 'Pronamic\WordPress\Pay\WebhookManager', 'settings_status' ), |
115
|
|
|
); |
116
|
|
|
|
117
|
1 |
|
return $fields; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Save post. |
122
|
|
|
* |
123
|
|
|
* @param array $data Data to save. |
124
|
|
|
* |
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
|
|
public function save_post( $data ) { |
128
|
|
|
// Set mode based on API key. |
129
|
|
|
if ( isset( $data[ self::API_KEY_META_KEY ], $data['_pronamic_gateway_mode'] ) ) { |
130
|
|
|
$api_key = trim( $data[ self::API_KEY_META_KEY ] ); |
131
|
|
|
|
132
|
|
|
if ( empty( $api_key ) ) { |
133
|
|
|
$mode = $data['_pronamic_gateway_mode']; |
134
|
|
|
} elseif ( 'live_' === substr( $api_key, 0, 5 ) ) { |
135
|
|
|
$mode = Gateway::MODE_LIVE; |
136
|
|
|
} else { |
137
|
|
|
$mode = Gateway::MODE_TEST; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$data['_pronamic_gateway_mode'] = $mode; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $data; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|