-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-meprnovalnet.php
executable file
·131 lines (120 loc) · 3.79 KB
/
class-meprnovalnet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* Novalnet payment addon
*
* This script is used for including gateway path and
* sending auto configuration call & configuring webhook URL
*
* @author Novalnet AG
* @copyright Copyright (c) Novalnet
* @link https://www.novalnet.de
* @package Novalnetpaymentaddon
*
* Script: MeprNovalnet.php
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' ); // Exit if accessed directly.
}
/**
* MeprNovalnet Class.
*
* @class MeprNovalnet
*/
class MeprNovalnet {
/**
* Store the POST/GET request
*
* @var array
*/
public $request;
/**
* MeprNovalnet Constructor.
*/
public function __construct() {
add_filter( 'mepr-gateway-paths', array( $this, 'mepr_novalnet_get_gateway_path' ), 10, 1 );
add_filter( 'mepr-ctrls-paths', array( $this, 'mepr_novalnet_get_gateway_path' ), 99, 1 );
add_filter( 'mepr-email-paths', array( $this, 'mepr_novalnet_get_mail_path' ), 99, 1 );
add_filter( 'mepr_view_paths', array( $this, 'mepr_novalnet_get_view_path' ), 99, 1 );
add_action( 'mepr-options-admin-enqueue-script', array( $this, 'mepr_novalnet_enqueue_script' ) );
add_filter( 'wp_ajax_novalnet_get_merchant_details', array( $this, 'mepr_novalnet_get_merchant_details' ) );
add_filter( 'wp_ajax_novalnet_configure_webhook', array( $this, 'mepr_novalnet_configure_webhook' ) );
// Store the request data.
$this->request = $_REQUEST; // phpcs:ignore WordPress.Security.NonceVerification
include_once 'includes/class-novalnet-helper.php';
}
/**
* Load Novalnet gateway path to general gateway page
*
* @param array $path This contains payment gateway paths.
* @return array
*/
public function mepr_novalnet_get_gateway_path( $path ) {
array_push( $path, MP_NOVALNET_PATH . 'includes' );
return $path;
}
/**
* Load Novalnet email path
*
* @param array $path This contains email paths.
* @return array
*/
public function mepr_novalnet_get_mail_path( $path ) {
array_push( $path, MP_NOVALNET_PATH . 'app/emails' );
return $path;
}
/**
* Load Novalnet email views
*
* @param array $path This contains email template paths.
* @return array
*/
public function mepr_novalnet_get_view_path( $path ) {
array_push( $path, MP_NOVALNET_PATH . 'app/views' );
return $path;
}
/**
* Include the configuration JS file
*
* @param string $hook Current actions hook name.
* @return array
*/
public static function mepr_novalnet_enqueue_script( $hook ) {
$mepr_options = MeprOptions::fetch();
$mepr_options = json_decode( $mepr_options, true );
if ( 'memberpress_page_memberpress-options' === $hook ) {
wp_enqueue_script(
'mp-novalnet-options-js',
MP_NOVALNET_URL . 'assets/js/config.js',
array( 'jquery' ),
MP_NOVALNET_VERSION,
true
);
return $hook;
}
}
/**
* Getting merchant details from Novalnet server
*/
public function mepr_novalnet_get_merchant_details() {
check_ajax_referer( 'novalnet-merchant-details', 'security_key' );
$data = array(
'signature' => sanitize_text_field( $this->request['signature'] ),
'access_key' => sanitize_text_field( $this->request['access_key'] ),
);
$merchant_details = novalnet_helper()->mepr_novalnet_get_merchant_details( $data );
wp_send_json( $merchant_details );
}
/**
* Configuring the webhook URL in the Novalnet Admin portal
*/
public function mepr_novalnet_configure_webhook() {
check_ajax_referer( 'novalnet-merchant-details', 'security_key' );
$input = array(
'signature' => sanitize_text_field( $this->request['signature'] ),
'access_key' => sanitize_text_field( $this->request['access_key'] ),
'webhook' => esc_url_raw( $this->request['mepr_clipboard_input'] ),
);
$response = novalnet_helper()->mepr_novalnet_configure_webhook( $input );
wp_send_json( $response );
}
}