function edd_process_paytm_gateway_ipn()
{
    global $edd_options;
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
        return;
    }
    $payment_id = $_GET['payment_id'];
    if (empty($payment_id)) {
        edd_send_back_to_checkout('?payment-mode=paytm_gateway');
    }
    // Fallback just in case post_max_size is lower than needed
    if (isset($_POST['ORDERID']) && isset($_POST['RESPCODE'])) {
        $order_sent = $_POST['ORDERID'];
        $responseDescription = $_POST['RESPMSG'];
        if ($_POST['RESPCODE'] == '01') {
            // success
            $order_sent = $_POST['ORDERID'];
            $res_code = $_POST['RESPCODE'];
            $responseDescription = $_POST['RESPMSG'];
            $checksum_recv = $_POST['CHECKSUMHASH'];
            $paramList = $_POST;
            $order_amount = $_POST['TXNAMOUNT'];
            //  code by paytm team
            $bool = "FALSE";
            $secret_key = $edd_options['paytm_mer_access_key'];
            $bool = verifychecksum_e($paramList, $secret_key, $checksum_recv);
            if ($bool == "TRUE") {
                $payment_meta = edd_get_payment_meta($payment_id);
                edd_insert_payment_note($payment_id, sprintf(__('Thank you for your order . Your transaction has been successful. Paytm Transaction ID: %s', 'edd'), $_REQUEST['TXNID']));
                edd_set_payment_transaction_id($payment_id, $_REQUEST['TXNID']);
                edd_update_payment_status($payment_id, 'complete');
                edd_empty_cart();
                edd_send_to_success_page();
            } else {
                edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed Invalid Checksum', 'edd'), ''), $payment_id);
                edd_update_payment_status($payment_id, 'failed');
                edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed Invalid Checksum', 'edd'), ''));
                wp_redirect('?page_id=6&payment-mode=paytm_gateway');
                //edd_send_back_to_checkout( '?payment-mode=paytm_gateway' );
            }
        } else {
            edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed. %s', 'edd'), $responseDescription), $payment_id);
            edd_update_payment_status($payment_id, 'failed');
            edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed. %s', 'edd'), $responseDescription));
            wp_redirect('?page_id=6&payment-mode=paytm_gateway');
        }
    } else {
        edd_record_gateway_error(__('Paytm Error', 'edd'), sprintf(__('Transaction Failed, No Response ', 'edd'), ''), $payment_id);
        edd_update_payment_status($payment_id, 'failed');
        edd_insert_payment_note($payment_id, sprintf(__('Transaction Failed, No Response ', 'edd'), ''));
        wp_redirect('?page_id=6&payment-mode=paytm_gateway');
    }
    exit;
}
 /**
  * Processes the "signup" IPN notice
  *
  * @since  1.0
  * @return void
  */
 public static function process_paypal_subscr_signup($ipn_data)
 {
     $parent_payment_id = absint($ipn_data['custom']);
     edd_update_payment_status($parent_payment_id, 'publish');
     // Record transaction ID
     edd_insert_payment_note($parent_payment_id, sprintf(__('PayPal Subscription ID: %s', 'edd-recurring'), $ipn_data['subscr_id']));
     // Store the IPN track ID
     update_post_meta($parent_payment_id, '_edd_recurring_ipn_track_id', $ipn_data['ipn_track_id']);
     $user_id = edd_get_payment_user_id($ipn_data['custom']);
     // Set user as subscriber
     EDD_Recurring_Customer::set_as_subscriber($user_id);
     // store the customer recurring ID
     EDD_Recurring_Customer::set_customer_id($user_id, $ipn_data['payer_id']);
     // Store the original payment ID in the customer meta
     EDD_Recurring_Customer::set_customer_payment_id($user_id, $ipn_data['custom']);
     // Set the customer's status to active
     EDD_Recurring_Customer::set_customer_status($user_id, 'active');
     // Calculate the customer's new expiration date
     $new_expiration = EDD_Recurring_Customer::calc_user_expiration($user_id, $parent_payment_id);
     // Set the customer's new expiration date
     EDD_Recurring_Customer::set_customer_expiration($user_id, $new_expiration);
 }
示例#3
0
 /**
  * Insert payment note
  *
  * @access  public
  * @since   1.3.1
  */
 public function insert_payment_note($payment_id = 0)
 {
     $referral = affiliate_wp()->referrals->get_by('reference', $payment_id, $this->context);
     if (empty($referral)) {
         return;
     }
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $affiliate_id = $referral->affiliate_id;
     $name = affiliate_wp()->affiliates->get_affiliate_name($affiliate_id);
     edd_insert_payment_note($payment_id, sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name));
 }
function pw_edd_process_payment($purchase_data)
{
    global $edd_options;
    /**********************************
     * set transaction mode
     **********************************/
    if (edd_is_test_mode()) {
        // set test credentials here
    } else {
        // set live credentials here
    }
    /**********************************
     * check for errors here
     **********************************/
    /*
    // errors can be set like this
    if( ! isset($_POST['card_number'] ) ) {
    	// error code followed by error message
    	edd_set_error('empty_card', __('You must enter a card number', 'edd'));
    }
    */
    /**********************************
    	* Purchase data comes in like this:
    
        $purchase_data = array(
            'downloads'     => array of download IDs,
            'tax' 			=> taxed amount on shopping cart
            'fees' 			=> array of arbitrary cart fees
            'discount' 		=> discounted amount, if any
            'subtotal'		=> total price before tax
            'price'         => total price of cart contents after taxes,
            'purchase_key'  =>  // Random key
            'user_email'    => $user_email,
            'date'          => date( 'Y-m-d H:i:s' ),
            'user_id'       => $user_id,
            'post_data'     => $_POST,
            'user_info'     => array of user's information and used discount code
            'cart_details'  => array of cart details,
         );
        */
    // check for any stored errors
    $errors = edd_get_errors();
    if (!$errors) {
        $purchase_summary = edd_get_purchase_summary($purchase_data);
        /****************************************
         * setup the payment details to be stored
         ****************************************/
        $payment = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => $edd_options['currency'], 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
        // record the pending payment
        $payment = edd_insert_payment($payment);
        $merchant_payment_confirmed = false;
        /**********************************
         * Process the credit card here.
         * If not using a credit card
         * then redirect to merchant
         * and verify payment with an IPN
         **********************************/
        // if the merchant payment is complete, set a flag
        $merchant_payment_confirmed = true;
        if ($merchant_payment_confirmed) {
            // this is used when processing credit cards on site
            // once a transaction is successful, set the purchase to complete
            edd_update_payment_status($payment, 'complete');
            // record transaction ID, or any other notes you need
            edd_insert_payment_note($payment, 'Transaction ID: XXXXXXXXXXXXXXX');
            // go to the success page
            edd_send_to_success_page();
        } else {
            $fail = true;
            // payment wasn't recorded
        }
    } else {
        $fail = true;
        // errors were detected
    }
    if ($fail !== false) {
        // if errors are present, send the user back to the purchase page so they can be corrected
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    }
}
/**
 * Update Edited Purchase
 *
 * Updates the purchase data for a payment.
 * Used primarily for adding new downloads to a purchase.
 *
 * @since 1.0
 * @param $data Arguments passed
 * @return void
 */
