Completed
Push — master ( efe305...a09dd1 )
by Remco
02:44
created

Integration::get_gateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: OmniKassa integration
9
 * Description:
10
 * Copyright: Copyright (c) 2005 - 2018
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
	public function __construct() {
19
		$this->id            = 'rabobank-omnikassa';
20
		$this->name          = 'Rabobank - OmniKassa';
21
		$this->product_url   = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/';
22
		$this->dashboard_url = array(
23
			__( 'admin', 'pronamic_ideal' )    => 'https://dashboard.omnikassa.rabobank.nl/',
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
			/** @scrutinizer ignore-call */ 
24
   __( 'admin', 'pronamic_ideal' )    => 'https://dashboard.omnikassa.rabobank.nl/',
Loading history...
24
			__( 'download', 'pronamic_ideal' ) => 'https://download.omnikassa.rabobank.nl/',
25
		);
26
		$this->provider      = 'rabobank';
27
		$this->deprecated    = true;
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...
28
29
		// Actions
30
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
31
32
		if ( ! has_action( 'wp_loaded', $function ) ) {
0 ignored issues
show
Bug introduced by
The function has_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
		if ( ! /** @scrutinizer ignore-call */ has_action( 'wp_loaded', $function ) ) {
Loading history...
33
			add_action( 'wp_loaded', $function );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
			/** @scrutinizer ignore-call */ 
34
   add_action( 'wp_loaded', $function );
Loading history...
34
		}
35
	}
36
37
	/**
38
	 * Get settings fields.
39
	 *
40
	 * @return array
41
	 */
42
	public function get_settings_fields() {
43
		$fields = array();
44
45
		// Merchant ID
46
		$fields[] = array(
47
			'section'  => 'general',
48
			'filter'   => FILTER_SANITIZE_STRING,
49
			'meta_key' => '_pronamic_gateway_omnikassa_merchant_id',
50
			'title'    => __( 'Merchant ID', 'pronamic_ideal' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
			'title'    => /** @scrutinizer ignore-call */ __( 'Merchant ID', 'pronamic_ideal' ),
Loading history...
51
			'type'     => 'text',
52
			'classes'  => array( 'code' ),
53
		);
54
55
		// Secret Key
56
		$fields[] = array(
57
			'section'  => 'general',
58
			'filter'   => FILTER_SANITIZE_STRING,
59
			'meta_key' => '_pronamic_gateway_omnikassa_secret_key',
60
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
61
			'type'     => 'text',
62
			'classes'  => array( 'large-text', 'code' ),
63
		);
64
65
		// Key Version
66
		$fields[] = array(
67
			'section'  => 'general',
68
			'filter'      => FILTER_SANITIZE_STRING,
69
			'meta_key'    => '_pronamic_gateway_omnikassa_key_version',
70
			'title'       => __( 'Key Version', 'pronamic_ideal' ),
71
			'type'        => 'text',
72
			'classes'     => array( 'code' ),
73
			'size'        => 5,
74
			'description' => sprintf( __( 'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.', 'pronamic_ideal' ), 'https://download.omnikassa.rabobank.nl/' ),
75
		);
76
77
		// Purchase ID
78
		$fields[] = array(
79
			'section'     => 'advanced',
80
			'filter'      => FILTER_SANITIZE_STRING,
81
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
82
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
83
			'type'        => 'text',
84
			'classes'     => array( 'regular-text', 'code' ),
85
			'tooltip'     => sprintf(
86
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
87
				sprintf( '<code>%s</code>', 'orderId' )
88
			),
89
			'description' => sprintf(
90
				'%s %s<br />%s',
91
				__( 'Available tags:', 'pronamic_ideal' ),
92
				sprintf(
93
					'<code>%s</code> <code>%s</code>',
94
					'{order_id}',
95
					'{payment_id}'
96
				),
97
				sprintf(
98
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
99
					'{payment_id}'
100
				)
101
			),
102
		);
103
104
		return $fields;
105
	}
106
107
	public function get_config( $post_id ) {
108
		$config = new Config();
109
110
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
0 ignored issues
show
Bug introduced by
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
		$config->merchant_id = /** @scrutinizer ignore-call */ get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
Loading history...
111
		$config->secret_key  = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_secret_key', true );
112
		$config->key_version = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_key_version', true );
113
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_order_id', true );
114
		$config->mode        = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
115
116
		return $config;
117
	}
118
119
	/**
120
	 * Get gateway.
121
	 *
122
	 * @param int $post_id Post ID.
123
	 * @return Gateway
124
	 */
125
	public function get_gateway( $post_id ) {
126
		return new Gateway( $this->get_config( $post_id ) );
127
	}
128
}
129