Skip to content

Commit

Permalink
Merge branch 'develop' into enhance/update_deprecated_uses
Browse files Browse the repository at this point in the history
  • Loading branch information
sapayth authored Feb 9, 2024
2 parents 53635df + 995cc8c commit 45a41ff
Show file tree
Hide file tree
Showing 26 changed files with 6,398 additions and 8,186 deletions.
78 changes: 47 additions & 31 deletions Lib/Gateway/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function prepare_to_send( $data ) {
$billing_amount = empty( $data['price'] ) ? 0 : $data['price'];

if ( isset( $_POST['coupon_id'] ) && ! empty( $_POST['coupon_id'] ) ) {
$billing_amount = WPUF_Coupons::init()->discount( $billing_amount, $_POST['coupon_id'], $data['item_number'] );
$billing_amount = wpuf_pro()->coupon->discount( $billing_amount, $_POST['coupon_id'], $data['item_number'] );

$coupon_id = $_POST['coupon_id'];
} else {
Expand Down Expand Up @@ -342,16 +342,30 @@ public function paypal_success() {
$insert_payment = false;

if ( isset( $_GET['action'] ) && $_GET['action'] == 'wpuf_paypal_success' ) {
WP_User_Frontend::log( 'paypal-payment-info', print_r( $_POST, true ) );
\WP_User_Frontend::log( 'paypal-payment-info', print_r( $_POST, true ) );

$post_id = 0;
$pack_id = 0;

$postdata = $_POST;
$type = $postdata['custom'];
$custom = json_decode( stripcslashes( $postdata['custom'] ) );
$type = isset( $postdata['custom'] ) ? $postdata['custom'] : '';
$custom = json_decode( stripcslashes( $type ) );
$item_number = ! empty( $postdata['item_number'] ) ? $postdata['item_number'] : 0;
$amount = $postdata['mc_gross'];

if ( property_exists( $custom, 'type' ) ) {
switch ( $custom->type ) {
case 'post':
$post_id = $item_number;
break;

case 'pack':
$pack_id = $item_number;
break;
}
}

$amount = isset( $postdata['mc_gross'] ) ? $postdata['mc_gross'] : 0;
$is_recurring = false;
$post_id = $custom->type === 'post' ? $item_number : 0;
$pack_id = $custom->type === 'pack' ? $item_number : 0;
$transaction_id = isset( $postdata['txn_id'] ) ? sanitize_text_field( $postdata['txn_id'] ) : '';

$coupon_id = isset( $custom->coupon_id ) ? $custom->coupon_id : false;
Expand All @@ -361,7 +375,7 @@ public function paypal_success() {
}

if ( isset( $postdata['txn_type'] ) && ( $postdata['txn_type'] == 'subscr_signup' ) ) {
WP_User_Frontend::log( 'paypal-recurring', 'got subscriber with email ' . $postdata['payer_email'] );
\WP_User_Frontend::log( 'paypal-recurring', 'got subscriber with email ' . $postdata['payer_email'] );

return;
}
Expand All @@ -385,14 +399,14 @@ public function paypal_success() {
$is_recurring = true;
$status = 'subscr_payment';

WP_User_Frontend::log( 'paypal-recurring', 'got subscr_payment, should insert of pack_id: ' . $pack_id );
\WP_User_Frontend::log( 'paypal-recurring', 'got subscr_payment, should insert of pack_id: ' . $pack_id );
} else {
$this->subscription_cancel( $custom->user_id );

WP_User_Frontend::log( 'paypal-recurring', 'got subscr_payment. billing validation failed, cancel subscription. user_id: ' . $custom->user_id );
\WP_User_Frontend::log( 'paypal-recurring', 'got subscr_payment. billing validation failed, cancel subscription. user_id: ' . $custom->user_id );
}
} elseif ( isset( $postdata['txn_type'] ) && ( $postdata['txn_type'] == 'web_accept' ) && ( strtolower( $postdata['payment_status'] ) == 'completed' ) ) {
WP_User_Frontend::log( 'paypal', 'got web_accept. type: ' . $custom->type . '. item_number: ' . $item_number );
\WP_User_Frontend::log( 'paypal', 'got web_accept. type: ' . $custom->type . '. item_number: ' . $item_number );

//verify payment
$status = 'web_accept';
Expand Down Expand Up @@ -434,25 +448,25 @@ public function paypal_success() {
} // payment type

$data = [
'user_id' => (int) $custom->user_id,
'status' => strtolower( $postdata['payment_status'] ),
'subtotal' => $postdata['mc_gross'],
'tax' => (float) $custom->tax,
'cost' => (float) $custom->subtotal,
'post_id' => isset( $post_id ) ? $post_id : '',
'pack_id' => isset( $pack_id ) ? $pack_id : '',
'payer_first_name' => $postdata['first_name'],
'payer_last_name' => $postdata['last_name'],
'payer_email' => $postdata['payer_email'],
'user_id' => property_exists( $custom, 'user_id' ) ? ( int) $custom->user_id : 0,
'status' => ! empty( $postdata['payment_status'] ) ? strtolower( $postdata['payment_status'] ) : '',
'subtotal' => ! empty( $postdata['mc_gross'] ) ? $postdata['mc_gross'] : '',
'tax' => property_exists( $custom, 'tax' ) ? (float) $custom->tax : 0,
'cost' => property_exists( $custom, 'subtotal' ) ? (float) $custom->subtotal : 0,
'post_id' => isset( $post_id ) ? $post_id : 0,
'pack_id' => isset( $pack_id ) ? $pack_id : 0,
'payer_first_name' => ! empty( $postdata['first_name'] ) ? $postdata['first_name'] : '',
'payer_last_name' => ! empty( $postdata['last_name'] ) ? $postdata['last_name'] : '',
'payer_email' => ! empty( $postdata['payer_email'] ) ? $postdata['payer_email'] : '',
'payment_type' => 'Paypal',
'payer_address' => isset( $postdata['residence_country'] ) ? $postdata['residence_country'] : null,
'transaction_id' => $transaction_id,
'created' => current_time( 'mysql' ),
];

WP_User_Frontend::log( 'payment', 'inserting payment to database. ' . print_r( $data, true ) );
\WP_User_Frontend::log( 'payment', 'inserting payment to database. ' . print_r( $data, true ) );

_Payment::insert_payment( $data, $transaction_id, $is_recurring );
\WeDevs\Wpuf\Frontend\Payment::insert_payment( $data, $transaction_id, $is_recurring );

if ( $coupon_id ) {
$pre_usage = get_post_meta( $coupon_id, '_coupon_used', true );
Expand All @@ -468,8 +482,10 @@ public function paypal_success() {
update_user_meta( $custom->user_id, '_wpuf_subscription_pack', $umeta );
}

delete_user_meta( $custom->user_id, '_wpuf_user_active' );
delete_user_meta( $custom->user_id, '_wpuf_activation_key' );
if ( is_object( $custom ) && $custom->user_id ) {
delete_user_meta( $custom->user_id, '_wpuf_user_active' );
delete_user_meta( $custom->user_id, '_wpuf_activation_key' );
}
}
}

Expand All @@ -493,7 +509,7 @@ public function handle_cancel_subscription( $data ) {
* @return bool
*/
public function validateIpn() {
WP_User_Frontend::log( 'paypal', 'Checking if PayPal IPN response is valid' );
\WP_User_Frontend::log( 'paypal', 'Checking if PayPal IPN response is valid' );

$this->set_mode();

Expand All @@ -518,20 +534,20 @@ public function validateIpn() {
}
$response = wp_safe_remote_post( $this->gateway_url, $params );

WP_User_Frontend::log( 'paypal', 'IPN Request: ' . print_r( $params, true ) );
WP_User_Frontend::log( 'paypal', 'IPN Response: ' . print_r( $response, true ) );
\WP_User_Frontend::log( 'paypal', 'IPN Request: ' . print_r( $params, true ) );
\WP_User_Frontend::log( 'paypal', 'IPN Response: ' . print_r( $response, true ) );

// check to see if the request was valid
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
WP_User_Frontend::log( 'paypal', 'Received valid response from PayPal' );
\WP_User_Frontend::log( 'paypal', 'Received valid response from PayPal' );

return true;
}

WP_User_Frontend::log( 'paypal', 'Received invalid response from PayPal' );
\WP_User_Frontend::log( 'paypal', 'Received invalid response from PayPal' );

if ( is_wp_error( $response ) ) {
WP_User_Frontend::log( 'paypal', 'Error response: ' . $response->get_error_message() );
\WP_User_Frontend::log( 'paypal', 'Error response: ' . $response->get_error_message() );
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<?php

if ( class_exists( 'WPUF_Subscription' ) ) {
$subscriptions = (new Subscription())->get_subscriptions();
$subscriptions = wpuf()->subscription->get_subscriptions();

if ( $subscriptions ) {
foreach ( $subscriptions as $pack ) {
Expand Down
6 changes: 6 additions & 0 deletions assets/css/frontend-forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -1833,3 +1833,9 @@ body .wpuf-attachment-upload-filelist + .moxie-shim {
.iti--allow-dropdown input[type="text"] {
padding-left: 52px !important;
}
img.wpuf-eye {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%) translateX(-6%);
}
3 changes: 3 additions & 0 deletions assets/images/eye-close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/js-templates/form-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class="option-chooser-radio"
<?php

if ( class_exists( 'WPUF_Subscription' ) ) {
$subscriptions = (new Subscription())->get_subscriptions();
$subscriptions = wpuf()->subscription->get_subscriptions();

if ( $subscriptions ) {
foreach ( $subscriptions as $pack ) {
Expand Down
15 changes: 15 additions & 0 deletions assets/js/frontend-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,4 +1492,19 @@
// Set name attribute for google map search field
$(".wpuf-form-add #wpuf-map-add-location").attr("name", "find_address");
});

$(function($) {
// eye icon for password field
$(document).on('click', '.wpuf-eye', function () {
const input = $( this ).siblings( 'input' );

if ( input.attr("type") === "password" ) {
input.attr( "type", "text" );
$( this ).attr( "src", wpuf_frontend.asset_url + '/images/eye-close.svg' );
} else {
input.attr( "type", "password" );
$( this ).attr( "src", wpuf_frontend.asset_url + '/images/eye.svg' );
}
});
});
})(jQuery, window);
7 changes: 7 additions & 0 deletions assets/less/frontend-forms.less
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,10 @@ ul.wpuf-form{
.iti--allow-dropdown input[type="text"] {
padding-left: 52px !important;
}

img.wpuf-eye {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%) translateX(-6%);
}
2 changes: 1 addition & 1 deletion class/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
add_filter( 'wpuf_add_post_redirect', [ $this, 'post_redirect' ], 10, 4 );

add_filter( 'wpuf_addpost_notice', [ $this, 'force_pack_notice' ], 20, 3 );
add_filter( 'wpuf_can_post', [ $this, 'force_pack_permission' ], 20, 3 );
// add_filter( 'wpuf_can_post', [ $this, 'force_pack_permission' ], 20, 3 );
add_action( 'wpuf_add_post_form_top', [ $this, 'add_post_info' ], 10, 2 );

add_action( 'wpuf_add_post_after_insert', [ $this, 'monitor_new_post' ], 10, 3 );
Expand Down
1 change: 0 additions & 1 deletion includes/Admin/Forms/Field_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use WeDevs\Wpuf\Fields\Form_Field_Image;
use WeDevs\Wpuf\Fields\Form_Field_MultiDropdown;
use WeDevs\Wpuf\Fields\Form_Field_Post_Content;
use WeDevs\Wpuf\Fields\Form_Field_Post_Excerpt;
use WeDevs\Wpuf\Fields\Form_Field_Post_Tags;
use WeDevs\Wpuf\Fields\Form_Field_Post_Taxonomy;
use WeDevs\Wpuf\Fields\Form_Field_Post_Title;
Expand Down
17 changes: 14 additions & 3 deletions includes/Admin/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,26 @@ public function is_submission_open( $form, $form_settings ) {
if ( isset( $this->form_settings['message_restrict'] ) && ! $guest_post_enabled && ! is_user_logged_in() ) {
$user_can_post = 'no';
$info = $this->form_settings['message_restrict'];

return [ $user_can_post, $info ];
}

$has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );

if ( ! $has_post_count ) {
$user_can_post = 'no';
$info = __( 'Post Limit Exceeded for your purchased subscription pack.', 'wp-user-frontend' );

return [ $user_can_post, $info ];
}


if ( $this->is_charging_enabled() ) {
$pay_per_post = $this->is_enabled_pay_per_post();
$pay_per_post_cost = (float) $this->get_pay_per_post_cost();
// $pay_per_post_cost = (float) $this->get_pay_per_post_cost();
$force_pack = $this->is_enabled_force_pack();
$fallback_enabled = $this->is_enabled_fallback_cost();
$fallback_cost = $this->get_subs_fallback_cost();
$has_post_count = $current_user->subscription()->has_post_count( $form_settings['post_type'] );
// $fallback_cost = $this->get_subs_fallback_cost();

// guest post payment checking
if ( ! is_user_logged_in() && isset( $form_settings['guest_post'] ) && $form_settings['guest_post'] === 'true' ) {
Expand Down
10 changes: 8 additions & 2 deletions includes/Admin/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct() {
add_action( 'wpuf_add_post_form_top', [ $this, 'add_post_info' ], 10, 2 );

add_action( 'wpuf_add_post_after_insert', [ $this, 'monitor_new_post' ], 10, 3 );
add_action( 'wpuf_add_post_after_insert', [ $this, 'reset_user_subscription_data' ], 10, 4 );
add_action( 'wpuf_draft_post_after_insert', [ $this, 'monitor_new_draft_post' ], 10, 3 );
add_action( 'wpuf_payment_received', [ $this, 'payment_received' ], 10, 2 );

Expand Down Expand Up @@ -64,7 +65,7 @@ public static function subscriber_cancel( $user_id, $pack_id ) {
);
$result = $wpdb->get_row( $sql );

$transaction_id = $result ? $result->transaction_id : 0;
$transaction_id = $result ? $result->transaction_id : 'Free';

$wpdb->update(
$wpdb->prefix . 'wpuf_subscribers', [ 'subscribtion_status' => 'cancel' ], [
Expand Down Expand Up @@ -532,7 +533,8 @@ public function set_pending( $postdata, $form_id, $form_settings, $form_vars ) {
* @param int $post_id
*/
public function monitor_new_post( $post_id, $form_id, $form_settings ) {
global $wpdb, $userdata;
global $userdata;

$post = get_post( $post_id );

// bail out if charging is not enabled
Expand Down Expand Up @@ -1109,6 +1111,10 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
$current_pack = $current_user->subscription()->current_pack();
$has_post_count = isset( $form_settings['post_type'] ) ? $current_user->subscription()->has_post_count( $form_settings['post_type'] ) : false;

if ( !$has_post_count ) {
return 'no';
}

if ( is_user_logged_in() ) {
if ( wpuf_get_user()->post_locked() ) {
return 'no';
Expand Down
16 changes: 0 additions & 16 deletions includes/Ajax/Frontend_Form_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,6 @@ public function submit_post() {
}
}

// check each form field for restricted shortcodes
foreach ( $this->form_fields as $single_field ) {
if ( empty( $single_field['rich'] ) || 'yes' !== $single_field['rich'] ) {
continue;
}

$current_data = ! empty( $_POST[ $single_field['name'] ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $single_field['name'] ] ) ) : '';

foreach ( $protected_shortcodes as $shortcode ) {
$search_for = '[' . $shortcode;
if ( strpos( $current_data, $search_for ) !== false ) {
wpuf()->ajax->send_error( sprintf( __( 'Using %s as shortcode is restricted', 'wp-user-frontend' ), $shortcode ) );
}
}
}

foreach ( $attachments_to_delete as $attach_id ) {
wp_delete_attachment( $attach_id, true );
}
Expand Down
Loading

0 comments on commit 45a41ff

Please sign in to comment.