function edd_update_edited_purchase($data)
{
    if (wp_verify_nonce($data['edd-payment-nonce'], 'edd_payment_nonce')) {
        $payment_id = $_POST['payment-id'];
        $payment_data = edd_get_payment_meta($payment_id);
        if (isset($_POST['edd-purchased-downloads'])) {
            $download_list = array();
            foreach ($_POST['edd-purchased-downloads'] as $key => $download) {
                if (isset($download['options']['price_id'])) {
                    $download_list[] = array('id' => $key, 'options' => array('price_id' => $download['options']['price_id']));
                } else {
                    $download_list[] = array('id' => $download);
                }
            }
            $payment_data['downloads'] = serialize($download_list);
        }
        $user_info = maybe_unserialize($payment_data['user_info']);
        $user_info['email'] = strip_tags($_POST['edd-buyer-email']);
        $user_info['user_id'] = strip_tags(intval($_POST['edd-buyer-user-id']));
        $payment_data['user_info'] = serialize($user_info);
        update_post_meta($payment_id, '_edd_payment_meta', $payment_data);
        update_post_meta($payment_id, '_edd_payment_user_email', strip_tags($_POST['edd-buyer-email']));
        update_post_meta($payment_id, '_edd_payment_user_id', strip_tags(intval($_POST['edd-buyer-user-id'])));
        if (!empty($_POST['edd-payment-note'])) {
            $note = wp_kses($_POST['edd-payment-note'], array());
            $note_id = edd_insert_payment_note($payment_id, $note);
        }
        if (!empty($_POST['edd-payment-amount'])) {
            update_post_meta($payment_id, '_edd_payment_total', sanitize_text_field(edd_sanitize_amount($_POST['edd-payment-amount'])));
        }
        if (!empty($_POST['edd-unlimited-downloads'])) {
            add_post_meta($payment_id, '_unlimited_file_downloads', '1');
        } else {
            delete_post_meta($payment_id, '_unlimited_file_downloads');
        }
        if ($_POST['edd-old-status'] != $_POST['edd-payment-status']) {
            edd_update_payment_status($payment_id, $_POST['edd-payment-status']);
        }
        if ($_POST['edd-payment-status'] == 'publish' && isset($_POST['edd-payment-send-email'])) {
            // Send the purchase receipt
            edd_email_purchase_receipt($payment_id, false);
        }
        do_action('edd_update_edited_purchase', $payment_id);
    }
}
/**
 * Record payment status change
 *
 * @since 1.4.3
 * @param int $payment_id the ID number of the payment
 * @param string $new_status the status of the payment, probably "publish"
 * @param string $old_status the status of the payment prior to being marked as "complete", probably "pending"
 * @return void
 */
function edd_record_status_change($payment_id, $new_status, $old_status)
{
    // Get the list of statuses so that status in the payment note can be translated
    $stati = edd_get_payment_statuses();
    $old_status = isset($stati[$old_status]) ? $stati[$old_status] : $old_status;
    $new_status = isset($stati[$new_status]) ? $stati[$new_status] : $new_status;
    $status_change = sprintf(__('Status changed from %s to %s', 'edd'), $old_status, $new_status);
    edd_insert_payment_note($payment_id, $status_change);
}
示例#7
0
 /**
  * Mark payments as Failed when returning to the Failed Transaction page
  * @return      void
  */
 public function voguepay_listen_for_failed_payments()
 {
     $failed_page = edd_get_option('failure_page', 0);
     if (!empty($failed_page) && is_page($failed_page) && !empty($_GET['payment-id'])) {
         $payment_id = absint($_GET['payment-id']);
         if (!empty($_POST)) {
             // create payment note for failed transaction.
             $payment_note = sprintf(__('voguepay Reference ID: %s <br> Merchant Reference ID: %s', 'edd-voguepay'), $_POST['voguepay_refID'], $_POST['merchant_ref']);
             $payment_note .= '<br> Message: ' . $_POST['status_msg'];
             edd_insert_payment_note($payment_id, $payment_note);
             edd_set_payment_transaction_id($payment_id, $post_data['voguepay_refID']);
         }
     }
 }
function sofort_ipn()
{
    global $edd_options;
    if (isset($_GET['sofort']) && $_GET['sofort'] == 'ipn') {
        require_once 'library/sofortLib.php';
        $notification = new SofortLib_Notification();
        $notification->getNotification();
        $transactionId = $notification->getTransactionId();
        if ($transactionId) {
            // fetch some information for the transaction id retrieved above
            $transactionData = new SofortLib_TransactionData(trim($edd_options['sofort_config_id']));
            $transactionData->setTransaction($transactionId);
            $transactionData->sendRequest();
            $reason = $transactionData->getReason();
            $payment_id = str_replace('CartId ', '', $reason[0]);
            edd_update_payment_status($payment_id, 'publish');
            edd_insert_payment_note($payment_id, 'Payment Successful. Transaction ID is ' . $transactionId);
        }
        exit;
    }
}
 /**
  * Remove an order from MailChimp if the payment was refunded
  *
  * @return bool
  */
 public function delete_ecommerce360_purchase($payment_id, $new_status, $old_status)
 {
     if ('publish' != $old_status && 'revoked' != $old_status) {
         return;
     }
     if ('refunded' != $new_status) {
         return;
     }
     // Make sure an API key has been entered
     if (empty($this->key)) {
         return FALSE;
     }
     // Send to MailChimp
     $options = array('CURLOPT_FOLLOWLOCATION' => false);
     $mailchimp = new EDD_MailChimp_API($this->key, $options);
     try {
         $result = $mailchimp->call('ecomm/order-del', array('store_id' => self::_edd_ec360_get_store_id(), 'order_id' => $payment_id));
         edd_insert_payment_note($payment_id, __('Order details have been removed from MailChimp successfully', 'eddmc'));
         return TRUE;
     } catch (Exception $e) {
         edd_insert_payment_note($payment_id, __('MailChimp Ecommerce360 Error: ', 'eddmc') . $e->getMessage());
         return FALSE;
     }
 }
示例#10
0
/**
 * Process the license upgrade during purchase
 *
 * @since 3.3
 * @return void
 */
