Test Failed
Push — develop ( 1f5549...88de64 )
by Reüel
14:27
created

src/Integration.php (1 issue)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: Buckaroo integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.0
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	public function __construct() {
19
		$this->id            = 'buckaroo';
20
		$this->name          = 'Buckaroo - HTML';
21
		$this->url           = 'https://plaza.buckaroo.nl/';
22
		$this->product_url   = __( 'http://www.buckaroo-payments.com', 'pronamic_ideal' );
23
		$this->manual_url    = __( 'https://www.pronamic.eu/support/how-to-connect-buckaroo-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' );
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...
24
		$this->dashboard_url = 'https://plaza.buckaroo.nl/';
25
		$this->provider      = 'buckaroo';
26
		$this->supports      = array(
27
			'webhook',
28
			'webhook_log',
29
			'webhook_no_config',
30
		);
31
32
		// Actions
33
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
34
35
		if ( ! has_action( 'wp_loaded', $function ) ) {
36
			add_action( 'wp_loaded', $function );
37
		}
38
	}
39
40
	public function get_settings_fields() {
41
		$fields = array();
42
43
		// Website Key.
44
		$fields[] = array(
45
			'section'  => 'general',
46
			'filter'   => FILTER_SANITIZE_STRING,
47
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
48
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
49
			'type'     => 'text',
50
			'classes'  => array( 'code' ),
51
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
52
		);
53
54
		// Secret Key.
55
		$fields[] = array(
56
			'section'  => 'general',
57
			'filter'   => FILTER_SANITIZE_STRING,
58
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
59
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
60
			'type'     => 'text',
61
			'classes'  => array( 'regular-text', 'code' ),
62
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboardb on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
63
		);
64
65
		// Excluded services.
66
		$fields[] = array(
67
			'section'  => 'advanced',
68
			'filter'   => FILTER_SANITIZE_STRING,
69
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
70
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
71
			'type'     => 'text',
72
			'classes'  => array( 'regular-text', 'code' ),
73
			'tooltip'  => sprintf(
74
				/* translators: %s: <code>brq_exludedservices</code> */
75
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
76
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
77
			),
78
		);
79
80
		// Invoice number.
81
		$fields[] = array(
82
			'section'     => 'advanced',
83
			'filter'      => FILTER_SANITIZE_STRING,
84
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
85
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
86
			'type'        => 'text',
87
			'classes'     => array( 'regular-text', 'code' ),
88
			'tooltip'     => sprintf(
89
				/* translators: %s: <code>brq_invoicenumber</code> */
90
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
91
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
92
			),
93
			'description' => sprintf(
94
				'%s<br />%s',
95
				/* translators: %s: <code>{order_id}</code> <code>{payment_id}</code> */
96
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
97
				/* translators: %s: <code>{payment_id}</code> */
98
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
99
			),
100
		);
101
102
		// Push URL.
103
		$fields[] = array(
104
			'section'  => 'feedback',
105
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
106
			'type'     => 'text',
107
			'classes'  => array( 'large-text', 'code' ),
108
			'value'    => add_query_arg( 'buckaroo_push', '', home_url( '/' ) ),
109
			'readonly' => true,
110
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
111
		);
112
113
		return $fields;
114
	}
115
116
	public function get_config( $post_id ) {
117
		$config = new Config();
118
119
		$config->website_key       = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true );
120
		$config->secret_key        = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true );
121
		$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true );
122
		$config->invoice_number    = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true );
123
		$config->mode              = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
124
125
		return $config;
126
	}
127
128
	/**
129
	 * Get gateway.
130
	 *
131
	 * @param int $post_id Post ID.
132
	 * @return Gateway
133
	 */
134
	public function get_gateway( $post_id ) {
135
		return new Gateway( $this->get_config( $post_id ) );
136
	}
137
}
138