Skip to content

Commit

Permalink
Updates to 1.11.34
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Aug 7, 2024
1 parent aade722 commit fa2c5af
Show file tree
Hide file tree
Showing 31 changed files with 491 additions and 230 deletions.
1 change: 1 addition & 0 deletions app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ public static function parse_standalone_request() {
if( $obj && ( $obj instanceof MeprBaseRealGateway ) ) {
$notifiers = $obj->notifiers();
if( isset($notifiers[$action]) ) {
nocache_headers();
call_user_func(array($obj,$notifiers[$action]));
exit;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/MeprCheckoutCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function display_signup_form($product) {
if(empty($payment_methods)) {
$payment_methods = array_keys($mepr_options->integrations);
}
$payment_methods = MeprHooks::apply_filters('mepr_options_helper_payment_methods', $payment_methods, 'mepr_payment_method');
$payment_methods = MeprHooks::apply_filters('mepr_options_helper_payment_methods', $payment_methods, 'mepr_payment_method', $product);
$payment_methods = array_map(function($pm_id) use($mepr_options) {
return $mepr_options->payment_method($pm_id);
}, $payment_methods);
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/MeprOnboardingCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ public static function admin_enqueue_scripts() {
'error_installing_addon' => __('An error occurred when installing an add-on, please download and install the add-ons manually.', 'memberpress'),
'edition_url_param' => isset($_GET['edition']) ? sanitize_text_field(wp_unslash($_GET['edition'])) : '',
]);

wp_enqueue_script('paypal-partner-sdk', 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js', [], MEPR_VERSION, true);
}
}

Expand Down
18 changes: 10 additions & 8 deletions app/controllers/MeprReadyLaunchCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ public static function enqueue_scripts() {
static::remove_styles( $handles );
static::add_template_scripts( 'checkout' );
}

if(
function_exists('bp_is_current_action') &&
bp_is_current_action('mp-subscriptions'))
{
wp_enqueue_style( 'mp-rl-buddyboss', MEPR_CSS_URL . '/readylaunch/compatibility.css', array(), MEPR_VERSION );
wp_enqueue_script( 'alpinejs', MEPR_JS_URL . '/vendor/alpine.min.js', array(), MEPR_VERSION, true );
wp_enqueue_script( 'mepr-accountjs', MEPR_JS_URL . '/readylaunch/account.js', array( 'jquery' ), MEPR_VERSION, true );
}

}

/**
Expand Down Expand Up @@ -620,7 +630,6 @@ public static function template_enabled( $template ) {
$page_name = $template . '_page_id';
$attribute_name = 'design_enable_' . $template . '_template';
$options = MeprOptions::fetch();
$courses_options = \get_option( 'mpcs-options' );

if ( 'pricing' === $template ) {
return isset( $post ) &&
Expand All @@ -636,13 +645,6 @@ public static function template_enabled( $template ) {
( isset( $post ) && is_a( $post, 'WP_Post' ) && is_singular( MeprProduct::$cpt ) );
}

if ( 'courses' === $template && is_array($courses_options) ) {
return isset($courses_options['classroom-mode']) &&
filter_var( $courses_options['classroom-mode'], FILTER_VALIDATE_BOOLEAN ) &&
MeprUser::is_account_page($post) &&
isset($_GET['action']) && $_GET['action'] == 'courses';
}

return isset( $wp_query ) &&
isset( $options->$page_name ) &&
is_page( $options->$page_name ) &&
Expand Down
6 changes: 6 additions & 0 deletions app/data/stripe_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@
'capabilities' => ['payment_intents'],
'async' => true,
],
[
'key' => 'twint',
'name' => 'TWINT',
'currencies' => ['CHF'],
'capabilities' => ['payment_intents'],
],
// Buy now, pay later
[
'key' => 'affirm',
Expand Down
30 changes: 25 additions & 5 deletions app/gateways/MeprAuthorizeWebhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public function process_webhook() {
MeprUtils::debug_log('Authorize.net auth_transaction: ' . MeprUtils::object_to_string($auth_transaction));
switch($request_json->eventType) {
case 'net.authorize.payment.authcapture.created':
case 'net.authorize.paymrecord_subscription_paymentent.capture.created':
case 'net.authorize.payment.capture.created':
case 'net.authorize.payment.fraud.approved':
if($request_json->payload->responseCode > 1) {
return $this->record_payment_failure($auth_transaction->transaction);
}
else {
return $this->record_subscription_payment($auth_transaction->transaction);
}
break;
case 'net.authorize.payment.refund.created':
return $this->record_refund($auth_transaction->transaction);
break;
case 'net.authorize.payment.fraud.declined':
return $this->record_payment_failure($auth_transaction->transaction);
default:
MeprUtils::debug_log('Authorize.net Webhook not processed: ' . $request_json->eventType);
}
Expand All @@ -53,7 +53,16 @@ public function process_webhook() {
// Transaction details are null
throw new MeprGatewayException(__('MeprAuthorizeAPI Error: Unable to retrieve transaction details. Check your logs for errors.', 'memberpress'));
}
} // We are only listening for payment webhooks
}
elseif($request_json && $request_json->eventType == 'net.authorize.customer.subscription.failed') {
MeprUtils::debug_log('Received net.authorize.customer.subscription.failed eventType');
$auth_transaction = $this->authorize_api->get_transaction_details($request_json->payload->transactionDetails->transId);

if(is_object($auth_transaction)) {
MeprUtils::debug_log('Authorize.net auth_transaction: ' . MeprUtils::object_to_string($auth_transaction));
return $this->record_payment_failure($auth_transaction->transaction);
}
}
}
else {
throw new MeprGatewayException(__('This is not a valid Webhook! Check your settings.', 'memberpress'));
Expand Down Expand Up @@ -86,10 +95,12 @@ private function validate_webhook($request_body) {
* net.authorize.payment.authcapture.created
* net.authorize.payment.capture.created
* net.authorize.payment.fraud.approved
*
* @param object $auth_transaction JSON transaction object
* @param boolean $setup_job Set to true to enqueue a job to retry if subscription data is not yet available.
* @return object|false MeprTransaction or false
*/
private function record_payment_failure($auth_transaction) {
public function record_payment_failure($auth_transaction, $setup_job = true) {
if(isset($auth_transaction->transId) and !empty($auth_transaction->transId)) {
$txn_res = MeprTransaction::get_one_by_trans_num($auth_transaction->transId);

Expand All @@ -98,6 +109,14 @@ private function record_payment_failure($auth_transaction) {
$txn->status = MeprTransaction::$failed_str;
$txn->store();
}
else if(!isset($auth_transaction->subscription->id) && $setup_job) {
$job = new MeprAuthorizeRetryJob();
$job->gateway_settings = $this->gateway_settings;
$job->transaction_data = json_encode($auth_transaction);
$job->payment_failed = true;
$job->enqueue_in('10m'); // Try again in 10 minutes, then it will retry every 30 minutes after.
return false;
}
else if(isset($auth_transaction->subscription->id) && $sub = MeprSubscription::get_one_by_subscr_id($auth_transaction->subscription->id) ) {
$txn = $this->insert_transaction($sub, $auth_transaction, MeprTransaction::$failed_str);

Expand Down Expand Up @@ -143,6 +162,7 @@ public function record_subscription_payment($auth_transaction, $setup_job = true
$job = new MeprAuthorizeRetryJob();
$job->gateway_settings = $this->gateway_settings;
$job->transaction_data = json_encode($auth_transaction);
$job->payment_failed = false;
$job->enqueue_in('10m'); //Try again in 10 minutes. Then it will retry every 30 minutes after
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions app/gateways/MeprStripeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,13 @@ private function filter_incompatible_payment_method_types(array $types, $amount
}
}

if(($key = array_search('twint', $types)) !== false) {
if(!is_null($amount) && $amount > 5000) {
// TWINT does not support a payment amount greater than 5000 CHF
array_splice($types, $key, 1);
}
}

return $types;
}

Expand Down
4 changes: 3 additions & 1 deletion app/helpers/MeprGroupsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public static function group_page_item($product, $group = null, $preview = false

?>
<div id="mepr-price-box-<?php echo $product->ID; ?>" class="mepr-price-box <?php echo $group_classes_str; ?>">
<div class="mepr-most-popular"><?php _e('Most Popular', 'memberpress'); ?></div>
<?php if ($product->is_highlighted) : ?>
<div class="mepr-most-popular"><?php _e('Most Popular', 'memberpress'); ?></div>
<?php endif; ?>
<div class="mepr-price-box-head">
<div class="mepr-price-box-title"><?php echo $product->pricing_title; ?></div>
<?php if($preview): ?>
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/MeprOptionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public static function payment_method_description($payment_method) {
public static function payment_methods_dropdown($field_name, $pms = false, $product = null) {
$mepr_options = MeprOptions::fetch();
$pms = $pms ? $pms : array_keys($mepr_options->integrations);
$pms = MeprHooks::apply_filters('mepr_options_helper_payment_methods',$pms,$field_name);
$pms = MeprHooks::apply_filters('mepr_options_helper_payment_methods', $pms, $field_name, $product);

if(count($pms) == 0):
return false;
Expand Down
23 changes: 19 additions & 4 deletions app/jobs/MeprAuthorizeRetryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@
require_once(__DIR__ . '/../gateways/MeprAuthorizeAPI.php');
require_once(__DIR__ . '/../gateways/MeprAuthorizeWebhooks.php');

/**
* @property string $transaction_data JSON-encoded Authorize.net transaction data.
* @property object $gateway_settings Gateway settings object.
* @property boolean $payment_failed Whether this job is for a failed payment (true), or a successful one (false).
*/
class MeprAuthorizeRetryJob extends MeprBaseJob {

/**
* Perform this job.
*
* @throws Exception
*/
public function perform() {
$last_transaction = json_decode($this->transaction_data);
$authorize_api = new MeprAuthorizeAPI((object)$this->gateway_settings);
$auth_transaction = $authorize_api->get_transaction_details($last_transaction->transId);

if($auth_transaction && $auth_transaction !== '') {
if(is_object($auth_transaction)) {
if(!isset($auth_transaction->transaction->subscription)) {
throw new Exception( __('No subscription data available', 'memberpress') );
}
else {
$auth_webhook = new MeprAuthorizeWebhooks((object)$this->gateway_settings);
$auth_webhook->record_subscription_payment($auth_transaction->transaction, false);
$auth_webhook = new MeprAuthorizeWebhooks((object) $this->gateway_settings);

if($this->payment_failed) {
$auth_webhook->record_payment_failure($auth_transaction->transaction, false);
}
else {
$auth_webhook->record_subscription_payment($auth_transaction->transaction, false);
}
}
}
else {
Expand Down
2 changes: 2 additions & 0 deletions app/lib/MeprReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ public static function subscription_stats($created_since=false) {

$stats = $wpdb->get_row($q, ARRAY_A);

$wpdb->query("SET SQL_BIG_SELECTS=1");

$q = $wpdb->prepare("
SELECT COUNT(*) AS active,
IFNULL(SUM(IF(s.status=%s,1,0)), 0) AS active_and_enabled
Expand Down
14 changes: 13 additions & 1 deletion app/lib/MeprUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function is_memberpress_admin_page() {
return false;
}
global $current_screen;
return preg_match('/^(memberpress|mp-|mpcs-course)/', $current_screen->post_type) || preg_match('/^memberpress_page_memberpress-/', $current_screen->id);
return preg_match('/^(memberpress|mp-)/', $current_screen->post_type) || preg_match('/^memberpress_page_memberpress-/', $current_screen->id);
}

public static function is_image($filename) {
Expand Down Expand Up @@ -2596,4 +2596,16 @@ public static function get_json_request_data($nonce_action) {

return $data;
}

/**
* Formats the given content for display.
*
* Parses blocks, shortcodes and formats paragraphs.
*
* @param string $content The content to format.
* @return string The formatted content.
*/
public static function format_content($content): string {
return do_shortcode(shortcode_unautop(wpautop(do_blocks($content))));
}
} // End class
17 changes: 6 additions & 11 deletions app/models/MeprRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,15 @@ public static function get_unauth_settings_for($post) {
// - Excerpts
if($post_settings->unauth_excerpt_type != 'default') {
$unauth->excerpt_type = $post_settings->unauth_excerpt_type;
$unauth->excerpt_size = $post_settings->unauth_excerpt_size;
$unauth->excerpt_size = (int) $post_settings->unauth_excerpt_size;
}
elseif($rule->unauth_excerpt_type != 'default') {
$unauth->excerpt_type = $rule->unauth_excerpt_type;
$unauth->excerpt_size = $rule->unauth_excerpt_size;
$unauth->excerpt_size = (int) $rule->unauth_excerpt_size;
}
else {
$unauth->excerpt_type = $global_settings->excerpt_type;
$unauth->excerpt_size = $global_settings->excerpt_size;
$unauth->excerpt_size = (int) $global_settings->excerpt_size;
}

// Set the actual Excerpt based on the type & size
Expand All @@ -1217,8 +1217,7 @@ public static function get_unauth_settings_for($post) {
$content = $post->post_content;
}

$unauth->excerpt = do_shortcode($content);
$unauth->excerpt = do_blocks($content);
$unauth->excerpt = MeprUtils::format_content($content);

if($unauth->excerpt_size) { //if set to 0, return the whole post -- though why protect it all in this case?
$unauth->excerpt = strip_tags($unauth->excerpt);
Expand All @@ -1229,8 +1228,6 @@ public static function get_unauth_settings_for($post) {
}
}
elseif($unauth->excerpt_type == 'more') { //Show till the more tag
$post->post_content = do_shortcode($post->post_content);
$post->post_content = do_blocks($post->post_content);
$pos = (extension_loaded('mbstring'))?mb_strpos($post->post_content, '<!--more'):strpos($post->post_content, '<!--more');

if($pos !== false) {
Expand All @@ -1242,12 +1239,10 @@ public static function get_unauth_settings_for($post) {
$unauth->excerpt = force_balance_tags(substr($post->post_content, 0, $pos));
}

$unauth->excerpt = wpautop($unauth->excerpt);
$unauth->excerpt = MeprUtils::format_content($unauth->excerpt);
}
else { //No more tag?
$unauth->excerpt = do_shortcode($post->post_excerpt);
$unauth->excerpt = do_blocks($post->post_excerpt);
$unauth->excerpt = wpautop($post->post_excerpt);
$unauth->excerpt = MeprUtils::format_content($post->post_excerpt);
}
}
elseif($unauth->excerpt_type == 'excerpt') {
Expand Down
6 changes: 2 additions & 4 deletions app/views/checkout/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?php do_action('mepr-above-checkout-form', $product->ID); ?>

<div class="mp_wrapper">
<form name="mepr_signup_form" id="mepr_signup_form" class="mepr-signup-form mepr-form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']).'#mepr_jump'; ?>" enctype="multipart/form-data" novalidate>
<form name="mepr_signup_form" id="mepr_signup_form" class="mepr-signup-form mepr-form" method="post" action="<?php echo esc_url(wp_unslash($_SERVER['REQUEST_URI']) . '#mepr_jump'); ?>" enctype="multipart/form-data" novalidate>
<input type="hidden" name="mepr_process_signup_form" value="Y" />
<input type="hidden" name="mepr_product_id" value="<?php echo $product->ID; ?>" />

Expand Down Expand Up @@ -147,9 +147,7 @@
<input type="hidden" id="mepr_coupon_code-<?php echo $product->ID; ?>" name="mepr_coupon_code" value="<?php echo (isset($mepr_coupon_code))?esc_attr(stripslashes($mepr_coupon_code)):''; ?>" />
<?php endif; ?>
<div class="mepr-payment-methods-wrapper">
<?php $active_pms = $product->payment_methods(); ?>
<?php $pms = $product->payment_methods(); ?>
<?php echo MeprOptionsHelper::payment_methods_dropdown('mepr_payment_method', $active_pms, $product); ?>
<?php echo MeprOptionsHelper::payment_methods_dropdown('mepr_payment_method', $product->payment_methods(), $product); ?>
</div>
<?php else: ?>
<input type="hidden" name="mepr_coupon_code" value="<?php echo (isset($mepr_coupon_code))?esc_attr(stripslashes($mepr_coupon_code)):''; ?>" />
Expand Down
2 changes: 1 addition & 1 deletion app/views/checkout/spc_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?php do_action('mepr-above-checkout-form', $product->ID); ?>

<div class="mp_wrapper">
<form name="mepr_signup_form" id="mepr_signup_form" class="mepr-signup-form mepr-form" method="post" action="<?php echo $_SERVER['REQUEST_URI'].'#mepr_jump'; ?>" enctype="multipart/form-data" novalidate>
<form name="mepr_signup_form" id="mepr_signup_form" class="mepr-signup-form mepr-form" method="post" action="<?php echo esc_url(wp_unslash($_SERVER['REQUEST_URI']) . '#mepr_jump'); ?>" enctype="multipart/form-data" novalidate>
<input type="hidden" name="mepr_process_signup_form" value="<?php echo isset($_GET['mepr_process_signup_form']) ? esc_attr($_GET['mepr_process_signup_form']) : 1 ?>" />
<input type="hidden" name="mepr_product_id" value="<?php echo esc_attr($product->ID); ?>" />
<input type="hidden" name="mepr_transaction_id" value="<?php echo isset($_GET['mepr_transaction_id']) ? esc_attr($_GET['mepr_transaction_id']) : ""; ?>" />
Expand Down
37 changes: 0 additions & 37 deletions app/views/readylaunch/account/courses_list.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/readylaunch/account/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
</div>
</td>
<td class="mepr-pro-account-table__col-actions" data-label="<?php _ex('Actions', 'ui', 'memberpress'); ?>">
<?php if ( $row_actions ) { ?>
<?php if ( trim($row_actions) ) { ?>
<svg class="mepr-tooltip-trigger" xmlns="http://www.w3.org/2000/svg" class="" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z" />
</svg>
Expand Down
Loading

0 comments on commit fa2c5af

Please sign in to comment.