PK a\"̆ ̆ enhanced-paypal-shortcodes.phpnu W+A Make a Donation. Designed with using iDevAffiliate or JROX Jam affiliate management programs which require additional code added to the button. This plugin was inspired by Paypal Shortcodes by Pixline. By Charly Leetham, version: 0.5a http://askcharlyleetham.com Copyright (C) Ask Charly Leetham (A Leetham Trust Project) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ define('TWPW_NAME', 'Enhanced Paypal Shortcodes'); // Name of the Plugin define('TWPW_VERSION', '0.5a'); // Current version of the Plugin define("ALT_ADD","Add to cart (Paypal)"); // alternate text for "Add to cart" image define("ALT_VIEW","View Paypal cart"); // alternate text for "View cart" image define("ALT_SUBS", "Subscribe Now (Paypal)"); // alternate text for "Subscribe" image /* Parameters for Shortcode for all Paypal buttons type = paynow, subscribe, addtocart or hosted For Hosted Buttons: buttonid = the button id number from your paypal code For All Button Types: imageurl = The location of the image for the button. Use full web address for the image - e.g http://domainname.com/mybuynowbutton.jpg. Default is https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif imagewidth = the width of the paypal image For PayNow, Subscribe and Add To Cart Buttons: email = the email address of the paypal account itemno = A unique identifier for your product / service name = Description of product / service noshipping = Prompt for Shipping address 0 is prompt, but don't require 1 is don't prompt 2 is prompt and require the shipping address defaults to 0 nonote = Prompt payers to include a note (Paynow buttons only) 0 is show the note box and prompt the user 1 is hide the note box and do not prompt the user defaults to 0 currencycode = The currency for the transaction Australian Dollar AUD Canadian Dollar CAD Czech Koruna CZK Danish Krone DKK Euro EUR Hong Kong Dollar HKD Hungarian Forint HUF Israeli New Sheqel ILS Japanese Yen JPY Mexican Peso MXN Norwegian Krone NOK New Zealand Dollar NZD Polish Zloty PLN Pound Sterling GBP Singapore Dollar SGD Swedish Krona SEK Swiss Franc CHF U.S. Dollar USD Default is USD rm = The return method. This will only work if returnurl is also set. This variable is often required by membership type software 0 – all shopping cart transactions use the GET method 1 – the payer’s browser is redirected to the return URL by the GET method, and no transaction variables are sent 2 – the payer’s browser is redirected to the return URL by the POST method, and all transaction variables are also posted The default is 0. notifyurl = The URL to send payment advice too. Often required for IPN or other notifications If this parameter is not used, no notifyurl value is added to the button returnurl = The URL to which the payer’s browser is redirected after completing the payment; for example, a URL on your site that displays a “Thank you for your payment” page. Default – The browser is redirected to a PayPal web page. cancelurl = The URL to which the payer’s browser is redirected if the purchaser cancels the payment transaction before completing the process scriptcode = the link to any script code that you may need to include. e.g For Jrox JAM, some script code is added to the paypal buttons. Usage /foldername/scriptcode.php If this parameter is not used, no notifyurl value is added to the button pagestyle = The custom payment page style for checkout pages. Allowable values: paypal – use the PayPal page style primary – use the page style that you marked as primary in your account profile page_style_name – use the custom payment page style from your account profile that has the specified name The default is primary if you added a custom payment page style to your account profile. Otherwise, the default is paypal. cbt = Sets the text for the Return to Merchant button on the PayPal Payment Complete page. For Business accounts, the return button displays your business name in place of the word “Merchant” by default. For Donate buttons, the text reads “Return to donations coordinator” by default. NOTE: The returnurl variable must also be set. cn = Label that appears above the note field on the Check Out page. This value is not saved and will not appear in any of your notifications. If omitted, the default label above the note field is "Add special instructions to merchant." The cn variable is not valid with Subscribe buttons or if you include nonote="1". lc = Sets the payer’s language for the billing information/log-in page only. The default is US. For allowable values visit: https://cms.paypal.com/au/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_countrycodes Paynow & Add To Cart Button only parameters amount = the amount to charge (for Paynow & Add To Cart buttons only) shipping = the amount of shipping to charge per item shipping2 = the amount of shipping to charge for each extra item purchased. Subscribe Button only parameters Trial Period 1: a1 = The value to charge for the first trial period p1 = The duration of the first trial. t1 = The units of duration. D for Days, allowable entries for p1: 1 to 90 W for Weeks, allowable entries for p1: 1 to 52 M for Months, allowable entries for p1: 1 to 24 Y for Years, allowable entries for p1: 1 to 5 Trial Period 2: a2 = The value to charge for the second trial period p2 = The duration of the second trial. t2 = The units of duration. D for Days, allowable entries for p2: 1 to 90 W for Weeks, allowable entries for p2: 1 to 52 M for Months, allowable entries for p2: 1 to 24 Y for Years, allowable entries for p2: 1 to 5 The full subscription Payment: a3 = The value to charge p3 = The duration between charging t3 = The units of duration. D for Days, allowable entries for p3: 1 to 90 W for Weeks, allowable entries for p3: 1 to 52 M for Months, allowable entries for p3: 1 to 24 Y for Years, allowable entries for p3: 1 to 5 src = Recurring payments. Subscription payments recur unless subscribers cancel their subscriptions before the end of the current billing cycle or you limit the number of times that payments recur with the value that you specify for srt. Allowable values: 0 – subscription payments do not recur 1 – subscription payments recur The default is 0. srt = Recurring times. Number of times that subscription payments recur. Specify an integer above 1. Valid only if you specify src="1". Allowable values:an integer above 1. sra = Reattempt on failure. If a recurring payment fails, PayPal attempts to collect the payment two more times before canceling the subscription. Allowable values: 0 – do not reattempt failed recurring payments 1 – reattempt failed recurring payments before canceling The default is 0 modify - Modification behavior. Allowable values: 0 – allows subscribers to only create new subscriptions 1 – allows subscribers to modify their current subscriptions or sign up for new ones 2 – allows subscribers to only modify their current subscriptions The default value is 0 Add To Cart display = Display the contents of the PayPal Shopping Cart to the buyer. If set, the shopping cart will be displayed after an item is added. If not set, the item will be added to the cart only. Formatting The plugin will wrap the paypal button in a
' . print_r( $_GET, true ) . '' ); ld_ipn_debug( 'IPN Listener Loading...' ); require __DIR__ . '/ipnlistener.php'; $listener = new IpnListener(); /** * Action for initial IpnListener to allow override of public attributes. * * @since 2.2.1.2 * * @param Object $listener Instance of IpnListener Class. */ do_action_ref_array( 'leandash_ipnlistener_init', array( &$listener ) ); ld_ipn_debug( 'IPN Listener Loaded' ); /* While testing your IPN script you should be using a PayPal "Sandbox" (get an account at: https://developer.paypal.com ) When you are ready to go live change use_sandbox to false.*/ $paypal_settings = LearnDash_Settings_Section::get_section_settings_all( 'LearnDash_Settings_Section_PayPal' ); $paypal_settings['paypal_sandbox'] = ( 'yes' === $paypal_settings['paypal_sandbox'] ) ? 1 : 0; ld_ipn_debug( 'DEBUG: paypal_settings
' . print_r( $paypal_settings, true ) . '' ); ld_ipn_debug( 'Course Settings Loaded.' ); $listener->use_sandbox = false; if ( ! empty( $paypal_settings['paypal_sandbox'] ) ) { $listener->use_sandbox = true; ld_ipn_debug( 'Sandbox Enabled.' ); } try { ld_ipn_debug( 'Checking Post Method.' ); $listener->requirePostMethod(); $verified = $listener->processIpn(); ld_ipn_debug( 'Post method check completed.' ); } catch ( Exception $e ) { ld_ipn_debug( 'Post method error:
' . print_r( $e->getMessage(), true ) . '' ); ld_ipn_debug( 'Found Exception. Ending Script.' ); exit( 0 ); } $transaction = $_POST; $transaction = array_map( 'trim', $transaction ); $transaction = array_map( 'esc_attr', $transaction ); $transaction['log_file'] = basename( $ipn_log_filename ); if ( ( isset( $transaction['item_number'] ) ) && ( ! empty( $transaction['item_number'] ) ) ) { $transaction['course_id'] = absint( $transaction['item_number'] ); $transaction['course'] = get_post( $transaction['course_id'] ); if ( ( ! $transaction['course'] ) || ( ! is_a( $transaction['course'], 'WP_Post' ) ) || ( learndash_get_post_type_slug( 'course' ) !== $transaction['course']->post_type ) ) { $transaction['course_id'] = 0; $transaction['course'] = ''; } } if ( ! empty( $transaction['course_id'] ) ) { $course_settings = learndash_get_setting( $transaction['course_id'] ); if ( isset( $transaction['mc_gross'] ) ) { if ( ( isset( $course_settings['course_price_type'] ) ) && ( 'paynow' === $course_settings['course_price_type'] ) ) { if ( ( isset( $course_settings['course_price'] ) ) && ( ! empty( $course_settings['course_price'] ) ) ) { $server_course_price = preg_replace( '/[^0-9.]/', '', $course_settings['course_price'] ); $server_course_price = number_format( floatval( $server_course_price ), 2, '.', '' ); $ipn_course_price = preg_replace( '/[^0-9.]/', '', $transaction['mc_gross'] ); $ipn_course_price = floatval( $ipn_course_price ); ld_ipn_debug( 'DEBUG: IPN GrossTax [' . $ipn_course_price . ']' ); if ( isset( $transaction['tax'] ) ) { $ipn_tax_price = preg_replace( '/[^0-9.]/', '', $transaction['tax'] ); } else { $ipn_tax_price = 0; } $ipn_tax_price = floatval( $ipn_tax_price ); ld_ipn_debug( 'DEBUG: IPN Tax [' . $ipn_tax_price . ']' ); $ipn_course_price = $ipn_course_price - $ipn_tax_price; $ipn_course_price = number_format( floatval( $ipn_course_price ), 2, '.', '' ); ld_ipn_debug( 'DEBUG: IPN Gross - Tax (result) [' . $ipn_course_price . ']' ); if ( $server_course_price == $ipn_course_price ) { ld_ipn_debug( 'IPN Price match: IPN Price [' . $ipn_course_price . '] Course Price [' . $server_course_price . ']' ); } else { ld_ipn_debug( 'Error: IPN Price mismatch: IPN Price [' . $ipn_course_price . '] Course Price [' . $server_course_price . ']' ); $verified = false; } } } } else { ld_ipn_debug( "Error: Missing 'mc_gross' in IPN data" ); $verified = false; } } else { ld_ipn_debug( "Error: Missing 'item_number' in IPN data" ); $verified = false; } $admin_email = get_option( 'admin_email' ); if ( ! empty( $admin_email ) ) { $admin_email = sanitize_email( $admin_email ); } if ( ! is_email( $admin_email ) ) { ld_ipn_debug( "Error: Invalid 'admin_email' get_option: " . $admin_email ); exit(); } $seller_email = $paypal_settings['paypal_email']; if ( ! empty( $seller_email ) ) { $seller_email = sanitize_email( $seller_email ); } if ( ! is_email( $seller_email ) ) { ld_ipn_debug( "Error: Invalid 'seller_email' in PayPal settings: " . $seller_email ); exit(); } ld_ipn_debug( 'Loaded Email IDs. Notification Email: ' . $admin_email . ' Seller Email: ' . $seller_email ); $notify_on_valid_ipn = 1; ld_ipn_debug( 'Payment Verified? : ' . ( ( $verified ) ? 'YES' : 'NO' ) ); /*The processIpn() method returned true if the IPN was "VERIFIED" and false if it was "INVALID".*/ if ( $verified ) { ld_ipn_debug( 'Sure, Verfied! Moving Ahead.' ); /* Once you have a verified IPN you need to do a few more checks on the POST fields--typically against data you stored in your database during when the end user made a purchase (such as in the "success" page on a web payments standard button). The fields PayPal recommends checking are: 1. Check the $_POST['payment_status'] is "Completed" 2. Check that $_POST['txn_id'] has not been previously processed 3. Check that $_POST['receiver_email'] is get_option('EVI_Paypal_Seller_email') 4. Check that $_POST['payment_amount'] and $_POST['payment_currency'] are correct */ // note: This is just notification for us. Paypal has already made up its mind and the payment has been processed // (you can't cancel that here) ld_ipn_debug( 'Receiver Email: ' . $transaction['receiver_email'] . ' Valid Receiver Email? :' . ( ( $transaction['receiver_email'] == $seller_email ) ? 'YES' : 'NO' ) ); if ( $transaction['receiver_email'] != $seller_email ) { if ( $admin_email != '' ) { // mail( $admin_email, 'Warning: IPN with invalid receiver email!', $listener->getTextReport() ); ld_ipn_debug( 'Warning! IPN with invalid receiver email!' ); } else { // error_log( 'notification email not set' ); } // We abort here to prevent fake IPN simulator posts creating users, etc. exit(); } ld_ipn_debug( 'Payment Status: ' . $transaction['payment_status'] . ' Completed? :' . ( ( 'Completed' === $transaction['payment_status'] ) ? 'YES' : 'NO' ) ); if ( 'Completed' === $transaction['payment_status'] ) { ld_ipn_debug( 'Sure, Completed! Moving Ahead.' ); // a customer has purchased from this website // add him to database for customer support // get / add user $email = sanitize_email( $transaction['payer_email'] ); if ( ! is_email( $email ) ) { ld_ipn_debug( "Error: Invalid 'payer_email' in IPN data: ". $email ); exit(); } ld_ipn_debug( 'Payment Email: ' . $email ); if ( ! empty( $transaction['custom'] ) ) { $user = get_user_by( 'id', absint( $transaction['custom'] ) ); if ( ( ! $user ) || ( ! is_a( $user, 'WP_User' ) ) ) { ld_ipn_debug( "Error: Unknown user 'custom' in IPN data: ". absint( $transaction['custom'] ) ); exit(); } ld_ipn_debug( 'User ID [' . $transaction['custom'] . '] passed back by Paypal. Checking if user exists. User Found: ' . ( ! empty( $user->ID ) ? 'Yes' : 'No' ) ); } if ( ! empty( $user->ID ) ) { $user_id = $user->ID; ld_ipn_debug( 'User found. Passed back by Paypal. User ID: ' . $user_id ); } elseif ( is_user_logged_in() ) { ld_ipn_debug( 'User is logged in.' ); $user = wp_get_current_user(); $user_id = $user->ID; ld_ipn_debug( 'User is logged in. User Id: ' . $user_id ); } else { ld_ipn_debug( 'User not logged in.' ); if ( $user_id = email_exists( $email ) ) { ld_ipn_debug( 'User email exists. User Found. User Id: ' . $user_id ); $user = get_user_by( 'id', $user_id ); } else { ld_ipn_debug( 'User email does not exists. Checking available username...' ); $username = $email; if ( username_exists( $email ) ) { ld_ipn_debug( 'Username matching email found, cannot use. Looking further with $count_$email.' ); $count = 1; do { $new_username = $count . '_' . $email; $count++; } while ( username_exists( $new_username ) ); $username = $new_username; ld_ipn_debug( 'Accepting user with $username as :' . $new_username ); } $random_password = wp_generate_password( 12, false ); ld_ipn_debug( 'Creating User with username:' . $username . ' email: ' . $email ); $user_id = wp_create_user( $username, $random_password, $email ); ld_ipn_debug( 'User created with user_id: ' . $user_id ); $user = get_user_by( 'id', $user_id ); // Handle all three versions of WP wp_new_user_notification global $wp_version; if ( version_compare( $wp_version, '4.3.0', '<' ) ) { wp_new_user_notification( $user_id, $user_pass ); } elseif ( version_compare( $wp_version, '4.3.0', '==' ) ) { wp_new_user_notification( $user_id, 'both' ); } elseif ( version_compare( $wp_version, '4.3.1', '>=' ) ) { wp_new_user_notification( $user_id, null, 'both' ); } ld_ipn_debug( 'Notification Sent.' ); } } // record in course ld_ipn_debug( 'Starting to give course access...' ); $meta = ld_update_course_access( absint( $user_id ), $transaction['course_id'] ); /* // Removed 2020-03-31: Not really sure why this is here. There is no user meta '_sfwd-courses' $usermeta = get_user_meta( $user_id, '_sfwd-courses', true ); ld_ipn_debug( 'Fetched User Meta:' . $usermeta ); if ( empty( $usermeta) ) { $usermeta = $course_id; } else { $usermeta .= ",$course_id"; } update_user_meta( $user_id, '_sfwd-courses', $usermeta ); ld_ipn_debug( 'Updated user meta:' . $usermeta ); */ // log transaction ld_ipn_debug( 'Starting Transaction Creation.' ); $course_title = ''; if ( ! empty( $transaction['course'] ) ) { $course_title = $transaction['course']->post_title; } ld_ipn_debug( 'Course Title: ' . $course_title ); $post_id = wp_insert_post( array( 'post_title' => "Course {$course_title} Purchased By {$email}", 'post_type' => 'sfwd-transactions', 'post_status' => 'publish', 'post_author' => $user_id, ) ); ld_ipn_debug( 'Created Transaction. Post Id: ' . $post_id ); foreach ( $transaction as $k => $v ) { update_post_meta( $post_id, $k, $v ); } } ld_ipn_debug( 'IPN Processing Completed Successfully.' ); $notifyOnValid = $notify_on_valid_ipn != '' ? $notify_on_valid_ipn : '0'; } else { /* An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's a good idea to have a developer or sys admin manually investigate any invalid IPN.*/ ld_ipn_debug( 'Invalid IPN. Shutting Down Processing.' ); } // we're done here PK a\"̆ ̆ enhanced-paypal-shortcodes.phpnu W+A PK a\ս ipnlistener.phpnu W+A PK a\8/ / ' ipn.phpnu W+A PK