function PMProGateway_stripe($gateway = NULL) { $this->gateway = $gateway; $this->gateway_environment = pmpro_getOption("gateway_environment"); Stripe::setApiKey(pmpro_getOption("stripe_secretkey")); return $this->gateway; }
function pmpro_checkLevelForBraintreeCompatibility($level = NULL) { $gateway = pmpro_getOption("gateway"); if ($gateway == "braintree") { global $wpdb; //check ALL the levels if (empty($level)) { $sqlQuery = "SELECT * FROM {$wpdb->pmpro_membership_levels} ORDER BY id ASC"; $levels = $wpdb->get_results($sqlQuery, OBJECT); if (!empty($levels)) { foreach ($levels as $level) { /* Braintree currently does not support: * Trial Amounts > 0. * Daily or Weekly billing periods. */ if ($level->trial_amount > 0 || $level->cycle_number > 0 && ($level->cycle_period == "Day" || $level->cycle_period == "Week")) { return false; } } } } else { //need to look it up? if (is_numeric($level)) { $level = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_membership_levels} WHERE id = '" . $wpdb->escape($level) . "' LIMIT 1"); } //check this level if ($level->trial_amount > 0 || $level->cycle_number > 0 && ($level->cycle_period == "Day" || $level->cycle_period == "Week")) { return false; } } } return true; }
function sendToPayFast(&$order) { global $pmpro_currency; //taxes on initial amount $initial_payment = $order->InitialPayment; $initial_payment_tax = $order->getTaxForPrice($initial_payment); $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2); //taxes on the amount $amount = $order->PaymentAmount; $amount_tax = $order->getTaxForPrice($amount); $order->subtotal = $amount; $amount = round((double) $amount + (double) $amount_tax, 2); //build PayFast Redirect $environment = pmpro_getOption("gateway_environment"); if ("sandbox" === $environment || "beta-sandbox" === $environment) { $merchant_id = self::SANDBOX_MERCHANT_ID; $merchant_key = self::SANDBOX_MERCHANT_KEY; $payfast_url = "https://sandbox.payfast.co.za/eng/process"; } else { $merchant_id = pmpro_getOption("payfast_merchant_id"); $merchant_key = pmpro_getOption("payfast_merchant_key"); $payfast_url = "https://www.payfast.co.za/eng/process"; } $data = array('merchant_id' => $merchant_id, 'merchant_key' => $merchant_key, 'return_url' => pmpro_url("confirmation", "?level=" . $order->membership_level->id), 'cancel_url' => '', 'notify_url' => admin_url("admin-ajax.php") . "?action=payfast_itn_handler", 'name_first' => $order->FirstName, 'name_last' => $order->LastName, 'email_address' => $order->Email, 'm_payment_id' => $order->code, 'amount' => number_format($initial_payment, 2), 'item_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127)); $pfOutput = ""; foreach ($data as $key => $val) { $pfOutput .= $key . '=' . urlencode(trim($val)) . '&'; } // Remove last ampersand $pfOutput = substr($pfOutput, 0, -1); $signature = md5($pfOutput); $payfast_url .= '?' . $pfOutput . '&signature=' . $signature; wp_redirect($payfast_url); exit; }
function pmpro_wp_mail_from($from_email) { $pmpro_from_email = pmpro_getOption("from_email"); if ($pmpro_from_email && is_email($pmpro_from_email)) { return $pmpro_from_email; } return $from_email; }
function pmpro_wp_signup_location($location) { if (is_multisite() && pmpro_getOption("redirecttosubscription")) { return pmpro_url("levels"); } else { return $location; } }
function pmpro_footer_link() { if (!pmpro_getOption("hide_footer_link")) { ?> <!-- <?php echo pmpro_link(); ?> --> <?php } }
function my_template_redirect() { global $current_user; $okay_pages = array('oops', 'login', 'lostpassword', 'resetpass', 'logout', pmpro_getOption('billing_page_id'), pmpro_getOption('account_page_id'), pmpro_getOption('levels_page_id'), pmpro_getOption('checkout_page_id'), pmpro_getOption('confirmation_page_id')); //if the user doesn't have a membership, send them home if (!$current_user->ID && !is_page($okay_pages) && !strpos($_SERVER['REQUEST_URI'], "login")) { wp_redirect(home_url("wp-login.php?redirect_to=" . urlencode($_SERVER['REQUEST_URI']))); } elseif (is_page() && !is_page($okay_pages) && !$current_user->membership_level->ID) { //change this to wp_redirect(pmpro_url("levels")); to redirect to the levels page. wp_redirect(wp_login_url()); } }
function PMProGateway_braintree($gateway = NULL) { $this->gateway = $gateway; $this->gateway_environment = pmpro_getOption("gateway_environment"); //convert to braintree nomenclature $environment = $this->gateway_environment; if ($environment == "live") { $environment = "production"; } Braintree_Configuration::environment($environment); Braintree_Configuration::merchantId(pmpro_getOption("braintree_merchantid")); Braintree_Configuration::publicKey(pmpro_getOption("braintree_publickey")); Braintree_Configuration::privateKey(pmpro_getOption("braintree_privatekey")); return $this->gateway; }
function pmpro_upgrade_1_4_2() { /* Setting the new use_ssl setting. PayPal Website Payments Pro, Authorize.net, and Stripe will default to use ssl. PayPal Express and the test gateway (no gateway) will default to not use ssl. */ $gateway = pmpro_getOption("gateway"); if ($gateway == "paypal" || $gateway == "authorizenet" || $gateway == "stripe") { pmpro_setOption("use_ssl", 1); } else { pmpro_setOption("use_ssl", 0); } pmpro_setOption("db_version", "1.42"); return 1.42; }
function pmproeewe_extra_emails() { global $wpdb; //make sure we only run once a day $today = date("Y-m-d 00:00:00"); /* Here is where you set how many emails you want to send, how early, and which template files to e-mail. If you set the template file to an empty string '' then it will send the default PMPro expiring e-mail. Place your email templates in a subfolder of your active theme. Create a paid-memberships-pro folder in your theme folder, and then create an email folder within that. Your template files should have a suffix of .html, but you don't put it below. So if you create a file in there called myexpirationemail.html, then you'd just put 'myexpirationemail' in the array below. (PMPro will fill in the .html for you.) */ $emails = array(30 => 'mem_expiring_30days', 60 => 'mem_expiring_60days', 90 => 'mem_expiring_90days'); //<--- !!! UPDATE THIS ARRAY TO CHANGE WHEN EMAILS GO OUT AND THEIR TEMPLATE FILES !!! --> ksort($emails, SORT_NUMERIC); //array to store ids of folks we sent emails to so we don't email them twice $sent_emails = array(); foreach (array_keys($emails) as $days) { //look for memberships that are going to expire within one week (but we haven't emailed them within a week) $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM {$wpdb->pmpro_memberships_users} mu LEFT JOIN {$wpdb->usermeta} um ON um.user_id = mu.user_id AND um.meta_key = 'pmpro_expiration_notice_" . $days . "' WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE_SUB(mu.enddate, INTERVAL " . $days . " Day) <= '" . $today . "' AND (um.meta_value IS NULL OR DATE_ADD(um.meta_value, INTERVAL " . $days . " Day) <= '" . $today . "') ORDER BY mu.enddate"; $expiring_soon = $wpdb->get_results($sqlQuery); foreach ($expiring_soon as $e) { if (!in_array($e->user_id, $sent_emails)) { //send an email $pmproemail = new PMProEmail(); $euser = get_userdata($e->user_id); if ($euser) { $euser->membership_level = pmpro_getMembershipLevelForUser($euser->ID); $pmproemail->email = $euser->user_email; $pmproemail->subject = sprintf(__("Your membership at %s will end soon", "pmpro"), get_option("blogname")); if (strlen($emails[$days]) > 0) { $pmproemail->template = $emails[$days]; } else { $pmproemail->template = "membership_expiring"; } $pmproemail->data = array("subject" => $pmproemail->subject, "name" => $euser->display_name, "user_login" => $euser->user_login, "sitename" => get_option("blogname"), "membership_id" => $euser->membership_level->id, "membership_level_name" => $euser->membership_level->name, "siteemail" => pmpro_getOption("from_email"), "login_link" => wp_login_url(), "enddate" => date(get_option('date_format'), $euser->membership_level->enddate), "display_name" => $euser->display_name, "user_email" => $euser->user_email); $pmproemail->sendEmail(); printf(__("Membership expiring email sent to %s. ", "pmpro"), $euser->user_email); $sent_emails[] = $e->user_id; } } //update user meta so we don't email them again update_user_meta($e->user_id, "pmpro_expiration_notice_" . $days, $today); } } }
function pmpro_init_recaptcha() { //don't load in admin if (is_admin()) { return; } //use recaptcha? global $recaptcha; $recaptcha = pmpro_getOption("recaptcha"); if ($recaptcha) { global $recaptcha_publickey, $recaptcha_privatekey; require_once PMPRO_DIR . "/includes/lib/recaptchalib.php"; function pmpro_recaptcha_get_html($pubkey, $error = null, $use_ssl = false) { $locale = get_locale(); if (!empty($locale)) { $parts = explode("_", $locale); $lang = $parts[0]; } else { $lang = "en"; } //filter $lang = apply_filters('pmpro_recaptcha_lang', $lang); ?> <div class="g-recaptcha" data-sitekey="<?php echo $pubkey; ?> "></div> <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?> "> </script> <?php } //for templates using the old recaptcha_get_html if (!function_exists('recaptcha_get_html')) { function recaptcha_get_html($pubkey, $error = null, $use_ssl = false) { return pmpro_recaptcha_get_html($pubkey, $error, $use_ssl); } } $recaptcha_publickey = pmpro_getOption("recaptcha_publickey"); $recaptcha_privatekey = pmpro_getOption("recaptcha_privatekey"); } }
function pmpro_wp_mail_from($from_email) { // default from email wordpress@sitename $sitename = strtolower($_SERVER['SERVER_NAME']); if (substr($sitename, 0, 4) == 'www.') { $sitename = substr($sitename, 4); } $default_from_email = 'wordpress@' . $sitename; //make sure it's the default email address if ($from_email == $default_from_email) { $pmpro_from_email = pmpro_getOption("from_email"); if ($pmpro_from_email && is_email($pmpro_from_email)) { $from_email = $pmpro_from_email; } } return $from_email; }
function pmpro_init_recaptcha() { //don't load in admin if (is_admin()) { return; } //use recaptcha? global $recaptcha; $recaptcha = pmpro_getOption("recaptcha"); if ($recaptcha) { global $recaptcha_publickey, $recaptcha_privatekey; if (!function_exists("recaptcha_get_html")) { require_once PMPRO_DIR . "/includes/lib/recaptchalib.php"; } $recaptcha_publickey = pmpro_getOption("recaptcha_publickey"); $recaptcha_privatekey = pmpro_getOption("recaptcha_privatekey"); } }
/** * Run on WP init * * @since 1.8 */ static function init() { //make sure payza is a gateway option add_filter('pmpro_gateways', array('PMProGateway_payza', 'pmpro_gateways')); //add fields to payment settings add_filter('pmpro_payment_options', array('PMProGateway_payza', 'pmpro_payment_options')); add_filter('pmpro_payment_option_fields', array('PMProGateway_payza', 'pmpro_payment_option_fields'), 10, 2); //add some fields to edit user page (Updates) add_action('pmpro_after_membership_level_profile_fields', array('PMProGateway_payza', 'user_profile_fields')); add_action('profile_update', array('PMProGateway_payza', 'user_profile_fields_save')); //updates cron add_action('pmpro_activation', array('PMProGateway_payza', 'pmpro_activation')); add_action('pmpro_deactivation', array('PMProGateway_payza', 'pmpro_deactivation')); add_action('pmpro_cron_example_subscription_updates', array('PMProGateway_payza', 'pmpro_cron_example_subscription_updates')); //code to add at checkout if payza is the current gateway $gateway = pmpro_getOption("gateway"); if ($gateway == "payza") { add_action('pmpro_checkout_preheader', array('PMProGateway_payza', 'pmpro_checkout_preheader')); add_filter('pmpro_checkout_order', array('PMProGateway_payza', 'pmpro_checkout_order')); add_filter('pmpro_include_billing_address_fields', array('PMProGateway_payza', 'pmpro_include_billing_address_fields')); add_filter('pmpro_include_cardtype_field', array('PMProGateway_payza', 'pmpro_include_billing_address_fields')); add_filter('pmpro_include_payment_information_fields', array('PMProGateway_payza', 'pmpro_include_payment_information_fields')); } }
<thead> <tr> <th colspan="2"><span class="pmpro_thead-msg"><?php printf(__('We accept %s', 'pmpro'), $pmpro_accepted_credit_cards_string); ?> </span><?php _e('Credit Card Information', 'pmpro'); ?> </th> </tr> </thead> <tbody> <tr valign="top"> <td> <?php $sslseal = pmpro_getOption("sslseal"); if ($sslseal) { ?> <div class="pmpro_sslseal"><?php echo stripslashes($sslseal); ?> </div> <?php } ?> <?php if (empty($pmpro_stripe_lite) || $gateway != "stripe") { ?> <div> <label for="CardType"><?php _e('Card Type', 'pmpro');
?> </td> </tr> </tbody> </table> <?php if ($gateway == "braintree") { ?> <input type='hidden' data-encrypted-name='expiration_date' id='credit_card_exp'/> <input type='hidden' name='AccountNumber' id='BraintreeAccountNumber'/> <script type="text/javascript" src="https://js.braintreegateway.com/v1/braintree.js"></script> <script type="text/javascript"> //setup braintree encryption var braintree = Braintree.create('<?php echo pmpro_getOption("braintree_encryptionkey"); ?> '); braintree.onSubmitEncryptForm('pmpro_form'); //pass expiration dates in original format function pmpro_updateBraintreeCardExp() { jQuery('#credit_card_exp').val(jQuery('#ExpirationMonth').val() + "/" + jQuery('#ExpirationYear').val()); } jQuery('#ExpirationMonth, #ExpirationYear').change(function () { pmpro_updateBraintreeCardExp(); }); pmpro_updateBraintreeCardExp(); //pass last 4 of credit card function pmpro_updateBraintreeAccountNumber() {
function pmpro_getGateway() { //grab from param or options if (!empty($_REQUEST['gateway'])) { $gateway = $_REQUEST['gateway']; } elseif (!empty($_REQUEST['review'])) { $gateway = "paypalexpress"; } else { $gateway = pmpro_getOption("gateway"); } //get from options //set valid gateways - the active gateway in the settings and any gateway added through the filter will be allowed if (pmpro_getOption("gateway", true) == "paypal") { $valid_gateways = apply_filters("pmpro_valid_gateways", array("paypal", "paypalexpress")); } else { $valid_gateways = apply_filters("pmpro_valid_gateways", array(pmpro_getOption("gateway", true))); } //make sure it's valid if (!in_array($gateway, $valid_gateways)) { $gateway = false; } //filter for good measure $gateway = apply_filters('pmpro_get_gateway', $gateway, $valid_gateways); return $gateway; }
/** * Save/update the values of the order in the database. */ function saveOrder() { global $current_user, $wpdb; //get a random code to use for the public ID if (empty($this->code)) { $this->code = $this->getRandomCode(); } //figure out how much we charged if (!empty($this->InitialPayment)) { $amount = $this->InitialPayment; } elseif (!empty($this->subtotal)) { $amount = $this->subtotal; } else { $amount = 0; } //Todo: Tax?!, Coupons, Certificates, affiliates if (empty($this->subtotal)) { $this->subtotal = $amount; } if (isset($this->tax)) { $tax = $this->tax; } else { $tax = $this->getTax(true); } $this->certificate_id = ""; $this->certificateamount = ""; //calculate total if (!empty($this->total)) { $total = $this->total; } else { $total = (double) $amount + (double) $tax; } //these fix some warnings/notices if (empty($this->billing)) { $this->billing = new stdClass(); $this->billing->name = $this->billing->street = $this->billing->city = $this->billing->state = $this->billing->zip = $this->billing->country = $this->billing->phone = ""; } if (empty($this->user_id)) { $this->user_id = 0; } if (empty($this->paypal_token)) { $this->paypal_token = ""; } if (empty($this->couponamount)) { $this->couponamount = ""; } if (empty($this->payment_type)) { $this->payment_type = ""; } if (empty($this->payment_transaction_id)) { $this->payment_transaction_id = ""; } if (empty($this->subscription_transaction_id)) { $this->subscription_transaction_id = ""; } if (empty($this->affiliate_id)) { $this->affiliate_id = ""; } if (empty($this->affiliate_subid)) { $this->affiliate_subid = ""; } if (empty($this->session_id)) { $this->session_id = ""; } if (empty($this->accountnumber)) { $this->accountnumber = ""; } if (empty($this->cardtype)) { $this->cardtype = ""; } if (empty($this->ExpirationDate)) { $this->ExpirationDate = ""; } if (empty($this->status)) { $this->status = ""; } if (empty($this->gateway)) { $this->gateway = pmpro_getOption("gateway"); } if (empty($this->gateway_environment)) { $this->gateway_environment = pmpro_getOption("gateway_environment"); } if (empty($this->notes)) { $this->notes = ""; } //build query if (!empty($this->id)) { //set up actions $before_action = "pmpro_update_order"; $after_action = "pmpro_updated_order"; //update $this->sqlQuery = "UPDATE {$wpdb->pmpro_membership_orders}\n\t\t\t\t\t\t\t\t\tSET `code` = '" . $this->code . "',\n\t\t\t\t\t\t\t\t\t`session_id` = '" . $this->session_id . "',\n\t\t\t\t\t\t\t\t\t`user_id` = " . intval($this->user_id) . ",\n\t\t\t\t\t\t\t\t\t`membership_id` = " . intval($this->membership_id) . ",\n\t\t\t\t\t\t\t\t\t`paypal_token` = '" . $this->paypal_token . "',\n\t\t\t\t\t\t\t\t\t`billing_name` = '" . esc_sql($this->billing->name) . "',\n\t\t\t\t\t\t\t\t\t`billing_street` = '" . esc_sql($this->billing->street) . "',\n\t\t\t\t\t\t\t\t\t`billing_city` = '" . esc_sql($this->billing->city) . "',\n\t\t\t\t\t\t\t\t\t`billing_state` = '" . esc_sql($this->billing->state) . "',\n\t\t\t\t\t\t\t\t\t`billing_zip` = '" . esc_sql($this->billing->zip) . "',\n\t\t\t\t\t\t\t\t\t`billing_country` = '" . esc_sql($this->billing->country) . "',\n\t\t\t\t\t\t\t\t\t`billing_phone` = '" . esc_sql($this->billing->phone) . "',\n\t\t\t\t\t\t\t\t\t`subtotal` = '" . $this->subtotal . "',\n\t\t\t\t\t\t\t\t\t`tax` = '" . $this->tax . "',\n\t\t\t\t\t\t\t\t\t`couponamount` = '" . $this->couponamount . "',\n\t\t\t\t\t\t\t\t\t`certificate_id` = " . intval($this->certificate_id) . ",\n\t\t\t\t\t\t\t\t\t`certificateamount` = '" . $this->certificateamount . "',\n\t\t\t\t\t\t\t\t\t`total` = '" . $this->total . "',\n\t\t\t\t\t\t\t\t\t`payment_type` = '" . $this->payment_type . "',\n\t\t\t\t\t\t\t\t\t`cardtype` = '" . $this->cardtype . "',\n\t\t\t\t\t\t\t\t\t`accountnumber` = '" . $this->accountnumber . "',\n\t\t\t\t\t\t\t\t\t`expirationmonth` = '" . $this->expirationmonth . "',\n\t\t\t\t\t\t\t\t\t`expirationyear` = '" . $this->expirationyear . "',\n\t\t\t\t\t\t\t\t\t`status` = '" . esc_sql($this->status) . "',\n\t\t\t\t\t\t\t\t\t`gateway` = '" . $this->gateway . "',\n\t\t\t\t\t\t\t\t\t`gateway_environment` = '" . $this->gateway_environment . "',\n\t\t\t\t\t\t\t\t\t`payment_transaction_id` = '" . esc_sql($this->payment_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t`subscription_transaction_id` = '" . esc_sql($this->subscription_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t`affiliate_id` = '" . esc_sql($this->affiliate_id) . "',\n\t\t\t\t\t\t\t\t\t`affiliate_subid` = '" . esc_sql($this->affiliate_subid) . "',\n\t\t\t\t\t\t\t\t\t`notes` = '" . esc_sql($this->notes) . "'\n\t\t\t\t\t\t\t\t\tWHERE id = '" . $this->id . "'\n\t\t\t\t\t\t\t\t\tLIMIT 1"; } else { //set up actions $before_action = "pmpro_add_order"; $after_action = "pmpro_added_order"; //insert $this->sqlQuery = "INSERT INTO {$wpdb->pmpro_membership_orders}\n\t\t\t\t\t\t\t\t(`code`, `session_id`, `user_id`, `membership_id`, `paypal_token`, `billing_name`, `billing_street`, `billing_city`, `billing_state`, `billing_zip`, `billing_country`, `billing_phone`, `subtotal`, `tax`, `couponamount`, `certificate_id`, `certificateamount`, `total`, `payment_type`, `cardtype`, `accountnumber`, `expirationmonth`, `expirationyear`, `status`, `gateway`, `gateway_environment`, `payment_transaction_id`, `subscription_transaction_id`, `timestamp`, `affiliate_id`, `affiliate_subid`, `notes`)\n\t\t\t\t\t\t\t\tVALUES('" . $this->code . "',\n\t\t\t\t\t\t\t\t\t '" . session_id() . "',\n\t\t\t\t\t\t\t\t\t " . intval($this->user_id) . ",\n\t\t\t\t\t\t\t\t\t " . intval($this->membership_id) . ",\n\t\t\t\t\t\t\t\t\t '" . $this->paypal_token . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql(trim($this->billing->name)) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql(trim($this->billing->street)) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->city) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->state) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->zip) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->billing->country) . "',\n\t\t\t\t\t\t\t\t\t '" . cleanPhone($this->billing->phone) . "',\n\t\t\t\t\t\t\t\t\t '" . $amount . "',\n\t\t\t\t\t\t\t\t\t '" . $tax . "',\n\t\t\t\t\t\t\t\t\t '" . $this->couponamount . "',\n\t\t\t\t\t\t\t\t\t " . intval($this->certificate_id) . ",\n\t\t\t\t\t\t\t\t\t '" . $this->certificateamount . "',\n\t\t\t\t\t\t\t\t\t '" . $total . "',\n\t\t\t\t\t\t\t\t\t '" . $this->payment_type . "',\n\t\t\t\t\t\t\t\t\t '" . $this->cardtype . "',\n\t\t\t\t\t\t\t\t\t '" . hideCardNumber($this->accountnumber, false) . "',\n\t\t\t\t\t\t\t\t\t '" . substr($this->ExpirationDate, 0, 2) . "',\n\t\t\t\t\t\t\t\t\t '" . substr($this->ExpirationDate, 2, 4) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->status) . "',\n\t\t\t\t\t\t\t\t\t '" . $this->gateway . "',\n\t\t\t\t\t\t\t\t\t '" . $this->gateway_environment . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->payment_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->subscription_transaction_id) . "',\n\t\t\t\t\t\t\t\t\t '" . current_time('mysql') . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->affiliate_id) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->affiliate_subid) . "',\n\t\t\t\t\t\t\t\t\t '" . esc_sql($this->notes) . "'\n\t\t\t\t\t\t\t\t\t )"; } do_action($before_action, $this); if ($wpdb->query($this->sqlQuery) !== false) { if (empty($this->id)) { $this->id = $wpdb->insert_id; } do_action($after_action, $this); return $this->getMemberOrderByID($this->id); } else { return false; } }
:</strong> <?php echo $pmpro_invoice->discount_code->code; ?> </li> <?php } ?> <?php do_action("pmpro_invoice_bullets_bottom", $pmpro_invoice); ?> </ul> <?php //check instructions if ($pmpro_invoice->gateway == "check" && !pmpro_isLevelFree($pmpro_invoice->membership_level)) { echo wpautop(pmpro_getOption("instructions")); } ?> <table id="pmpro_invoice_table" class="pmpro_invoice" width="100%" cellpadding="0" cellspacing="0" border="0"> <thead> <tr> <?php if (!empty($pmpro_invoice->billing->name)) { ?> <th><?php _e('Billing Address', 'pmpro'); ?> </th> <?php }
if (pmpro_hasMembershipLevel($level->id, $user_id)) { global $wpdb; $sqlQuery = "SELECT startdate FROM {$wpdb->pmpro_memberships_users} WHERE user_id = '" . esc_sql($user_id) . "' AND membership_id = '" . esc_sql($level->id) . "' AND status = 'active' ORDER BY id DESC LIMIT 1"; $old_startdate = $wpdb->get_var($sqlQuery); if (!empty($old_startdate)) { $startdate = "'" . $old_startdate . "'"; } } return $startdate; } add_filter("pmpro_checkout_start_date", "pmpro_checkout_start_date_keep_startdate", 10, 3); /* Stripe Lite Pulled into Core Plugin */ //Stripe Lite, Set the Globals/etc $stripe_billingaddress = pmpro_getOption("stripe_billingaddress"); if (empty($stripe_billingaddress)) { global $pmpro_stripe_lite; $pmpro_stripe_lite = true; add_filter("pmpro_stripe_lite", "__return_true"); add_filter("pmpro_required_billing_fields", "pmpro_required_billing_fields_stripe_lite"); } //Stripe Lite, Don't Require Billing Fields function pmpro_required_billing_fields_stripe_lite($fields) { global $gateway; //ignore if not using stripe if ($gateway != "stripe") { return $fields; } //some fields to remove
function subscribe(&$order) { //create a code for the order if(empty($order->code)) $order->code = $order->getRandomCode(); //setup customer $this->getCustomer($order); if(empty($this->customer)) return false; //error retrieving customer //figure out the amounts $amount = $order->PaymentAmount; $amount_tax = $order->getTaxForPrice($amount); $order->subtotal = $amount; $amount = round((float)$amount + (float)$amount_tax, 2); /* There are two parts to the trial. Part 1 is simply the delay until the first payment since we are doing the first payment as a separate transaction. The second part is the actual "trial" set by the admin. Stripe only supports Year or Month for billing periods, but we account for Days and Weeks just in case. */ //figure out the trial length (first payment handled by initial charge) if($order->BillingPeriod == "Year") $trial_period_days = $order->BillingFrequency * 365; //annual elseif($order->BillingPeriod == "Day") $trial_period_days = $order->BillingFrequency * 1; //daily elseif($order->BillingPeriod == "Week") $trial_period_days = $order->BillingFrequency * 7; //weekly else $trial_period_days = $order->BillingFrequency * 30; //assume monthly //convert to a profile start date $order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $trial_period_days . " Day")) . "T0:0:0"; //filter the start date $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order); //convert back to days $trial_period_days = ceil(abs(strtotime(date("Y-m-d")) - strtotime($order->ProfileStartDate)) / 86400); //now add the actual trial set by the site if(!empty($order->TrialBillingCycles)) { $trialOccurrences = (int)$order->TrialBillingCycles; if($order->BillingPeriod == "Year") $trial_period_days = $trial_period_days + (365 * $order->BillingFrequency * $trialOccurrences); //annual elseif($order->BillingPeriod == "Day") $trial_period_days = $trial_period_days + (1 * $order->BillingFrequency * $trialOccurrences); //daily elseif($order->BillingPeriod == "Week") $trial_period_days = $trial_period_days + (7 * $order->BillingFrequency * $trialOccurrences); //weekly else $trial_period_days = $trial_period_days + (30 * $order->BillingFrequency * $trialOccurrences); //assume monthly } //create a plan try { $plan = Stripe_Plan::create(array( "amount" => $amount * 100, "interval_count" => $order->BillingFrequency, "interval" => strtolower($order->BillingPeriod), "trial_period_days" => $trial_period_days, "name" => $order->membership_name . " for order " . $order->code, "currency" => strtolower(pmpro_getOption("currency")), "id" => $order->code) ); } catch (Exception $e) { $order->error = "Error creating plan with Stripe:" . $e->getMessage(); $order->shorterror = $order->error; return false; } //subscribe to the plan try { $this->customer->updateSubscription(array("prorate" => false, "plan" => $order->code)); } catch (Exception $e) { //try to delete the plan $plan->delete(); //return error $order->error = "Error subscribing customer to plan with Stripe:" . $e->getMessage(); $order->shorterror = $order->error; return false; } //delete the plan $plan = Stripe_Plan::retrieve($plan['id']); $plan->delete(); //if we got this far, we're all good $order->status = "success"; $order->subscription_transaction_id = $this->customer['id']; //transaction id is the customer id, we save it in user meta later too return true; }
$order->billing->state = ""; $order->billing->zip = ""; $order->billing->country = ""; $order->billing->phone = ""; $order->subtotal = ""; $order->tax = ""; $order->couponamount = ""; $order->total = ""; $order->payment_type = ""; $order->cardtype = ""; $order->accountnumber = ""; $order->expirationmonth = ""; $order->expirationyear = ""; $order->status = "success"; $order->gateway = pmpro_getOption("gateway"); $order->gateway_environment = pmpro_getOption("gateway_environment"); $order->payment_transaction_id = ""; $order->subscription_transaction_id = ""; $order->affiliate_id = ""; $order->affiliate_subid = ""; $order->notes = ""; } } } require_once dirname(__FILE__) . "/admin_header.php"; ?> <?php if (!empty($order)) { ?>
function sendToFondy(&$order) { global $pmpro_currency; global $wpdb; //taxes on initial amount $initial_payment = $order->InitialPayment; $initial_payment_tax = $order->getTaxForPrice($initial_payment); $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2); $fields = array('merchant_data' => 'name=' . $order->billing->name . '=phone=' . $order->billing->phone, 'product_id' => $order->membership_id, 'subscription_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'order_id' => $order->code . FondyForm::ORDER_SEPARATOR . time(), 'merchant_id' => pmpro_getOption("fondy_merchantid"), 'order_desc' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'amount' => round($initial_payment * 100), 'currency' => $pmpro_currency, 'server_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'response_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'sender_email' => $order->Email, 'required_rectoken' => 'Y', 'subscription' => 'Y'); $last_subscr_order = new MemberOrder(); //print_r ($order); $last = new MemberOrder($last_subscr_order->getLastMemberOrder($order->user_id, $status = 'success', $membership_id = NULL, $gateway = NULL, $gateway_environment = NULL)); if (isset($last->user_id) && isset($last->code)) { $result = $wpdb->get_row("SELECT fondy_token from `{$wpdb->pmpro_membership_orders}` WHERE user_id='" . $last->user_id . "' AND code='" . $last->code . "'"); if (isset($result->fondy_token)) { $fields['rectoken'] = $result->fondy_token; } } $fields['signature'] = FondyForm::getSignature($fields, pmpro_getOption("fondy_securitykey")); //print_r ($last->user_id);die; unset($fields['currency']); $data = 'currency=' . $pmpro_currency . '&'; foreach ($fields as $key => $val) { $data .= $key . "=" . $val . '&'; } $url = 'https://api.fondy.eu/api/checkout/url/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.fondy.eu/api/checkout/url/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); $str = urldecode($result); parse_str($str, $mass); $fondy_url = $mass['checkout_url']; wp_redirect($fondy_url); exit; }
$isapage = true; global $logstr; $logstr = ""; //you can define a different # of seconds (define PMPRO_STRIPE_WEBHOOK_DELAY in your wp-config.php) if you need this webhook to delay more or less if (!defined('PMPRO_STRIPE_WEBHOOK_DELAY')) { define('PMPRO_STRIPE_WEBHOOK_DELAY', 2); } //in case the file is loaded directly if (!defined("WP_USE_THEMES")) { define('WP_USE_THEMES', false); require_once dirname(__FILE__) . '/../../../../wp-load.php'; } if (!class_exists("Stripe")) { require_once dirname(__FILE__) . "/../includes/lib/Stripe/Stripe.php"; } Stripe::setApiKey(pmpro_getOption("stripe_secretkey")); // retrieve the request's body and parse it as JSON if (empty($_REQUEST['event_id'])) { $body = @file_get_contents('php://input'); $post_event = json_decode($body); //get the id if (!empty($post_event)) { $event_id = $post_event->id; } } else { $event_id = $_REQUEST['event_id']; } //get the event through the API now if (!empty($event_id)) { try { $event = Stripe_Event::retrieve($event_id);
} ?> <?php if (!empty($pmpro_invoice)) { ?> <?php $pmpro_invoice->getUser(); $pmpro_invoice->getMembershipLevel(); $confirmation_message .= "<p>" . sprintf(__('Below are details about your membership account and a receipt for your initial membership invoice. A welcome email with a copy of your initial membership invoice has been sent to %s.', 'pmpro'), $pmpro_invoice->user->user_email) . "</p>"; //check instructions if ($pmpro_invoice->gateway == "check" && !pmpro_isLevelFree($pmpro_invoice->membership_level)) { $confirmation_message .= wpautop(pmpro_getOption("instructions")); } $confirmation_message = apply_filters("pmpro_confirmation_message", $confirmation_message, $pmpro_invoice); echo apply_filters("the_content", $confirmation_message); ?> <h3> <?php printf(__('Invoice #%s on %s', 'pmpro'), $pmpro_invoice->code, date_i18n(get_option('date_format'), $pmpro_invoice->timestamp)); ?> </h3> <a class="pmpro_a-print" href="javascript:window.print()"><?php _e('Print', 'pmpro'); ?>
function pmpro_checkout_preheader() { // Register the script wp_register_script('pmpro-wepay', plugins_url('/js/pmpro-wepay.js', dirname(__FILE__))); // Localize the script with new data $translation_array = array('enviroment' => pmpro_getOption('gateway_environment'), 'billingaddress' => pmpro_getOption('wepay_billingaddress'), 'client_id' => pmpro_getOption('wepay_client_id')); wp_localize_script('pmpro-wepay', 'pmprowepay', $translation_array); // Enqueued script with localized data. wp_enqueue_script('wepay', 'https://static.wepay.com/min/js/tokenization.v2.js', array(), '2'); wp_enqueue_script('pmpro-wepay'); return; }
function pmpro_set_current_user() { //this code runs at the beginning of the plugin global $current_user, $wpdb; get_currentuserinfo(); $id = intval($current_user->ID); if ($id) { $current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID); if (!empty($current_user->membership_level)) { $current_user->membership_level->categories = pmpro_getMembershipCategories($current_user->membership_level->ID); } $current_user->membership_levels = pmpro_getMembershipLevelsForUser($current_user->ID); } //hiding ads? $hideads = pmpro_getOption("hideads"); $hideadslevels = pmpro_getOption("hideadslevels"); if (!is_array($hideadslevels)) { $hideadslevels = explode(",", $hideadslevels); } if ($hideads == 1 && pmpro_hasMembershipLevel() || $hideads == 2 && pmpro_hasMembershipLevel($hideadslevels)) { //disable ads in ezAdsense if (class_exists("ezAdSense")) { global $ezCount, $urCount; $ezCount = 100; $urCount = 100; } //disable ads in Easy Adsense (newer versions) if (class_exists("EzAdSense")) { global $ezAdSense; $ezAdSense->ezCount = 100; $ezAdSense->urCount = 100; } //set a global variable to hide ads global $pmpro_display_ads; $pmpro_display_ads = false; } else { global $pmpro_display_ads; $pmpro_display_ads = true; } do_action("pmpro_after_set_current_user"); }
function pmprorh_pmpro_registration_checks($okay) { global $current_user; //only check if we're okay so far and there is an email to check if ($okay && (!empty($_REQUEST['bemail']) || !empty($current_user->user_email))) { //are we restricting emails for this level global $pmpro_level; $restrict_emails = pmpro_getOption("level_" . $pmpro_level->id . "_restrict_emails"); if (!empty($restrict_emails)) { $restrict_emails = strtolower(str_replace(array(";", ",", " "), "\n", $restrict_emails)); if (!empty($current_user->user_email)) { $needle = strtolower($current_user->user_email); } else { $needle = strtolower($_REQUEST['bemail']); } $haystack = explode("\n", $restrict_emails); array_walk($haystack, create_function('&$val', '$val = trim($val);')); if (!in_array($needle, $haystack)) { global $pmpro_msg, $pmpro_msgt; $pmpro_msg = "This membership level is restricted to certain users only. Make sure you've entered your email address correctly."; $pmpro_msgt = "pmpro_error"; $okay = false; //no further checks here return $okay; } } //are we restricting user names for this level $restrict_usernames = pmpro_getOption("level_" . $pmpro_level->id . "_restrict_usernames"); if (!empty($restrict_usernames)) { $restrict_usernames = strtolower(str_replace(array(";", ",", " "), "\n", $restrict_usernames)); if (!empty($current_user->user_login)) { $needle = strtolower($current_user->user_login); } else { $needle = strtolower($_REQUEST['username']); } $haystack = explode("\n", $restrict_usernames); array_walk($haystack, create_function('&$val', '$val = trim($val);')); if (!in_array($needle, $haystack)) { global $pmpro_msg, $pmpro_msgt; $pmpro_msg = "This membership level is restricted to certain users only. Make sure you are logged into your existing account and using the proper username."; $pmpro_msgt = "pmpro_error"; $okay = false; } } } return $okay; }
/** * PAYPAL Function * Send HTTP POST Request * * @param string The API method name * @param string The POST Message fields in &name=value pair format * @return array Parsed HTTP Response body */ function PPHttpPost($methodName_, $nvpStr_) { global $gateway_environment; $environment = $gateway_environment; $API_UserName = pmpro_getOption("apiusername"); $API_Password = pmpro_getOption("apipassword"); $API_Signature = pmpro_getOption("apisignature"); $API_Endpoint = "https://api-3t.paypal.com/nvp"; if ("sandbox" === $environment || "beta-sandbox" === $environment) { $API_Endpoint = "https://api-3t.{$environment}.paypal.com/nvp"; } $version = urlencode('72.0'); // NVPRequest for submitting to server $nvpreq = "METHOD=" . urlencode($methodName_) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER="******"&SIGNATURE=" . urlencode($API_Signature) . "&bn=" . urlencode(PAYPAL_BN_CODE) . $nvpStr_; //post to PayPal $response = wp_remote_post($API_Endpoint, array('sslverify' => FALSE, 'body' => $nvpreq)); if (is_wp_error($response)) { $error_message = $response->get_error_message(); die("methodName_ failed: {$error_message}"); } else { //extract the response details $httpParsedResponseAr = array(); parse_str(wp_remote_retrieve_body($response), $httpParsedResponseAr); //check for valid response if (0 == sizeof($httpParsedResponseAr) || !array_key_exists('ACK', $httpParsedResponseAr)) { exit("Invalid HTTP Response for POST request({$nvpreq}) to {$API_Endpoint}."); } } return $httpParsedResponseAr; }
function pmproet_email_data($data, $email) { global $current_user, $pmpro_currency_symbol, $wpdb; if (!empty($data) && !empty($data['user_login'])) { $user = get_user_by('login', $data['user_login']); } if (empty($user)) { $user = $current_user; } $pmpro_user_meta = $wpdb->get_row("SELECT * FROM {$wpdb->pmpro_memberships_users} WHERE user_id = '" . $user->ID . "' AND status='active'"); //make sure data is an array if (!is_array($data)) { $data = array(); } //general data $new_data['sitename'] = get_option("blogname"); $new_data['siteemail'] = pmpro_getOption("from_email"); if (empty($new_data['login_link'])) { $new_data['login_link'] = wp_login_url(); } $new_data['levels_link'] = pmpro_url("levels"); //user data if (!empty($user)) { $new_data['name'] = $user->display_name; $new_data['user_login'] = $user->user_login; $new_data['display_name'] = $user->display_name; $new_data['user_email'] = $user->user_email; } //membership data if (!empty($user->membership_level)) { $new_data['enddate'] = date(get_option('date_format'), $user->membership_level->enddate); } //invoice data if (!empty($data['invoice_id'])) { $invoice = new MemberOrder($data['invoice_id']); if (!empty($invoice)) { $new_data['billing_name'] = $invoice->billing->name; $new_data['billing_street'] = $invoice->billing->street; $new_data['billing_city'] = $invoice->billing->city; $new_data['billing_state'] = $invoice->billing->state; $new_data['billing_zip'] = $invoice->billing->zip; $new_data['billing_country'] = $invoice->billing->country; $new_data['billing_phone'] = $invoice->billing->phone; $new_data['cardtype'] = $invoice->cardtype; $new_data['accountnumber'] = hideCardNumber($invoice->accountnumber); $new_data['expirationmonth'] = $invoice->expirationmonth; $new_data['expirationyear'] = $invoice->expirationyear; $new_data['instructions'] = wpautop(pmpro_getOption('instructions')); $new_data['invoice_id'] = $invoice->code; $new_data['invoice_total'] = $pmpro_currency_symbol . number_format($invoice->total, 2); $new_data['invoice_link'] = pmpro_url('invoice', '?invoice=' . $invoice->code); //billing address $new_data["billing_address"] = pmpro_formatAddress($invoice->billing->name, $invoice->billing->street, "", $invoice->billing->city, $invoice->billing->state, $invoice->billing->zip, $invoice->billing->country, $invoice->billing->phone); } } //membership change if (!empty($user->membership_level) && !empty($user->membership_level->ID)) { $new_data["membership_change"] = sprintf(__("The new level is %s.", "pmpro"), $user->membership_level->name); } else { $new_data["membership_change"] = __("Your membership has been cancelled", "pmpro"); } if (!empty($user->membership_level) && !empty($user->membership_level->enddate)) { $new_data["membership_change"] .= ". " . sprintf(__("This membership will expire on %s", "pmpro"), date(get_option('date_format'), $user->membership_level->enddate)); } elseif (!empty($email->expiration_changed)) { $new_data["membership_change"] .= ". " . __("This membership does not expire", "pmpro"); } //membership expiration $new_data['membership_expiration'] = ''; if (!empty($pmpro_user_meta->enddate)) { $new_data['membership_expiration'] = "<p>" . sprintf(__("This membership will expire on %s.", "pmpro"), $pmpro_user_meta->enddate . "</p>\n"); } //if others are used in the email look in usermeta $et_body = pmpro_getOption('email_' . $email->template . '_body'); $templates_in_email = preg_match_all("/!!([^!]+)!!/", $et_body, $matches); if (!empty($templates_in_email)) { $matches = $matches[1]; foreach ($matches as $match) { if (empty($new_data[$match])) { $usermeta = get_user_meta($user->ID, $match, true); if (!empty($usermeta)) { if (is_array($usermeta) && !empty($usermeta['fullurl'])) { $new_data[$match] = $usermeta['fullurl']; } elseif (is_array($usermeta)) { $new_data[$match] = implode(", ", $usermeta); } else { $new_data[$match] = $usermeta; } } } } } //now replace any new_data not already in data foreach ($new_data as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } return $data; }