This repository has been archived by the owner on Jul 14, 2018. It is now read-only.
forked from ctala/wp-skeleton
/
WcMercadoPago.php
197 lines (166 loc) · 5.63 KB
/
WcMercadoPago.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
193
194
195
196
197
<?php
/*
Plugin Name: Pagos con Mercado Pago
Plugin URI: https://github.com/NAITUSEIRL/wc-ctala-mercadopago
Description: Utiliza Mercado Pagos para Woocommerce
Version: 0.1
Author: Cristian Tala Sánchez
Author URI: http://www.cristiantala.cl
License: MIT
License URI: http://opensource.org/licenses/MIT
Domain Path: /languages
Text Domain: ctala-text_domain
*/
//include_once 'helpers/debug.php';
require_once( 'vendor/autoload.php' );
require_once ('classes/WOOMPApi.php');
define("CTALA_MP_CLIENTID", "3456644172902315");
define("CTALA_MP_CLIENTSCRETET", "eZHN1ladm87NneOypJqp91iZqesN82nt");
function theme_slug_filter_the_content($content) {
$custom_content = probandoMP();
$custom_content .= $content;
return $custom_content;
}
add_filter('the_content', 'theme_slug_filter_the_content');
function probandoMP() {
$sessionid = "1234567890";
$payer = array(
"name" => "Cristian ",
"surname" => "Tala S.",
"email" => "naito.neko@gmail.com",
"date_created" => "",
"phone" => array(
"area_code" => "-",
"number" => "+56991629602"
),
"address" => array(
"zip_code" => "00000",
"street_name" => "Presidente Kennedy",
"street_number" => "5933"
),
"identification" => array(
"number" => "null",
"type" => "null"
)
);
$shipments = array(
"receiver_address" => array(
"floor" => "-",
"zip_code" => "000000",
"street_name" => "DESTINO",
"apartment" => "-",
"street_number" => "-"
)
);
$items = array(
array(
"id" => $sessionid,
"title" => "Producto",
"description" => "x",
"quantity" => 1,
"unit_price" => 10, //decimal
"currency_id" => "CLP", // string Argentina: ARS (peso argentino) � USD (D�lar estadounidense); Brasil: BRL (Real).,
"picture_url" => "",
"category_id" => ""
)
);
//set back url
$back_urls = array(
"pending" => "URLPENDING", // string
"success" => "URLSUCCESS" // string
);
//mount array pref
$pref = array();
$pref['external_reference'] = $sessionid;
$pref['payer'] = $payer;
$pref['shipments'] = $shipments;
$pref['items'] = $items;
$pref['back_urls'] = $back_urls;
$pref['payment_methods'] = $payment_methods;
$mp = new MP(CTALA_MP_CLIENTID, CTALA_MP_CLIENTSCRETET);
$preferenceResult = $mp->create_preference($pref);
$result = "";
$result.="<pre>";
if ($preferenceResult['status'] == 201):
if (true):
$link = $preferenceResult['response']['sandbox_init_point'];
else:
$link = $preferenceResult['response']['init_point'];
endif;
else:
$result.= "Error: " . $preferenceResult['status'];
endif;
$result.=print_r($preferenceResult, true);
$filters = array(
"id" => null,
"site_id" => null,
"external_reference" => null
);
$searchResult = $mp->search_payment($filters);
$result.= print_r($searchResult, true);
$result.= "</pre>";
return $result;
}
//add_action('current_screen', 'probandoMP');
// Registramos los menus correspondientes
function ctala_setup_admin_menu() {
add_menu_page('CTala', 'CTala', 'manage_options', 'ctala', 'ctala_view_admin');
add_submenu_page('ctala', 'SubMen', 'Admin Page', 'manage_options', 'myplugin-top-level-admin-menu', 'myplugin_admin_page');
}
function ctala_view_admin() {
include_once 'views/admin/viewAdmin.php';
}
add_action('admin_menu', 'ctala_setup_admin_menu');
// Creating the widget
class wpb_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'wpb_widget',
// Widget name will appear in UI
__('WPBeginner CTALA Widget', 'wpb_widget_domain'),
// Widget description
array('description' => __('Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain'),)
);
}
// Creating widget front-end
// This is where the action happens
public function widget($args, $instance) {
$title = apply_filters('widget_title', $instance['title']);
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if (!empty($title))
echo $args['before_title'] . $title . $args['after_title'];
// This is where you run the code and display the output
probandoMP();
echo $args['after_widget'];
}
// Widget Backend
public function form($instance) {
if (isset($instance['title'])) {
$title = $instance['title'];
} else {
$title = __('New title', 'wpb_widget_domain');
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update($new_instance, $old_instance) {
$instance = array();
$instance['title'] = (!empty($new_instance['title']) ) ? strip_tags($new_instance['title']) : '';
return $instance;
}
}
// Class wpb_widget ends here
// Register and load the widget
function wpb_load_widget() {
register_widget('wpb_widget');
}
add_action('widgets_init', 'wpb_load_widget');
?>