function edd_sl_process_license_upgrade($download_id = 0, $payment_id = 0, $type = 'default', $cart_item = array(), $cart_index = 0)
{
    // Bail if this is not a renewal item
    if (empty($cart_item['item_number']['options']['is_upgrade'])) {
        return;
    }
    $license_id = $cart_item['item_number']['options']['license_id'];
    $upgrade_id = $cart_item['item_number']['options']['upgrade_id'];
    $upgrade = edd_sl_get_upgrade_path($download_id, $upgrade_id);
    $old_payment_ids = get_post_meta($license_id, '_edd_sl_payment_id');
    $old_payment_id = end($old_payment_ids);
    // We only want the most recent one
    $old_download_id = edd_software_licensing()->get_download_id($license_id);
    $old_price_id = edd_software_licensing()->get_price_id($license_id);
    $purchase_date = get_post_field('post_date', $old_payment_id);
    if (edd_is_bundled_product($download_id)) {
        // Upgrade to a bundle from a standard license
        $downloads = array();
        $bundle_licensing = (bool) get_post_meta($download_id, '_edd_sl_enabled', true);
        $parent_license_id = 0;
        $activation_limit = false;
        $user_info = edd_get_payment_meta_user_info($payment_id);
        if ($bundle_licensing) {
            $downloads[] = $download_id;
        }
        $downloads = array_merge($downloads, edd_get_bundled_products($download_id));
        if (edd_has_variable_prices($download_id)) {
            $activation_limit = edd_software_licensing()->get_price_activation_limit($download_id, $cart_item['item_number']['options']['price_id']);
            $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $cart_item['item_number']['options']['price_id']);
        }
        foreach ($downloads as $d_id) {
            if ((int) $d_id === (int) $old_download_id) {
                continue;
            }
            if (!get_post_meta($d_id, '_edd_sl_enabled', true)) {
                continue;
            }
            $license_title = get_the_title($d_id) . ' - ' . $user_info['email'];
            $license_args = array('post_type' => 'edd_license', 'post_title' => $license_title, 'post_status' => 'publish', 'post_date' => get_post_field('post_date', $payment_id, 'raw'));
            if ($parent_license_id) {
                $license_args['post_parent'] = $parent_license_id;
            }
            $l_id = wp_insert_post(apply_filters('edd_sl_insert_license_args', $license_args));
            if ($bundle_licensing && $download_id == $d_id && !$parent_license_id) {
                $parent_license_id = $l_id;
            }
            $license_key = edd_software_licensing()->get_new_download_license_key($d_id);
            if (!$license_key) {
                // No predefined license key available, generate a random one
                $license_key = edd_software_licensing()->generate_license_key($l_id, $d_id, $payment_id, $cart_index);
            }
            $price_id = isset($cart_item['item_number']['options']['price_id']) ? (int) $cart_item['item_number']['options']['price_id'] : false;
            add_post_meta($l_id, '_edd_sl_download_id', $d_id);
            if (false !== $price_id) {
                add_post_meta($l_id, '_edd_sl_download_price_id', $price_id);
            }
            add_post_meta($l_id, '_edd_sl_cart_index', $cart_index);
            add_post_meta($l_id, '_edd_sl_payment_id', $payment_id);
            add_post_meta($l_id, '_edd_sl_key', $license_key);
            add_post_meta($l_id, '_edd_sl_user_id', $user_info['id']);
            add_post_meta($l_id, '_edd_sl_status', 'inactive');
            add_post_meta($l_id, '_edd_sl_site_count', 0);
            if ($parent_license_id && !empty($activation_limit)) {
                add_post_meta($l_id, '_edd_sl_limit', $activation_limit);
            }
            // Get license length
            $license_length = edd_software_licensing()->get_license_length($l_id, $payment_id, $d_id);
            if (empty($is_lifetime) && 'lifetime' !== $license_length) {
                // Set license expiration date
                delete_post_meta($l_id, '_edd_sl_is_lifetime');
                edd_software_licensing()->set_license_expiration($l_id, strtotime($license_length, strtotime($purchase_date)));
            } else {
                edd_software_licensing()->set_license_as_lifetime($l_id);
            }
            do_action('edd_sl_store_license', $l_id, $d_id, $payment_id, $type);
        }
        // Now update the original license
        wp_update_post(array('ID' => $license_id, 'post_parent' => $parent_license_id));
        update_post_meta($license_id, '_edd_sl_cart_index', $cart_index);
        add_post_meta($license_id, '_edd_sl_payment_id', $payment_id);
    } else {
        // Standard license upgrade
        $new_title = get_the_title($download_id) . ' - ' . edd_get_payment_user_email($payment_id);
        wp_update_post(array('ID' => $license_id, 'post_title' => $new_title));
        update_post_meta($license_id, '_edd_sl_cart_index', $cart_index);
        add_post_meta($license_id, '_edd_sl_payment_id', $payment_id);
        update_post_meta($license_id, '_edd_sl_download_id', $download_id);
        if (edd_has_variable_prices($download_id)) {
            $limit = edd_software_licensing()->get_price_activation_limit($download_id, $upgrade['price_id']);
            $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $upgrade['price_id']);
            update_post_meta($license_id, '_edd_sl_download_price_id', $upgrade['price_id']);
        } else {
            $limit = edd_software_licensing()->get_license_limit($download_id, $license_id);
        }
        update_post_meta($license_id, '_edd_sl_limit', $limit);
        $license_length = edd_software_licensing()->get_license_length($license_id, $payment_id, $download_id);
        if (empty($is_lifetime) && 'lifetime' !== $license_length) {
            // Set license expiration date
            delete_post_meta($license_id, '_edd_sl_is_lifetime');
            edd_software_licensing()->set_license_expiration($license_id, strtotime($license_length, strtotime($purchase_date)));
        } else {
            edd_software_licensing()->set_license_as_lifetime($license_id);
        }
    }
    // Now store upgrade details / notes on payments
    $old_product = get_the_title($old_download_id);
    if (false !== $old_price_id) {
        $old_product .= ' - ' . edd_get_price_option_name($old_download_id, $old_price_id);
    }
    $new_product = get_the_title($download_id);
    if (edd_has_variable_prices($download_id)) {
        $new_product .= ' - ' . edd_get_price_option_name($download_id, $upgrade['price_id']);
    }
    $note = sprintf(__('License upgraded from %s to %s', 'edd_sl'), $old_product, $new_product);
    edd_insert_payment_note($payment_id, $note);
    update_post_meta($payment_id, '_edd_sl_upgraded_payment_id', $old_payment_id);
    update_post_meta($old_payment_id, '_edd_sl_upgraded_to_payment_id', $payment_id);
}
 /**
  * Add a note to a payment
  *
  * @since 2.5
  * @param string $note The note to add
  * @return void
  */
 public function add_note($note = false)
 {
     // Bail if no note specified
     if (!$note) {
         return false;
     }
     edd_insert_payment_note($this->ID, $note);
 }
 function gourledd_gourlcallback($user_id, $order_id, $payment_details, $box_status)
 {
     if (!in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated"))) {
         return false;
     }
     if (strpos($order_id, "order") === 0) {
         $payment_id = substr($order_id, 5);
     } else {
         return false;
     }
     if (!$user_id || $payment_details["status"] != "payment_received") {
         return false;
     }
     $payment = get_post($payment_id);
     if (!$payment || !$payment->post_status) {
         return false;
     }
     $coinName = ucfirst($payment_details["coinname"]);
     $amount = $payment_details["amount"] . " " . $payment_details["coinlabel"] . "&#160; ( \$" . $payment_details["amountusd"] . " )";
     $payID = $payment_details["paymentID"];
     $confirmed = $payment_details["is_confirmed"] ? __('Yes', GOURLEDD) : __('No', GOURLEDD);
     // a. New Payment Received - Awaiting Transaction Confirmation...
     if ($box_status == "cryptobox_newrecord") {
         // Save Log
         edd_insert_payment_note($payment_id, sprintf(__("<b>%s</b> Payment Received <br/>%s <br/><a href='%s'>Payment ID: %s</a>. <br/>Awaiting network confirmation...", GOURLEDD), __($coinName, GOURLEDD), $amount, GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID) . ' <br/>');
         edd_set_payment_transaction_id($payment_id, $payment_details["tx"]);
     }
     // b. Existing Payment Confirmed (6+ transaction confirmations)
     if ($payment_details["is_confirmed"]) {
         // Save Log
         edd_insert_payment_note($payment_id, sprintf(__("%s Payment ID: <a href='%s'>%s</a> - <b>Confirmed</b>", GOURLEDD), __($coinName, GOURLEDD), GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID) . ' <br/>');
     }
     // c. Update Status to Completed
     if ($payment->post_status != 'publish') {
         edd_update_payment_status($payment_id, 'publish');
     }
     return true;
 }
