forked from humanmade/wp-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-stripe.php
161 lines (126 loc) · 4.88 KB
/
wp-stripe.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
<?php
/*
Plugin Name: WP Stripe
Plugin URI: http://wordpress.org/extend/plugins/wp-stripe/
Description: Integration of the payment system Stripe as an alternative to PayPal.
Author: Noel Tock
Version: 1.4.7
Author URI: http://www.noeltock.com
*/
// Defines
// -----------------------------------------------------
define ( 'WP_STRIPE_VERSION', '1.4.7' );
define ( 'WP_STRIPE_PATH', WP_PLUGIN_URL . '/' . end( explode( DIRECTORY_SEPARATOR, dirname( __FILE__ ) ) ) );
// Load PHP Lib - https://github.com/stripe/stripe-php
// -----------------------------------------------------
if (!class_exists('Stripe')) {
include_once('stripe-php/lib/Stripe.php');
}
// Load WordPress Files
// -----------------------------------------------------
include_once('includes/stripe-cpt.php');
include_once('includes/stripe-options-transactions.php');
include_once('includes/stripe-options.php');
include_once('includes/stripe-functions.php');
include_once('includes/stripe-display.php');
// In Progress
// include_once('includes/stripe-options-projects.php');
// Select correct API Key
// -----------------------------------------------------
$options = get_option('wp_stripe_options');
$switch = $options['stripe_api_switch'];
if ( $options['stripe_api_switch'] ) {
if ( $options['stripe_api_switch'] == 'Yes') {
Stripe::setApiKey($options['stripe_test_api']);
} else {
Stripe::setApiKey($options['stripe_prod_api']);
}
}
if ( $options['stripe_api_switch'] ) {
if ( $options['stripe_api_switch'] == 'Yes') {
define( 'WP_STRIPE_KEY', $options['stripe_test_api_publish']);
} else {
define( 'WP_STRIPE_KEY', $options['stripe_prod_api_publish']);
}
}
// Enable Recent Donations/Payments Widget?
// -----------------------------------------------------
if ( $options['stripe_recent_switch'] == 'Yes' ) {
include_once('includes/stripe-widget-recent.php');
}
// Register Settings ( & Defaults )
// -----------------------------------------------------
if (get_option('wp_stripe_options')== '') {
register_activation_hook(__FILE__, 'wp_stripe_defaults');
}
function wp_stripe_defaults() {
$arr = array(
'stripe_header' => 'Donate',
'stripe_css_switch' => 'Yes',
'stripe_api_switch'=>'Yes',
'stripe_recent_switch'=>'Yes',
'stripe_modal_ssl'=>'No',
'stripe_currency' => 'USD',
'stripe_labels_on' => 'No',
'stripe_placeholders_on' => 'Yes',
'stripe_email_required' => 'No'
);
update_option('wp_stripe_options', $arr);
}
// Actions (Overview)
// -----------------------------------------------------
add_action('admin_init', 'wp_stripe_options_init' );
add_action('admin_menu', 'wp_stripe_add_page');
add_action('wp_print_styles', 'load_wp_stripe_css');
add_action('wp_print_scripts', 'load_wp_stripe_js');
add_action('admin_print_styles', 'load_wp_stripe_admin_css');
add_action('admin_print_scripts', 'load_wp_stripe_admin_js');
// JS & CSS
// -----------------------------------------------------
function load_wp_stripe_js() {
wp_enqueue_script( 'stripe-js', 'https://js.stripe.com/v1/', array('jquery') );
wp_enqueue_script( 'wp-stripe-js', WP_STRIPE_PATH . '/js/wp-stripe.js', array('jquery') );
wp_localize_script( 'wp-stripe-js', 'wpstripekey', WP_STRIPE_KEY );
wp_localize_script( 'wp-stripe-js', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
}
function load_wp_stripe_admin_js() {
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-tabs');
}
function load_wp_stripe_css() {
$options = get_option('wp_stripe_options');
if ( $options['stripe_css_switch'] ) {
if ( $options['stripe_css_switch'] == 'Yes') {
wp_enqueue_style('stripe-payment-css', WP_STRIPE_PATH . '/css/wp-stripe-display.css');
}
}
wp_enqueue_style('stripe-widget-css', WP_STRIPE_PATH . '/css/wp-stripe-widget.css');
}
function load_wp_stripe_admin_css() {
wp_enqueue_style('stripe-css', WP_STRIPE_PATH . '/css/wp-stripe-admin.css');
}
// Add Thickbox to all Pages
// -----------------------------------------------------
function wp_stripe_thickbox() {
wp_enqueue_script('thickbox');
wp_enqueue_style('stripe-thickbox', WP_STRIPE_PATH . '/css/wp-stripe-thickbox.css');
}
add_action('wp_print_styles','wp_stripe_thickbox');
function wp_stripe_thickbox_imgs() {
$thickbox_path = get_option('siteurl') . '/wp-includes/js/thickbox/';
$stripe_path = WP_STRIPE_PATH . '/images/';
echo "<script type=\"text/javascript\">\n";
echo " var tb_pathToImage = \"${thickbox_path}loadingAnimation.gif\";\n";
echo " var tb_closeImage = \"${stripe_path}thickbox_close.png\";\n";
echo "</script>\n";
}
add_action('wp_footer', 'wp_stripe_thickbox_imgs');
// Create API Key
// -----------------------------------------------------
/*
$api = get_option('wp_stripe_api');
if ( !$api ) {
update_option('wp_stripe_api', wp_stripe_base62_encode(rand(1,2147483646)) );
}
*/
?>