Failed Conditions
Push — master ( 9dbde9...83dade )
by Reüel
08:20 queued 11s
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-2021 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.1.1
15
 * @since   1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	/**
19
	 * Construct iDEAL Basic integration.
20
	 *
21
	 * @param array $args Arguments.
22
	 */
23
	public function __construct( $args = array() ) {
24
		$args = wp_parse_args(
25
			$args,
26
			array(
27
				'id'                => 'ideal-basic',
28
				'name'              => 'iDEAL Basic',
29
				'url'               => \__( 'https://www.ideal.nl/en/', 'pronamic_ideal' ),
30
				'product_url'       => \__( 'https://www.ideal.nl/en/', 'pronamic_ideal' ),
31
				'manual_url'        => null,
32
				'dashboard_url'     => null,
33
				'provider'          => null,
34
				'acquirer_url'      => null,
35
				'acquirer_test_url' => null,
36
				'deprecated'        => false,
37
				'supports'          => array(
38
					'webhook',
39
					'webhook_log',
40
				),
41
			)
42
		);
43
44
		parent::__construct( $args );
45
46
		// Acquirer URL.
47
		$this->acquirer_url      = $args['acquirer_url'];
0 ignored issues
show
Bug Best Practice introduced by
The property acquirer_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
		$this->acquirer_test_url = $args['acquirer_test_url'];
0 ignored issues
show
Bug Best Practice introduced by
The property acquirer_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
		// Actions.
51
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
52
53
		if ( ! has_action( 'wp_loaded', $function ) ) {
54
			add_action( 'wp_loaded', $function );
55
		}
56
	}
57
58
	/**
59
	 * Get settings fields.
60
	 *
61
	 * @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
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->acquirer_url;
113
114
		if ( 'test' === $mode && null !== $this->acquirer_test_url ) {
115
			$config->url = $this->acquirer_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