-
Notifications
You must be signed in to change notification settings - Fork 3
/
shortcodes.php
87 lines (69 loc) · 2.55 KB
/
shortcodes.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
<?php
//========================================================================
//! This shortcode will use OAuth2 to POST CODE and to retrive the TOKEN
//========================================================================
add_shortcode("stripe_token", "stripe_token_function");
function stripe_token_function() {
if (get_option('stripe_appid') && get_option('stripe_secret')) {
if (isset($_GET['code'])) { // Redirect w/ code
$oauth = (new StripeOAuth(APPID,SECRET));
$token = $oauth->getAccessToken($_GET['code']);
$key = $oauth->getPublishableKey($_GET['code']);
$userid = $oauth->getUserId($_GET['code']); //This needs to be changed.
global $wpdb;
$table = $wpdb->prefix."stripe_connect";
$wpdb->insert($table , array(
'time' => current_time('mysql'),
'access_token' => $token,
'stripe_publishable_key' => $key,
'stripe_user_id' => $userid)
);
$response = '<h4>Thank you for connecting with Stripe. This information has been saved in the database and can be viewed in the Admin Panel.</h4>';
$response .= '<strong>Access token: </strong>' . ($token) . '<br /><strong>Key:</strong> ' . ($key) . '<br />'. '<strong>UserId:</strong> ' . ($userid) . '';
return $response;
} elseif (isset($_GET['error_description'])) {
return $_GET['error_description'];
} else {
return 'An error has occured.';
}
} else {
return NOKEY;
}
}
//=====================
//! Shortcode Builder
//=====================
add_shortcode("stripe", "stripe_register_function");
function stripe_register_function($atts) {
//extract short code attributes
extract( shortcode_atts( array(
'style' => '1',
'type' => 'register',
'text' => 'Register with Stripe',
'class'
), $atts ));
//switch the style variables
switch ($style) {
case '1':
$btn_class = 'stripe-connect';
break;
case '2':
$btn_class = 'stripe-connect dark';
break;
case '3':
$btn_class = 'stripe-connect light-blue';
break;
case '4':
$btn_class = 'stripe-connect light-blue dark';
break;
}
$oauth = (new StripeOAuth(APPID,SECRET));
$url = $oauth->getAuthorizeUri();
$button = '<a class="'.$btn_class.'" href="'.$url.'&stripe_landing='.$type.'"><span>'.$text.'</span></a>';
if (get_option('stripe_appid') && get_option('stripe_secret')) {
return $button;
} else {
return NOKEY;
}
}
?>