示例#13
0
/**
 * Email the product update to the customer in a customizable message
 *
 * @param int $payment_id Payment ID
 * @param int $email_id Email ID for a edd_pup_email post-type
 * @return void
 */
function edd_pup_ajax_send_email($payment_id, $email_id, $test_mode = null)
{
    $userid = get_current_user_id();
    $emailpost = get_post($email_id);
    $emailmeta = get_post_custom($email_id);
    $payment_data = edd_get_payment_meta($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $from_name = $emailmeta['_edd_pup_from_name'][0];
    $from_email = $emailmeta['_edd_pup_from_email'][0];
    $attachments = apply_filters('edd_pup_attachments', array(), $payment_id, $payment_data);
    $lognotes = edd_get_option('edd_pup_log_notes');
    add_filter('edd_email_template', 'edd_pup_template');
    /* If subject doesn't use tags (and thus is the same for each customer)
     * then store it in a transient for quick access on subsequent loops. */
    $subject = get_transient('edd_pup_subject_' . $userid);
    if (false === $subject || $emailmeta['_edd_pup_subject'][0] != $subject) {
        if (empty($emailmeta['_edd_pup_subject'][0])) {
            $subject = '(no subject)';
            wp_update_post(array('ID' => $email_id, 'post_excerpt' => $subject));
            update_post_meta($email_id, '_edd_pup_subject', $subject);
            set_transient('edd_pup_subject_' . $userid, $subject, 60 * 60);
        } else {
            $subject = edd_do_email_tags($emailmeta['_edd_pup_subject'][0], $payment_id);
            if ($subject == $emailmeta['_edd_pup_subject'][0]) {
                set_transient('edd_pup_subject_' . $userid, $subject, 60 * 60);
            }
        }
    }
    if (version_compare(get_option('edd_version'), '2.1') >= 0) {
        $edd_emails = new EDD_emails();
        $message = edd_do_email_tags($emailpost->post_content, $payment_id);
        $edd_emails->__set('from_name', $from_name);
        $edd_emails->__set('from_address', $from_email);
        $mailresult = isset($test_mode) ? true : $edd_emails->send($email, $subject, $message, $attachments);
    } else {
        $email_body_header = get_transient('edd_pup_email_body_header_' . $userid);
        if (false === $email_body_header) {
            $email_body_header = edd_get_email_body_header();
            set_transient('edd_pup_email_body_header_' . $userid, $email_body_header, 60 * 60);
        }
        $email_body_footer = get_transient('edd_pup_email_body_footer_' . $userid);
        if (false === $email_body_footer) {
            $email_body_footer = edd_get_email_body_footer();
            set_transient('edd_pup_email_body_footer_' . $userid, $email_body_footer, 60 * 60);
        }
        $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
        $headers .= "Reply-To: " . $from_email . "\r\n";
        $headers .= "Content-Type: text/html; charset=utf-8\r\n";
        $message = $email_body_header;
        $message .= apply_filters('edd_pup_message', edd_email_template_tags($emailpost->post_content, $payment_data, $payment_id), $payment_id, $payment_data);
        $message .= $email_body_footer;
        $mailresult = isset($test_mode) ? true : wp_mail($email, $subject, $message, $headers, $attachments);
    }
    // Update payment notes to log this email being sent
    if (!isset($lognotes['sent'])) {
        edd_insert_payment_note($payment_id, 'Sent product update email "' . $subject . '" <a href="' . admin_url('edit.php?post_type=download&page=edd-prod-updates&view=view_pup_email&id=' . $email_id) . '">View Email</a>');
    }
    return $mailresult;
}
示例#14
0
function edd_ti_send_tracking($post)
{
    $nonce = !empty($post['nonce']) ? $post['nonce'] : false;
    if (!wp_verify_nonce($nonce, 'edd-ti-send-tracking')) {
        wp_die();
    }
    $tracking_id = edd_ti_get_payment_tracking_id($post['payment_id']);
    if (empty($tracking_id)) {
        return;
    }
    $from_name = edd_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES));
    $from_email = edd_get_option('from_email', get_bloginfo('admin_email'));
    $to_email = edd_get_payment_user_email($post['payment_id']);
    $subject = 'Your order has shipped';
    $heading = 'Your order has shipped!';
    $message = '<p>Your recent order ' . $post['payment_id'] . ' has been shipped.</p>';
    $message .= '<p>Tracking ID: <a href="' . edd_ti_get_payment_tracking_link($post['payment_id']) . '">' . $tracking_id . '</a></p>';
    $message .= '<p>Thank you!</p>';
    $message .= '<p>The ' . $from_name . ' team</p>';
    $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n";
    $headers .= "Reply-To: " . $from_email . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $attachments = array();
    $emails = EDD()->emails;
    $emails->__set('from_name', $from_name);
    $emails->__set('from_email', $from_email);
    $emails->__set('heading', $heading);
    $emails->__set('headers', $headers);
    $result = $emails->send($to_email, $subject, $message, $attachments);
    $response = array('success' => $result);
    $response['message'] = $result ? __('Email sent.', 'edd-tracking-info') : __('Error sending email. Try again later.', 'edd-tracking-info');
    if ($result) {
        edd_update_payment_meta($post['payment_id'], 'edd_tracking_info_sent', true);
        edd_insert_payment_note($post['payment_id'], sprintf(__('Tracking information sent to %s.', 'edd-tracking-info'), $to_email));
    }
    echo json_encode($response);
    die;
}
 /**
  * The $purchase_data array consists of the following data:
  *
  * $purchase_data = array(
  *   'downloads'    => array of download IDs,
  *   'tax'          => taxed amount on shopping cart
  *   'subtotal'     => total price before tax
  *   'price'        => total price of cart contents after taxes,
  *   'purchase_key' => Random key
  *   'user_email'   => $user_email,
  *   'date'         => date( 'Y-m-d H:i:s' ),
  *   'user_id'      => $user_id,
  *   'post_data'    => $_POST,
  *   'user_info'    => array of user's information and used discount code
  *   'cart_details' => array of cart details,
  * );
  */
 public function process_purchase($purchase_data)
 {
     $config_id = edd_get_option($this->id . '_config_id');
     // 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' => $this->id, 'status' => 'pending');
     // Record the pending payment
     $payment_id = edd_insert_payment($payment_data);
     // Check payment
     if (!$payment_id) {
         // Log error
         edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id);
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         $data = new Pronamic_WP_Pay_Extensions_EDD_PaymentData($payment_id, $payment_data);
         $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id);
         if ($gateway) {
             // Start
             $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method);
             $error = $gateway->get_error();
             if (is_wp_error($error)) {
                 edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id);
                 edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message());
                 foreach ($error->get_error_messages() as $i => $message) {
                     edd_set_error('pronamic_pay_error_' . $i, $message);
                 }
                 edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
             } else {
                 // Transaction ID
                 // @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.3/includes/payments/functions.php#L1400-L1416
                 edd_set_payment_transaction_id($payment_id, $payment->get_transaction_id());
                 // Payment note
                 $payment_link = add_query_arg(array('post' => $payment->get_id(), 'action' => 'edit'), admin_url('post.php'));
                 $note = sprintf(__('Payment %s pending.', 'pronamic_ideal'), sprintf('<a href="%s">#%s</a>', $payment_link, $payment->get_id()));
                 edd_insert_payment_note($payment_id, $note);
                 $gateway->redirect($payment);
                 exit;
             }
         } else {
             edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message());
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
     }
 }
 /**
  * Record notes on failed payments
  *
  * Once payments have attempted to be processed, any payments
  * that still failed shold record a note on that payment.
  *
  * @since Astoundify Crowdfunding 1.8
  *
  * @return void
  */
 function log_failed()
 {
     if (empty($this->failed_payments)) {
         return;
     }
     foreach ($this->failed_payments as $gateway => $payments) {
         foreach ($payments['payments'] as $payment_id) {
             edd_insert_payment_note($payment_id, apply_filters('atcf_failed_payment_note', sprintf(__('Error processing preapproved payment via %s when automatically collecting funds.', 'atcf'), $gateway)));
             // Allow plugins to do other things when a payment fails
             do_action('atcf_failed_payment', $payment_id, $gateway);
         }
     }
 }
