Test Failed
Push — master ( 233d8c...79f9a8 )
by Remco
21:05 queued 13:03
created

src/Integration.php (3 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
				'dashboard_url'    => null,
30
				'provider'         => null,
31
				'aquirer_url'      => null,
32
				'aquirer_test_url' => null,
33
				'deprecated'       => false,
34
			)
35
		);
36
37
		$this->id            = $args['id'];
38
		$this->name          = $args['name'];
39
		$this->url           = $args['url'];
40
		$this->product_url   = $args['product_url'];
41
		$this->dashboard_url = $args['dashboard_url'];
42
		$this->provider      = $args['provider'];
43
		$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...
44
45
		$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...
46
		$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...
47
48
		$this->supports = array(
49
			'webhook',
50
			'webhook_log',
51
		);
52
53
		// Actions.
54
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
55
56
		if ( ! has_action( 'wp_loaded', $function ) ) {
57
			add_action( 'wp_loaded', $function );
58
		}
59
	}
60
61
	public function get_settings_fields() {
62
		$fields = parent::get_settings_fields();
63
64
		// Hash Key
65
		$fields[] = array(
66
			'section'  => 'general',
67
			'filter'   => FILTER_SANITIZE_STRING,
68
			'meta_key' => '_pronamic_gateway_ideal_hash_key',
69
			'title'    => __( 'Hash Key', 'pronamic_ideal' ),
70
			'type'     => 'text',
71
			'classes'  => array( 'regular-text', 'code' ),
72
			'tooltip'  => __( 'Hash key (also known as: key or secret key) as mentioned in the payment provider dashboard.', 'pronamic_ideal' ),
73
			'methods'  => array( 'ideal-basic' ),
74
		);
75
76
		// XML Notification URL.
77
		$fields[] = array(
78
			'section'  => 'feedback',
79
			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */
80
			'title'    => _x( 'XML Notification URL', 'iDEAL Basic dashboard', 'pronamic_ideal' ),
81
			'type'     => 'text',
82
			'classes'  => array( 'regular-text', 'code' ),
83
			'value'    => add_query_arg(
84
				array(
85
					'gateway'          => 'IDealBasic',
86
					'xml_notification' => 'true',
87
				),
88
				site_url( '/' )
89
			),
90
			'methods'  => array( 'ideal-basic' ),
91
			'readonly' => true,
92
			'size'     => 200,
93
			/* translators: Translate 'XML notification URL' the same as in the iDEAL Basic dashboard. */
94
			'tooltip'  => _x(
95
				'Copy the XML notification URL to the payment provider dashboard to receive automatic transaction status updates.',
96
				'iDEAL Basic dashboard',
97
				'pronamic_ideal'
98
			),
99
		);
100
101
		// Return fields.
102
		return $fields;
103
	}
104
105
	public function get_config( $post_id ) {
106
		$mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
107
108
		$config = new Config();
109
110
		$config->url = $this->aquirer_url;
111
112
		if ( 'test' === $mode && null !== $this->aquirer_test_url ) {
113
			$config->url = $this->aquirer_test_url;
114
		}
115
116
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_merchant_id', true );
117
		$config->sub_id      = get_post_meta( $post_id, '_pronamic_gateway_ideal_sub_id', true );
118
		$config->hash_key    = get_post_meta( $post_id, '_pronamic_gateway_ideal_hash_key', true );
119
		$config->purchase_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_purchase_id', true );
120
121
		return $config;
122
	}
123
124
	/**
125
	 * Get gateway.
126
	 *
127
	 * @param int $post_id Post ID.
128
	 * @return Gateway
129
	 */
130
	public function get_gateway( $post_id ) {
131
		return new Gateway( $this->get_config( $post_id ) );
132
	}
133
}
134