function eMember_validate_and_create_membership() { // Check Product Name , Price , Currency , Receivers email , $error_msg = ""; // Read the IPN and validate $payment_status = $this->ipn_data['payment_status']; if (!empty($payment_status)) { if ($payment_status != "Completed" && $payment_status != "Processed" && $payment_status != "Refunded") { $error_msg .= 'Funds have not been cleared yet. Product(s) will be delivered when the funds clear!'; $this->debug_log($error_msg, false); return false; } } $custom = $this->ipn_data['custom']; $delimiter = "&"; $customvariables = array(); $namevaluecombos = explode($delimiter, $custom); foreach ($namevaluecombos as $keyval_unparsed) { $equalsignposition = strpos($keyval_unparsed, '='); if ($equalsignposition === false) { $customvariables[$keyval_unparsed] = ''; continue; } $key = substr($keyval_unparsed, 0, $equalsignposition); $value = substr($keyval_unparsed, $equalsignposition + 1); $customvariables[$key] = $value; } $transaction_type = $this->ipn_data['txn_type']; $transaction_id = $this->ipn_data['txn_id']; $gross_total = $this->ipn_data['mc_gross']; if ($gross_total < 0) { // This is a refund or reversal eMember_handle_subsc_cancel_stand_alone($this->ipn_data, true); $this->debug_log('This is a refund notification. Refund amount: ' . $gross_total, true); return true; } if ($transaction_type == "cart") { $this->debug_log('Transaction Type: Shopping Cart', true); // Cart Items $num_cart_items = $this->ipn_data['num_cart_items']; $this->debug_log('Number of Cart Items: ' . $num_cart_items, true); $i = 1; $cart_items = array(); while ($i < $num_cart_items + 1) { $item_number = $this->ipn_data['item_number' . $i]; $item_name = $this->ipn_data['item_name' . $i]; $quantity = $this->ipn_data['quantity' . $i]; $mc_gross = $this->ipn_data['mc_gross_' . $i]; $mc_currency = $this->ipn_data['mc_currency']; $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_currency' => $mc_currency); array_push($cart_items, $current_item); $i++; } } else { if ($transaction_type == "subscr_signup") { $this->debug_log('Subscription signup IPN received... nothing to do here(handled by the subscription IPN handler)', true); // Code to handle the signup IPN for subscription $subsc_ref = $customvariables['subsc_ref']; if (!empty($subsc_ref)) { if (function_exists('wp_eMember_install')) { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); $eMember_id = $customvariables['eMember_id']; eMember_handle_subsc_signup_stand_alone($this->ipn_data, $subsc_ref, $this->ipn_data['subscr_id'], $eMember_id); } //Handle customized subscription signup } return true; } else { if ($transaction_type == "subscr_cancel" || $transaction_type == "subscr_eot" || $transaction_type == "subscr_failed") { // Code to handle the IPN for subscription cancellation if (function_exists('wp_eMember_install')) { eMember_handle_subsc_cancel_stand_alone($this->ipn_data); } $this->debug_log('Subscription cancellation IPN received... nothing to do here(handled by the subscription IPN handler)', true); return true; } else { $cart_items = array(); $this->debug_log('Transaction Type: Buy Now/Subscribe', true); $item_number = $this->ipn_data['item_number']; $item_name = $this->ipn_data['item_name']; $quantity = $this->ipn_data['quantity']; $mc_gross = $this->ipn_data['mc_gross']; $mc_currency = $this->ipn_data['mc_currency']; $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_currency' => $mc_currency); array_push($cart_items, $current_item); } } } $product_id_array = array(); $product_name_array = array(); $product_price_array = array(); $attachments_array = array(); $download_link_array = array(); $counter = 0; foreach ($cart_items as $current_cart_item) { $cart_item_data_num = $current_cart_item['item_number']; $cart_item_data_name = trim($current_cart_item['item_name']); $cart_item_data_quantity = $current_cart_item['quantity']; $cart_item_data_total = $current_cart_item['mc_gross']; $cart_item_data_currency = $current_cart_item['mc_currency']; if (empty($cart_item_data_quantity)) { $cart_item_data_quantity = 1; } $this->debug_log('Item Number: ' . $cart_item_data_num, true); $this->debug_log('Item Name: ' . $cart_item_data_name, true); $this->debug_log('Item Quantity: ' . $cart_item_data_quantity, true); $this->debug_log('Item Total: ' . $cart_item_data_total, true); $this->debug_log('Item Currency: ' . $cart_item_data_currency, true); //*** Handle Membership Payment *** //-------------------------------------------------------------------------------------- // ========= Need to find the $member_ref (level ID) in the custom variable ============ $subsc_ref = $customvariables['subsc_ref']; $this->debug_log('Membership payment paid for membership level ID: ' . $subsc_ref, true); if (!empty($subsc_ref)) { $eMember_id = ""; if (isset($customvariables['eMember_id'])) { $eMember_id = $customvariables['eMember_id']; } if ($transaction_type == "web_accept") { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup_stand_alone($this->ipn_data, $subsc_ref, $this->ipn_data['txn_id'], $eMember_id); } else { if ($transaction_type == "cart") { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup_stand_alone($this->ipn_data, $subsc_ref, $this->ipn_data['txn_id'], $eMember_id); } else { if ($transaction_type == "subscr_payment") { eMember_update_member_subscription_start_date_if_applicable($this->ipn_data); } } } } else { $this->debug_log('Membership level ID is missing in the payment notification! Cannot process this notification', false); } //== End of Membership payment handling == $counter++; } //wp_mail($this->ipn_data['payer_email'], $subject, $body, $headers); // Do Post operation and cleanup if (function_exists('wp_aff_platform_install')) { $this->debug_log('WP Affiliate Platform is installed, checking if custom field has affiliate data...', true); //It expects the value of the custom field to be like the following: //<input type="hidden" name="custom" value="subsc_ref=4&ap_id=AFF_ID" /> $custom_field_val = $this->ipn_data['custom']; $this->debug_log('Custom field value: ' . $custom_field_val, true); $findme = 'ap_id'; $pos = strpos($custom_field_val, $findme); if ($pos !== false) { parse_str($custom_field_val); $referrer = $ap_id; } else { $this->debug_log('Could not find affiliate ID (ap_id) data in the custom field', true); } if (!empty($referrer)) { $total_tax = $this->ipn_data['tax']; if (empty($total_tax)) { $total_tax = 0; } $total_shipping = 0; if (!empty($this->ipn_data['shipping'])) { $total_shipping = $this->ipn_data['shipping']; } else { if (!empty($this->ipn_data['mc_shipping'])) { $total_shipping = $this->ipn_data['mc_shipping']; } } $gross_sale_amt = $this->ipn_data['mc_gross']; $this->debug_log('Gross sale amount: ' . $gross_sale_amt . ' Tax: ' . $total_tax . ' Shipping: ' . $total_shipping, true); $sale_amount = $gross_sale_amt - $total_shipping - $total_tax; $txn_id = $this->ipn_data['txn_id']; $item_id = $this->ipn_data['item_number']; $buyer_email = $this->ipn_data['payer_email']; $buyer_name = $this->ipn_data['first_name'] . " " . $this->ipn_data['last_name']; wp_aff_award_commission_unique($referrer, $sale_amount, $txn_id, $item_id, $buyer_email, '', '', $buyer_name); $aff_details_debug = "Referrer: " . $referrer . " Sale Amt: " . $sale_amount . " Buyer Email: " . $buyer_email . " Txn ID: " . $txn_id; $this->debug_log('Affiliate Commission Details => ' . $aff_details_debug, true); } else { $this->debug_log("Referrer value is empty! No commission will be awarded for this sale", true); } } return true; }
$secret_key_received = $_REQUEST['secret_key']; $right_secret_key = $emember_config->getValue('wp_eMember_secret_word_for_post'); if ($secret_key_received != $right_secret_key) { echo "Error!\n"; echo "Secret key is invalid\n"; eMember_log_debug('secret key invalid...', false); exit; } $custom = strip_tags($_REQUEST['custom']); $delimiter = "&"; $customvariables = array(); $namevaluecombos = explode($delimiter, $custom); foreach ($namevaluecombos as $keyval_unparsed) { $equalsignposition = strpos($keyval_unparsed, '='); if ($equalsignposition === false) { $customvariables[$keyval_unparsed] = ''; continue; } $key = substr($keyval_unparsed, 0, $equalsignposition); $value = substr($keyval_unparsed, $equalsignposition + 1); $customvariables[$key] = $value; } $subscr_id = strip_tags($_REQUEST['subscr_id']); $subsc_ref = $customvariables['subsc_ref']; $eMember_id = $customvariables['eMember_id']; foreach ($_REQUEST as $field => $value) { $ipn_data["{$field}"] = $value; } eMember_log_debug('API - registering member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup_stand_alone($ipn_data, $subsc_ref, $subscr_id, $eMember_id);
$customvariables = array(); $namevaluecombos = explode($delimiter, $custom); foreach ($namevaluecombos as $keyval_unparsed) { $equalsignposition = strpos($keyval_unparsed, '='); if ($equalsignposition === false) { $customvariables[$keyval_unparsed] = ''; continue; } $key = substr($keyval_unparsed, 0, $equalsignposition); $value = substr($keyval_unparsed, $equalsignposition + 1); $customvariables[$key] = $value; } $cb_ipn_data['membership_level_id'] = $customvariables['membership_level_id']; eMember_log_debug("Payment received for membership level ID:" . $cb_ipn_data['membership_level_id'], true); //handle the membership payment data eMember_handle_subsc_signup_stand_alone($cb_ipn_data, $cb_ipn_data['membership_level_id'], $cb_ipn_data['txn_id']); eMember_log_debug("End of clickbank membership payment processing!", true, true); //Return value 1=passed, 0=fail function eMember_clickbank_ipnVerification($clickbank_secretKey = "") { eMember_log_debug("Validating IPN authenticity. Secret Key:" . $clickbank_secretKey, true); $secretKey = $clickbank_secretKey; $pop = ""; $ipnFields = array(); foreach ($_POST as $key => $value) { if ($key == "cverify") { continue; } $ipnFields[] = $key; } sort($ipnFields);