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