forked from eneldoserrata/visanet-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 1
/
payment-gateway.php
192 lines (158 loc) · 4.87 KB
/
payment-gateway.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
class WC_Visanet_Payment_Gateway extends WC_Payment_Gateway
{
public $id = 'visanet_gateway';
public $title = 'VisaNet - Pago con tarjeta Débito/Crédito';
public $method_title = 'Visanet';
public $method_description = 'Acepte tarjetas Débito/Crédito en su negocio';
public $has_fields = false;
protected $setupPaymentForm = 'wc_visanet_form_setup';
public function __construct()
{
$this->init_form_fields();
$this->init_settings();
add_action(
'woocommerce_update_options_payment_gateways_' . $this->id,
array( $this, 'process_admin_options' )
);
}
public function init_form_fields()
{
$paymentFormPage = $this->get_payment_form_page();
$pages = $this->get_pages();
if ($paymentFormPage === false) {
$paymentFormPage = $this->setupPaymentForm;
}
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Activar', 'wc-visanet' ),
'type' => 'checkbox',
'label' => __( 'Activar pago con tarjeta.', 'wc-visanet' ),
'default' => 'yes'
),
'testing_mode' => array(
'title' => __( 'Modo', 'wc-visanet' ),
'type' => 'select',
'options' => array(
'no' => 'Producción',
'yes' => 'Prueba '
),
'default' => 'yes'
),
'profile_id' => array(
'title' => __( 'Profile ID', 'wc-visanet' ),
'type' => 'text',
'default' => '',
),
'merchant_id' => array(
'title' => __( 'Merchant ID', 'wc-visanet' ),
'type' => 'text',
'default' => '',
),
'access_key' => array(
'title' => __( 'Access Key (llave de acceso)', 'wc-visanet' ),
'type' => 'password',
'default' => '',
),
'secret_key' => array(
'title' => __( 'Secret Key (llave secreta)', 'wc-visanet' ),
'type' => 'password',
'default' => '',
'autocomplete' => 'off',
),
'transaction_key' => array(
'title' => __( 'Transaction Key (llave para transacciones)', 'wc-visanet' ),
'type' => 'password',
'default' => '',
'autocomplete' => 'off',
),
'currency' => array(
'title' => __( 'Moneda', 'wc-visanet' ),
'type' => 'select',
'options' => array(
'DOP' => 'DOP',
'USD' => 'USD',
),
'default' => 'DOP',
),
'payment_form_page' => array(
'title' => 'Página del formulario de pago',
'type' => 'select',
'options' => $pages,
'default' => $paymentFormPage
),
'auto_authorize' => array(
'title' => __( 'Liquidación Automática', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Sí', 'wc-visanet' ),
'default' => 'yes'
),
);
}
public function process_admin_options() {
$fieldName = 'woocommerce_visanet_gateway_payment_form_page';
if (
isset($_REQUEST[$fieldName])
&& $_REQUEST[$fieldName] === $this->setupPaymentForm
) {
$_REQUEST[$fieldName] = wc_visanet_create_default_payment_form_page();
$_POST[$fieldName] = $_REQUEST[$fieldName];
}
return parent::process_admin_options($args);
}
protected function get_payment_form_page() {
$paymentFormPage = $this->get_option('payment_form_page');
if (!empty($paymentFormPage)) return $paymentFormPage;
return wc_visanet_get_default_payment_form_page();
}
protected function get_pages() {
$pages = get_pages(array(
'sort_order' => 'asc',
'sort_column' => 'post_title',
'hierarchical' => 1,
'post_type' => 'page',
'post_status' => 'publish'
));
$options = array();
$options[$this->setupPaymentForm] = '(Crear Formulario de Pago)';
foreach($pages as $page) {
$options[ $page->ID ] = $page->post_title;
}
return $options;
}
function admin_options() {
?>
<h2><?php _e('Tarjeta de Crédito Visa','wc-visanet'); ?></h2>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
<tr valign="top">
<th scope="row" class="titledesc">
URL de retorno
</th>
<td class="forminp">
<?php bloginfo('url'); ?>/?wc_visanet_return=1
</td>
</table>
<?php
}
public function payment_fields()
{
require_once __DIR__ . '/parts/payment-form.php';
}
public function process_payment($order_id)
{
$pageId = $this->get_option('payment_form_page');
$page = get_post($pageId);
if (!$pageId || $page === NULL) {
wc_add_notice( __('Error en pago con visanet: formulario de pago no definido', 'wc-visanet'), 'error' );
return;
}
$pageUrl = get_permalink($pageId);
$pageUrl = add_query_arg('wc_visanet_form', $order_id, $pageUrl);
return array(
'result' => 'success',
'redirect' => $pageUrl
);
}
}
?>