Test Failed
Push — develop ( b01831...dd0621 )
by Remco
04:43
created

Integration::get_gateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Icepay;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: ICEPAY 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 1
	public function __construct( $args = array() ) {
19 1
		$args = wp_parse_args( $args, array(
20 1
			'id'            => 'icepay-ideal',
21 1
			'name'          => 'ICEPAY',
22 1
			'url'           => 'https://icepay.com/',
23 1
			'product_url'   => __( 'https://icepay.com/nl/en/pricing-and-accounts/', 'pronamic_ideal' ),
24 1
			'dashboard_url' => 'https://portal.icepay.com/',
25
			'provider'      => 'icepay',
26
		) );
27 1
28
		$this->id            = $args['id'];
29 1
		$this->name          = $args['name'];
30 1
		$this->url           = $args['url'];
31
		$this->product_url   = $args['product_url'];
32 1
		$this->dashboard_url = $args['dashboard_url'];
33
		$this->provider      = $args['provider'];
34 1
35 1
		// Actions
36
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
37
38
		if ( ! has_action( 'wp_loaded', $function ) ) {
39
			add_action( 'wp_loaded', $function );
40
		}
41
	}
42
43
	public function get_settings_fields() {
44
		$fields = array();
45
46
		// Merchant ID
47
		$fields[] = array(
48
			'section'  => 'general',
49
			'filter'   => FILTER_SANITIZE_STRING,
50
			'meta_key' => '_pronamic_gateway_icepay_merchant_id',
51
			'title'    => _x( 'Merchant ID', 'icepay', 'pronamic_ideal' ),
52
			'type'     => 'text',
53
			'tooltip'  => __( 'Merchant ID as mentioned in the ICEPAY dashboard at the "My websites" page.', 'pronamic_ideal' ),
54
		);
55
56
		// Secret Code
57
		$fields[] = array(
58
			'section'  => 'general',
59
			'filter'   => FILTER_SANITIZE_STRING,
60
			'meta_key' => '_pronamic_gateway_icepay_secret_code',
61
			'title'    => _x( 'Secret Code', 'icepay', 'pronamic_ideal' ),
62
			'type'     => 'text',
63
			'classes'  => array( 'regular-text', 'code' ),
64
			'tooltip'  => __( 'Secret Code as mentioned in the ICEPAY dashboard at the "My websites" page.', 'pronamic_ideal' ),
65
		);
66
67
		// Purchase ID
68
		$fields[] = array(
69
			'section'     => 'advanced',
70
			'filter'      => array(
71
				'filter' => FILTER_SANITIZE_STRING,
72
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
73
			),
74
			'meta_key'    => '_pronamic_gateway_icepay_order_id',
75
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
76
			'type'        => 'text',
77
			'classes'     => array( 'regular-text', 'code' ),
78
			'tooltip'     => sprintf(
79
				/* translators: %s: <code>OrderID</code> */
80
				__( 'The Icepay %s parameter.', 'pronamic_ideal' ),
81
				sprintf( '<code>%s</code>', 'OrderID' )
82
			),
83
			'description' => sprintf(
84
				'%s %s<br />%s',
85
				__( 'Available tags:', 'pronamic_ideal' ),
86
				sprintf(
87
					'<code>%s</code> <code>%s</code>',
88
					'{order_id}',
89
					'{payment_id}'
90
				),
91
				sprintf(
92
					/* translators: %s: <code>{payment_id}</code> */
93
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
94
					'{payment_id}'
95
				)
96
			),
97
		);
98
99
		// Thank you page URL
100
		$fields[] = array(
101
			'section'  => 'feedback',
102
			'title'    => __( 'Thank you page URL', 'pronamic_ideal' ),
103
			'type'     => 'text',
104
			'classes'  => array( 'regular-text', 'code' ),
105
			'value'    => home_url( '/' ),
106
			'readonly' => true,
107
		);
108
109
		// Error page URL
110
		$fields[] = array(
111
			'section'  => 'feedback',
112
			'title'    => __( 'Error page URL', 'pronamic_ideal' ),
113
			'type'     => 'text',
114
			'classes'  => array( 'regular-text', 'code' ),
115
			'value'    => home_url( '/' ),
116
			'readonly' => true,
117
		);
118
119
		// Postback URL
120
		$fields[] = array(
121
			'section'  => 'feedback',
122
			'title'    => __( 'Postback URL', 'pronamic_ideal' ),
123
			'type'     => 'text',
124
			'classes'  => array( 'regular-text', 'code' ),
125
			'value'    => home_url( '/' ),
126
			'readonly' => true,
127
		);
128
129
		return $fields;
130
	}
131
132
	public function get_config( $post_id ) {
133
		$config = new Config();
134
135
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_icepay_merchant_id', true );
136
		$config->secret_code = get_post_meta( $post_id, '_pronamic_gateway_icepay_secret_code', true );
137
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_icepay_order_id', true );
138
139
		return $config;
140
	}
141
142
	/**
143
	 * Get gateway.
144
	 *
145
	 * @param int $post_id Post ID.
146
	 * @return Gateway
147
	 */
148
	public function get_gateway( $post_id ) {
149
		return new Gateway( $this->get_config( $post_id ) );
150
	}
151
}
152