Version Description
- 2019-04-25 =
- BUG FIX: Fixed fatal error on return from 2Checkout.
- BUG FIX: Removed error when installing PMPro via WP-CLI.
- BUG FIX: Fix database upgrade error on localhost environment. (Thanks, codezz on GitHub)
- BUG FIX: Fixed issue where the credit card expiring email didn't include user info because the user ID wasn't passed in properly. (Thanks, David Cervantes Caballero)
- BUG FIX: Fixed typo on edit level page. (Thanks, Theuns Coetzee)
- BUG FIX: Fixed bug with daily revenue reports not showing up in some cases.
- BUG FIX: Now checking before cancelling a Stripe subscription at the gateway to see if it has already been cancelled.
- BUG FIX/ENHANCEMENT: Now caching the query results in pmpro_getMembershipLevelsForUser(). This improves performance, especially when there are many posts on one page to check membership for. (Thanks, Seagyn Davis)
- BUG FIX/ENHANCEMENT: Now sending display_name to the $data array passed to PMPro email filters. (Thanks, David Cervantes Caballero)
- BUG FIX/ENHANCEMENT: Now searching for the last order with "success" or "pending" status on the Billing page.
- BUG FIX/ENHANCEMENT: Added pmpro_checkout_preheader_before_get_level_at_checkout and pmpro_checkout_preheader_after_get_level_at_checkout action hooks. Using pmpro_checkout_preheader_before_get_level_at_checkout to start the session earlier now.
- BUG FIX/ENHANCEMENT: Removed the "membership_code_id" and "membership_code" as field options for the member shortcode. These weren't working and it's unclear what would be meant to ask for a user's discount code since a user could have several orders with or without discount codes. Added "membership_description" and "membership_confirmation" instead.
- BUG FIX/ENHANCEMENT: Filtering the password reset message to make sure the link still works in all cases when we convert emails to HTML.
- REFACTOR: Now running the pmpro_billing_preheader hook after the jquery.creditCardValidator script is enqueued in preheader/billing.php to match how we do it in preheader/checkout.php. (Thanks, Rafe Colton)
Download this release
Release Info
Developer | strangerstudios |
Plugin | ![]() |
Version | 2.0.5 |
Comparing to | |
See all releases |
Code changes from version 2.0.4 to 2.0.5
- adminpages/advancedsettings.php +9 -0
- adminpages/emailsettings.php +6 -2
- adminpages/membershiplevels.php +1 -1
- adminpages/reports/sales.php +3 -3
- classes/class.memberorder.php +1 -1
- classes/class.pmproemail.php +4 -3
- classes/gateways/class.pmprogateway_paypal.php +2 -2
- classes/gateways/class.pmprogateway_paypalexpress.php +2 -2
- classes/gateways/class.pmprogateway_stripe.php +1643 -1752
- css/blocks.style.css +0 -27
- includes/email.php +44 -18
- includes/functions.php +52 -26
- includes/login.php +2 -2
- includes/pointers.php +2 -3
- includes/recaptcha.php +115 -31
- includes/sessions.php +1 -1
- includes/updates/upgrade_1.php +8 -3
- js/frontend.blocks.js +0 -83
- languages/paid-memberships-pro.mo +0 -0
- languages/paid-memberships-pro.po +584 -512
- languages/paid-memberships-pro.pot +584 -512
- pages/checkout.php +2 -2
- pages/invoice.php +25 -24
- paid-memberships-pro.php +11 -6
- preheaders/billing.php +5 -5
- preheaders/checkout.php +23 -3
- readme.txt +17 -1
- scheduled/crons.php +1 -1
- services/twocheckout-ins.php +9 -7
- shortcodes/pmpro_member.php +2 -2
adminpages/advancedsettings.php
CHANGED
@@ -36,6 +36,7 @@
|
|
36 |
|
37 |
//captcha
|
38 |
pmpro_setOption("recaptcha");
|
|
|
39 |
pmpro_setOption("recaptcha_publickey");
|
40 |
pmpro_setOption("recaptcha_privatekey");
|
41 |
|
@@ -72,6 +73,7 @@
|
|
72 |
$redirecttosubscription = pmpro_getOption("redirecttosubscription");
|
73 |
|
74 |
$recaptcha = pmpro_getOption("recaptcha");
|
|
|
75 |
$recaptcha_publickey = pmpro_getOption("recaptcha_publickey");
|
76 |
$recaptcha_privatekey = pmpro_getOption("recaptcha_privatekey");
|
77 |
|
@@ -245,6 +247,13 @@ if(pmpro_displayAds())
|
|
245 |
<tr id="recaptcha_tr" <?php if(!$recaptcha) { ?>style="display: none;"<?php } ?>>
|
246 |
<th scope="row" valign="top"> </th>
|
247 |
<td>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
<label for="recaptcha_publickey"><?php _e('reCAPTCHA Site Key', 'paid-memberships-pro' );?>:</label>
|
249 |
<input type="text" id="recaptcha_publickey" name="recaptcha_publickey" size="60" value="<?php echo esc_attr($recaptcha_publickey);?>" />
|
250 |
<br /><br />
|
36 |
|
37 |
//captcha
|
38 |
pmpro_setOption("recaptcha");
|
39 |
+
pmpro_setOption("recaptcha_version");
|
40 |
pmpro_setOption("recaptcha_publickey");
|
41 |
pmpro_setOption("recaptcha_privatekey");
|
42 |
|
73 |
$redirecttosubscription = pmpro_getOption("redirecttosubscription");
|
74 |
|
75 |
$recaptcha = pmpro_getOption("recaptcha");
|
76 |
+
$recaptcha_version = pmpro_getOption("recaptcha_version");
|
77 |
$recaptcha_publickey = pmpro_getOption("recaptcha_publickey");
|
78 |
$recaptcha_privatekey = pmpro_getOption("recaptcha_privatekey");
|
79 |
|
247 |
<tr id="recaptcha_tr" <?php if(!$recaptcha) { ?>style="display: none;"<?php } ?>>
|
248 |
<th scope="row" valign="top"> </th>
|
249 |
<td>
|
250 |
+
<label for="recaptcha_version"><?php _e( 'reCAPTCHA Version', 'paid-memberships-pro' );?>:</label>
|
251 |
+
<select id="recaptcha_version" name="recaptcha_version">
|
252 |
+
<option value="2_checkbox" <?php selected( '2_checkbox', $recaptcha_version ); ?>><?php _e( ' v2 - Checkbox', 'paid-memberships-pro' ); ?></option>
|
253 |
+
<option value="3_invisible" <?php selected( '3_invisible', $recaptcha_version ); ?>><?php _e( 'v3 - Invisible', 'paid-memberships-pro' ); ?></option>
|
254 |
+
</select>
|
255 |
+
<small><?php _e( 'Changing your version will require new API keys.', 'paid-memberships-pro' ); ?></small>
|
256 |
+
<br /><br />
|
257 |
<label for="recaptcha_publickey"><?php _e('reCAPTCHA Site Key', 'paid-memberships-pro' );?>:</label>
|
258 |
<input type="text" id="recaptcha_publickey" name="recaptcha_publickey" size="60" value="<?php echo esc_attr($recaptcha_publickey);?>" />
|
259 |
<br /><br />
|
adminpages/emailsettings.php
CHANGED
@@ -51,8 +51,12 @@
|
|
51 |
{
|
52 |
$parsed = parse_url(home_url());
|
53 |
$hostname = $parsed["host"];
|
54 |
-
$
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
$from_email = "wordpress@" . $email_domain;
|
57 |
pmpro_setOption("from_email", $from_email);
|
58 |
}
|
51 |
{
|
52 |
$parsed = parse_url(home_url());
|
53 |
$hostname = $parsed["host"];
|
54 |
+
$host_parts = explode(".", $hostname);
|
55 |
+
if ( count( $host_parts ) > 1 ) {
|
56 |
+
$email_domain = $host_parts[count($host_parts) - 2] . "." . $host_parts[count($host_parts) - 1];
|
57 |
+
} else {
|
58 |
+
$email_domain = $parsed['host'];
|
59 |
+
}
|
60 |
$from_email = "wordpress@" . $email_domain;
|
61 |
pmpro_setOption("from_email", $from_email);
|
62 |
}
|
adminpages/membershiplevels.php
CHANGED
@@ -387,7 +387,7 @@
|
|
387 |
}
|
388 |
?>
|
389 |
</div>
|
390 |
-
<input id="confirmation_in_email" name="confirmation_in_email" type="checkbox" value="yes" <?php checked( $confirmation_in_email, 1); ?> /> <label for="confirmation_in_email"><?php _e('Check to include this message in the membership
|
391 |
</td>
|
392 |
</tr>
|
393 |
</tbody>
|
387 |
}
|
388 |
?>
|
389 |
</div>
|
390 |
+
<input id="confirmation_in_email" name="confirmation_in_email" type="checkbox" value="yes" <?php checked( $confirmation_in_email, 1); ?> /> <label for="confirmation_in_email"><?php _e('Check to include this message in the membership confirmation email.', 'paid-memberships-pro' );?></label>
|
391 |
</td>
|
392 |
</tr>
|
393 |
</tbody>
|
adminpages/reports/sales.php
CHANGED
@@ -152,7 +152,7 @@ function pmpro_report_sales_page()
|
|
152 |
if($period == "daily")
|
153 |
{
|
154 |
$startdate = $year . '-' . substr("0" . $month, strlen($month) - 1, 2) . '-01';
|
155 |
-
$enddate = $year . '-' . substr("0" . $month, strlen($month) - 1, 2) . '-
|
156 |
$date_function = 'DAY';
|
157 |
$currently_in_period = ( intval( date( 'Y' ) ) == $year && intval( date( 'n' ) ) == $month );
|
158 |
}
|
@@ -183,7 +183,7 @@ function pmpro_report_sales_page()
|
|
183 |
$sqlQuery .= "WHERE o.total > 0 AND o.timestamp >= '" . esc_sql( $startdate ) . "' AND o.status NOT IN('refunded', 'review', 'token', 'error') AND o.gateway_environment = '" . esc_sql( $gateway_environment ) . "' ";
|
184 |
|
185 |
if(!empty($enddate))
|
186 |
-
$sqlQuery .= "AND o.timestamp
|
187 |
|
188 |
if(!empty($l))
|
189 |
$sqlQuery .= "AND o.membership_id IN(" . esc_sql( $l ) . ") ";
|
@@ -615,4 +615,4 @@ function pmpro_report_sales_delete_transients()
|
|
615 |
delete_transient("pmpro_report_revenue");
|
616 |
}
|
617 |
add_action("pmpro_after_checkout", "pmpro_report_sales_delete_transients");
|
618 |
-
add_action("pmpro_updated_order", "pmpro_report_sales_delete_transients");
|
152 |
if($period == "daily")
|
153 |
{
|
154 |
$startdate = $year . '-' . substr("0" . $month, strlen($month) - 1, 2) . '-01';
|
155 |
+
$enddate = $year . '-' . substr("0" . $month, strlen($month) - 1, 2) . '-31';
|
156 |
$date_function = 'DAY';
|
157 |
$currently_in_period = ( intval( date( 'Y' ) ) == $year && intval( date( 'n' ) ) == $month );
|
158 |
}
|
183 |
$sqlQuery .= "WHERE o.total > 0 AND o.timestamp >= '" . esc_sql( $startdate ) . "' AND o.status NOT IN('refunded', 'review', 'token', 'error') AND o.gateway_environment = '" . esc_sql( $gateway_environment ) . "' ";
|
184 |
|
185 |
if(!empty($enddate))
|
186 |
+
$sqlQuery .= "AND o.timestamp <= '" . esc_sql( $enddate ) . "' ";
|
187 |
|
188 |
if(!empty($l))
|
189 |
$sqlQuery .= "AND o.membership_id IN(" . esc_sql( $l ) . ") ";
|
615 |
delete_transient("pmpro_report_revenue");
|
616 |
}
|
617 |
add_action("pmpro_after_checkout", "pmpro_report_sales_delete_transients");
|
618 |
+
add_action("pmpro_updated_order", "pmpro_report_sales_delete_transients");
|
classes/class.memberorder.php
CHANGED
@@ -619,7 +619,7 @@
|
|
619 |
$this->gateway_environment = pmpro_getOption("gateway_environment");
|
620 |
|
621 |
if(empty($this->datetime) && empty($this->timestamp))
|
622 |
-
$this->datetime = date("Y-m-d H:i:s",
|
623 |
elseif(empty($this->datetime) && !empty($this->timestamp) && is_numeric($this->timestamp))
|
624 |
$this->datetime = date("Y-m-d H:i:s", $this->timestamp); //get datetime from timestamp
|
625 |
elseif(empty($this->datetime) && !empty($this->timestamp))
|
619 |
$this->gateway_environment = pmpro_getOption("gateway_environment");
|
620 |
|
621 |
if(empty($this->datetime) && empty($this->timestamp))
|
622 |
+
$this->datetime = date("Y-m-d H:i:s", time());
|
623 |
elseif(empty($this->datetime) && !empty($this->timestamp) && is_numeric($this->timestamp))
|
624 |
$this->datetime = date("Y-m-d H:i:s", $this->timestamp); //get datetime from timestamp
|
625 |
elseif(empty($this->datetime) && !empty($this->timestamp))
|
classes/class.pmproemail.php
CHANGED
@@ -142,7 +142,7 @@
|
|
142 |
$this->email = $user->user_email;
|
143 |
$this->subject = sprintf(__('Your membership at %s has been CANCELLED', 'paid-memberships-pro'), get_option("blogname"));
|
144 |
|
145 |
-
$this->data = array("
|
146 |
|
147 |
if(!empty($old_level_id)) {
|
148 |
if(!is_array($old_level_id))
|
@@ -228,6 +228,7 @@
|
|
228 |
$this->data = array(
|
229 |
"subject" => $this->subject,
|
230 |
"name" => $user->display_name,
|
|
|
231 |
"user_login" => $user->user_login,
|
232 |
"sitename" => get_option("blogname"),
|
233 |
"siteemail" => pmpro_getOption("from_email"),
|
@@ -832,7 +833,7 @@
|
|
832 |
$this->email = $user->user_email;
|
833 |
$this->subject = sprintf(__("Your membership at %s has been changed", "paid-memberships-pro"), get_option("blogname"));
|
834 |
|
835 |
-
$this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url());
|
836 |
|
837 |
if($user->membership_level->ID)
|
838 |
$this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name);
|
@@ -879,7 +880,7 @@
|
|
879 |
$this->email = get_bloginfo("admin_email");
|
880 |
$this->subject = sprintf(__("Membership for %s at %s has been changed", "paid-memberships-pro"), $user->user_login, get_option("blogname"));
|
881 |
|
882 |
-
$this->data = array("subject" => $this->subject, "name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "membership_level_name" => $membership_level_name, "siteemail" => get_bloginfo("admin_email"), "login_link" => wp_login_url());
|
883 |
|
884 |
if(!empty($user->membership_level) && !empty($user->membership_level->ID)) {
|
885 |
$this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name);
|
142 |
$this->email = $user->user_email;
|
143 |
$this->subject = sprintf(__('Your membership at %s has been CANCELLED', 'paid-memberships-pro'), get_option("blogname"));
|
144 |
|
145 |
+
$this->data = array("user_email" => $user->user_email, "display_name" => $user->display_name, "user_login" => $user->user_login, "sitename" => get_option("blogname"), "siteemail" => pmpro_getOption("from_email"));
|
146 |
|
147 |
if(!empty($old_level_id)) {
|
148 |
if(!is_array($old_level_id))
|
228 |
$this->data = array(
|
229 |
"subject" => $this->subject,
|
230 |
"name" => $user->display_name,
|
231 |
+
"display_name" => $user->display_name,
|
232 |
"user_login" => $user->user_login,
|
233 |
"sitename" => get_option("blogname"),
|
234 |
"siteemail" => pmpro_getOption("from_email"),
|
833 |
$this->email = $user->user_email;
|
834 |
$this->subject = sprintf(__("Your membership at %s has been changed", "paid-memberships-pro"), get_option("blogname"));
|
835 |
|
836 |
+
$this->data = array("subject" => $this->subject, "name" => $user->display_name, "display_name" => $user->display_name, "user_login" => $user->user_login, "user_email" => $user->user_email, "sitename" => get_option("blogname"), "membership_id" => $user->membership_level->id, "membership_level_name" => $user->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url());
|
837 |
|
838 |
if($user->membership_level->ID)
|
839 |
$this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name);
|
880 |
$this->email = get_bloginfo("admin_email");
|
881 |
$this->subject = sprintf(__("Membership for %s at %s has been changed", "paid-memberships-pro"), $user->user_login, get_option("blogname"));
|
882 |
|
883 |
+
$this->data = array("subject" => $this->subject, "name" => $user->display_name, "display_name" => $user->display_name, "user_login" => $user->user_login, "user_email" => $user->user_email, "sitename" => get_option("blogname"), "membership_level_name" => $membership_level_name, "siteemail" => get_bloginfo("admin_email"), "login_link" => wp_login_url());
|
884 |
|
885 |
if(!empty($user->membership_level) && !empty($user->membership_level->ID)) {
|
886 |
$this->data["membership_change"] = sprintf(__("The new level is %s", 'paid-memberships-pro' ), $user->membership_level->name);
|
classes/gateways/class.pmprogateway_paypal.php
CHANGED
@@ -198,13 +198,13 @@
|
|
198 |
<?php if($gateway == "paypal" || $gateway == "paypalexpress" || $gateway == "paypalstandard") { ?>
|
199 |
<span id="pmpro_paypalexpress_checkout" <?php if(($gateway != "paypalexpress" && $gateway != "paypalstandard") || !$pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
200 |
<input type="hidden" name="submit-checkout" value="1" />
|
201 |
-
<input type="image" class="pmpro_btn-submit-checkout" value="<?php _e('Check Out with PayPal', 'paid-memberships-pro' );?> »" src="<?php echo apply_filters("pmpro_paypal_button_image", "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif");?>" />
|
202 |
</span>
|
203 |
<?php } ?>
|
204 |
|
205 |
<span id="pmpro_submit_span" <?php if(($gateway == "paypalexpress" || $gateway == "paypalstandard") && $pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
206 |
<input type="hidden" name="submit-checkout" value="1" />
|
207 |
-
<input type="submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php if($pmpro_requirebilling) { _e('Submit and Check Out', 'paid-memberships-pro' ); } else { _e('Submit and Confirm', 'paid-memberships-pro' );}?> »" />
|
208 |
</span>
|
209 |
<?php
|
210 |
|
198 |
<?php if($gateway == "paypal" || $gateway == "paypalexpress" || $gateway == "paypalstandard") { ?>
|
199 |
<span id="pmpro_paypalexpress_checkout" <?php if(($gateway != "paypalexpress" && $gateway != "paypalstandard") || !$pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
200 |
<input type="hidden" name="submit-checkout" value="1" />
|
201 |
+
<input type="image" id="pmpro_btn-submit-paypal" class="pmpro_btn-submit-checkout" value="<?php _e('Check Out with PayPal', 'paid-memberships-pro' );?> »" src="<?php echo apply_filters("pmpro_paypal_button_image", "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif");?>" />
|
202 |
</span>
|
203 |
<?php } ?>
|
204 |
|
205 |
<span id="pmpro_submit_span" <?php if(($gateway == "paypalexpress" || $gateway == "paypalstandard") && $pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
206 |
<input type="hidden" name="submit-checkout" value="1" />
|
207 |
+
<input type="submit" id="pmpro_btn-submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php if($pmpro_requirebilling) { _e('Submit and Check Out', 'paid-memberships-pro' ); } else { _e('Submit and Confirm', 'paid-memberships-pro' );}?> »" />
|
208 |
</span>
|
209 |
<?php
|
210 |
|
classes/gateways/class.pmprogateway_paypalexpress.php
CHANGED
@@ -440,12 +440,12 @@
|
|
440 |
?>
|
441 |
<span id="pmpro_paypalexpress_checkout" <?php if(($gateway != "paypalexpress" && $gateway != "paypalstandard") || !$pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
442 |
<input type="hidden" name="submit-checkout" value="1" />
|
443 |
-
<input type="image" class="pmpro_btn-submit-checkout" value="<?php _e('Check Out with PayPal', 'paid-memberships-pro' );?> »" src="<?php echo apply_filters("pmpro_paypal_button_image", "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif");?>" />
|
444 |
</span>
|
445 |
|
446 |
<span id="pmpro_submit_span" <?php if(($gateway == "paypalexpress" || $gateway == "paypalstandard") && $pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
447 |
<input type="hidden" name="submit-checkout" value="1" />
|
448 |
-
<input type="submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php if($pmpro_requirebilling) { _e('Submit and Check Out', 'paid-memberships-pro' ); } else { _e('Submit and Confirm', 'paid-memberships-pro' );}?> »" />
|
449 |
</span>
|
450 |
<?php
|
451 |
|
440 |
?>
|
441 |
<span id="pmpro_paypalexpress_checkout" <?php if(($gateway != "paypalexpress" && $gateway != "paypalstandard") || !$pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
442 |
<input type="hidden" name="submit-checkout" value="1" />
|
443 |
+
<input type="image" id="pmpro_btn-submit-paypalexpress" class="pmpro_btn-submit-checkout" value="<?php _e('Check Out with PayPal', 'paid-memberships-pro' );?> »" src="<?php echo apply_filters("pmpro_paypal_button_image", "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif");?>" />
|
444 |
</span>
|
445 |
|
446 |
<span id="pmpro_submit_span" <?php if(($gateway == "paypalexpress" || $gateway == "paypalstandard") && $pmpro_requirebilling) { ?>style="display: none;"<?php } ?>>
|
447 |
<input type="hidden" name="submit-checkout" value="1" />
|
448 |
+
<input type="submit" id="pmpro_btn-submit" class="pmpro_btn pmpro_btn-submit-checkout" value="<?php if($pmpro_requirebilling) { _e('Submit and Check Out', 'paid-memberships-pro' ); } else { _e('Submit and Confirm', 'paid-memberships-pro' );}?> »" />
|
449 |
</span>
|
450 |
<?php
|
451 |
|
classes/gateways/class.pmprogateway_stripe.php
CHANGED
@@ -1,2048 +1,1939 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
/**
|
21 |
-
*
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
*
|
25 |
-
* @since
|
26 |
*/
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
* @since 1.4
|
37 |
-
*/
|
38 |
-
function __construct($gateway = NULL)
|
39 |
-
{
|
40 |
-
$this->gateway = $gateway;
|
41 |
-
$this->gateway_environment = pmpro_getOption("gateway_environment");
|
42 |
-
|
43 |
-
if( true === $this->dependencies() ) {
|
44 |
-
$this->loadStripeLibrary();
|
45 |
-
Stripe\Stripe::setApiKey(pmpro_getOption("stripe_secretkey"));
|
46 |
-
Stripe\Stripe::setAPIVersion( PMPRO_STRIPE_API_VERSION );
|
47 |
-
self::$is_loaded = true;
|
48 |
-
}
|
49 |
-
|
50 |
-
return $this->gateway;
|
51 |
}
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
*
|
56 |
-
* @return bool
|
57 |
-
* @since 1.8.6.8.1
|
58 |
-
* @since 1.8.13.6 - Add json dependency
|
59 |
-
*/
|
60 |
-
public static function dependencies()
|
61 |
-
{
|
62 |
-
global $msg, $msgt, $pmpro_stripe_error;
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
$msg = -1;
|
68 |
-
$msgt = sprintf(__("The Stripe Gateway requires PHP 5.3.29 or greater. We recommend upgrading to PHP %s or greater. Ask your host to upgrade.", "paid-memberships-pro" ), PMPRO_PHP_MIN_VERSION );
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
|
|
75 |
}
|
76 |
|
77 |
-
|
|
|
78 |
|
79 |
-
|
80 |
-
if(!extension_loaded($module)){
|
81 |
-
$pmpro_stripe_error = true;
|
82 |
-
$msg = -1;
|
83 |
-
$msgt = sprintf(__("The %s gateway depends on the %s PHP extension. Please enable it, or ask your hosting provider to enable it.", 'paid-memberships-pro' ), 'Stripe', $module);
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
return true;
|
95 |
-
}
|
96 |
-
|
97 |
-
/**
|
98 |
-
* Load the Stripe API library.
|
99 |
-
*
|
100 |
-
* @since 1.8
|
101 |
-
* Moved into a method in version 1.8 so we only load it when needed.
|
102 |
-
*/
|
103 |
-
function loadStripeLibrary()
|
104 |
-
{
|
105 |
-
//load Stripe library if it hasn't been loaded already (usually by another plugin using Stripe)
|
106 |
-
if(!class_exists("Stripe\Stripe")) {
|
107 |
-
require_once( PMPRO_DIR . "/includes/lib/Stripe/init.php" );
|
108 |
}
|
109 |
}
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
* @since 1.8
|
115 |
-
*/
|
116 |
-
static function init()
|
117 |
-
{
|
118 |
-
//make sure Stripe is a gateway option
|
119 |
-
add_filter('pmpro_gateways', array('PMProGateway_stripe', 'pmpro_gateways'));
|
120 |
-
|
121 |
-
//add fields to payment settings
|
122 |
-
add_filter('pmpro_payment_options', array('PMProGateway_stripe', 'pmpro_payment_options'));
|
123 |
-
add_filter('pmpro_payment_option_fields', array('PMProGateway_stripe', 'pmpro_payment_option_fields'), 10, 2);
|
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 |
-
$current_gateway = pmpro_getGateway();
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
add_filter('pmpro_checkout_order', array('PMProGateway_stripe', 'pmpro_checkout_order'));
|
156 |
-
add_filter('pmpro_billing_order', array('PMProGateway_stripe', 'pmpro_checkout_order'));
|
157 |
-
add_filter('pmpro_include_billing_address_fields', array('PMProGateway_stripe', 'pmpro_include_billing_address_fields'));
|
158 |
-
add_filter('pmpro_include_cardtype_field', array('PMProGateway_stripe', 'pmpro_include_billing_address_fields'));
|
159 |
-
add_filter('pmpro_include_payment_information_fields', array('PMProGateway_stripe', 'pmpro_include_payment_information_fields'));
|
160 |
-
|
161 |
-
//make sure we clean up subs we will be cancelling after checkout before processing
|
162 |
-
add_action('pmpro_checkout_before_processing', array('PMProGateway_stripe', 'pmpro_checkout_before_processing'));
|
163 |
-
}
|
164 |
|
165 |
-
|
|
|
166 |
}
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
*/
|
171 |
-
public static function pmpro_clear_saved_subscriptions() {
|
172 |
-
|
173 |
-
if ( ! is_user_logged_in() ) {
|
174 |
-
return;
|
175 |
-
}
|
176 |
|
177 |
-
|
178 |
-
|
179 |
|
180 |
-
|
181 |
-
if ( !empty( $preserve ) ) {
|
182 |
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
}
|
189 |
-
}
|
190 |
|
191 |
-
|
192 |
-
}
|
193 |
}
|
|
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
$gateways['stripe'] = __('Stripe', 'paid-memberships-pro' );
|
204 |
-
|
205 |
-
return $gateways;
|
206 |
-
}
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
*
|
211 |
-
* @since 1.8
|
212 |
-
*/
|
213 |
-
static function getGatewayOptions()
|
214 |
-
{
|
215 |
-
$options = array(
|
216 |
-
'sslseal',
|
217 |
-
'nuclear_HTTPS',
|
218 |
-
'gateway_environment',
|
219 |
-
'stripe_secretkey',
|
220 |
-
'stripe_publishablekey',
|
221 |
-
'stripe_billingaddress',
|
222 |
-
'currency',
|
223 |
-
'use_ssl',
|
224 |
-
'tax_state',
|
225 |
-
'tax_rate',
|
226 |
-
'accepted_credit_cards'
|
227 |
-
);
|
228 |
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
$stripe_options = self::getGatewayOptions();
|
241 |
|
242 |
-
|
243 |
-
|
244 |
|
245 |
-
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
<
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
<
|
262 |
-
<
|
263 |
-
|
264 |
-
|
265 |
-
<
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
if(!empty($values['stripe_publishablekey']) && $public_key_prefix != 'pk_') {
|
270 |
-
?>
|
271 |
-
<br /><small class="pmpro_message pmpro_error"><?php _e('Your Publishable Key appears incorrect.', 'paid-memberships-pro');?></small>
|
272 |
-
<?php
|
273 |
-
}
|
274 |
?>
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
</
|
285 |
-
<
|
286 |
-
<
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
<
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
</
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
* @since 1.8
|
317 |
-
*/
|
318 |
-
static function pmpro_checkout_preheader()
|
319 |
-
{
|
320 |
-
global $gateway, $pmpro_level;
|
321 |
-
|
322 |
-
$default_gateway = pmpro_getOption("gateway");
|
323 |
-
|
324 |
-
if(($gateway == "stripe" || $default_gateway == "stripe") && !pmpro_isLevelFree($pmpro_level))
|
325 |
-
{
|
326 |
-
//stripe js library
|
327 |
-
wp_enqueue_script("stripe", "https://js.stripe.com/v2/", array(), NULL);
|
328 |
-
|
329 |
-
if ( ! function_exists( 'pmpro_stripe_javascript' ) ) {
|
330 |
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
// this identifies your website in the createToken call below
|
339 |
-
Stripe.setPublishableKey('<?php echo pmpro_getOption("stripe_publishablekey"); ?>');
|
340 |
|
341 |
-
|
342 |
|
343 |
-
|
|
|
|
|
|
|
344 |
|
345 |
-
|
346 |
-
jQuery(".pmpro_form").submit(function(event) {
|
347 |
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
?>
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
Stripe.createToken(args, stripeResponseHandler);
|
387 |
-
}
|
388 |
-
} else {
|
389 |
Stripe.createToken(args, stripeResponseHandler);
|
390 |
}
|
391 |
-
|
392 |
-
// prevent the form from submitting with the default action
|
393 |
-
return false;
|
394 |
} else {
|
395 |
-
|
396 |
-
return true; //not using Stripe anymore
|
397 |
}
|
398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
});
|
|
|
400 |
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
|
406 |
-
|
407 |
-
|
408 |
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
// and submit
|
432 |
-
form$.get(0).submit();
|
433 |
-
}
|
434 |
-
}
|
435 |
-
-->
|
436 |
-
</script>
|
437 |
-
<?php
|
438 |
-
}
|
439 |
-
add_action("wp_head", "pmpro_stripe_javascript");
|
440 |
-
}
|
441 |
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
{
|
446 |
-
unset($fields['CVV']);
|
447 |
-
return $fields;
|
448 |
}
|
449 |
-
|
|
|
|
|
450 |
}
|
|
|
451 |
}
|
452 |
}
|
|
|
453 |
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
$bconfirmemail = $bemail;
|
474 |
-
}
|
475 |
-
//remove the fields
|
476 |
-
foreach ($remove as $field)
|
477 |
-
unset($fields[$field]);
|
478 |
}
|
479 |
-
|
480 |
-
|
|
|
481 |
}
|
482 |
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
|
|
|
|
|
|
|
|
|
|
489 |
{
|
490 |
-
//
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
$
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
if(intval($matches[1])>$tokennum) {
|
499 |
-
$thetoken = sanitize_text_field($param);
|
500 |
-
$tokennum = intval($matches[1]);
|
501 |
-
}
|
502 |
}
|
503 |
}
|
504 |
-
$morder->stripeToken = $thetoken;
|
505 |
-
unset($_REQUEST['stripeToken'.$tokennum]);
|
506 |
}
|
|
|
|
|
|
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
{
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
elseif(!empty($_REQUEST['first_name']) && !empty($_REQUEST['last_name']))
|
518 |
-
{
|
519 |
-
$morder->FirstName = sanitize_text_field($_REQUEST['first_name']);
|
520 |
-
$morder->LastName = sanitize_text_field($_REQUEST['last_name']);
|
521 |
-
}
|
522 |
}
|
523 |
-
|
524 |
-
return $morder;
|
525 |
}
|
526 |
|
527 |
-
|
528 |
-
|
529 |
-
*
|
530 |
-
* @since 1.8
|
531 |
-
*/
|
532 |
-
static function pmpro_after_checkout($user_id, $morder)
|
533 |
-
{
|
534 |
-
global $gateway;
|
535 |
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
|
|
|
|
|
|
|
|
|
|
542 |
}
|
543 |
}
|
|
|
544 |
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
$include = false;
|
554 |
|
555 |
-
|
556 |
-
|
557 |
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
global $pmpro_requirebilling, $pmpro_show_discount_code, $discount_code, $CardType, $AccountNumber, $ExpirationMonth, $ExpirationYear;
|
566 |
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
<?php } ?>
|
583 |
-
<div class="pmpro_checkout-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
<?php
|
585 |
-
$
|
586 |
-
if($
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
<?php foreach($pmpro_accepted_credit_cards as $cc) { ?>
|
591 |
-
<option value="<?php echo $cc?>" <?php if($CardType == $cc) { ?>selected="selected"<?php } ?>><?php echo $cc?></option>
|
592 |
-
<?php } ?>
|
593 |
-
</select>
|
594 |
-
</div>
|
595 |
-
<?php } else { ?>
|
596 |
-
<input type="hidden" id="CardType" name="CardType" value="<?php echo esc_attr($CardType);?>" />
|
597 |
-
<script>
|
598 |
-
<!--
|
599 |
-
jQuery(document).ready(function() {
|
600 |
-
jQuery('#AccountNumber').validateCreditCard(function(result) {
|
601 |
-
var cardtypenames = {
|
602 |
-
"amex":"American Express",
|
603 |
-
"diners_club_carte_blanche":"Diners Club Carte Blanche",
|
604 |
-
"diners_club_international":"Diners Club International",
|
605 |
-
"discover":"Discover",
|
606 |
-
"jcb":"JCB",
|
607 |
-
"laser":"Laser",
|
608 |
-
"maestro":"Maestro",
|
609 |
-
"mastercard":"Mastercard",
|
610 |
-
"visa":"Visa",
|
611 |
-
"visa_electron":"Visa Electron"
|
612 |
-
}
|
613 |
-
|
614 |
-
if(result.card_type)
|
615 |
-
jQuery('#CardType').val(cardtypenames[result.card_type.name]);
|
616 |
-
else
|
617 |
-
jQuery('#CardType').val('Unknown Card Type');
|
618 |
-
});
|
619 |
-
});
|
620 |
-
-->
|
621 |
-
</script>
|
622 |
-
<?php } ?>
|
623 |
-
<div class="pmpro_checkout-field pmpro_payment-account-number">
|
624 |
-
<label for="AccountNumber"><?php _e('Card Number', 'paid-memberships-pro' );?></label>
|
625 |
-
<input id="AccountNumber" class="input <?php echo pmpro_getClassForField("AccountNumber");?>" type="text" size="25" value="<?php echo esc_attr($AccountNumber)?>" autocomplete="off" />
|
626 |
</div>
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
<option value="05" <?php if($ExpirationMonth == "05") { ?>selected="selected"<?php } ?>>05</option>
|
635 |
-
<option value="06" <?php if($ExpirationMonth == "06") { ?>selected="selected"<?php } ?>>06</option>
|
636 |
-
<option value="07" <?php if($ExpirationMonth == "07") { ?>selected="selected"<?php } ?>>07</option>
|
637 |
-
<option value="08" <?php if($ExpirationMonth == "08") { ?>selected="selected"<?php } ?>>08</option>
|
638 |
-
<option value="09" <?php if($ExpirationMonth == "09") { ?>selected="selected"<?php } ?>>09</option>
|
639 |
-
<option value="10" <?php if($ExpirationMonth == "10") { ?>selected="selected"<?php } ?>>10</option>
|
640 |
-
<option value="11" <?php if($ExpirationMonth == "11") { ?>selected="selected"<?php } ?>>11</option>
|
641 |
-
<option value="12" <?php if($ExpirationMonth == "12") { ?>selected="selected"<?php } ?>>12</option>
|
642 |
-
</select>/<select id="ExpirationYear" class=" <?php echo pmpro_getClassForField("ExpirationYear");?>">
|
643 |
-
<?php
|
644 |
-
for($i = date_i18n("Y"); $i < date_i18n("Y") + 10; $i++) { ?>
|
645 |
-
<option value="<?php echo $i?>" <?php if($ExpirationYear == $i) { ?>selected="selected"<?php } ?>><?php echo $i?></option>
|
646 |
-
<?php } ?>
|
647 |
-
</select>
|
648 |
</div>
|
649 |
-
<?php
|
650 |
-
$pmpro_show_cvv = apply_filters("pmpro_show_cvv", true);
|
651 |
-
if($pmpro_show_cvv) { ?>
|
652 |
-
<div class="pmpro_checkout-field pmpro_payment-cvv">
|
653 |
-
<label for="CVV"><?php _e('Security Code (CVC)', 'paid-memberships-pro' );?></label>
|
654 |
-
<input id="CVV" type="text" size="4" value="<?php if(!empty($_REQUEST['CVV'])) { echo esc_attr(sanitize_text_field($_REQUEST['CVV'])); }?>" class="input <?php echo pmpro_getClassForField("CVV");?>" /> <small>(<a href="javascript:void(0);" onclick="javascript:window.open('<?php echo pmpro_https_filter(PMPRO_URL)?>/pages/popup-cvv.html','cvv','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=600, height=475');"><?php _e("what's this?", 'paid-memberships-pro' );?></a>)</small>
|
655 |
-
</div>
|
656 |
-
<?php } ?>
|
657 |
-
<?php if($pmpro_show_discount_code) { ?>
|
658 |
-
<div class="pmpro_checkout-field pmpro_payment-discount-code">
|
659 |
-
<label for="discount_code"><?php _e('Discount Code', 'paid-memberships-pro' );?></label>
|
660 |
-
<input class="input <?php echo pmpro_getClassForField("discount_code");?>" id="discount_code" name="discount_code" type="text" size="10" value="<?php echo esc_attr($discount_code)?>" />
|
661 |
-
<input type="button" id="discount_code_button" name="discount_code_button" value="<?php _e('Apply', 'paid-memberships-pro' );?>" />
|
662 |
-
<p id="discount_code_message" class="pmpro_message" style="display: none;"></p>
|
663 |
-
</div>
|
664 |
-
<?php } ?>
|
665 |
-
</div> <!-- end pmpro_checkout-fields -->
|
666 |
-
<?php if(!empty($sslseal)) { ?>
|
667 |
-
<div class="pmpro_checkout-fields-rightcol pmpro_sslseal"><?php echo stripslashes($sslseal); ?></div>
|
668 |
-
</div> <!-- end pmpro_checkout-fields-display-seal -->
|
669 |
<?php } ?>
|
670 |
-
</div> <!-- end
|
671 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
672 |
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
global $wpdb, $current_user, $pmpro_currency_symbol;
|
685 |
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
|
704 |
-
|
705 |
-
|
706 |
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
|
714 |
-
|
715 |
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
update_user_meta($user->ID, "pmpro_stripe_updates", array());
|
720 |
|
721 |
-
|
722 |
-
|
723 |
-
{
|
724 |
-
?>
|
725 |
-
<p><?php printf( __('%1$sNote:%2$s Subscription %3$s%4$s%5$s could not be found at Stripe. It may have been deleted.', 'paid-memberships-pro'), '<strong>', '</strong>', '<strong>', esc_attr($last_order->subscription_transaction_id), '</strong>' ); ?></p>
|
726 |
-
<?php
|
727 |
-
}
|
728 |
-
}
|
729 |
-
elseif ( true === self::$is_loaded )
|
730 |
{
|
731 |
?>
|
732 |
-
<
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
}
|
777 |
?>
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
<span class="updates_billing" <?php if($update['when'] == "now") { ?>style="display: none;"<?php } ?>>
|
783 |
-
<?php echo $pmpro_currency_symbol?><input name="updates_billing_amount[]" type="text" size="10" value="<?php echo esc_attr($update['billing_amount']);?>" />
|
784 |
-
<small><?php _e('per', 'paid-memberships-pro' );?></small>
|
785 |
-
<input name="updates_cycle_number[]" type="text" size="5" value="<?php echo esc_attr($update['cycle_number']);?>" />
|
786 |
-
<select name="updates_cycle_period[]">
|
787 |
-
<?php
|
788 |
-
foreach ( $cycles as $name => $value ) {
|
789 |
-
echo "<option value='$value'";
|
790 |
-
if(!empty($update['cycle_period']) && $update['cycle_period'] == $value) echo " selected='selected'";
|
791 |
-
echo ">$name</option>";
|
792 |
}
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
<
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
817 |
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
|
824 |
-
|
825 |
-
|
826 |
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
|
833 |
-
|
834 |
-
|
835 |
|
836 |
-
|
837 |
-
|
838 |
|
839 |
-
|
840 |
-
|
841 |
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
}
|
865 |
}
|
|
|
866 |
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
global $wpdb;
|
875 |
-
|
876 |
-
//check capabilities
|
877 |
-
$membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
|
878 |
-
if(!current_user_can($membership_level_capability))
|
879 |
-
return false;
|
880 |
|
881 |
-
|
882 |
-
|
883 |
-
|
|
|
884 |
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
$update = array();
|
893 |
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
$update['cycle_period'] = sanitize_text_field($_POST['updates_cycle_period'][$i]);
|
899 |
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
$update['date_year'] = intval($_POST['updates_date_year'][$i]);
|
906 |
-
}
|
907 |
|
908 |
-
|
909 |
-
|
910 |
-
|
|
|
|
|
|
|
|
|
911 |
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
PMProGateway_stripe::updateSubscription($update, $user_id);
|
916 |
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
if(!empty($next_on_date_update))
|
922 |
-
$next_on_date_update = min($next_on_date_update, $update['date_year'] . "-" . $update['date_month'] . "-" . $update['date_day']);
|
923 |
-
else
|
924 |
-
$next_on_date_update = $update['date_year'] . "-" . $update['date_month'] . "-" . $update['date_day'];
|
925 |
-
}
|
926 |
|
927 |
-
|
928 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
929 |
}
|
930 |
|
931 |
-
//
|
932 |
-
|
933 |
-
|
934 |
-
//save date of next on-date update to make it easier to query for these in cron job
|
935 |
-
update_user_meta($user_id, "pmpro_stripe_next_on_date_update", $next_on_date_update);
|
936 |
}
|
937 |
|
938 |
-
|
939 |
-
|
940 |
-
*
|
941 |
-
* @since 1.8
|
942 |
-
*/
|
943 |
-
static function pmpro_activation()
|
944 |
-
{
|
945 |
-
pmpro_maybe_schedule_event(time(), 'daily', 'pmpro_cron_stripe_subscription_updates');
|
946 |
-
}
|
947 |
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
* @since 1.8
|
952 |
-
*/
|
953 |
-
static function pmpro_deactivation()
|
954 |
-
{
|
955 |
-
wp_clear_scheduled_hook('pmpro_cron_stripe_subscription_updates');
|
956 |
-
}
|
957 |
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
//get all updates for today (or before today)
|
968 |
-
$sqlQuery = "SELECT *
|
969 |
-
FROM $wpdb->usermeta
|
970 |
-
WHERE meta_key = 'pmpro_stripe_next_on_date_update'
|
971 |
-
AND meta_value IS NOT NULL
|
972 |
-
AND meta_value <> ''
|
973 |
-
AND meta_value < '" . date_i18n("Y-m-d", strtotime("+1 day", current_time('timestamp'))) . "'";
|
974 |
-
$updates = $wpdb->get_results($sqlQuery);
|
975 |
-
|
976 |
-
if(!empty($updates))
|
977 |
-
{
|
978 |
-
//loop through
|
979 |
-
foreach($updates as $update)
|
980 |
-
{
|
981 |
-
//pull values from update
|
982 |
-
$user_id = $update->user_id;
|
983 |
|
984 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
985 |
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
991 |
|
992 |
-
|
993 |
-
}
|
994 |
|
995 |
-
|
996 |
-
|
|
|
|
|
997 |
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
}
|
1021 |
}
|
|
|
1022 |
|
1023 |
-
|
1024 |
-
|
1025 |
|
1026 |
-
|
1027 |
-
|
1028 |
-
}
|
1029 |
}
|
1030 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1031 |
|
1032 |
/**
|
1033 |
-
*
|
1034 |
-
*
|
1035 |
-
*
|
1036 |
-
* instead of updating their billing information via the billing info page.
|
1037 |
*/
|
1038 |
-
|
1039 |
-
global $wpdb, $current_user;
|
1040 |
-
|
1041 |
-
// we're only worried about cases where the user is logged in
|
1042 |
-
if( ! is_user_logged_in() ) {
|
1043 |
-
return;
|
1044 |
-
}
|
1045 |
-
|
1046 |
-
// make sure we're checking out with Stripe
|
1047 |
-
$current_gateway = pmpro_getGateway();
|
1048 |
-
if ( $current_gateway != 'stripe' ) {
|
1049 |
-
return;
|
1050 |
-
}
|
1051 |
-
|
1052 |
-
//check the $pmpro_cancel_previous_subscriptions filter
|
1053 |
-
//this is used in add ons like Gift Memberships to stop PMPro from cancelling old memberships
|
1054 |
-
$pmpro_cancel_previous_subscriptions = true;
|
1055 |
-
$pmpro_cancel_previous_subscriptions = apply_filters( 'pmpro_cancel_previous_subscriptions', $pmpro_cancel_previous_subscriptions );
|
1056 |
-
if( ! $pmpro_cancel_previous_subscriptions ) {
|
1057 |
-
return;
|
1058 |
-
}
|
1059 |
-
|
1060 |
-
//get user and membership level
|
1061 |
-
$membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
|
1062 |
-
|
1063 |
-
//no level, then probably no subscription at Stripe anymore
|
1064 |
-
if(empty($membership_level))
|
1065 |
-
return;
|
1066 |
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
*
|
1094 |
-
* @param int $days Grace period defaults to 3 days
|
1095 |
-
* @param object $membership Membership row from pmpro_memberships_users including membership_id, user_id, and enddate
|
1096 |
-
*/
|
1097 |
-
$days_grace = apply_filters('pmpro_stripe_days_grace_when_canceling_existing_subscriptions_at_checkout', 3, $memberships_users_row);
|
1098 |
-
$new_enddate = date('Y-m-d H:i:s', current_time('timestamp')+3600*24*$days_grace);
|
1099 |
-
$wpdb->update( $wpdb->pmpro_memberships_users, array('enddate'=>$new_enddate), array('user_id'=>$current_user->ID, 'membership_id'=>$level_to_cancel, 'status'=>'active'), array('%s'), array('%d', '%d', '%s') );
|
1100 |
-
}
|
1101 |
}
|
1102 |
}
|
1103 |
}
|
1104 |
}
|
|
|
1105 |
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
if($this->charge($order))
|
1123 |
-
{
|
1124 |
-
if(pmpro_isLevelRecurring($order->membership_level))
|
1125 |
-
{
|
1126 |
-
if($this->subscribe($order))
|
1127 |
-
{
|
1128 |
-
//yay!
|
1129 |
-
return true;
|
1130 |
-
}
|
1131 |
-
else
|
1132 |
-
{
|
1133 |
-
//try to refund initial charge
|
1134 |
-
return false;
|
1135 |
-
}
|
1136 |
-
}
|
1137 |
-
else
|
1138 |
-
{
|
1139 |
-
//only a one time charge
|
1140 |
-
$order->status = "success"; //saved on checkout page
|
1141 |
return true;
|
|
|
|
|
|
|
1142 |
}
|
|
|
|
|
|
|
|
|
1143 |
}
|
1144 |
-
|
1145 |
-
{
|
1146 |
-
if(
|
1147 |
-
if ( ! self::$is_loaded ) {
|
1148 |
|
1149 |
-
|
1150 |
|
1151 |
-
|
1152 |
|
1153 |
-
|
1154 |
-
}
|
1155 |
}
|
1156 |
-
|
1157 |
-
return false;
|
1158 |
}
|
|
|
|
|
1159 |
}
|
1160 |
}
|
|
|
1161 |
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
$currency_unit_multiplier = 100; //ie 100 cents per USD
|
1171 |
-
|
1172 |
-
//account for zero-decimal currencies like the Japanese Yen
|
1173 |
-
if(is_array($pmpro_currencies[$pmpro_currency]) && isset($pmpro_currencies[$pmpro_currency]['decimals']) && $pmpro_currencies[$pmpro_currency]['decimals'] == 0)
|
1174 |
-
$currency_unit_multiplier = 1;
|
1175 |
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
|
|
1179 |
|
1180 |
-
|
1181 |
-
|
|
|
|
|
1182 |
|
1183 |
-
|
1184 |
-
|
1185 |
-
$tax = $order->getTax(true);
|
1186 |
-
$amount = pmpro_round_price((float)$order->subtotal + (float)$tax);
|
1187 |
|
1188 |
-
|
1189 |
-
|
|
|
|
|
1190 |
|
1191 |
-
|
1192 |
-
|
1193 |
-
//failed to create customer
|
1194 |
-
return false;
|
1195 |
-
}
|
1196 |
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
$response = Stripe_Charge::create(array(
|
1201 |
-
"amount" => $amount * $currency_unit_multiplier, # amount in cents, again
|
1202 |
-
"currency" => strtolower($pmpro_currency),
|
1203 |
-
"customer" => $this->customer->id,
|
1204 |
-
"description" => apply_filters('pmpro_stripe_order_description', "Order #" . $order->code . ", " . trim($order->FirstName . " " . $order->LastName) . " (" . $order->Email . ")", $order)
|
1205 |
-
)
|
1206 |
-
);
|
1207 |
-
}
|
1208 |
-
catch (Exception $e)
|
1209 |
-
{
|
1210 |
-
//$order->status = "error";
|
1211 |
-
$order->errorcode = true;
|
1212 |
-
$order->error = "Error: " . $e->getMessage();
|
1213 |
-
$order->shorterror = $order->error;
|
1214 |
-
return false;
|
1215 |
-
}
|
1216 |
-
|
1217 |
-
if(empty($response["failure_message"]))
|
1218 |
-
{
|
1219 |
-
//successful charge
|
1220 |
-
$order->payment_transaction_id = $response["id"];
|
1221 |
-
$order->updateStatus("success");
|
1222 |
-
$order->saveOrder();
|
1223 |
-
return true;
|
1224 |
-
}
|
1225 |
-
else
|
1226 |
-
{
|
1227 |
-
//$order->status = "error";
|
1228 |
-
$order->errorcode = true;
|
1229 |
-
$order->error = $response['failure_message'];
|
1230 |
-
$order->shorterror = $response['failure_message'];
|
1231 |
-
return false;
|
1232 |
-
}
|
1233 |
}
|
1234 |
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
//already have it?
|
1253 |
-
if(!empty($this->customer) && !$force)
|
1254 |
-
return $this->customer;
|
1255 |
-
|
1256 |
-
//figure out user_id and user
|
1257 |
-
if(!empty($order->user_id))
|
1258 |
-
$user_id = $order->user_id;
|
1259 |
|
1260 |
-
|
1261 |
-
|
1262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1263 |
|
1264 |
-
|
1265 |
-
|
1266 |
-
|
1267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1268 |
|
1269 |
-
//transaction id
|
1270 |
-
if
|
1271 |
-
|
1272 |
-
|
1273 |
-
|
1274 |
-
|
1275 |
-
|
1276 |
-
|
1277 |
-
$
|
|
|
|
|
1278 |
}
|
1279 |
|
1280 |
-
//
|
1281 |
-
if
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
1287 |
-
|
1288 |
-
|
1289 |
-
$last_order = new MemberOrder();
|
1290 |
-
$last_order->getLastMemberOrder($user_id, array('success', 'cancelled'), NULL, 'stripe', $order->Gateway->gateway_environment);
|
1291 |
-
if(!empty($last_order->payment_transaction_id))
|
1292 |
-
$payment_transaction_id = $last_order->payment_transaction_id;
|
1293 |
-
}
|
1294 |
-
|
1295 |
-
//we have a transaction id to look up
|
1296 |
-
if(!empty($payment_transaction_id))
|
1297 |
-
{
|
1298 |
-
if(strpos($payment_transaction_id, "ch_") !== false)
|
1299 |
-
{
|
1300 |
-
//charge, look it up
|
1301 |
-
try {
|
1302 |
-
$charge = Stripe_Charge::retrieve($payment_transaction_id);
|
1303 |
-
} catch( \Exception $exception ) {
|
1304 |
-
$order->error = sprintf( __( 'Error: %s', 'paid-memberships-pro' ), $exception->getMessage() );
|
1305 |
-
return false;
|
1306 |
-
}
|
1307 |
-
|
1308 |
-
if(!empty($charge) && !empty($charge->customer))
|
1309 |
-
$customer_id = $charge->customer;
|
1310 |
}
|
1311 |
-
else if(strpos($payment_transaction_id, "in_") !== false)
|
1312 |
-
{
|
1313 |
-
//invoice look it up
|
1314 |
-
try {
|
1315 |
-
$invoice = Stripe_Invoice::retrieve($payment_transaction_id);
|
1316 |
-
} catch( \Exception $exception ) {
|
1317 |
-
$order->error = sprintf( __( 'Error: %s', 'paid-memberships-pro' ), $exception->getMessage() );
|
1318 |
-
return false;
|
1319 |
-
}
|
1320 |
|
1321 |
-
|
1322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1323 |
}
|
1324 |
-
}
|
1325 |
|
1326 |
-
|
1327 |
-
|
1328 |
-
|
1329 |
}
|
1330 |
-
}
|
1331 |
-
|
1332 |
-
//get name and email values from order in case we update
|
1333 |
-
if(!empty($order->FirstName) && !empty($order->LastName))
|
1334 |
-
$name = trim($order->FirstName . " " . $order->LastName);
|
1335 |
-
elseif(!empty($order->FirstName))
|
1336 |
-
$name = $order->FirstName;
|
1337 |
-
elseif(!empty($order->LastName))
|
1338 |
-
$name = $order->LastName;
|
1339 |
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
//still empty?
|
1345 |
-
if(empty($name))
|
1346 |
-
$name = $user->user_login;
|
1347 |
-
}
|
1348 |
-
elseif(empty($name))
|
1349 |
-
$name = "No Name";
|
1350 |
-
|
1351 |
-
if(!empty($order->Email))
|
1352 |
-
$email = $order->Email;
|
1353 |
-
else
|
1354 |
-
$email = "";
|
1355 |
-
if(empty($email) && !empty($user->ID) && !empty($user->user_email))
|
1356 |
-
{
|
1357 |
-
$email = $user->user_email;
|
1358 |
}
|
1359 |
-
|
1360 |
-
$email = "No Email";
|
1361 |
-
|
1362 |
-
//check for an existing stripe customer
|
1363 |
-
if(!empty($customer_id))
|
1364 |
-
{
|
1365 |
-
try
|
1366 |
-
{
|
1367 |
-
$this->customer = Stripe_Customer::retrieve($customer_id);
|
1368 |
-
|
1369 |
-
//update the customer description and card
|
1370 |
-
if(!empty($order->stripeToken))
|
1371 |
-
{
|
1372 |
-
$this->customer->description = $name . " (" . $email . ")";
|
1373 |
-
$this->customer->email = $email;
|
1374 |
-
$this->customer->card = $order->stripeToken;
|
1375 |
-
$this->customer->save();
|
1376 |
-
}
|
1377 |
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1383 |
}
|
|
|
|
|
|
|
|
|
1384 |
}
|
|
|
1385 |
|
1386 |
-
|
1387 |
-
|
1388 |
-
{
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
$order->error = __("Error creating customer record with Stripe:", 'paid-memberships-pro' ) . " " . $e->getMessage();
|
1400 |
-
$order->shorterror = $order->error;
|
1401 |
-
return false;
|
1402 |
-
}
|
1403 |
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
-
function pmpro_user_register_stripe_customerid($user_id)
|
1416 |
-
{
|
1417 |
-
global $pmpro_stripe_customer_id;
|
1418 |
-
update_user_meta($user_id, "pmpro_stripe_customerid", $pmpro_stripe_customer_id);
|
1419 |
-
}
|
1420 |
-
add_action("user_register", "pmpro_user_register_stripe_customerid");
|
1421 |
}
|
|
|
1422 |
}
|
1423 |
-
|
1424 |
-
return apply_filters('pmpro_stripe_create_customer', $this->customer);
|
1425 |
}
|
1426 |
|
1427 |
-
return
|
1428 |
}
|
1429 |
|
1430 |
-
|
1431 |
-
|
1432 |
-
*
|
1433 |
-
* @since 1.8
|
1434 |
-
*/
|
1435 |
-
function getSubscription(&$order)
|
1436 |
-
{
|
1437 |
-
global $wpdb;
|
1438 |
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
|
|
|
|
|
|
|
|
1442 |
|
1443 |
-
|
|
|
|
|
|
|
1444 |
|
1445 |
-
|
1446 |
-
if(empty($result))
|
1447 |
-
return false;
|
1448 |
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
{
|
1454 |
-
$sub = $this->customer->subscriptions->retrieve($order->subscription_transaction_id);
|
1455 |
-
}
|
1456 |
-
catch (Exception $e)
|
1457 |
-
{
|
1458 |
-
$order->error = __("Error getting subscription with Stripe:", 'paid-memberships-pro' ) . $e->getMessage();
|
1459 |
-
$order->shorterror = $order->error;
|
1460 |
-
return false;
|
1461 |
-
}
|
1462 |
|
1463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1464 |
}
|
1465 |
|
1466 |
-
|
1467 |
-
|
1468 |
-
return false;
|
1469 |
|
1470 |
-
|
1471 |
-
|
|
|
|
|
1472 |
|
1473 |
-
|
1474 |
-
|
1475 |
-
return false;
|
1476 |
|
1477 |
-
|
1478 |
-
|
|
|
|
|
1479 |
|
1480 |
-
|
1481 |
-
|
1482 |
-
{
|
1483 |
-
if(in_array($sub->plan->id, $codes))
|
1484 |
-
{
|
1485 |
-
return $sub;
|
1486 |
-
}
|
1487 |
-
}
|
1488 |
|
1489 |
-
|
1490 |
-
|
|
|
|
|
|
|
1491 |
}
|
1492 |
|
1493 |
-
|
1494 |
-
|
1495 |
-
|
1496 |
-
|
1497 |
-
|
1498 |
-
|
1499 |
-
|
1500 |
-
|
|
|
|
|
|
|
1501 |
|
1502 |
-
|
1503 |
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
|
1512 |
-
|
1513 |
-
|
1514 |
|
1515 |
-
|
1516 |
-
|
1517 |
-
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
}
|
1523 |
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
|
|
1528 |
|
1529 |
-
|
1530 |
-
|
1531 |
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
|
|
|
|
|
|
|
|
|
|
1536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1537 |
/*
|
1538 |
-
|
1539 |
-
since we are doing the first payment as a separate transaction.
|
1540 |
-
The second part is the actual "trial" set by the admin.
|
1541 |
|
1542 |
-
|
1543 |
*/
|
1544 |
-
|
1545 |
-
|
1546 |
-
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
else
|
1552 |
-
$trial_period_days = $order->BillingFrequency * 30; //assume monthly
|
1553 |
-
|
1554 |
-
//convert to a profile start date
|
1555 |
-
$order->ProfileStartDate = date_i18n("Y-m-d", strtotime("+ " . $trial_period_days . " Day", current_time("timestamp"))) . "T0:0:0";
|
1556 |
-
|
1557 |
-
//filter the start date
|
1558 |
-
$order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
|
1559 |
-
|
1560 |
-
//convert back to days
|
1561 |
-
$trial_period_days = ceil(abs(strtotime(date_i18n("Y-m-d"), current_time("timestamp")) - strtotime($order->ProfileStartDate, current_time("timestamp"))) / 86400);
|
1562 |
-
|
1563 |
-
//for free trials, just push the start date of the subscription back
|
1564 |
-
if(!empty($order->TrialBillingCycles) && $order->TrialAmount == 0)
|
1565 |
-
{
|
1566 |
-
$trialOccurrences = (int)$order->TrialBillingCycles;
|
1567 |
-
if($order->BillingPeriod == "Year")
|
1568 |
-
$trial_period_days = $trial_period_days + (365 * $order->BillingFrequency * $trialOccurrences); //annual
|
1569 |
-
elseif($order->BillingPeriod == "Day")
|
1570 |
-
$trial_period_days = $trial_period_days + (1 * $order->BillingFrequency * $trialOccurrences); //daily
|
1571 |
-
elseif($order->BillingPeriod == "Week")
|
1572 |
-
$trial_period_days = $trial_period_days + (7 * $order->BillingFrequency * $trialOccurrences); //weekly
|
1573 |
-
else
|
1574 |
-
$trial_period_days = $trial_period_days + (30 * $order->BillingFrequency * $trialOccurrences); //assume monthly
|
1575 |
-
}
|
1576 |
-
elseif(!empty($order->TrialBillingCycles))
|
1577 |
-
{
|
1578 |
-
/*
|
1579 |
-
Let's set the subscription to the trial and give the user an "update" to change the sub later to full price (since v2.0)
|
1580 |
|
1581 |
-
|
1582 |
-
|
1583 |
-
|
1584 |
-
|
1585 |
-
|
1586 |
-
'billing_amount' => $order->PaymentAmount,
|
1587 |
-
'cycle_period' => $order->BillingPeriod,
|
1588 |
-
'cycle_number' => $order->BillingFrequency
|
1589 |
-
);
|
1590 |
-
|
1591 |
-
//now amount to equal the trial #s
|
1592 |
-
$amount = $order->TrialAmount;
|
1593 |
-
$amount_tax = $order->getTaxForPrice($amount);
|
1594 |
-
$amount = pmpro_round_price((float)$amount + (float)$amount_tax);
|
1595 |
-
}
|
1596 |
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
);
|
1609 |
-
|
1610 |
-
$plan = Stripe_Plan::create(apply_filters('pmpro_stripe_create_plan_array', $plan));
|
1611 |
-
}
|
1612 |
-
catch (Exception $e)
|
1613 |
-
{
|
1614 |
-
$order->error = __("Error creating plan with Stripe:", 'paid-memberships-pro' ) . $e->getMessage();
|
1615 |
-
$order->shorterror = $order->error;
|
1616 |
-
return false;
|
1617 |
-
}
|
1618 |
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
|
1626 |
-
|
1627 |
-
|
|
|
|
|
|
|
1628 |
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
$subscription = array("plan" => $order->code);
|
1633 |
-
$result = $this->customer->subscriptions->create(apply_filters('pmpro_stripe_create_subscription_array', $subscription));
|
1634 |
-
}
|
1635 |
-
catch (Exception $e)
|
1636 |
-
{
|
1637 |
-
//try to delete the plan
|
1638 |
-
$plan->delete();
|
1639 |
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
|
|
|
|
|
|
|
|
1643 |
|
1644 |
-
|
1645 |
-
|
1646 |
-
|
1647 |
-
return false;
|
1648 |
}
|
1649 |
|
1650 |
-
//
|
1651 |
-
$
|
1652 |
-
$
|
|
|
|
|
1653 |
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
//empty out updates unless set above
|
1662 |
-
if(empty($new_user_updates))
|
1663 |
-
$new_user_updates = array();
|
1664 |
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
-
|
1669 |
-
|
1670 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1671 |
global $pmpro_stripe_updates;
|
1672 |
-
|
1673 |
-
function pmpro_user_register_stripe_updates($user_id)
|
1674 |
-
{
|
1675 |
-
global $pmpro_stripe_updates;
|
1676 |
-
update_user_meta($user_id, "pmpro_stripe_updates", $pmpro_stripe_updates);
|
1677 |
-
}
|
1678 |
-
add_action("user_register", "pmpro_user_register_stripe_updates");
|
1679 |
}
|
|
|
1680 |
}
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
update_user_meta($user_id, "pmpro_stripe_updates", $old_user_updates);
|
1685 |
-
}
|
1686 |
-
|
1687 |
-
return true;
|
1688 |
}
|
1689 |
|
1690 |
-
|
1691 |
-
|
1692 |
-
*/
|
1693 |
-
static function ignoreCancelWebhookForThisSubscription($subscription_id, $user_id = NULL) {
|
1694 |
-
if(empty($user_id)) {
|
1695 |
-
global $current_user;
|
1696 |
-
$user_id = $current_user->ID;
|
1697 |
-
}
|
1698 |
-
|
1699 |
-
$preserve = get_user_meta( $user_id, 'pmpro_stripe_dont_cancel', true );
|
1700 |
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
|
|
|
|
|
|
|
|
1705 |
|
1706 |
-
|
1707 |
-
$preserve[$subscription_id] = current_time( 'timestamp' );
|
1708 |
|
1709 |
-
|
|
|
|
|
1710 |
}
|
1711 |
|
1712 |
-
|
1713 |
-
|
1714 |
-
*/
|
1715 |
-
static function updateSubscription($update, $user_id) {
|
1716 |
-
global $wpdb;
|
1717 |
|
1718 |
-
|
1719 |
-
|
1720 |
|
1721 |
-
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
|
1727 |
-
|
|
|
1728 |
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
|
|
|
|
1732 |
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
if ( !function_exists( 'pmpro_stripe_user_profile_fields_save_error' )) {
|
1738 |
-
//throw error and halt save
|
1739 |
-
function pmpro_stripe_user_profile_fields_save_error( $errors, $update, $user ) {
|
1740 |
-
$errors->add( 'pmpro_stripe_updates', __( 'Could not cancel the old subscription. Updates have not been processed.', 'paid-memberships-pro' ) );
|
1741 |
-
}
|
1742 |
|
1743 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1744 |
}
|
1745 |
|
1746 |
-
|
1747 |
-
return;
|
1748 |
}
|
|
|
|
|
|
|
1749 |
}
|
|
|
1750 |
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
//build order object
|
1756 |
-
$update_order = new MemberOrder();
|
1757 |
-
$update_order->setGateway('stripe');
|
1758 |
-
$update_order->user_id = $user_id;
|
1759 |
-
$update_order->membership_id = $user_level->id;
|
1760 |
-
$update_order->membership_name = $user_level->name;
|
1761 |
-
$update_order->InitialPayment = 0;
|
1762 |
-
$update_order->PaymentAmount = $update['billing_amount'];
|
1763 |
-
$update_order->ProfileStartDate = date_i18n("Y-m-d", $end_timestamp);
|
1764 |
-
$update_order->BillingPeriod = $update['cycle_period'];
|
1765 |
-
$update_order->BillingFrequency = $update['cycle_number'];
|
1766 |
-
|
1767 |
-
//need filter to reset ProfileStartDate
|
1768 |
-
add_filter('pmpro_profile_start_date', create_function('$startdate, $order', 'return "' . $update_order->ProfileStartDate . 'T0:0:0";'), 10, 2);
|
1769 |
-
|
1770 |
-
//update subscription
|
1771 |
-
$update_order->Gateway->subscribe($update_order, false);
|
1772 |
-
|
1773 |
-
//update membership
|
1774 |
-
$sqlQuery = "UPDATE $wpdb->pmpro_memberships_users
|
1775 |
-
SET billing_amount = '" . esc_sql($update['billing_amount']) . "',
|
1776 |
-
cycle_number = '" . esc_sql($update['cycle_number']) . "',
|
1777 |
-
cycle_period = '" . esc_sql($update['cycle_period']) . "',
|
1778 |
-
trial_amount = '',
|
1779 |
-
trial_limit = ''
|
1780 |
-
WHERE user_id = '" . esc_sql($user_id) . "'
|
1781 |
-
AND membership_id = '" . esc_sql($last_order->membership_id) . "'
|
1782 |
-
AND status = 'active'
|
1783 |
-
LIMIT 1";
|
1784 |
-
|
1785 |
-
$wpdb->query($sqlQuery);
|
1786 |
-
|
1787 |
-
//save order so we know which plan to look for at stripe (order code = plan id)
|
1788 |
-
$update_order->status = "success";
|
1789 |
-
$update_order->saveOrder();
|
1790 |
}
|
1791 |
|
1792 |
-
|
1793 |
-
|
1794 |
-
|
1795 |
-
|
1796 |
-
|
1797 |
-
|
1798 |
-
|
1799 |
-
|
1800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1801 |
|
1802 |
-
|
1803 |
-
|
1804 |
-
|
1805 |
-
|
1806 |
-
|
1807 |
-
|
1808 |
-
|
1809 |
-
|
|
|
|
|
|
|
|
|
|
|
1810 |
}
|
|
|
1811 |
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
|
1819 |
-
global $pmpro_stripe_event;
|
1820 |
|
1821 |
-
|
1822 |
-
|
1823 |
-
|
|
|
1824 |
|
1825 |
-
|
1826 |
-
|
1827 |
-
|
|
|
1828 |
|
1829 |
-
|
1830 |
-
|
1831 |
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
$subscription = $this->getSubscription($order);
|
1836 |
|
1837 |
-
|
1838 |
-
|
1839 |
-
{
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
else
|
1845 |
-
{
|
1846 |
-
$order->error = __("Could not cancel old subscription.", 'paid-memberships-pro' );
|
1847 |
-
$order->shorterror = $order->error;
|
1848 |
|
1849 |
-
|
1850 |
-
}
|
1851 |
}
|
1852 |
-
|
1853 |
-
/*
|
1854 |
-
Clear updates for this user. (But not if checking out, we would have already done that.)
|
1855 |
-
*/
|
1856 |
-
if(empty($_REQUEST['submit-checkout']))
|
1857 |
-
update_user_meta($order->user_id, "pmpro_stripe_updates", array());
|
1858 |
-
|
1859 |
-
return true;
|
1860 |
}
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
|
|
1866 |
}
|
1867 |
-
}
|
1868 |
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
//need a valid sub
|
1877 |
-
if(empty($subscription->id))
|
1878 |
-
return false;
|
1879 |
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1883 |
|
1884 |
-
|
1885 |
-
|
1886 |
-
|
1887 |
-
|
1888 |
-
$r = $subscription->cancel();
|
1889 |
|
1890 |
-
|
1891 |
-
|
|
|
1892 |
|
1893 |
-
|
1894 |
-
|
|
|
|
|
1895 |
|
1896 |
-
|
1897 |
-
|
1898 |
-
$invoices = $invoices->all();
|
1899 |
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
|
|
|
|
1913 |
}
|
1914 |
}
|
|
|
1915 |
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
|
|
1919 |
|
1920 |
-
|
1921 |
-
|
1922 |
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
{
|
1927 |
-
return false;
|
1928 |
-
}
|
1929 |
}
|
|
|
1930 |
|
1931 |
-
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
1938 |
-
|
1939 |
-
|
1940 |
-
|
1941 |
-
|
1942 |
-
|
1943 |
-
|
1944 |
-
|
1945 |
-
//
|
1946 |
-
|
1947 |
-
|
1948 |
-
|
1949 |
-
$
|
1950 |
-
|
1951 |
-
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
|
1956 |
-
|
1957 |
-
} else {
|
1958 |
-
return $false; // shouldn't really get here
|
1959 |
-
}
|
1960 |
-
}
|
1961 |
}
|
1962 |
}
|
1963 |
-
|
1964 |
-
return $timestamp;
|
1965 |
}
|
1966 |
|
1967 |
-
|
1968 |
-
|
1969 |
-
* @param object &$order Related PMPro order object.
|
1970 |
-
* @param string $transaction_id Payment or Invoice id to void.
|
1971 |
-
* @return bool True or false if the void worked
|
1972 |
-
*/
|
1973 |
-
function void(&$order, $transaction_id = null)
|
1974 |
-
{
|
1975 |
-
//stripe doesn't differentiate between voids and refunds, so let's just pass on to the refund function
|
1976 |
-
return $this->refund($order, $transaction_id);
|
1977 |
-
}
|
1978 |
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
|
1983 |
-
|
1984 |
-
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
1988 |
-
|
1989 |
-
$transaction_id = $order->payment_transaction_id;
|
1990 |
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1994 |
|
1995 |
-
|
1996 |
-
|
1997 |
-
|
|
|
1998 |
|
1999 |
-
|
2000 |
-
|
2001 |
-
|
2002 |
|
2003 |
-
|
2004 |
-
|
2005 |
-
$charge = Stripe_Charge::retrieve($transaction_id);
|
2006 |
-
} catch (Exception $e) {
|
2007 |
-
$charge = false;
|
2008 |
}
|
|
|
2009 |
|
2010 |
-
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
|
2015 |
-
|
2016 |
|
2017 |
-
|
2018 |
-
|
|
|
|
|
|
|
|
|
2019 |
|
2020 |
-
|
2021 |
-
|
2022 |
-
{
|
2023 |
-
$refund = $charge->refund();
|
2024 |
-
}
|
2025 |
-
catch (Exception $e)
|
2026 |
-
{
|
2027 |
-
//$order->status = "error";
|
2028 |
-
$order->errorcode = true;
|
2029 |
-
$order->error = __("Error: ", 'paid-memberships-pro' ) . $e->getMessage();
|
2030 |
-
$order->shorterror = $order->error;
|
2031 |
-
return false;
|
2032 |
-
}
|
2033 |
|
2034 |
-
|
2035 |
-
|
2036 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2037 |
|
2038 |
-
|
2039 |
-
|
2040 |
-
|
2041 |
-
$order->errorcode = true;
|
2042 |
-
$order->error = sprintf(__("Error: Unkown error while refunding charge #%s", 'paid-memberships-pro' ), $transaction_id);
|
2043 |
-
$order->shorterror = $order->error;
|
2044 |
|
2045 |
-
|
2046 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2047 |
}
|
2048 |
}
|
|
1 |
<?php
|
2 |
+
// For compatibility with old library (Namespace Alias)
|
3 |
+
use Stripe\Customer as Stripe_Customer;
|
4 |
+
use Stripe\Invoice as Stripe_Invoice;
|
5 |
+
use Stripe\Plan as Stripe_Plan;
|
6 |
+
use Stripe\Charge as Stripe_Charge;
|
7 |
+
|
8 |
+
define( "PMPRO_STRIPE_API_VERSION", "2017-08-15" );
|
9 |
+
|
10 |
+
//include pmprogateway
|
11 |
+
require_once(dirname(__FILE__) . "/class.pmprogateway.php");
|
12 |
+
|
13 |
+
//load classes init method
|
14 |
+
add_action('init', array('PMProGateway_stripe', 'init'));
|
15 |
+
|
16 |
+
// loading plugin activation actions
|
17 |
+
add_action('activate_paid-memberships-pro', array('PMProGateway_stripe', 'pmpro_activation'));
|
18 |
+
add_action('deactivate_paid-memberships-pro', array('PMProGateway_stripe', 'pmpro_deactivation'));
|
19 |
+
|
20 |
+
/**
|
21 |
+
* PMProGateway_stripe Class
|
22 |
+
*
|
23 |
+
* Handles Stripe integration.
|
24 |
+
*
|
25 |
+
* @since 1.4
|
26 |
+
*/
|
27 |
+
class PMProGateway_stripe extends PMProGateway
|
28 |
+
{
|
29 |
/**
|
30 |
+
* @var bool Is the Stripe/PHP Library loaded
|
31 |
+
*/
|
32 |
+
private static $is_loaded = false;
|
33 |
+
/**
|
34 |
+
* Stripe Class Constructor
|
35 |
*
|
36 |
+
* @since 1.4
|
37 |
*/
|
38 |
+
function __construct($gateway = NULL) {
|
39 |
+
$this->gateway = $gateway;
|
40 |
+
$this->gateway_environment = pmpro_getOption("gateway_environment");
|
41 |
+
|
42 |
+
if( true === $this->dependencies() ) {
|
43 |
+
$this->loadStripeLibrary();
|
44 |
+
Stripe\Stripe::setApiKey(pmpro_getOption("stripe_secretkey"));
|
45 |
+
Stripe\Stripe::setAPIVersion( PMPRO_STRIPE_API_VERSION );
|
46 |
+
self::$is_loaded = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
+
return $this->gateway;
|
50 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
/**
|
53 |
+
* Warn if required extensions aren't loaded.
|
54 |
+
*
|
55 |
+
* @return bool
|
56 |
+
* @since 1.8.6.8.1
|
57 |
+
* @since 1.8.13.6 - Add json dependency
|
58 |
+
*/
|
59 |
+
public static function dependencies() {
|
60 |
+
global $msg, $msgt, $pmpro_stripe_error;
|
61 |
|
62 |
+
if ( version_compare( PHP_VERSION, '5.3.29', '<' )) {
|
|
|
|
|
63 |
|
64 |
+
$pmpro_stripe_error = true;
|
65 |
+
$msg = -1;
|
66 |
+
$msgt = sprintf(__("The Stripe Gateway requires PHP 5.3.29 or greater. We recommend upgrading to PHP %s or greater. Ask your host to upgrade.", "paid-memberships-pro" ), PMPRO_PHP_MIN_VERSION );
|
67 |
|
68 |
+
if ( !is_admin() ) {
|
69 |
+
pmpro_setMessage( $msgt, "pmpro_error" );
|
70 |
}
|
71 |
|
72 |
+
return false;
|
73 |
+
}
|
74 |
|
75 |
+
$modules = array( 'curl', 'mbstring', 'json' );
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
foreach($modules as $module){
|
78 |
+
if(!extension_loaded($module)){
|
79 |
+
$pmpro_stripe_error = true;
|
80 |
+
$msg = -1;
|
81 |
+
$msgt = sprintf(__("The %s gateway depends on the %s PHP extension. Please enable it, or ask your hosting provider to enable it.", 'paid-memberships-pro' ), 'Stripe', $module);
|
82 |
|
83 |
+
//throw error on checkout page
|
84 |
+
if(!is_admin())
|
85 |
+
pmpro_setMessage($msgt, 'pmpro_error');
|
86 |
|
87 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
}
|
89 |
}
|
90 |
|
91 |
+
self::$is_loaded = true;
|
92 |
+
return true;
|
93 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
/**
|
96 |
+
* Load the Stripe API library.
|
97 |
+
*
|
98 |
+
* @since 1.8
|
99 |
+
* Moved into a method in version 1.8 so we only load it when needed.
|
100 |
+
*/
|
101 |
+
function loadStripeLibrary() {
|
102 |
+
//load Stripe library if it hasn't been loaded already (usually by another plugin using Stripe)
|
103 |
+
if(!class_exists("Stripe\Stripe")) {
|
104 |
+
require_once( PMPRO_DIR . "/includes/lib/Stripe/init.php" );
|
105 |
+
}
|
106 |
+
}
|
107 |
|
108 |
+
/**
|
109 |
+
* Run on WP init
|
110 |
+
*
|
111 |
+
* @since 1.8
|
112 |
+
*/
|
113 |
+
static function init() {
|
114 |
+
//make sure Stripe is a gateway option
|
115 |
+
add_filter('pmpro_gateways', array('PMProGateway_stripe', 'pmpro_gateways'));
|
116 |
+
|
117 |
+
//add fields to payment settings
|
118 |
+
add_filter('pmpro_payment_options', array('PMProGateway_stripe', 'pmpro_payment_options'));
|
119 |
+
add_filter('pmpro_payment_option_fields', array('PMProGateway_stripe', 'pmpro_payment_option_fields'), 10, 2);
|
120 |
+
|
121 |
+
//add some fields to edit user page (Updates)
|
122 |
+
add_action('pmpro_after_membership_level_profile_fields', array('PMProGateway_stripe', 'user_profile_fields'));
|
123 |
+
add_action('profile_update', array('PMProGateway_stripe', 'user_profile_fields_save'));
|
124 |
+
|
125 |
+
//old global RE showing billing address or not
|
126 |
+
global $pmpro_stripe_lite;
|
127 |
+
$pmpro_stripe_lite = apply_filters("pmpro_stripe_lite", !pmpro_getOption("stripe_billingaddress")); //default is oposite of the stripe_billingaddress setting
|
128 |
+
add_filter('pmpro_required_billing_fields', array('PMProGateway_stripe', 'pmpro_required_billing_fields'));
|
129 |
+
|
130 |
+
//updates cron
|
131 |
+
add_action('pmpro_cron_stripe_subscription_updates', array('PMProGateway_stripe', 'pmpro_cron_stripe_subscription_updates'));
|
132 |
+
|
133 |
+
/*
|
134 |
+
Filter pmpro_next_payment to get actual value
|
135 |
+
via the Stripe API. This is disabled by default
|
136 |
+
for performance reasons, but you can enable it
|
137 |
+
by copying this line into a custom plugin or
|
138 |
+
your active theme's functions.php and uncommenting
|
139 |
+
it there.
|
140 |
+
*/
|
141 |
+
//add_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3);
|
142 |
|
143 |
+
//code to add at checkout if Stripe is the current gateway
|
144 |
+
$default_gateway = pmpro_getOption('gateway');
|
145 |
+
$current_gateway = pmpro_getGateway();
|
146 |
|
147 |
+
if( ($default_gateway == "stripe" || $current_gateway == "stripe") && empty($_REQUEST['review'] ) ) //$_REQUEST['review'] means the PayPal Express review page
|
148 |
+
{
|
149 |
+
add_action('pmpro_checkout_preheader', array('PMProGateway_stripe', 'pmpro_checkout_preheader'));
|
150 |
+
add_action('pmpro_billing_preheader', array('PMProGateway_stripe', 'pmpro_checkout_preheader'));
|
151 |
+
add_filter('pmpro_checkout_order', array('PMProGateway_stripe', 'pmpro_checkout_order'));
|
152 |
+
add_filter('pmpro_billing_order', array('PMProGateway_stripe', 'pmpro_checkout_order'));
|
153 |
+
add_filter('pmpro_include_billing_address_fields', array('PMProGateway_stripe', 'pmpro_include_billing_address_fields'));
|
154 |
+
add_filter('pmpro_include_cardtype_field', array('PMProGateway_stripe', 'pmpro_include_billing_address_fields'));
|
155 |
+
add_filter('pmpro_include_payment_information_fields', array('PMProGateway_stripe', 'pmpro_include_payment_information_fields'));
|
156 |
+
|
157 |
+
//make sure we clean up subs we will be cancelling after checkout before processing
|
158 |
+
add_action('pmpro_checkout_before_processing', array('PMProGateway_stripe', 'pmpro_checkout_before_processing'));
|
159 |
+
}
|
160 |
|
161 |
+
add_action( 'init', array( 'PMProGateway_stripe', 'pmpro_clear_saved_subscriptions' ) );
|
162 |
|