Test Failed
Push — develop ( 1379c5...9ee7ad )
by Reüel
10:59
created

src/Integration.php (4 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\IDealBasic;
4
5
use Pronamic\WordPress\Pay\Gateways\IDeal\AbstractIntegration;
6
7
/**
8
 * Title: Integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.4
15
 * @since   1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	/**
19
	 * Construct and initialize integration.
20
	 */
21
	public function __construct( $args = array() ) {
22
		$args = wp_parse_args(
23
			$args,
24
			array(
25
				'id'               => 'ideal-basic',
26
				'name'             => 'iDEAL Basic',
27
				'url'              => __( 'https://www.ideal.nl/en/', 'pronamic_ideal' ),
28
				'product_url'      => __( 'https://www.ideal.nl/en/', 'pronamic_ideal' ),
29
				'manual_url'       => null,
30
				'dashboard_url'    => null,
31
				'provider'         => null,
32
				'aquirer_url'      => null,
33
				'aquirer_test_url' => null,
34
				'deprecated'       => false,
35
			)
36
		);
37
38
		$this->id            = $args['id'];
39
		$this->name          = $args['name'];
40
		$this->url           = $args['url'];
41
		$this->product_url   = $args['product_url'];
42
		$this->manual_url    = $args['manual_url'];
0 ignored issues
show
Bug Best Practice introduced by
The property manual_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
		$this->dashboard_url = $args['dashboard_url'];
44
		$this->provider      = $args['provider'];
45
		$this->deprecated    = $args['deprecated'];
0 ignored issues
show
Bug Best Practice introduced by
The property deprecated does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
46
47
		$this->aquirer_url      = $args['aquirer_url'];
0 ignored issues
show
Bug Best Practice introduced by
The property aquirer_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
		$this->aquirer_test_url = $args['aquirer_test_url'];
0 ignored issues
show
Bug Best Practice introduced by
The property aquirer_test_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
49
50
		$this->supports = array(
51
			'webhook',
52
			'webhook_log',
53
		);
54
55
		// Actions.
56
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
57
58
		if ( ! has_action( 'wp_loaded', $function ) ) {
59
			add_action( 'wp_loaded', $function );
60
		}
61
	}
62
63
	public function get_settings_fields() {
64
		$fields = parent::get_settings_fields();
65
66
		// Hash Key
67
		$fields[] = array(
68
			'section'  => 'general',
69
			'filter'   => FILTER_SANITIZE_STRING,
70
			'meta_key' => '_pronamic_gateway_ideal_hash_key',
71
			'title'    => __( 'Hash Key', 'pronamic_ideal' ),
72
			'type'     => 'text',
73
			'classes'  => array( 'regular-text', 'code' ),
74
			'tooltip'  => __( 'Hash key (also known as: key or secret key) as mentioned in the payment provider dashboard.', 'pronamic_ideal' ),
75
			'methods'  => array( 'ideal-basic' ),
76
		);
77
78
		// XML Notification URL.
79
		$fields[] = array(
80
			'section'  => 'feedback',
81
			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */
82
			'title'    => _x( 'XML Notification URL', 'iDEAL Basic dashboard', 'pronamic_ideal' ),
83
			'type'     => 'text',
84
			'classes'  => array( 'regular-text', 'code' ),
85
			'value'    => add_query_arg(
86
				array(
87
					'gateway'          => 'IDealBasic',
88
					'xml_notification' => 'true',
89
				),
90
				site_url( '/' )
91
			),
92
			'methods'  => array( 'ideal-basic' ),
93
			'readonly' => true,
94
			'size'     => 200,
95
			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */
96
			'tooltip'  => _x(
97
				'Copy the XML notification URL to the payment provider dashboard to receive automatic transaction status updates.',
98
				'iDEAL Basic dashboard',
99
				'pronamic_ideal'
100
			),
101
		);
102
103
		// Return fields.
104
		return $fields;
105
	}
106
107
	public function get_config( $post_id ) {
108
		$mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
109
110
		$config = new Config();
111
112
		$config->url = $this->aquirer_url;
113
114
		if ( 'test' === $mode && null !== $this->aquirer_test_url ) {
115
			$config->url = $this->aquirer_test_url;
116
		}
117
118
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_merchant_id', true );
119
		$config->sub_id      = get_post_meta( $post_id, '_pronamic_gateway_ideal_sub_id', true );
120
		$config->hash_key    = get_post_meta( $post_id, '_pronamic_gateway_ideal_hash_key', true );
121
		$config->purchase_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_purchase_id', true );
122
123
		return $config;
124
	}
125
126
	/**
127
	 * Get gateway.
128
	 *
129
	 * @param int $post_id Post ID.
130
	 * @return Gateway
131
	 */
132
	public function get_gateway( $post_id ) {
133
		return new Gateway( $this->get_config( $post_id ) );
134
	}
135
}
136