function eStore_check_stamping_flag_and_generate_download_key($retrieved_product, $product_id, $url = '', $payment_data = '')
{
    if ($retrieved_product->use_pdf_stamper == 1 && !empty($payment_data)) {
        if (WP_ESTORE_STAMP_PDF_FILE_AT_DOWNLOAD_TIME === '1') {
            //Check if file sould be stamped at download time option is enabled
            $download_key = eStore_generate_download_key($product_id, $url);
            return $download_key;
        }
        if (!empty($url)) {
            $src_file = $url;
        } else {
            $src_file = $retrieved_product->product_download_url;
        }
        eStore_payment_debug('Stamping request for product ID: ' . $product_id, true);
        //Check if it is a multiple file URL product
        $multi_file_product = false;
        $product_urls = explode(',', $retrieved_product->product_download_url);
        if (sizeof($product_urls) > 1) {
            $multi_file_product = true;
        }
        $txn_id = $payment_data['txn_id'];
        $force_restamp = false;
        if (isset($payment_data['force_restamp']) && $payment_data['force_restamp'] == '1') {
            //Don't lookup cached copy
            eStore_payment_debug('Force restamping is enabled in the request.', true);
            $force_restamp = true;
        }
        if (!empty($txn_id) && !$multi_file_product && !$force_restamp) {
            eStore_payment_debug('Checking for a reference to the stamped copy of the file for this transaction before invoking another stamp request:' . $txn_id, true);
            $cond = " txn_id = '{$txn_id}'";
            $result = WP_eStore_Db_Access::findAll(WP_ESTORE_DOWNLOAD_LINKS_TABLE_NAME, $cond);
            if ($result) {
                eStore_payment_debug('Found a reference to the stamped copy of a file. Performing an indepth check...', true);
                $random_key = get_option('eStore_random_code');
                foreach ($result as $download_item) {
                    $download_key = $download_item->download_key;
                    eStore_payment_debug('Decrypting download key: ' . $download_key, true);
                    $decrypted_data = RC4Crypt::decrypt($random_key, base64_decode(rawurldecode($download_key)));
                    list($product_id_of_stamped_file, $timestamp, $stamped_file_url) = explode('|', $decrypted_data);
                    eStore_payment_debug('Decrypted data... Product ID: ' . $product_id_of_stamped_file . ', Stamped File URL:' . $stamped_file_url, true);
                    if ($product_id == $product_id_of_stamped_file) {
                        eStore_payment_debug('Product IDs match. Using the existing stamped copy of the file.', true);
                        $new_download_key = eStore_generate_download_key($product_id_of_stamped_file, $stamped_file_url);
                        eStore_payment_debug('New Download Key: ' . $new_download_key, true);
                        return $new_download_key;
                    }
                }
                eStore_payment_debug('Product IDs do not match. Need to proceed with a fresh stamping.', true);
            } else {
                eStore_payment_debug('Could not find a reference to the stamped copy of a file', true);
            }
        }
        $stamped_file_url = eStore_stamp_pdf_file($payment_data, $src_file);
        if ($stamped_file_url === 'Error!') {
            eStore_payment_debug('PDF Stamping did not finish correctly!', false);
            $download_key = "Error with PDF stamping (Error code: PDF01). Perform a manual stamping and make sure the PDF stamper is working on your server.";
            return $download_key;
        }
        $download_key = eStore_generate_download_key($product_id, $stamped_file_url);
    } else {
        $download_key = eStore_generate_download_key($product_id, $url);
    }
    return $download_key;
}
Esempio n. 2
0
 $eStore_debug_manager->downloads('PDF File stamping at download time feature is enabled. Checking if file need to be stamped. File Key: ' . $file_key, ESTORE_LEVEL_SUCCESS);
 if ($retrieved_product->use_pdf_stamper == 1) {
     $eStore_debug_manager->downloads('PDF stamping is enabled for this product. Preparing to stamp the file.', ESTORE_LEVEL_SUCCESS);
     $cond = " download_key = '{$file_key}'";
     $resultset = WP_eStore_Db_Access::find(WP_ESTORE_DOWNLOAD_LINKS_TABLE_NAME, $cond);
     if ($resultset) {
         $transaction_id = $resultset->txn_id;
         $eStore_debug_manager->downloads('Retrieved the transaction ID of the corresponding transaction. Txn ID: ' . $transaction_id, ESTORE_LEVEL_SUCCESS);
         $customer_table_name = WP_ESTORE_CUSTOMER_TABLE_NAME;
         $customer_data_rs = $wpdb->get_row("SELECT * FROM {$customer_table_name} WHERE txn_id = '{$transaction_id}'", OBJECT);
         if ($customer_data_rs) {
             $eStore_debug_manager->downloads('Retrieved the customer data for this transaction. Customer email ' . $customer_data->email_address, ESTORE_LEVEL_SUCCESS);
             $payment_data = eSore_create_payment_data_from_customer_resultset($customer_data_rs);
             $src_file = $file_path;
             //$retrieved_product->product_download_url;
             $stamped_file_url = eStore_stamp_pdf_file($payment_data, $src_file);
             if ($stamped_file_url === 'Error!') {
                 $stamping_error = 'PDF Stamping did not finish correctly! Perform a manual stamping from PDF stamper admin menu and make sure the PDF stamper is working on your server.';
                 $eStore_debug_manager->downloads($stamping_error, ESTORE_LEVEL_FAILURE);
                 eStore_dlvs::error($stamping_error);
                 exit;
             }
             $file_path = $stamped_file_url;
             $eStore_debug_manager->downloads('File stamped successfully. Stamped file URL: ' . $file_path, ESTORE_LEVEL_SUCCESS);
         } else {
             $stamping_error = "Failed to retrieve customer data for the given transaction ID! Make sure you made a live transaction before exercising the download option with PDF stamping. PDF file stamping does not work unless real customer details is present from the gateway transaction.";
             $eStore_debug_manager->downloads($stamping_error, ESTORE_LEVEL_FAILURE);
             eStore_dlvs::error($stamping_error);
             exit;
         }
     } else {