示例#17
0
/**
 * Unsubscribe or resubscribe a customer, update their payment log, and
 * then show them the appropriate message
 * 
 * @access public
 * @param mixed $payment_id
 * @param mixed $purchase_key
 * @param mixed $email
 * @param mixed $action    either prod_update_unsub or prod_update_resub
 * @return void
 */
function edd_pup_unsub_page($payment_id, $purchase_key, $email, $action)
{
    $payment_meta = edd_get_payment_meta($payment_id);
    $lognotes = edd_get_option('edd_pup_log_notes');
    // Only update payment info if user is currently subscribed for updates
    if (edd_pup_unsub_status($payment_id) && $action == 'prod_update_unsub') {
        // Unsubscribe customer from futurue updates
        $payment_meta['edd_send_prod_updates'] = false;
        // Update the payment meta with the new array
        update_post_meta($payment_id, '_edd_payment_meta', $payment_meta);
        // Update customer log with note about unsubscribing
        if (!isset($lognotes['unsubscribe'])) {
            edd_insert_payment_note($payment_id, __('User unsubscribed from product update emails', 'edd-pup'));
        }
    } else {
        if (!edd_pup_unsub_status($payment_id) && $action == 'prod_update_resub') {
            // Unsubscribe customer from futurue updates
            $payment_meta['edd_send_prod_updates'] = true;
            // Update the payment meta with the new array
            update_post_meta($payment_id, '_edd_payment_meta', $payment_meta);
            // Update customer log with note about resubscribing
            if (!isset($lognotes['resubscribe'])) {
                edd_insert_payment_note($payment_id, __('User re-subscribed to product update emails', 'edd-pup'));
            }
        }
    }
    edd_pup_unsub_message($payment_id, $purchase_key, $email, $action);
}
 /**
  * Update the status of the specified payment
  *
  * @param Pronamic_Pay_Payment $payment
  */
 public static function status_update(Pronamic_Pay_Payment $payment)
 {
     $source_id = $payment->get_source_id();
     $data = new Pronamic_WP_Pay_Extensions_EDD_PaymentData($source_id, array());
     // Only update if order is not completed
     $should_update = edd_get_payment_status($source_id) !== Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_PUBLISH;
     if ($should_update) {
         switch ($payment->get_status()) {
             case Pronamic_WP_Pay_Statuses::CANCELLED:
                 // Nothing to do?
                 break;
             case Pronamic_WP_Pay_Statuses::EXPIRED:
                 edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_ABANDONED);
                 break;
             case Pronamic_WP_Pay_Statuses::FAILURE:
                 edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_FAILED);
                 break;
             case Pronamic_WP_Pay_Statuses::SUCCESS:
                 edd_insert_payment_note($source_id, __('Payment completed.', 'pronamic_ideal'));
                 /*
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/admin/payments/view-order-details.php#L36
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/admin/payments/view-order-details.php#L199-L206
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/payments/functions.php#L1312-L1332
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/gateways/paypal-standard.php#L555-L576
                  */
                 edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_PUBLISH);
                 edd_empty_cart();
                 break;
             case Pronamic_WP_Pay_Statuses::OPEN:
                 edd_insert_payment_note($source_id, __('Payment open.', 'pronamic_ideal'));
                 break;
             default:
                 edd_insert_payment_note($source_id, __('Payment unknown.', 'pronamic_ideal'));
                 break;
         }
     }
 }
 /**
  * Process refunds
  *
  * @access      public
  * @since       1.0.0
  * @param       int $payment_id The ID of a payment
  * @param       string $new_status The new status of the payment
  * @param       string $old_status The old status of the payment
  * @return      void
  */
 public function process_refund($payment_id, $new_status, $old_status)
 {
     if ($old_status != 'publish' && $old_status != 'revoked') {
         return;
     }
     if ($new_status != 'refunded') {
         return;
     }
     if (edd_get_payment_gateway($payment_id) !== 'wallet') {
         return;
     }
     $user_id = edd_get_payment_user_id($payment_id);
     $refund_amount = edd_get_payment_amount($payment_id);
     // Deposit the funds
     edd_wallet()->wallet->deposit($user_id, $refund_amount, 'refund');
     // Insert payment note
     edd_insert_payment_note($payment_id, __('Refund completed to Wallet.', 'edd-wallet'));
 }
