Failed Conditions
Push — develop ( 431013...77ac21 )
by Remco
12:28
created

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