wp-pay-gateways /
omnikassa-2
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Integration |
||
| 4 | * |
||
| 5 | * @author Pronamic <[email protected]> |
||
| 6 | * @copyright 2005-2019 Pronamic |
||
| 7 | * @license GPL-3.0-or-later |
||
| 8 | * @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; |
||
| 12 | |||
| 13 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Integration |
||
| 17 | * |
||
| 18 | * @author Remco Tolsma |
||
| 19 | * @version 2.1.0 |
||
| 20 | * @since 1.0.0 |
||
| 21 | */ |
||
| 22 | class Integration extends AbstractIntegration { |
||
| 23 | /** |
||
| 24 | * Construct and initialize integration. |
||
| 25 | */ |
||
| 26 | public function __construct() { |
||
| 27 | $this->id = 'rabobank-omnikassa-2'; |
||
| 28 | $this->name = 'Rabobank - OmniKassa 2.0'; |
||
| 29 | $this->product_url = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/'; |
||
| 30 | $this->dashboard_url = 'https://bankieren.rabobank.nl/omnikassa-dashboard/'; |
||
| 31 | $this->provider = 'rabobank'; |
||
| 32 | $this->supports = array( |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 33 | 'webhook', |
||
| 34 | ); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Webhook listener function. |
||
| 38 | * |
||
| 39 | * @var callable $webhook_listener_function |
||
| 40 | */ |
||
| 41 | $webhook_listener_function = array( __NAMESPACE__ . '\WebhookListener', 'listen' ); |
||
| 42 | |||
| 43 | if ( ! has_action( 'wp_loaded', $webhook_listener_function ) ) { |
||
| 44 | add_action( 'wp_loaded', $webhook_listener_function ); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Save post. |
||
| 49 | * |
||
| 50 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736 |
||
| 51 | * |
||
| 52 | * @var callable $delete_access_token_meta_function |
||
| 53 | */ |
||
| 54 | $delete_access_token_meta_function = array( __NAMESPACE__ . '\ConfigFactory', 'delete_access_token_meta' ); |
||
| 55 | |||
| 56 | if ( ! has_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ) ) { |
||
| 57 | add_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Admin notices. |
||
| 62 | * |
||
| 63 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264 |
||
| 64 | * |
||
| 65 | * @var callable $admin_notices_function |
||
| 66 | */ |
||
| 67 | $admin_notices_function = array( $this, 'admin_notice_tld_test' ); |
||
| 68 | |||
| 69 | if ( ! has_action( 'admin_notices', $admin_notices_function ) ) { |
||
| 70 | add_action( 'admin_notices', $admin_notices_function ); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Admin notice TLD .test. |
||
| 76 | * |
||
| 77 | * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264 |
||
| 78 | * @link https://developer.wordpress.org/reference/hooks/admin_notices/ |
||
| 79 | * @link https://developer.wordpress.org/reference/functions/get_current_screen/ |
||
| 80 | */ |
||
| 81 | public function admin_notice_tld_test() { |
||
| 82 | if ( has_filter( 'pronamic_pay_omnikassa_2_merchant_return_url' ) ) { |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | $screen = get_current_screen(); |
||
| 87 | |||
| 88 | if ( null === $screen ) { |
||
| 89 | return; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ( 'pronamic_gateway' !== $screen->id ) { |
||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | $host = wp_parse_url( home_url( '/' ), PHP_URL_HOST ); |
||
| 97 | |||
| 98 | if ( is_array( $host ) ) { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | if ( '.test' !== substr( $host, -5 ) ) { |
||
| 103 | return; |
||
| 104 | } |
||
| 105 | |||
| 106 | $post_id = get_the_ID(); |
||
| 107 | |||
| 108 | if ( empty( $post_id ) ) { |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | $gateway_id = get_post_meta( $post_id, '_pronamic_gateway_id', true ); |
||
| 113 | |||
| 114 | if ( 'rabobank-omnikassa-2' !== $gateway_id ) { |
||
| 115 | return; |
||
| 116 | } |
||
| 117 | |||
| 118 | $class = 'notice notice-error'; |
||
| 119 | $message = sprintf( |
||
| 120 | /* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */ |
||
| 121 | __( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ), |
||
| 122 | sprintf( |
||
| 123 | '<strong>%s</strong>', |
||
| 124 | __( 'Pronamic Pay', 'pronamic_ideal' ) |
||
| 125 | ), |
||
| 126 | 'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address', |
||
| 127 | '<code>.test</code>' |
||
| 128 | ); |
||
| 129 | |||
| 130 | printf( |
||
| 131 | '<div class="%1$s"><p>%2$s</p></div>', |
||
| 132 | esc_attr( $class ), |
||
| 133 | wp_kses( |
||
| 134 | $message, |
||
| 135 | array( |
||
| 136 | 'a' => array( |
||
| 137 | 'href' => true, |
||
| 138 | ), |
||
| 139 | 'code' => array(), |
||
| 140 | 'strong' => array(), |
||
| 141 | ) |
||
| 142 | ) |
||
| 143 | ); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Get config factory class. |
||
| 148 | * |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | public function get_config_factory_class() { |
||
| 152 | return __NAMESPACE__ . '\ConfigFactory'; |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Get settings fields. |
||
| 157 | * |
||
| 158 | * @return array |
||
| 159 | */ |
||
| 160 | public function get_settings_fields() { |
||
| 161 | $fields = array(); |
||
| 162 | |||
| 163 | // Refresh Token. |
||
| 164 | $fields[] = array( |
||
| 165 | 'section' => 'general', |
||
| 166 | 'filter' => FILTER_SANITIZE_STRING, |
||
| 167 | 'meta_key' => '_pronamic_gateway_omnikassa_2_refresh_token', |
||
| 168 | 'title' => _x( 'Refresh Token', 'omnikassa', 'pronamic_ideal' ), |
||
| 169 | 'type' => 'textarea', |
||
| 170 | 'classes' => array( 'code' ), |
||
| 171 | ); |
||
| 172 | |||
| 173 | // Signing Key. |
||
| 174 | $fields[] = array( |
||
| 175 | 'section' => 'general', |
||
| 176 | 'filter' => FILTER_SANITIZE_STRING, |
||
| 177 | 'meta_key' => '_pronamic_gateway_omnikassa_2_signing_key', |
||
| 178 | 'title' => _x( 'Signing Key', 'omnikassa', 'pronamic_ideal' ), |
||
| 179 | 'type' => 'text', |
||
| 180 | 'classes' => array( 'large-text', 'code' ), |
||
| 181 | ); |
||
| 182 | |||
| 183 | // Purchase ID. |
||
| 184 | $fields[] = array( |
||
| 185 | 'section' => 'advanced', |
||
| 186 | 'filter' => FILTER_SANITIZE_STRING, |
||
| 187 | 'meta_key' => '_pronamic_gateway_omnikassa_2_order_id', |
||
| 188 | 'title' => __( 'Order ID', 'pronamic_ideal' ), |
||
| 189 | 'type' => 'text', |
||
| 190 | 'classes' => array( 'regular-text', 'code' ), |
||
| 191 | 'tooltip' => sprintf( |
||
| 192 | /* translators: %s: Parameter */ |
||
| 193 | __( 'The OmniKassa %s parameter.', 'pronamic_ideal' ), |
||
| 194 | sprintf( '<code>%s</code>', 'orderId' ) |
||
| 195 | ), |
||
| 196 | 'description' => sprintf( |
||
| 197 | '%s %s<br />%s', |
||
| 198 | __( 'Available tags:', 'pronamic_ideal' ), |
||
| 199 | sprintf( |
||
| 200 | '<code>%s</code> <code>%s</code>', |
||
| 201 | '{order_id}', |
||
| 202 | '{payment_id}' |
||
| 203 | ), |
||
| 204 | sprintf( |
||
| 205 | /* translators: %s: {payment_id} */ |
||
| 206 | __( 'Default: <code>%s</code>', 'pronamic_ideal' ), |
||
| 207 | '{payment_id}' |
||
| 208 | ) |
||
| 209 | ), |
||
| 210 | ); |
||
| 211 | |||
| 212 | // Webhook. |
||
| 213 | $fields[] = array( |
||
| 214 | 'section' => 'feedback', |
||
| 215 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||
| 216 | 'type' => 'text', |
||
| 217 | 'classes' => array( 'large-text', 'code' ), |
||
| 218 | 'value' => add_query_arg( 'omnikassa2_webhook', '', home_url( '/' ) ), |
||
| 219 | 'readonly' => true, |
||
| 220 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||
| 221 | ); |
||
| 222 | |||
| 223 | return $fields; |
||
| 224 | } |
||
| 225 | } |
||
| 226 |