示例#20
0
function mondca_process_payment($purchase_data)
{
    global $edd_options;
    // check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    // 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' => 'mondca', 'status' => 'pending');
    if (!mondca_is_credit_card_number($purchase_data['post_data']['card_number'])) {
        edd_set_error('invalid_card_number', __('Credit Card Number is not valid.', 'mondca_patsatech'));
    }
    if (!mondca_is_correct_expire_date(date("y", strtotime($purchase_data['post_data']['card_exp_month'])), $purchase_data['post_data']['card_exp_year'])) {
        edd_set_error('invalid_card_expiry', __('Card Expire Date is not valid.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_cvc']) {
        edd_set_error('invalid_card_cvc', __('Card CVV is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_name']) {
        edd_set_error('invalid_card_name', __('CardHolder Name is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_address']) {
        edd_set_error('invalid_card_address', __('Billing Address is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_zip']) {
        edd_set_error('invalid_card_zip', __('Post Code is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_state']) {
        edd_set_error('invalid_card_state', __('State is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['card_city']) {
        edd_set_error('invalid_card_city', __('City is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['edd_first']) {
        edd_set_error('invalid_edd_first', __('First Name is not entered.', 'mondca_patsatech'));
    }
    if (!$purchase_data['post_data']['edd_last']) {
        edd_set_error('invalid_edd_last', __('Last Name is not entered.', 'mondca_patsatech'));
    }
    $errors = edd_get_errors();
    if ($errors) {
        // problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // record the pending payment
        $payment = edd_insert_payment($payment_data);
        // check payment
        if (!$payment) {
            // problems? send back
            edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
        } else {
            $store_id = $edd_options['mondca_storeid'];
            $api_token = $edd_options['mondca_apitoken'];
            $type = 'purchase';
            //$cust_id = $order->order_key;
            $amount = number_format($purchase_data['price'], 2, '.', '');
            $pan = $purchase_data['post_data']['card_number'];
            $cavv = $purchase_data['post_data']['card_cvc'];
            $expiry_date = substr($purchase_data['post_data']['card_exp_year'], -2) . sprintf("%02s", $purchase_data['post_data']['card_exp_month']);
            $crypt = '7';
            $status_check = 'false';
            $stamp = date("YdmHisB");
            $orderid = $stamp . '|' . $payment;
            /***************** Transactional Associative Array ********************/
            //$arr=explode("|",$teststring);
            $txnArray = array('type' => $type, 'order_id' => $orderid, 'cust_id' => '', 'amount' => $amount, 'pan' => $pan, 'expdate' => $expiry_date, 'cavv' => $cavv);
            /********************** Transaction Object ****************************/
            $mpgTxn = new mpgTransaction($txnArray);
            /************************ Request Object ******************************/
            $mpgRequest = new mpgRequest($mpgTxn);
            /*********************** HTTPSPost Object ****************************/
            $mpgHttpPost = new mpgHttpsPost($store_id, $api_token, $mpgRequest);
            /*************************** Response *********************************/
            $mpgResponse = $mpgHttpPost->getMpgResponse();
            $txnno = $mpgResponse->getTxnNumber();
            $receipt = explode("|", $mpgResponse->getReceiptId());
            $respcode = $mpgResponse->getResponseCode();
            $refnum = $mpgResponse->getReferenceNum();
            $auth = $mpgResponse->getAuthCode();
            $mess = $mpgResponse->getMessage();
            if ($respcode < '50' && $respcode > '0') {
                edd_update_payment_status($payment, 'publish');
                edd_insert_payment_note($payment, sprintf(__('Moneris CA Payment %s. The Transaction Id is %s', 'mondca_patsatech'), $mess, $txnno));
                edd_empty_cart();
                edd_send_to_success_page();
            } else {
                edd_insert_payment_note($payment, sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess));
                edd_set_error('error_tranasction_failed', sprintf(__('Transaction Error. Message : %s', 'mondca_patsatech'), $mess));
                edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
            }
        }
    }
}
 /**
  * Refund a charge in Amazon
  *
  * @access public
  * @since  2.4
  * @param  $payment_id int The ID number of the payment being refunded
  * @return string
  */
 private function refund($payment_id = 0)
 {
     $refund = $this->client->refund(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => edd_get_payment_meta($payment_id, '_edd_amazon_capture_id', true), 'refund_reference_id' => md5(edd_get_payment_key($payment_id) . '-refund'), 'refund_amount' => edd_get_payment_amount($payment_id), 'currency_code' => edd_get_payment_currency_code($payment_id)));
     if (200 == $refund->response['Status']) {
         $refund = new ResponseParser($refund->response);
         $refund = $refund->toArray();
         $reference_id = $refund['RefundResult']['RefundDetails']['RefundReferenceId'];
         $status = $refund['RefundResult']['RefundDetails']['RefundStatus']['State'];
         switch ($status) {
             case 'Declined':
                 $code = $refund['RefundResult']['RefundDetails']['RefundStatus']['ReasonCode'];
                 $note = __('Refund declined in Amazon. Refund ID: %s', 'edd');
                 break;
             case 'Completed':
                 $refund_id = $refund['RefundResult']['RefundDetails']['AmazonRefundId'];
                 $note = sprintf(__('Refund completed in Amazon. Refund ID: %s', 'edd'), $refund_id);
                 break;
             case 'Pending':
                 $note = sprintf(__('Refund initiated in Amazon. Reference ID: %s', 'edd'), $reference_id);
                 break;
         }
         edd_insert_payment_note($payment_id, $note);
     } else {
         edd_insert_payment_note($payment_id, __('Refund request failed in Amazon.', 'edd'));
     }
 }
 /**
  * process_payment function.
  *
  * Submit payment and handle response
  *
  * @access public
  */
 public function process_payment($purchase_data)
 {
     //edd_options contains the values of the admin settings
     global $edd_options;
     if (edd_is_test_mode()) {
         $paystack_public = $edd_options['test_public_key'];
         $paystack_secret = $edd_options['test_secret_key'];
     } else {
         $paystack_public = $edd_options['live_public_key'];
         $paystack_secret = $edd_options['live_secret_key'];
     }
     //txcode POSTed from payment form
     $txcode = isset($_POST['txcode']) ? $_POST['txcode'] : null;
     /**
      * check for checkout fields errors
      *
      */
     // check if there is a gateway name
     if (!isset($purchase_data['post_data']['edd-gateway'])) {
         return;
     }
     // get EDD errors
     $errors = edd_get_errors();
     // Paystack errors
     $paystack_error = null;
     /**
      * end checkout fields error checks
      */
     // if no errors
     if (!$errors) {
         // record purchase summary
         $summary = edd_get_purchase_summary($purchase_data, false);
         // cart quantity
         $quantity = edd_get_cart_quantity();
         /**
          * setup the 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_options['currency'], 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
         // record the pending payment
         $payment = edd_insert_payment($payment_data);
         $order_id = $payment;
         if (!$payment) {
             // Record the error
             edd_record_gateway_error(__('Payment Error', 'po_paystack'), sprintf(__('Payment creation failed before loading Paystack. Payment data: %s', 'po_paystack'), json_encode($payment_data)), $payment);
             // Problems? send back
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         } else {
             if (!$order_id || !$paystack_public) {
                 edd_record_gateway_error(__('Invalid transaction', 'po_paystack'), sprintf(__('Invalid transaction; possible hack attempt. Payment data: %s', 'po_paystack'), json_encode($payment_data)), $payment);
                 edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
             }
             if (!$txcode) {
                 $error = "Error! An invalid transaction code was reported.";
                 edd_update_payment_status($order_id, 'failed');
                 throw new Exception(__($error));
             } else {
                 $amount = $payment_data['price'] * 100;
                 //convert to kobo
                 if (intval($amount) < 100) {
                     $error = "Invalid transaction. Paystack cannot process orders under 100 kobo in value. Transaction code: " . $txcode;
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 }
                 $email = $payment_data['user_email'];
                 require_once dirname(__FILE__) . '/paystack-class/Paystack.php';
                 // Create the library object
                 $paystack = new Paystack($paystack_secret);
                 list($headers, $body, $code) = $paystack->transaction->verify(['reference' => $txcode]);
                 $resp = $body;
                 if (array_key_exists("status", $resp) && !$resp["status"]) {
                     $error = "Failed with message from Paystack: " . $resp["message"];
                     edd_insert_payment_note($order_id, __($error));
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 } elseif ($resp["data"]["customer"]["email"] !== $email) {
                     $error = "Invalid customer email associated with Transaction code:" . $txcode . " and Paystack reference: " . $resp["data"]['reference'] . ". Possible hack attempt.";
                     edd_insert_payment_note($order_id, __($error));
                     edd_update_payment_status($order_id, 'failed');
                     throw new Exception(__($error));
                 } else {
                     // Authcode and Authdesc. To be used in future version, for recurrent billing
                     $authcode = $resp["data"]["authorization"]["authorization_code"];
                     $authdesc = $resp["data"]["authorization"]["description"];
                     $paystackref = $resp["data"]["reference"];
                     // Complete the order. once a transaction is successful, set the purchase status to complete
                     edd_update_payment_status($payment, 'complete');
                     // record transaction ID, or any other notes you need
                     edd_insert_payment_note($payment, "Paystack.co payment completed (using " . strtoupper($authdesc) . " and Transaction code:" . $txcode . ") with Paystack reference:" . $paystackref);
                     // go to the success page
                     edd_send_to_success_page();
                 }
             }
         }
     } else {
         // errors present
         $fail = true;
     }
     if ($fail !== false) {
         // if errors are present, send the user back to the purchase page so they can be corrected
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
 }
示例#23
0
function edd_ajax_store_payment_note()
{
    $payment_id = absint($_POST['payment_id']);
    $note = wp_kses($_POST['note'], array());
    if (!current_user_can('edit_shop_payments', $payment_id)) {
        wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    if (empty($payment_id)) {
        die('-1');
    }
    if (empty($note)) {
        die('-1');
    }
    $note_id = edd_insert_payment_note($payment_id, $note);
    die(edd_get_payment_note_html($note_id));
}
 update_post_meta($payment_id, '_edd_payment_user_ip', get_post_meta($order->id, '_customer_ip_address', true));
 update_post_meta($payment_id, '_wc_order_key', get_post_meta($order->id, '_order_key', true));
 update_post_meta($payment_id, '_edd_payment_mode', 'live');
 update_post_meta($payment_id, '_edd_completed_date', get_post_meta($order->id, '_completed_date', true));
 update_post_meta($payment_id, '_wc_order_id', $o->ID);
 // Order Notes
 $args = array('post_id' => $order->id, 'approve' => 'approve');
 $wc_notes = get_comments($args);
 $temp_log_str = "\nOrder Notes fetched ...\n";
 $log_str .= $temp_log_str;
 echo $temp_log_str;
 foreach ($wc_notes as $note) {
     $temp_log_str = "\nWC Order Note - {$note->comment_ID}\n";
     $log_str .= $temp_log_str;
     echo $temp_log_str;
     $edd_note_id = edd_insert_payment_note($payment_id, $note->comment_content);
     // Update relevant data from old comment
     wp_update_comment(array('comment_ID' => $edd_note_id, 'comment_date' => $note->comment_date, 'comment_date_gmt' => $note->comment_date_gmt, 'comment_author' => $note->comment_author, 'comment_author_email' => $note->comment_author_email));
     update_comment_meta($edd_note_id, '_wc_order_note_id', $note->comment_ID);
     $temp_log_str = "\nWC Order Note migrated ...\n";
     $log_str .= $temp_log_str;
     echo $temp_log_str;
 }
 // Software License.
 //	$edd_sl_cpt = 'edd_license';
 // Fetch WC SL
 //	var_dump($order->order_key);
 //	$wc_sl_list = WCAM()->helpers->get_users_activation_data( $user_id, $order->order_key );
 //	$temp_log_str = "\nWC SL fetched ...\n";
 //	$log_str .= $temp_log_str;
 //	echo $temp_log_str;
/**
 * Process PayPal IPN Refunds
 *
 * @since 1.3.4
 * @param array   $data IPN Data
 * @return void
 */
function edd_process_paypal_refund($data, $payment_id = 0)
{
    // Collect payment details
    if (empty($payment_id)) {
        return;
    }
    if (get_post_status($payment_id) == 'refunded') {
        return;
        // Only refund payments once
    }
    $payment_amount = edd_get_payment_amount($payment_id);
    $refund_amount = $data['payment_gross'] * -1;
    if (number_format((double) $refund_amount, 2) < number_format((double) $payment_amount, 2)) {
        edd_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'edd'), $data['parent_txn_id']));
        return;
        // This is a partial refund
    }
    edd_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'edd'), $data['parent_txn_id'], $data['reason_code']));
    edd_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'edd'), $data['txn_id']));
    edd_update_payment_status($payment_id, 'refunded');
}
示例#26
0
/**
 * Update Edited Purchase
 *
 * Updates the purchase data for a payment.
 * Used primarily for adding new downloads to a purchase.
 *
 * @access      private
 * @since       1.0
 * @return      void
*/
function edd_update_edited_purchase($data)
{
    if (wp_verify_nonce($data['edd-payment-nonce'], 'edd_payment_nonce')) {
        $payment_id = $_POST['payment-id'];
        $payment_data = edd_get_payment_meta($payment_id);
        if (isset($_POST['edd-purchased-downloads'])) {
            $updated_downloads = array();
            foreach ($_POST['edd-purchased-downloads'] as $download) {
                if (isset($payment_data['cart_details'])) {
                    $updated_downloads[] = array('id' => $download);
                } else {
                    $updated_downloads[] = $download;
                }
            }
            $payment_data['downloads'] = serialize($updated_downloads);
        }
        $payment_data['email'] = strip_tags($_POST['edd-buyer-email']);
        update_post_meta($payment_id, '_edd_payment_meta', $payment_data);
        update_post_meta($payment_id, '_edd_payment_user_email', $payment_data['email']);
        if (isset($_POST['edd-payment-note'])) {
            $note = wp_kses($_POST['edd-payment-note'], array());
            $note_id = edd_insert_payment_note($payment_id, $note);
        }
        if ($_POST['edd-old-status'] != $_POST['edd-payment-status']) {
            edd_update_payment_status($payment_id, $_POST['edd-payment-status']);
        }
        if ($_POST['edd-payment-status'] == 'publish' && isset($_POST['edd-payment-send-email'])) {
            // send the purchase receipt
            edd_email_purchase_receipt($payment_id, false);
        }
    }
}
示例#27
0
 /**
  * Update the status of the specified payment
  *
  * @param Pronamic_Pay_Payment $payment
  * @param boolean			  $can_redirect (optional, defaults to false)
  */
 public static function status_update(Pronamic_Pay_Payment $payment, $can_redirect = false)
 {
     $source_id = $payment->get_source_id();
     $data = new Pronamic_WP_Pay_Extensions_EDD_PaymentData($source_id, array());
     // Only update if order is not completed
     $should_update = edd_get_payment_status($source_id) !== Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_PUBLISH;
     // Defaults
     $status = null;
     $note = null;
     $url = $data->get_normal_return_url();
     $status = $payment->get_status();
     switch ($status) {
         case Pronamic_WP_Pay_Statuses::CANCELLED:
             $url = $data->get_cancel_url();
             break;
         case Pronamic_WP_Pay_Statuses::EXPIRED:
             if ($should_update) {
                 edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_ABANDONED);
             }
             $url = $data->get_error_url();
             break;
         case Pronamic_WP_Pay_Statuses::FAILURE:
             if ($should_update) {
                 edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_FAILED);
             }
             $url = $data->get_error_url();
             break;
         case Pronamic_WP_Pay_Statuses::SUCCESS:
             if ($should_update) {
                 edd_insert_payment_note($source_id, __('Payment completed.', 'pronamic_ideal'));
                 /*
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/admin/payments/view-order-details.php#L36
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/admin/payments/view-order-details.php#L199-L206
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/payments/functions.php#L1312-L1332
                  * @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.2.8/includes/gateways/paypal-standard.php#L555-L576
                  */
             }
             edd_update_payment_status($source_id, Pronamic_WP_Pay_Extensions_EDD_EasyDigitalDownloads::ORDER_STATUS_PUBLISH);
             edd_empty_cart();
             $url = $data->get_success_url();
             break;
         case Pronamic_WP_Pay_Statuses::OPEN:
             if ($should_update) {
                 edd_insert_payment_note($source_id, __('Payment open.', 'pronamic_ideal'));
             }
             break;
         default:
             if ($should_update) {
                 edd_insert_payment_note($source_id, __('Payment unknown.', 'pronamic_ideal'));
             }
             break;
     }
     if ($can_redirect) {
         wp_redirect($url, 303);
         exit;
     }
 }
