PKa\"̆̆enhanced-paypal-shortcodes.phpnuW+AMake 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
tag. The formatting options available are: divwidth = the width of the div. This should be at least the width of the image. Default - 100% textalign = the alignment of the image / text within the div Allowable values: left - text is left justified right - text is right justified center - text is centered No default, taken from page format float = position of the div on the page left - the div 'floats' on the left right - the div 'floats' on the right Default - if this value is missing, the div is centered on the page marginleft = the amount of space between the div and the text to the left of the div (particularly good to use when using float=right) Default - if this value is missing, the page format is used marginright = the amount of space between the div and the text to the right of the div (particularly good to use when using float=left) Default - if this value is missing, the page format is used margintop = the amount of space to the line above the div Default = 10px; marginbottom = the amount of space to the line below the div Default = 10px; Button Formatting: Image Classes: The shortcode will add a 'placeholder' Paypal image that is 1px wide by 1px tall into the button. The code adds a class of "ppalholder" to this image. This will allow site owners to add the class to their theme styles and remove any borders that cause the image to be 'visible'. Class added to Buy Now, Add To Cart, Hosted or Subscribe button The code will add the class "ppalbtn" to the actual image embedded on the page to allow for more formatting choices. Sample Usage: Buy Now Button: [paypal type="paynow" amount="12.99" email="payments@arvoreentreasures.com" itemno="12345657" name="Description" noshipping="1" nonote="1" qty="1" shipping="4.00" shipping2="1.00" currencycode="USD" imageurl="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" rm="2" notifyurl="http://notifyurl.com" returnurl="http://returnurl.com" scriptcode="scriptcode" imagewidth="100px" pagestyle="paypal" lc="AU" cbt="Complete Your Purchase"] Subscribe Button with 2 trial periods and recurring Monthly payments. [paypal type="subscribe" email="payments@arvoreentreasures.com" itemno="12345657" name="Description" noshipping="1" currencycode="USD" imageurl="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" a1="1" p1="7" t1="D" a2="3" p2="1" t3="M" a3="47" p3="1" t3="M" rm="2" notifyurl="http://notifyurl.com" returnurl="http://returnurl.com" scriptcode="scriptcode" imagewidth="100px" pagestyle="paypal" lc="AU" cbt="Complete Your Purchase"] Hosted Button [paypal type="hosted" buttonid="1234456" imageurl="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"] Add To Cart Button [paypal type="addtocart" amount="1.99" email="payments@arvoreentreasures.com" itemno="12345657" name="Description" noshipping="1" nonote="1" currencycode="USD" imageurl="https://www.paypalobjects.com/en_AU/i/btn/btn_cart_LG.gif" rm="2" notifyurl="http://notifyurl.com" returnurl="http://returnurl.com" scriptcode="scriptcode" cbt="Return to Me" cancelreturn="http://shoppingcartcancelurl.com" lc="AU" qty="4" shipping="3.00" shipping2="1.50" pagestyle="paypal"] Adding formatting to Hosted Button To use your own custom image hosted on your site, that is 200px wide, center the button in the line and leave 20px space above and 10px space below: [paypal type="hosted" buttonid="1234456" imageurl="http://yourdomainname.com/images/buynow.jpg" imagewidth="200px" divwidth="200px" margintop="20px" marginbottom="10px"] All formatting options work on three button types. */ if ( !function_exists('enhanced_paypal_shortcode') ) { function enhanced_paypal_shortcode($atts) { $atts = shortcode_atts( Array( 'type' => '', 'textalign' => '', 'divwidth' => '', 'float' => '', 'marginleft' => '', 'marginright' => '', 'margintop' => '', 'marginbottom' => '', 'sandbox' => '', 'qty' => '1', 'shipping' => '', 'shipping2' => '', 'imageurl' => '', 'imagewidth' => '100px', 'noshipping' => '1', 'nonote' => '1', 'rm' => '2', 'lc' => '', 'cbt' => esc_html__('Complete Your Purchase', 'learndash'), 'cn' => '', 'pagestyle' => 'paypal', 'notifyurl' => '', 'notifyurl2' => '', 'returnurl' => '', 'cancelurl' => '', // 'scriptcode' => 'scriptcode', 'scriptcode' => '', // Removed value as this was causing 404 errors 'email' => '', 'currencycode' => '', 'itemno' => '', 'name' => '', 'amount' => '', 'cancelreturn' => '', 'a1' => '', 'p1' => '', 't1' => '', 'a2' => '', 'p2' => '', 't2' => '', 'a3' => '', 'p3' => '', 't3' => '', 'src' => 1, 'srt' => 0, 'sra' => 1, 'modify' => '', 'custom' => '', ), $atts ); $user_id = get_current_user_id(); /* $learndash_plus_paypal_settings = get_option( 'learndash_plus_paypal_settings' ); $paypal_email = isset($learndash_plus_paypal_settings['paypal_email'])? $learndash_plus_paypal_settings['paypal_email']:""; $paypal_currency = isset($learndash_plus_paypal_settings['paypal_currency'])? $learndash_plus_paypal_settings['paypal_currency']:"USD"; $paypal_country = isset($learndash_plus_paypal_settings['paypal_country'])? $learndash_plus_paypal_settings['paypal_country']:"US"; $paypal_cancel_url = isset($learndash_plus_paypal_settings['paypal_cancel_url'])? $learndash_plus_paypal_settings['paypal_cancel_url']:get_bloginfo('wpurl'); $paypal_return_url = isset($learndash_plus_paypal_settings['paypal_return_url'])? $learndash_plus_paypal_settings['paypal_return_url']:get_bloginfo('wpurl'); $paypal_notify_url = isset($learndash_plus_paypal_settings['paypal_notify_url'])? $learndash_plus_paypal_settings['paypal_notify_url']:get_bloginfo('wpurl')."/?ldp-paypal-ipn=1"; $paypal_sandbox = isset($learndash_plus_paypal_settings['paypal_sandbox'])? $learndash_plus_paypal_settings['paypal_sandbox']:""; if(empty($atts['email'])) $atts['email'] = $paypal_email; if(empty($atts['notifyurl'])) $atts['notifyurl'] = $paypal_notify_url; if(empty($atts['returnurl'])) $atts['returnurl'] = $paypal_return_url; if(empty($atts['cancelurl'])) $atts['cancelurl'] = $paypal_cancel_url; if($atts['sandbox'] == '') $atts['sandbox'] = $paypal_sandbox; if($atts['currencycode'] == '') $atts['currencycode'] = $paypal_currency; if($atts['lc'] == '') $atts['lc'] = $paypal_country; */ $button_text = LearnDash_Custom_Label::get_label( 'button_take_this_course' ); switch($atts['type']): case "paynow": $code = '
3 ) // $atts['currencycode'] = substr( $atts['currencycode'], 0, 3 ); if ( strlen( $atts['lc'] ) > 2 ) $atts['lc'] = substr( $atts['lc'], 0, 2 ); if ( strlen( $atts['itemno'] ) ) $atts['itemno'] = substr( $atts['itemno'], 0, 127 ); // if ( ( isset( $atts['amount'] ) ) && ( !empty( $atts['amount'] ) ) ) { // // format the Course price to be proper XXX.YY no leading dollar signs or other values. // $course_price = preg_replace("/[^0-9.]/", '', $atts['amount'] ); // $atts['amount'] = number_format(floatval($course_price), 2, '.', '' ); // } $code.='">
'; // Add Quantity if ($atts['qty']=="ask") { $code .=''; } else { $code.=''; } // Add Shipping if ($atts['shipping']) { $code.=''; } // Add Shipping2 - additional items shipping if ($atts['shipping2']) { $code.=''; } // Define Image to Use if ($atts['imageurl']) { $code.=''; } $code .= ''; if ($atts['noshipping'] > -1) { $code.=' '; } if ($atts['nonote'] > -1) { $code.=' '; } if ($atts['rm'] > -1) { $code.=' '; } // Add language code if ($atts['lc']) { $code.=''; } /* Checkout Page Variables */ // Add return to merchant text if ($atts['cbt']) { $code.=''; } // Add Cancel Return URL if ($atts['cancelreturn']) { $code.=''; } // Add Special Instructions if ($atts['cn']) { $code.=''; } // Add Page Style if ($atts['pagestyle']) { $code.=''; } if ($atts['notifyurl']) { $code.=''; } if ($atts['notifyurl2']) { $code.=''; } if ($atts['returnurl']) { $code.=''; } if ($atts['cancelurl']) { $code.=''; } if ($atts['custom']) { $code.=''; } if ($atts['scriptcode']) { $code.=''; } $code.='
'; $code.='
'; break; case "subscribe": $code = '
'; if ($atts['imageurl']) { $code.=''; } $code .= ''; if ($atts['email']) { $code.=''; } if ($atts['currencycode']) { $code.=''; } if ($atts['itemno']) { $code.=''; } if ($atts['name']) { $code.=''; } if ($atts['amount']) { $code.=''; } if ($atts['noshipping'] >-1 ) { $code.=''; } $code.=''; /*Trial 1 settings */ if ($atts['a1'] > -1) { $code.=''; } if ($atts['p1'] > 0) { $code.=''; } if ($atts['t1']) { $code.=''; } /*Trial 2 settings */ if ($atts['a2'] > -1) { $code.=''; } if ($atts['p2'] > 0 ) { $code.=''; } if ($atts['t2']) { $code.=''; } /*Ongoing subscription*/ if ($atts['a3'] > 0) { $code.=''; } if ($atts['p3'] > 0) { $code.=''; } if ($atts['t3']) { $code.=''; } /* SRC - are payments recurring? 0 = No, 1 = Yes */ if ($atts['src']==0) { $code.=''; } else { $code.=''; } /* SRT - no of time payments recur? */ if ($atts['srt']>1) { $code.=''; } /* SRA - re-attempt if fail? 0 = No, 1 = Yes */ if ($atts['sra']==0) { $code.=''; } else { $code.=''; } if ($atts['rm'] > -1) { $code.=''; } // Add language code if ($atts['lc']) { $code.=''; } // Add return to merchant text if ($atts['cbt']) { $code.=''; } // Modify Subscriptions if ($atts['modify']) { $code.=''; } // Add Cancel Return URL if ($atts['cancelreturn']) { $code.=''; } // Add Special Instructions if ($atts['cn']) { $code.=''; } // Add Page Style if ($atts['pagestyle']) { $code.=''; } if ($atts['notifyurl']) { $code.=''; } if ($atts['notifyurl2']) { $code.=''; } if ($atts['returnurl']) { $code.=''; } if ($atts['cancelurl']) { $code.=''; } if ($atts['scriptcode']) { $code.=''; } $code.='
'; break; case "hosted": $code = '
'; if ($atts['imageurl']) { $code.=''; } $code .= ''; $code.='
'; break; case "addtocart": $code = '
'; if ($atts['display']==1) { $code.=''; } $code.=' '; if ($atts['amount']) { $code.=''; } $code.=''; if ($atts['noshipping'] > -1) { $code.=''; } if ($atts['nonote'] > -1) { $code.=' '; } if ($atts['rm'] > -1) { $code.=''; } // Add Quantity if ($atts['qty']=="ask") { $code .=''; } else { $code.=''; } // Add Shipping if ($atts['shipping']) { $code.=''; } // Add Shipping2 - additional items shipping if ($atts['shipping2']) { $code.=''; } // Add return to merchant text if ($atts['cbt']) { $code.=''; } // Add Cancel Return URL if ($atts['cancelreturn']) { $code.=''; } // Add Special Instructions if ($atts['cn']) { $code.=''; } // Add Page Style if ($atts['pagestyle']) { $code.=''; } if ($atts['notifyurl']) { $code.=''; } if ($atts['notifyurl2']) { $code.=''; } if ($atts['returnurl']) { $code.=''; } if ($atts['cancelurl']) { $code.=''; } if ($atts['scriptcode']) { $code.=''; } // Define Image to Use if ($atts['imageurl']) { $code.=''; } $code .= ''; $code.='
'; endswitch; return apply_filters('learndash_paypal_payment_button', $code, array('code' => $code, 'atts' => $atts)) ; } } add_shortcode('paypal', 'enhanced_paypal_shortcode'); PKa\ս ipnlistener.phpnuW+Ause_ssl) { $uri = 'https://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } else { $uri = 'http://'.$this->getPaypalHost().'/cgi-bin/webscr'; $this->post_uri = $uri; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $uri); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $this->follow_location); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: sfwd-lms')); if ($this->force_ssl_v3) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); } else if(defined("LEANRDASH_FORCE_SSL_VERSION")) { curl_setopt($ch, CURLOPT_SSLVERSION, LEANRDASH_FORCE_SSL_VERSION); } $this->response = curl_exec($ch); $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE)); if ($this->response === false || $this->response_status == '0') { $errno = curl_errno($ch); $errstr = curl_error($ch); throw new Exception("cURL error: [$errno] $errstr"); } } /** * Post Back Using fsockopen() * * Sends the post back to PayPal using the fsockopen() function. Called by * the processIpn() method if the use_curl property is false. Throws an * exception if the post fails. Populates the response, response_status, * and post_uri properties on success. * * @param string The post data as a URL encoded string */ protected function fsockPost($encoded_data) { if ($this->use_ssl) { $uri = 'ssl://'.$this->getPaypalHost(); $port = '443'; $this->post_uri = $uri.'/cgi-bin/webscr'; } else { $uri = $this->getPaypalHost(); //no "http://" in call to fsockopen() $port = '80'; $this->post_uri = 'http://'.$uri.'/cgi-bin/webscr'; } $fp = fsockopen($uri, $port, $errno, $errstr, $this->timeout); if (!$fp) { //fsockopen error throw new Exception("fsockopen error: [$errno] $errstr"); } $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: ".strlen($encoded_data)."\r\n"; $header .= "Connection: Close\r\n\r\n"; fputs($fp, $header.$encoded_data."\r\n\r\n"); while(!feof($fp)) { if (empty($this->response)) { //extract HTTP status from first line $this->response .= $status = fgets($fp, 1024); $this->response_status = trim(substr($status, 9, 4)); } else { $this->response .= fgets($fp, 1024); } } fclose($fp); } private function getPaypalHost() { if ($this->use_sandbox) return IpnListener::SANDBOX_HOST; else return IpnListener::PAYPAL_HOST; } /** * Get POST URI * * Returns the URI that was used to send the post back to PayPal. This can * be useful for troubleshooting connection problems. The default URI * would be "ssl://www.sandbox.paypal.com:443/cgi-bin/webscr" * * @return string */ public function getPostUri() { return $this->post_uri; } /** * Get Response * * Returns the entire response from PayPal as a string including all the * HTTP headers. * * @return string */ public function getResponse() { return $this->response; } /** * Get Response Status * * Returns the HTTP response status code from PayPal. This should be "200" * if the post back was successful. * * @return string */ public function getResponseStatus() { return $this->response_status; } /** * Get Text Report * * Returns a report of the IPN transaction in plain text format. This is * useful in emails to order processors and system administrators. Override * this method in your own class to customize the report. * * @return string */ public function getTextReport() { $r = ''; //date and POST url for ($i=0; $i<80; $i++) { $r .= '-'; } $r .= "\n[".date('m/d/Y g:i A').'] - '.$this->getPostUri(); if ($this->use_curl) $r .= " (curl)\n"; else $r .= " (fsockopen)\n"; //HTTP Response for ($i=0; $i<80; $i++) { $r .= '-'; } $r .= "\n{$this->getResponse()}\n"; //POST vars for ($i=0; $i<80; $i++) { $r .= '-'; } $r .= "\n"; foreach ($this->post_data as $key => $value) { $value = maybe_serialize($value); $r .= str_pad($key, 25)."$value\n"; } $r .= "\n\n"; return $r; } /** * Process IPN * * Handles the IPN post back to PayPal and parsing the response. Call this * method from your IPN listener script. Returns true if the response came * back as "VERIFIED", false if the response came back "INVALID", and * throws an exception if there is an error. * * @param array * * @return boolean */ public function processIpn($post_data=null) { $encoded_data = 'cmd=_notify-validate'; if ($post_data === null) { //use raw POST data if (!empty($_POST)) { $this->post_data = $_POST; $encoded_data .= '&'.file_get_contents('php://input'); } else { throw new Exception("No POST data found."); } } else { //use provided data array $this->post_data = $post_data; foreach ($this->post_data as $key => $value) { $encoded_data .= "&$key=".urlencode($value); } } if ($this->use_curl) $this->curlPost($encoded_data); else $this->fsockPost($encoded_data); if (strpos($this->response_status, '200') === false) { throw new Exception("Invalid response status: ".$this->response_status); } if (strpos($this->response, "VERIFIED") !== false) { return true; } elseif (strpos($this->response, "INVALID") !== false) { return false; } else { throw new Exception("Unexpected response from PayPal."); } } /** * Require Post Method * * Throws an exception and sets a HTTP 405 response header if the request * method was not POST. */ public function requirePostMethod() { //require POST requests if ($_SERVER['REQUEST_METHOD'] && $_SERVER['REQUEST_METHOD'] != 'POST') { header('Allow: POST', true, 405); throw new Exception("Invalid HTTP request method."); } } } PKa\8//ipn.phpnuW+A' . print_r( $_POST, true ) . '' ); ld_ipn_debug( 'DEBUG: _GET
' . 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 PKa\"̆̆enhanced-paypal-shortcodes.phpnuW+APKa\ս ipnlistener.phpnuW+APKa\8//'ipn.phpnuW+APK