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