示例#28
0
/**
 * Process refund in Stripe
 *
 * @access      public
 * @since       1.8
 * @return      void
 */
function edd_stripe_process_refund($payment_id, $new_status, $old_status)
{
    global $edd_options;
    if (empty($_POST['edd_refund_in_stripe'])) {
        return;
    }
    if ('publish' != $old_status && 'revoked' != $old_status) {
        return;
    }
    if ('refunded' != $new_status) {
        return;
    }
    $charge_id = false;
    $notes = edd_get_payment_notes($payment_id);
    foreach ($notes as $note) {
        if (preg_match('/^Stripe Charge ID: ([^\\s]+)/', $note->comment_content, $match)) {
            $charge_id = $match[1];
            break;
        }
    }
    // Bail if no charge ID was found
    if (empty($charge_id)) {
        return;
    }
    if (!class_exists('Stripe')) {
        require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php';
    }
    $secret_key = edd_is_test_mode() ? trim($edd_options['test_secret_key']) : trim($edd_options['live_secret_key']);
    Stripe::setApiKey($secret_key);
    $ch = Stripe_Charge::retrieve($charge_id);
    try {
        $ch->refund();
        edd_insert_payment_note($payment_id, __('Charge refunded in Stripe', 'edds'));
    } catch (Exception $e) {
        // some sort of other error
        $body = $e->getJsonBody();
        $err = $body['error'];
        if (isset($err['message'])) {
            $error = $err['message'];
        } else {
            $error = __('Something went wrong while refunding the Charge in Stripe.', 'edds');
        }
        wp_die($error);
    }
}
 public function create_discount($name = '', $email = '', $payment_id = 0, $download_id = '')
 {
     if (!class_exists('RCP_Discounts')) {
         return false;
     }
     $db = new RCP_Discounts();
     $code = md5($name . $email . $payment_id);
     $multiuse = $this->is_gift_multiuse($download_id) ? 0 : 1;
     $expires = $this->gift_expires($download_id);
     $sublevel = $this->gift_subscription_level($download_id);
     $discount = array('name' => $name, 'description' => sprintf(__('Gifted discount for %s', 'rcp-gifts'), $name), 'amount' => '100', 'status' => 'active', 'unit' => '%', 'code' => $code, 'max_uses' => $multiuse, 'expiration' => $expires, 'subscription_id' => $sublevel);
     $discount_id = $db->insert($discount);
     $note = sprintf(__('Purchased as gift for %s. Coupon: %s', 'rcp-gifts'), $name, $code);
     // Store a payment note about this gift
     edd_insert_payment_note($payment_id, $note);
     // store discount ids for each gifted product
     add_post_meta($payment_id, '_edd_rcp_gift_id', $discount_id, true);
 }
/**
 * Store a payment note about this commission
 *
 * This makes it really easy to find commissions recorded for a specific payment.
 * Especially useful for when payments are refunded
 *
 * @access      private
 * @since       2.0
 * @return      void
 */
function eddc_record_commission_note($recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id)
{
    $note = sprintf(__('Commission of %s recorded for %s &ndash; <a href="%s">View</a>', 'eddc'), edd_currency_filter(edd_format_amount($commission_amount)), get_userdata($recipient)->display_name, admin_url('edit.php?post_type=download&page=edd-commissions&payment=' . $payment_id));
    edd_insert_payment_note($payment_id, $note);
}