<?php continue; // Skip this item if can't view it ?> <?php } ?> <?php if (empty($item['in_bundle'])) { ?> <tr> <td> <?php $price_id = edd_get_cart_item_price_id($item); $download_files = edd_get_download_files($item['id'], $price_id); ?> <div class="edd_purchase_receipt_product_name"> <?php echo esc_html($item['name']); ?> <?php if (!is_null($price_id)) { ?> <span class="edd_purchase_receipt_price_name"> – <?php echo edd_get_price_option_name($item['id'], $price_id, $payment->ID); ?> </span> <?php
/** * Email template tag: file_urls * A plain-text list of download URLs for each download purchased * * @param int $payment_id * * @return string $file_urls */ function edd_email_tag_file_urls($payment_id) { $payment_data = edd_get_payment_meta($payment_id); $file_urls = ''; $cart_items = edd_get_payment_meta_cart_details($payment_id); $email = edd_get_payment_user_email($payment_id); foreach ($cart_items as $item) { $price_id = edd_get_cart_item_price_id($item); $files = edd_get_download_files($item['id'], $price_id); if ($files) { foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $item['id'], $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } elseif (edd_is_bundled_product($item['id'])) { $bundled_products = apply_filters('edd_email_tag_bundled_products', edd_get_bundled_products($item['id']), $item, $payment_id, 'file_urls'); foreach ($bundled_products as $bundle_item) { $files = edd_get_download_files($bundle_item); foreach ($files as $filekey => $file) { $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $bundle_item, $price_id); $file_urls .= esc_html($file_url) . '<br/>'; } } } } return $file_urls; }
/** * Get cart item title * * @since 2.4.3 * @param int $item Cart item array * @return string item title */ function edd_get_cart_item_name($item = array()) { $item_title = get_the_title($item['id']); if (empty($item_title)) { $item_title = $item['id']; } if (edd_has_variable_prices($item['id']) && false !== edd_get_cart_item_price_id($item)) { $item_title .= ' - ' . edd_get_cart_item_price_name($item); } return apply_filters('edd_get_cart_item_name', $item_title, $item['id'], $item); }
/** * Callback on the `edd_complete_purchase` hook that updates the user's role based on purchase * * @since 1.0.0 * @access public * @param int $payment_id * @return bool */ function role_map_edd_complete_purchase($payment_id = 0) { // User info $user_info = edd_get_payment_meta_user_info($payment_id); // User ID $user_id = $user_info['id']; // Cart details $downloads = edd_get_payment_meta_cart_details($payment_id); // Bail if there are no downloads. if (!is_array($downloads)) { return; } // Get user roles purchased. $roles = array(); foreach ($downloads as $download) { // Bypass downloads that are not memberships. if (!get_post_meta($download['id'], '_edd_members_length_enabled', true)) { continue; } // Get price id. $price_id = edd_get_cart_item_price_id($download); // Get the price option role. $roles[] = role_map_edd_get_price_option_role($download['id'], $price_id); } // If we have roles. if ($roles) { // Note: We're currently grabbing the first role. We need to add a check to // get the highest priced role in case someone purchases multiple. role_map_edd_set_user_role($user_id, array_shift($roles)); } }
/** * * @param unknown $payment * @param string $edd_receipt_args */ public function edd_osgi_action_payment_receipt_after_table($payment, $edd_receipt_args = null) { if ($this->osgipub_osgi_debug) { echo "<p>debug: this is the action after table</p>\n"; } if (isset($payment) && edd_is_payment_complete($payment->ID)) { $meta = get_post_meta($payment->ID); if ($this->osgipub_osgi_debug) { echo "<p>debug: Payment vardump="; var_dump($payment); echo "</p>\n"; echo "<p>debug: Payment metadata vardump="; var_dump($meta); echo "</p>\n"; } // same $cart = edd_get_payment_meta_cart_details( $payment->ID, true ); $downloads = edd_get_payment_meta_cart_details($payment->ID, true); $edd_payment_post_id = $payment->ID; $edd_payment_user_id = (string) $meta['_edd_payment_user_id'][0]; $edd_payment_customer_id = (string) $meta['_edd_payment_customer_id'][0]; //TODO REMOVED BECAUSE NOT BEING GENERATED $edd_payment_number = ( string ) $meta ['_edd_payment_number'] [0]; $edd_payment_number = $edd_payment_post_id; $edd_payment_purchase_key = (string) $meta['_edd_payment_purchase_key'][0]; // see easy-digital-downloads/templates/history-downloads.php // add_query_arg( 'payment_key', edd_get_payment_key( $post->ID ), edd_get_success_page_uri() ) if ($downloads) { $display_licence_table = false; // check if any downloads are osgi licenced foreach ($downloads as $download) { if ($this->is_osgi_licenced($download['id'])) { $display_licence_table = true; } } if ($display_licence_table) { echo "<div id=\"osgi_licence_list_table\" class=\"osgi_licence_list\">\n"; echo "<h3>OSGi Licences</h3>\n"; echo "<p>One of more of your purchased downloads have associated OSGi Licences.<BR>To generate your licences select the links below.</p>\n"; echo "<table>\n"; } // used to set change licence name for multiple downloads $download_no = 0; foreach ($downloads as $download) { // Skip over Bundles. Products included with a bundle will be displayed individually if (edd_is_bundled_product($download['id'])) { continue; } // if not osgi licenced bundle skip if (!$this->is_osgi_licenced($download['id'])) { continue; } $download_no++; $price_id = edd_get_cart_item_price_id($download); $download_files = edd_get_download_files($download['id'], $price_id); $name = get_the_title($download['id']); // quantity used to handle multiple licences per download for ($quantity = 1; $quantity <= $download['quantity']; $quantity++) { if (isset($edd_payment_number)) { // start of table row echo " <tr>\n"; echo " <td>\n"; // product id string from download // contains maven unique id of product to which this licence applies $edd_osgiProductIdStr = get_post_meta($download['id'], '_edd_osgiProductIdStr', true); // try loading modified LicenceMetadataSpecStr from this product efinition and apply to licence post $edd_modified_osgiLicenceMetadataSpecStr = get_post_meta($download['id'], '_edd_modified_osgiLicenceMetadataSpecStr', true); // Retrieve and append the price option name if (!empty($price_id)) { $name .= ' - ' . edd_get_price_option_name($download['id'], $price_id, $payment->ID); } // product name - payment number - download number $licence_post_title = $name . ' - ' . $edd_payment_number . '-' . $download_no . '-' . $quantity; // remove whitepsace $licence_post_name = preg_replace('/\\s+/', '', $licence_post_title); if ($this->osgipub_osgi_debug) { echo "<p>debug: download [id]=" . $download['id'] . '</p>\\n'; if (!isset($edd_osgiProductIdStr)) { echo "<p>debug: from download edd_osgiProductIdStr not set for download [id]=" . $download['id'] . '</p>\\n'; } else { echo "<p>debug: from download edd_osgiProductIdStr="; echo $edd_osgiProductIdStr; echo "</p>\n"; } echo "<p>debug: payment name="; echo $name; echo "</p>\n"; echo "<p>debug: licence_post_title="; echo $licence_post_title; echo "</p>\n"; echo "<p>debug: licence_post_name="; echo $licence_post_name; echo "</p>\n"; echo "<p>debug: edd_payment_number="; echo $edd_payment_number; echo "</p>\n"; } $found_post = null; if ($posts = get_posts(array('name' => $licence_post_name, 'post_type' => 'osgi_licence_post', 'post_status' => 'publish', 'posts_per_page' => 1))) { $found_post = $posts[0]; } // Now, we can do something with $found_post if (!is_null($found_post)) { if ($this->osgipub_osgi_debug) { echo "<p>debug: we found the licence post="; echo $found_post->ID; echo "</p>\n"; } echo '<a href="' . get_post_permalink($found_post->ID) . '" >Link to Licence: ' . $licence_post_title . '</a>'; echo "\n"; } else { // get post with payment number metadata OR create post with metadata $post = array('post_content' => '<p>DO NOT EDIT: You can only view or change this licence post by using View Post.</p>', 'post_name' => $licence_post_name, 'post_title' => $licence_post_title, 'post_status' => 'publish', 'post_type' => 'osgi_licence_post', 'ping_status' => 'closed', 'comment_status' => 'closed'); // Default is the option 'default_comment_status', or 'closed'. // 'post_category' => [ array(<category id>, ...) ] // Default empty. // 'tags_input' => [ '<tag>, <tag>, ...' | array ] // Default empty. // 'tax_input' => [ array( <taxonomy> => <array | string> ) ] // For custom taxonomies. Default empty. // 'page_template' => '../edd-downloads-as-osgi.php' // Requires name of template file, eg template.php. Default empty. $newpost_id = wp_insert_post($post); // setting product id for licence // update_post_meta ( $newpost_id, 'edd_osgiProductIdStr', 'org.opennms.co.uk/org.opennms.co.uk.newfeature/0.0.1-SNAPSHOT' ); update_post_meta($newpost_id, 'edd_osgiProductIdStr', $edd_osgiProductIdStr); // apply modified metadata to this licence post update_post_meta($newpost_id, '_edd_modified_osgiLicenceMetadataSpecStr', $edd_modified_osgiLicenceMetadataSpecStr); // setting customer metadata - not yet used in the template update_post_meta($newpost_id, 'edd_payment_customer_id', $edd_payment_customer_id); update_post_meta($newpost_id, 'edd_payment_user_id', $edd_payment_user_id); // setting edd_osgiLicencee information $f_name = (string) get_user_meta($edd_payment_user_id, 'first_name', true); $first_name = isset($f_name) ? $f_name : ""; $l_name = (string) get_user_meta($edd_payment_user_id, 'last_name', true); $last_name = isset($l_name) ? $l_name : ""; $address = ""; $addr = edd_get_customer_address($edd_payment_user_id); if (isset($addr)) { $address = implode(", ", $addr); } $edd_osgiLicencee = $first_name . ", " . $last_name . ", " . $address; update_post_meta($newpost_id, 'edd_osgiLicencee', $edd_osgiLicencee); // for reverse lookup of post id of the associated payment update_post_meta($newpost_id, 'edd_payment_post_id', $edd_payment_post_id); if ($this->osgipub_osgi_debug) { echo "<p>debug: we created a new licence post="; echo $newpost_id; echo "</p>\n"; } echo '<a href="' . get_post_permalink($newpost_id) . '" >Link to Licence: ' . $licence_post_title . '</a>'; echo "\n"; } echo " </td>\n"; echo " </tr>\n"; } } } if ($display_licence_table) { echo "</table>\n"; echo "</div> <!-- div id=osgi_licence_list_table -->"; } } } else { echo '<p>payment not set</p>\\n'; } if ($this->osgipub_osgi_debug) { if (isset($edd_receipt_args)) { echo "<p>debug: edd_receipt_args vardump="; var_dump($edd_receipt_args); echo "</p>\n"; } else { echo '<p>debug: edd_receipt_args not set</p>\\n'; } } }
<?php foreach ($purchases as $payment) { $downloads = edd_get_payment_meta_cart_details($payment->ID, true); $purchase_data = edd_get_payment_meta($payment->ID); $email = edd_get_payment_user_email($payment->ID); if ($downloads) { foreach ($downloads as $download) { // Skip over Bundles. Products included with a bundle will be displayed individually if (edd_is_bundled_product($download['id'])) { continue; } ?> <tr class="edd_download_history_row"> <?php $price_id = edd_get_cart_item_price_id($download); $download_files = edd_get_download_files($download['id'], $price_id); $name = get_the_title($download['id']); // Retrieve and append the price option name if (!empty($price_id)) { $name .= ' - ' . edd_get_price_option_name($download['id'], $price_id, $payment->ID); } do_action('edd_download_history_row_start', $payment->ID, $download['id']); ?> <td class="edd_download_download_name"><?php echo esc_html($name); ?> </td> <?php if (!edd_no_redownload()) {
/** * Get cart item price name * * @since 1.8 * @param int $item Cart item array * @return string Price name */ function edd_get_cart_item_price_name($item = array()) { $price_id = (int) edd_get_cart_item_price_id($item); $prices = edd_get_variable_prices($item['id']); $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; return apply_filters('edd_get_cart_item_price_name', $name, $item['id'], $price_id, $item); }
/** * Record Commissions * * @access private * @since 1.0 * @return void */ function eddc_record_commission($payment_id, $new_status, $old_status) { // Check if the payment was already set to complete if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the commission is only recorded when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) { return; } // do not record commission on manual payments unless specified if (edd_get_payment_meta($payment_id, '_edd_completed_date')) { return; } $payment_data = edd_get_payment_meta($payment_id); $user_info = maybe_unserialize($payment_data['user_info']); $cart_details = edd_get_payment_meta_cart_details($payment_id); $calc_base = edd_get_option('edd_commissions_calc_base', 'subtotal'); $shipping = edd_get_option('edd_commissions_shipping', 'ignored'); // loop through each purchased download and award commissions, if needed foreach ($cart_details as $download) { $download_id = absint($download['id']); $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true); if ('subtotal' == $calc_base) { $price = $download['subtotal']; } else { if ('total_pre_tax' == $calc_base) { $price = $download['price'] - $download['tax']; } else { $price = $download['price']; } } if (!empty($download['fees'])) { foreach ($download['fees'] as $fee_id => $fee) { if (false !== strpos($fee_id, 'shipping')) { // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined if ('ignored' !== $shipping) { continue; } } $price += $fee['amount']; } } // if we need to award a commission, and the price is greater than zero if ($commissions_enabled && floatval($price) > '0') { // set a flag so downloads with commissions awarded are easy to query update_post_meta($download_id, '_edd_has_commission', true); $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true); if ($commission_settings) { $type = eddc_get_commission_type($download_id); // but if we have price variations, then we need to get the name of the variation $has_variable_prices = edd_has_variable_prices($download_id); if ($has_variable_prices) { $price_id = edd_get_cart_item_price_id($download); $variation = edd_get_price_option_name($download_id, $price_id); } $recipients = eddc_get_recipients($download_id); // Record a commission for each user foreach ($recipients as $recipient) { $rate = eddc_get_recipient_rate($download_id, $recipient); // percentage amount of download price $args = array('price' => $price, 'rate' => $rate, 'type' => $type, 'download_id' => $download_id, 'recipient' => $recipient, 'payment_id' => $payment_id); $commission_amount = eddc_calc_commission_amount($args); // calculate the commission amount to award $currency = $payment_data['currency']; // If shipping is included or not included, we need to adjust the amount if (!empty($download['fees']) && 'ignored' !== $shipping) { foreach ($download['fees'] as $fee_id => $fee) { if (false !== strpos($fee_id, 'shipping')) { // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined if ('include_shipping' == $shipping) { $commission_amount += $fee['amount']; } } } } $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish'); $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission)); $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id, $payment_id, $download_id); eddc_set_commission_status($commission_id, 'unpaid'); update_post_meta($commission_id, '_edd_commission_info', $commission_info); update_post_meta($commission_id, '_download_id', $download_id); update_post_meta($commission_id, '_user_id', $recipient); update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id); // If we are dealing with a variation, then save variation info if ($has_variable_prices && isset($variation)) { update_post_meta($commission_id, '_edd_commission_download_variation', $variation); } // If it's a renewal, save that detail if (!empty($download['item_number']['options']['is_renewal'])) { update_post_meta($commission_id, '_edd_commission_is_renewal', true); } do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id); } } } } }
)</script> </td> </tr> <?php } } } elseif (edd_is_bundled_product($cart_item['id'])) { $bundled_products = edd_get_bundled_products($cart_item['id']); foreach ($bundled_products as $bundle_item) { $product = get_post($bundle_item); $bundle_license = edd_software_licensing()->get_license_by_purchase($payment_id, $product->ID); //$post_meta = get_post_meta($product->ID, '_edd_sl_download_id', true); $price_id = edd_get_cart_item_price_id(0); $download_files = edd_get_download_files($product->ID, $price_id); $product_domains_check = get_post($download_files[0]['attachment_id']); //$cart_key = array_search($bundle_item, array_column($cart, 'id')); // (PHP 5 >= 5.5.0) $products_domains = edd_software_licensing()->get_sites($bundle_license->ID); foreach ($cart as $cart_row => $cart_item) { if ($cart_item['id'] == $bundle_item) { $cart_key = $cart_row; break; } } $download_files = edd_get_download_files($bundle_item); $license_date = get_post_meta($bundle_license->ID, '_edd_sl_expiration', true); $unlimited_license = get_post_meta($bundle_license->ID, '_unlimited_license', true); $now = strtotime(date('Y-m-d H:i:s')); $expired_license = $license_date > $now || $unlimited_license == 1 ? 0 : 1;
/** * Process PayPal Purchase * * @since 1.0 * @global $edd_options Array of all the EDD Options * @param array $purchase_data Purchase Data * @return void */ function edd_process_paypal_purchase($purchase_data) { global $edd_options; // Collect payment data $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'paypal', 'status' => 'pending'); // Record the pending payment $payment = edd_insert_payment($payment_data); // Check payment if (!$payment) { // Record the error edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'edd'), json_encode($payment_data)), $payment); // Problems? send back edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { // Only send to PayPal if the pending payment is created successfully $listener_url = add_query_arg('edd-listener', 'IPN', home_url('index.php')); // Get the success url $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment), get_permalink($edd_options['success_page'])); // Get the PayPal redirect uri $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?'; // Setup PayPal arguments $paypal_args = array('business' => $edd_options['paypal_email'], 'email' => $purchase_data['user_email'], 'invoice' => $purchase_data['purchase_key'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => edd_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => edd_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url, 'page_style' => edd_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'EasyDigitalDownloads_SP'); if (!empty($purchase_data['user_info']['address'])) { $paypal_args['address1'] = $purchase_data['user_info']['address']['line1']; $paypal_args['address2'] = $purchase_data['user_info']['address']['line2']; $paypal_args['city'] = $purchase_data['user_info']['address']['city']; $paypal_args['country'] = $purchase_data['user_info']['address']['country']; } $paypal_extra_args = array('cmd' => '_cart', 'upload' => '1'); $paypal_args = array_merge($paypal_extra_args, $paypal_args); // Add cart items $i = 1; foreach ($purchase_data['cart_details'] as $item) { if (edd_has_variable_prices($item['id']) && edd_get_cart_item_price_id($item) !== false) { $item['name'] .= ' - ' . edd_get_cart_item_price_name($item); } $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wp_strip_all_tags($item['name']), ENT_COMPAT, 'UTF-8')); $paypal_args['quantity_' . $i] = $item['quantity']; $paypal_args['amount_' . $i] = round($item['subtotal'] / $item['quantity'], 2); if (edd_use_skus()) { $paypal_args['item_number_' . $i] = edd_get_download_sku($item['id']); } $i++; } // Calculate discount $discounted_amount = 0.0; if (!empty($purchase_data['fees'])) { $i = empty($i) ? 1 : $i; foreach ($purchase_data['fees'] as $fee) { if (floatval($fee['amount']) > '0') { // this is a positive fee $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wp_strip_all_tags($fee['label']), ENT_COMPAT, 'UTF-8')); $paypal_args['quantity_' . $i] = '1'; $paypal_args['amount_' . $i] = edd_sanitize_amount($fee['amount']); $i++; } else { // This is a negative fee (discount) $discounted_amount += abs($fee['amount']); } } } if ($discounted_amount > '0') { $paypal_args['discount_amount_cart'] = edd_sanitize_amount($discounted_amount); } // Add taxes to the cart if (edd_use_taxes()) { $paypal_args['tax_cart'] = edd_sanitize_amount($purchase_data['tax']); } $paypal_args = apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data); // Build query $paypal_redirect .= http_build_query($paypal_args); // Fix for some sites that encode the entities $paypal_redirect = str_replace('&', '&', $paypal_redirect); // Get rid of cart contents edd_empty_cart(); // Redirect to PayPal wp_redirect($paypal_redirect); exit; } }
/** * Email Template Tags * * @since 1.0 * * @param string $message Message with the template tags * @param array $payment_data Payment Data * @param int $payment_id Payment ID * * @return string $message Fully formatted message */ function edd_email_template_tags($message, $payment_data, $payment_id) { global $edd_options; $has_tags = strpos($message, '{') !== false; if (!$has_tags) { return $message; } $user_info = maybe_unserialize($payment_data['user_info']); $fullname = ''; if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) { $user_data = get_userdata($user_info['id']); $name = $user_info['first_name']; $fullname = $user_info['first_name'] . ' ' . $user_info['last_name']; $username = $user_data->user_login; } elseif (isset($user_info['first_name'])) { $name = $user_info['first_name']; $fullname = $user_info['first_name'] . ' ' . $user_info['last_name']; $username = $user_info['first_name']; } else { $name = $user_info['email']; $username = $user_info['email']; } $file_urls = ''; $download_list = '<ul>'; $cart_items = edd_get_payment_meta_cart_details($payment_id); if ($cart_items) { $show_names = apply_filters('edd_email_show_names', true); foreach ($cart_items as $item) { if (edd_use_skus()) { $sku = edd_get_download_sku($item['id']); } $price_id = edd_get_cart_item_price_id($item); if ($show_names) { $title = get_the_title($item['id']); if (!empty($sku)) { $title .= " – " . __('SKU', 'edd') . ': ' . $sku; } if ($price_id !== false) { $title .= " – " . edd_get_price_option_name($item['id'], $price_id); } $download_list .= '<li>' . apply_filters('edd_email_receipt_download_title', $title, $item['id'], $price_id) . '<br/>'; $download_list .= '<ul>'; } $files = edd_get_download_files($item['id'], $price_id); if ($files) { foreach ($files as $filekey => $file) { $download_list .= '<li>'; $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id); $download_list .= '<a href="' . esc_url($file_url) . '">' . $file['name'] . '</a>'; $download_list .= '</li>'; $file_urls .= esc_html($file_url) . '<br/>'; } } if ($show_names) { $download_list .= '</ul>'; } if ('' != edd_get_product_notes($item['id'])) { $download_list .= ' — <small>' . edd_get_product_notes($item['id']) . '</small>'; } if ($show_names) { $download_list .= '</li>'; } } } $download_list .= '</ul>'; $subtotal = isset($payment_data['subtotal']) ? $payment_data['subtotal'] : $payment_data['amount']; $subtotal = edd_currency_filter(edd_format_amount($subtotal)); $tax = isset($payment_data['tax']) ? $payment_data['tax'] : 0; $tax = edd_currency_filter(edd_format_amount($tax)); $price = edd_currency_filter(edd_format_amount($payment_data['amount'])); $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true)); $receipt_id = $payment_data['key']; $message = str_replace('{name}', $name, $message); $message = str_replace('{fullname}', $fullname, $message); $message = str_replace('{username}', $username, $message); $message = str_replace('{download_list}', $download_list, $message); $message = str_replace('{file_urls}', $file_urls, $message); $message = str_replace('{date}', date_i18n(get_option('date_format'), strtotime($payment_data['date'])), $message); $message = str_replace('{sitename}', get_bloginfo('name'), $message); $message = str_replace('{subtotal}', $subtotal, $message); $message = str_replace('{tax}', $tax, $message); $message = str_replace('{price}', $price, $message); $message = str_replace('{payment_method}', $gateway, $message); $message = str_replace('{receipt_id}', $receipt_id, $message); $message = str_replace('{payment_id}', $payment_id, $message); $message = str_replace('{receipt_link}', sprintf(__('%1$sView it in your browser.%2$s', 'edd'), '<a href="' . add_query_arg(array('purchase_key' => $receipt_id, 'edd_action' => 'view_receipt'), home_url()) . '">', '</a>'), $message); $message = apply_filters('edd_email_template_tags', $message, $payment_data, $payment_id); return $message; }
/** * Record Commissions * * @access private * @since 1.0 * @return void */ function eddc_record_commission($payment_id, $new_status, $old_status) { // Check if the payment was already set to complete if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the commission is only recorded when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) { return; } // do not record commission on manual payments unless specified $payment_data = edd_get_payment_meta($payment_id); $user_info = maybe_unserialize($payment_data['user_info']); $cart_details = maybe_unserialize($payment_data['cart_details']); // loop through each purchased download and award commissions, if needed foreach ($cart_details as $download) { $download_id = absint($download['id']); $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true); if ('subtotal' == edd_get_option('edd_commissions_calc_base', 'subtotal')) { $price = $download['subtotal']; } else { $price = $download['price']; } // if we need to award a commission, and the price is greater than zero if ($commissions_enabled && floatval($price) > '0') { // set a flag so downloads with commissions awarded are easy to query update_post_meta($download_id, '_edd_has_commission', true); $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true); if ($commission_settings) { $type = eddc_get_commission_type($download_id); // but if we have price variations, then we need to get the name of the variation if (edd_has_variable_prices($download_id)) { $price_id = edd_get_cart_item_price_id($download); $variation = edd_get_price_option_name($download_id, $price_id); } $recipients = eddc_get_recipients($download_id); // Record a commission for each user foreach ($recipients as $recipient) { $rate = eddc_get_recipient_rate($download_id, $recipient); // percentage amount of download price $commission_amount = eddc_calc_commission_amount($price, $rate, $type); // calculate the commission amount to award $currency = $payment_data['currency']; $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish'); $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission)); $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id); update_post_meta($commission_id, '_edd_commission_info', $commission_info); update_post_meta($commission_id, '_commission_status', 'unpaid'); update_post_meta($commission_id, '_download_id', $download_id); update_post_meta($commission_id, '_user_id', $recipient); update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id); //if we are dealing with a variation, then save variation info if (isset($variation)) { update_post_meta($commission_id, '_edd_commission_download_variation', $variation); } do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id); } } } } }
/** * Email template tag: updated_products_links * A list of updated products with download links included * * @access public * @param mixed $payment_id * @return void */ function edd_pup_products_links_tag_plain($payment_id, $email = null) { // Used to generate accurate tag outputs for preview and test emails if (isset($email) && absint($email) != 0) { $updated_products = get_post_meta($email, '_edd_pup_updated_products', true); $updated_products = is_array($updated_products) ? $updated_products : array($updated_products); foreach ($updated_products as $id => $name) { $customer_updates[$id] = array('id' => $id, 'name' => $name); } } else { $email = get_transient('edd_pup_sending_email_' . get_current_user_id()); $updated_products = get_post_meta($email, '_edd_pup_updated_products', true); $updated_products = is_array($updated_products) ? $updated_products : array($updated_products); $customer_updates = edd_pup_get_customer_updates($payment_id, $email); $customer_updates = is_array($customer_updates) ? $customer_updates : array($customer_updates); } $filters = get_post_meta($email, '_edd_pup_filters', true); if ($customer_updates) { $show_names = apply_filters('edd_pup_email_show_names', true); $payment_data = edd_get_payment_meta($payment_id); // Set email to most recent email if it's been changed from initial email if (isset($payment_data['user_info']['email']) && $payment_data['user_info']['email'] != $payment_data['email']) { $payment_data['email'] = $payment_data['user_info']['email']; } // Used for detecting when to place commas $c = 1; $download_list = ''; foreach ($customer_updates as $item) { if (edd_use_skus()) { $sku = edd_get_download_sku($item['id']); } $price_id = edd_get_cart_item_price_id($item); if ($show_names) { $title = $c == 1 ? $item['name'] : ', ' . $item['name']; if (!empty($sku)) { $title .= " – " . __('SKU', 'edd') . ': ' . $sku; } $download_list .= apply_filters('edd_pup_email_products_link_title_plain', $title, $item, $price_id, $payment_id); } $files = edd_get_download_files($item['id'], $price_id); if ($files) { // $f used for detecting when to place commas $f = 1; $download_list .= ' ('; foreach ($files as $filekey => &$file) { $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $item['id'], $price_id); $download_list .= $f == 1 ? edd_get_file_name($file) . ': ' . esc_url($file_url) : ', ' . edd_get_file_name($file) . ': ' . esc_url($file_url); $f++; } $download_list .= ')'; } if (edd_is_bundled_product($item['id'])) { $b = 1; $bundled_products = edd_get_bundled_products($item['id']); $download_list .= " – "; foreach ($bundled_products as $bundle_item) { if ($filters['bundle_1'] == 'all' || isset($updated_products[$bundle_item])) { $download_list .= $b == 1 ? get_the_title($bundle_item) : '; ' . get_the_title($bundle_item); $fb = 1; $bundlefiles = edd_get_download_files($bundle_item); $download_list .= ' ('; foreach ($bundlefiles as $bundlefilekey => $bundlefile) { $bundlefile_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $bundlefilekey, $bundle_item, $price_id); $download_list .= $fb == 1 ? $bundlefile['name'] . ': ' . esc_url($bundlefile_url) : ', ' . $bundlefile['name'] . ': ' . esc_url($bundlefile_url); $fb++; } $download_list .= ')'; } $b++; } } if ('' != edd_get_product_notes($item['id'])) { $download_list .= ' – ' . edd_get_product_notes($item['id']); } $c++; } return $download_list; } }
/** * Returns the link to the file available for download * * @since 0.1 */ function eddflg_build_download_url($payment_id) { $downloads = edd_get_payment_meta_cart_details($payment_id, true); $purchase_data = edd_get_payment_meta($payment_id); if ($downloads) { $price_id = edd_get_cart_item_price_id($downloads[0]); $download_files = edd_get_download_files($downloads[0]['id'], $price_id); } foreach ($download_files as $filekey => $file) { $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $downloads[0]['id'], $price_id); } return $download_url; }
/** * Is service * @param int $item_id ID of download * @return boolean true if service, false otherwise * @return boolean */ public function is_service($item_id) { global $edd_receipt_args, $edd_options; // get array of service categories $service_categories = isset($edd_options['edd_das_service_categories']) ? $edd_options['edd_das_service_categories'] : ''; $term_ids = array(); if ($service_categories) { foreach ($service_categories as $term_id => $term_name) { $term_ids[] = $term_id; } } $is_service = get_post_meta($item_id, '_edd_das_enabled', true); // get payment $payment = get_post($edd_receipt_args['id']); $meta = isset($payment) ? edd_get_payment_meta($payment->ID) : ''; $cart = isset($payment) ? edd_get_payment_meta_cart_details($payment->ID, true) : ''; if ($cart) { foreach ($cart as $key => $item) { $price_id = edd_get_cart_item_price_id($item); $download_files = edd_get_download_files($item_id, $price_id); // if the service has a file attached, we still want to show it if ($download_files) { return; } } } // check if download has meta key or has a service term assigned to it if ($is_service || has_term($term_ids, 'download_category', $item_id)) { return true; } return false; }
/** * Create license key * * @since 1.0.0 * @return void */ function edd_slm_create_license_keys($payment_id) { // Collect license keys $licenses = array(); // Payment meta $payment_meta = edd_get_payment_meta($payment_id); //edd_slm_print_pretty($payment_meta); foreach ($payment_meta['cart_details'] as $item) { $download_id = $item['id']; if (edd_slm_is_licensing_enabled($download_id)) { // Download data $download_data = edd_get_download($download_id); if ($download_data) { $download_quantity = absint($item['quantity']); for ($i = 1; $i <= $download_quantity; $i++) { // Get price id $price_id = edd_get_cart_item_price_id($item); $price_name = edd_get_cart_item_price_name($item); // Sites allowed $sites_allowed = edd_slm_get_sites_allowed($price_id, $payment_id, $download_id); if (!$sites_allowed) { $sites_allowed_error = __('License could not be created: Invalid sites allowed number.', 'edd-slm'); $int = edd_insert_payment_note($payment_id, $sites_allowed_error); break; } // Transaction id $transaction_id = edd_get_payment_transaction_id($payment_id); // Build item name $item_name = !empty($price_name) ? $item['name'] . ' - ' . $price_name : $item['name']; // Build parameters $api_params = array(); $api_params['slm_action'] = 'slm_create_new'; $api_params['secret_key'] = EDD_SLM_API_SECRET; $api_params['first_name'] = isset($payment_meta['user_info']['first_name']) ? $payment_meta['user_info']['first_name'] : ''; $api_params['last_name'] = isset($payment_meta['user_info']['last_name']) ? $payment_meta['user_info']['last_name'] : ''; $api_params['email'] = isset($payment_meta['user_info']['email']) ? $payment_meta['user_info']['email'] : ''; $api_params['company_name'] = ''; $api_params['txn_id'] = $transaction_id . ' - ' . $item_name; $api_params['max_allowed_domains'] = $sites_allowed; $api_params['date_created'] = date('Y-m-d'); $api_params['date_expiry'] = '0000-00-00'; // Send query to the license manager server $url = EDD_SLM_API_URL . '?' . http_build_query($api_params); $response = wp_remote_get($url, array('timeout' => 30)); edd_slm_add_log('Item: ' . $item_name); edd_slm_add_log('- SLM Response Body: ' . $response['body']); foreach ($response['response'] as $key => $value) { edd_slm_add_log('- SLM Response ' . $key . ': ' . $value); } // Get license key $license_key = edd_slm_get_license_key($response); // Collect license keys if ($license_key) { $licenses[] = array('item' => $item_name, 'key' => $license_key); } } } } } // Payment note edd_slm_payment_note($payment_id, $licenses); // Assign licenses edd_slm_assign_licenses($payment_id, $licenses); }