/** * Set Error * * Stores an error in a session var. * * @access public * @since 1.0 * @param $error_id string - the ID of the error being set * @param $error_message - the message to store with the error * @return void */ function edd_set_error($error_id, $error_message) { $errors = edd_get_errors(); if (!$errors) { $errors = array(); } $errors[$error_id] = $error_message; $_SESSION['edd-errors'] = $errors; }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @version 1.0.8.1 * @return void */ function edd_process_purchase_form() { // no need to run on admin if (is_admin()) { return; } // verify the nonce for this action if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) { return; } // make sure the cart isn't empty $cart = edd_get_cart_contents(); if (empty($cart)) { wp_die(sprintf(__('Your cart is empty, please return to the %ssite%s and try again.', 'edd'), '<a href="' . esc_url(home_url()) . '" title="' . get_bloginfo('name') . '">', '</a>'), __('Error', 'edd')); } // validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // allow themes and plugins to hoook to errors do_action('edd_checkout_error_checks', $_POST); // check errors if (false !== ($errors = edd_get_errors())) { // we have errors, send back to checkout edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']); exit; } // check user if (false === ($user = edd_get_purchase_form_user($valid_data))) { // something went wrong when collecting data, send back to checkout edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']); exit; } // setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']); // setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'subtotal' => edd_get_cart_amount(false), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_amount(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // add the user data for hooks $valid_data['user'] = $user; // allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // if the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase if ($purchase_data['price'] <= 0) { // revert to manual $valid_data['gateway'] = 'manual'; } // used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($purchase_data); // send info to the gateway for payment processing edd_send_to_gateway($valid_data['gateway'], $purchase_data); exit; }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @version 1.0.8.1 * @return void */ function edd_process_purchase_form() { global $edd_options; // no need to run on admin if (is_admin()) { return; } // verify the nonce for this action if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) { return; } // validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // allow themes and plugins to hoook to errors do_action('edd_checkout_error_checks', $_POST); // check errors if (false !== ($errors = edd_get_errors())) { // we have errors, send back to checkout edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']); exit; } // check user if (false === ($user = edd_get_purchase_form_user($valid_data))) { // something went wrong when collecting data, send back to checkout edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']); exit; } // setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']); // setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'price' => edd_get_cart_amount(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // add the user data for hooks $valid_data['user'] = $user; // allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // if the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase if ($purchase_data['price'] <= 0) { // revert to manual $valid_data['gateway'] = 'manual'; } if (isset($edd_options['show_links_on_success'])) { // used for showing download links to non logged-in users after purchase edd_set_purchase_session($purchase_data); } // send info to the gateway for payment processing edd_send_to_gateway($valid_data['gateway'], $purchase_data); exit; }
function pw_edd_process_payment($purchase_data) { global $edd_options; /********************************** * set transaction mode **********************************/ if (edd_is_test_mode()) { $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?'; } else { if ($edd_options['paytm_select_mode'] == '1') { $paytm_redirect = 'https://secure.paytm.in/oltp-web/processTransaction?'; } else { $paytm_redirect = 'https://pguat.paytm.com/oltp-web/processTransaction?'; } } // 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'], 'gateway' => 'paytm', '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; $secret_key = $edd_options['paytm_mer_access_key']; $params = array('REQUEST_TYPE' => 'DEFAULT', 'MID' => $edd_options['paytm_merchant_id'], 'TXN_AMOUNT' => $purchase_data['price'], 'CHANNEL_ID' => "WEB", 'INDUSTRY_TYPE_ID' => $edd_options['paytm_industry_type'], 'WEBSITE' => $edd_options['paytm_website_name'], 'CUST_ID' => $purchase_data['user_email'], 'ORDER_ID' => $purchase_data['purchase_key'], 'EMAIL' => $purchase_data['user_email']); if ($edd_options['paytm_callback'] == '1') { $params['CALLBACK_URL'] = get_site_url() . '/?edd-listener=PAYTM_IPN&payment_id=' . $payment; } $checksum = getChecksumFromArray($params, $secret_key); $params['CHECKSUMHASH'] = $checksum; foreach ($params as $key => $val) { $submit_Params .= trim($key) . '=' . trim(urlencode($val)) . '&'; } $submit_Params = substr($submit_Params, 0, -1); $request = $paytm_redirect . $submit_Params; wp_redirect($request); exit; } 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']); } }
function sofort_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_options['currency'], 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending'); $errors = edd_get_errors(); if ($errors) { // problems? send back edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { $payment = edd_insert_payment($payment_data); // check payment if (!$payment) { edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { if (!class_exists('SofortLib')) { require_once 'library/sofortLib.php'; } $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page'])); $Sofort = new SofortLib_Multipay(trim($edd_options['sofort_config_id'])); $Sofort->setSofortueberweisung(); $Sofort->setAmount($purchase_data['price']); $Sofort->setReason('CartId ' . $payment, $purchase_data['post_data']['edd_first'] . ' ' . $purchase_data['post_data']['edd_last']); $Sofort->addUserVariable($payment); $Sofort->setSuccessUrl($return_url); $Sofort->setAbortUrl(edd_get_failed_transaction_uri()); $Sofort->setTimeoutUrl(edd_get_failed_transaction_uri()); $Sofort->setNotificationUrl(home_url('/?sofort=ipn')); $Sofort->sendRequest(); if ($Sofort->isError()) { //PNAG-API didn't accept the data wp_die($Sofort->getError(), 'Error'); } else { //buyer must be redirected to $paymentUrl else payment cannot be successfully completed! $paymentUrl = $Sofort->getPaymentUrl(); edd_empty_cart(); wp_redirect($paymentUrl); exit; } } } }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @version 1.0.8.1 * @return void */ function edd_process_purchase_form() { // Make sure the cart isn't empty if (!edd_get_cart_contents()) { edd_set_error('empty_cart', __('Your cart is empty', 'edd')); } else { // Validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // Allow themes and plugins to hoook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); } $is_ajax = isset($_POST['edd_ajax']); $user = edd_get_purchase_form_user($valid_data); if (edd_get_errors() || !$user) { if ($is_ajax) { do_action('edd_ajax_checkout_errors'); edd_die(); } else { return false; } } if ($is_ajax) { echo 'success'; edd_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']); // Setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // If the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase if (!$purchase_data['price']) { // Revert to manual $valid_data['gateway'] = 'manual'; } // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($purchase_data); // Send info to the gateway for payment processing edd_send_to_gateway($valid_data['gateway'], $purchase_data); edd_die(); }
function edd_fd_process_payment($purchase_data) { global $edd_options; // setup gateway appropriately for test mode if (edd_is_test_mode()) { $endpoint = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/v11/wsdl'; } else { $endpoint = 'https://api.globalgatewaye4.firstdata.com/transaction/v11/wsdl'; } // check the posted cc deails $cc = edd_fd_check_cc_details($purchase_data); // fcheck for errors before we continue to processing if (!edd_get_errors()) { $purchase_summary = edd_get_purchase_summary($purchase_data); $payment = 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'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending'); // record the pending payment $payment = edd_insert_payment($payment); $address = esc_textarea($_POST['card_address'] . ' ' . $_POST['card_address_2'] . '|' . $_POST['card_zip'] . '|' . $_POST['card_city'] . '|' . $_POST['card_state'] . '|' . $_POST['billing_country']); $firstdata['Transaction'] = array('ExactID' => $edd_options['firstdata_gateway_id'], 'Password' => $edd_options['firstdata_gateway_password'], 'Transaction_Type' => $edd_options['firstdata_transaction_type'], 'DollarAmount' => $purchase_data['price'], 'Card_Number' => $cc['card_number'], 'Expiry_Date' => $cc['card_exp_month'] . $cc['card_exp_year'], 'CardHoldersName' => $cc['card_name'], 'VerificationStr1' => $address, 'VerificationStr2' => $cc['card_cvc'], 'CVD_Presence_Ind' => 1, 'Reference_No' => $payment, 'ZipCode' => $cc['card_zip'], 'Customer_Ref' => $purchase_data['user_info']['id'], 'Client_IP' => $_SERVER['REMOTE_ADDR'], 'Client_Email' => $purchase_data['user_email'], 'Currency' => $edd_options['currency'], 'Ecommerce_Flag' => is_ssl() ? 8 : 7); try { $api = @new SoapClient($endpoint); $result = $api->__soapCall('SendAndCommit', $firstdata); } catch (Exception $e) { edd_set_error('firstdata_api_error', sprintf(__('FirstData System Error: %s', 'edd_firstdata'), $e->getMessage())); edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); $fail = true; } if (isset($result) && $result->Transaction_Approved) { edd_update_payment_status($payment, 'complete'); edd_send_to_success_page(); } elseif ($result->Transaction_Error) { edd_set_error('firstdata_decline', sprintf(__('Transaction Declined: %s', 'edd_firstdata'), $result->EXact_Message)); edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); $fail = true; } } else { $fail = true; } }
/** * Process the purchase and create the charge in Amazon * * @access public * @since 2.4 * @param $purchase_data array Cart details * @return void */ public function process_purchase($purchase_data) { if (empty($purchase_data['post_data']['edd_amazon_reference_id'])) { edd_set_error('missing_reference_id', __('Missing Reference ID, please try again', 'edd')); } $errors = edd_get_errors(); if ($errors) { edd_send_back_to_checkout('?payment-mode=amazon'); } $args = apply_filters('edd_amazon_charge_args', array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_reference_id' => $purchase_data['post_data']['edd_amazon_reference_id'], 'authorization_reference_id' => $purchase_data['purchase_key'], 'charge_amount' => $purchase_data['price'], 'currency_code' => edd_get_currency(), 'charge_note' => html_entity_decode(edd_get_purchase_summary($purchase_data, false)), 'charge_order_id' => $purchase_data['purchase_key'], 'store_name' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'transaction_timeout' => 0), $purchase_data); $args['platform_id'] = 'A3JST9YM1SX7LB'; $charge = $this->client->charge($args); if (200 == $charge->response['Status']) { $charge = new ResponseParser($charge->response); $charge = $charge->toArray(); $status = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['State']; if ('Declined' === $status) { $reason = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['ReasonCode']; edd_set_error('payment_declined', sprintf(__('Your payment could not be authorized, please try a different payment method. Reason: %s', 'edd'), $reason)); edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']); } // Setup payment data to be recorded $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->gateway_id, 'status' => 'pending'); $payment_id = edd_insert_payment($payment_data); $authorization_id = $charge['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId']; $capture_id = str_replace('-A', '-C', $authorization_id); $reference_id = sanitize_text_field($_POST['edd_amazon_reference_id']); // Confirm the capture was completed $capture = $this->client->getCaptureDetails(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => $capture_id)); $capture = new ResponseParser($capture->response); $capture = $capture->toArray(); // Check capture status edd_update_payment_meta($payment_id, '_edd_amazon_authorization_id', $authorization_id); edd_update_payment_meta($payment_id, '_edd_amazon_capture_id', $capture_id); edd_set_payment_transaction_id($payment_id, $reference_id); edd_update_payment_status($payment_id, 'publish'); // Empty the shopping cart edd_empty_cart(); edd_send_to_success_page(); } else { // Set an error edd_set_error('amazon_error', sprintf(__('There was an issue processing your payment. Amazon error: %s', 'edd'), print_r($charge, true))); edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']); } }
/** * Validates the supplied discount sent via AJAX. * * @since 1.0 * @return void */ function edd_ajax_apply_discount() { if (isset($_POST['code'])) { $discount_code = sanitize_text_field($_POST['code']); $return = array('msg' => '', 'code' => $discount_code); $user = ''; if (is_user_logged_in()) { $user = get_current_user_id(); } else { parse_str($_POST['form'], $form); if (!empty($form['edd_email'])) { $user = urldecode($form['edd_email']); } } if (edd_is_discount_valid($discount_code, $user)) { $discount = edd_get_discount_by_code($discount_code); $amount = edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)); $discounts = edd_set_cart_discount($discount_code); $total = edd_get_cart_total($discounts); $return = array('msg' => 'valid', 'amount' => $amount, 'total_plain' => $total, 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $discount_code, 'html' => edd_get_cart_discounts_html($discounts)); } else { $errors = edd_get_errors(); $return['msg'] = $errors['edd-discount-error']; edd_unset_error('edd-discount-error'); } // Allow for custom discount code handling $return = apply_filters('edd_ajax_discount_response', $return); echo json_encode($return); } edd_die(); }
/** * Removes (unsets) a stored error * * @since 1.3.4 * @uses EDD_Session::set() * @param int $error_id ID of the error being set * @return string */ function edd_unset_error($error_id) { $errors = edd_get_errors(); if ($errors) { unset($errors[$error_id]); EDD()->session->set('edd_errors', $errors); } }
/** * Register And Login New User * * @param array $user_data * * @access private * @since 1.0.8.1 * @return integer */ function edd_register_and_login_new_user($user_data = array()) { // Verify the array if (empty($user_data)) { return -1; } if (edd_get_errors()) { return -1; } $user_args = apply_filters('edd_insert_user_args', array('user_login' => isset($user_data['user_login']) ? $user_data['user_login'] : '', 'user_pass' => isset($user_data['user_pass']) ? $user_data['user_pass'] : '', 'user_email' => isset($user_data['user_email']) ? $user_data['user_email'] : '', 'first_name' => isset($user_data['user_first']) ? $user_data['user_first'] : '', 'last_name' => isset($user_data['user_last']) ? $user_data['user_last'] : '', 'user_registered' => date('Y-m-d H:i:s'), 'role' => get_option('default_role')), $user_data); // Insert new user $user_id = wp_insert_user($user_args); // Validate inserted user if (is_wp_error($user_id)) { return -1; } // Allow themes and plugins to filter the user data $user_data = apply_filters('edd_insert_user_data', $user_data, $user_args); // Allow themes and plugins to hook do_action('edd_insert_user', $user_id, $user_data); // Login new user edd_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']); // Return user id return $user_id; }
/** * Process Login Form * * @access private * @since 1.0 * @return void */ function edd_process_login_form($data) { if (wp_verify_nonce($data['edd_login_nonce'], 'edd-login-nonce')) { $user_data = get_user_by('login', $data['edd_user_login']); if ($user_data) { $user_ID = $user_data->ID; $user_email = $user_data->user_email; if (wp_check_password($data['edd_user_pass'], $user_data->user_pass, $user_data->ID)) { edd_log_user_in($user_data->ID, $data['edd_user_login'], $data['edd_user_pass']); } else { edd_set_error('password_incorrect', __('The password you entered is incorrect', 'edd')); } } else { edd_set_error('username_incorrect', __('The username you entered does not exist', 'edd')); } // check for errors and redirect if none present $errors = edd_get_errors(); if (!$errors) { $redirect = apply_filters('edd_login_redirect', $data['edd_redirect'], $user_ID); wp_redirect($redirect); exit; } } }
function edd_veritrans_payment($purchase_data) { global $edd_options; require_once plugin_dir_path(__FILE__) . '/lib/Veritrans.php'; /********************************** * set transaction mode **********************************/ if (edd_is_test_mode()) { // set test credentials here Veritrans_Config::$isProduction = false; Veritrans_Config::$serverKey = $edd_options['vt_sandbox_api_key']; } else { // set live credentials here Veritrans_Config::$isProduction = true; Veritrans_Config::$serverKey = $edd_options['vt_production_api_key']; } // check for any stored errors $errors = edd_get_errors(); if (!$errors) { $purchase_summary = edd_get_purchase_summary($purchase_data); // error_log('purchase data: '.print_r($purchase_data,true)); //debugan // error_log('purchase summary: '.print_r($purchase_summary,true)); //debugan // error_log('plugin_dir_path : '.plugin_dir_path(__FILE__)); //debugan /********************************** * setup the payment details **********************************/ // error_log(json_encode($purchase_data, true)); $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); // create item $transaction_details = array(); foreach ($purchase_data['cart_details'] as $item) { $vt_item = array('id' => $item['id'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'name' => $item['name']); array_push($transaction_details, $vt_item); } $vt_params = array('transaction_details' => array('order_id' => $payment, 'gross_amount' => $purchase_data['price']), 'customer_details' => array('first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'email' => $purchase_data['user_info']['email'], 'billing_address' => array('first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'])), 'item_details' => $transaction_details); //get enabled payment opts from backend $enabled_payments = edd_get_vtpayment_ops(); if (!empty($enabled_payments)) { $vt_params['vtweb']['enabled_payments'] = $enabled_payments; } // error_log('vt_3ds '.$edd_options['vt_3ds']); //debugan // get rid of cart contents edd_empty_cart(); // Redirect to veritrans // error_log('vt_params: '.print_r($vt_params,true)); //debugan wp_redirect(Veritrans_Vtweb::getRedirectionUrl($vt_params)); exit; } 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']); } }
/** * Delete a customer * * @since 2.3 * @param array $args The $_POST array being passeed * @return int Wether it was a successful deletion */ function edd_customer_delete($args) { $customer_edit_role = apply_filters('edd_edit_customers_role', 'edit_shop_payments'); if (!is_admin() || !current_user_can($customer_edit_role)) { wp_die(__('You do not have permission to delete this customer.', 'edd')); } if (empty($args)) { return; } $customer_id = (int) $args['customer_id']; $confirm = !empty($args['edd-customer-delete-confirm']) ? true : false; $remove_data = !empty($args['edd-customer-delete-records']) ? true : false; $nonce = $args['_wpnonce']; if (!wp_verify_nonce($nonce, 'delete-customer')) { wp_die(__('Cheatin\' eh?!', 'edd')); } if (!$confirm) { edd_set_error('customer-delete-no-confirm', __('Please confirm you want to delete this customer', 'edd')); } if (edd_get_errors()) { wp_redirect(admin_url('edit.php?post_type=download&page=edd-customers&view=overview&id=' . $customer_id)); exit; } $customer = new EDD_Customer($customer_id); do_action('edd_pre_delete_customer', $customer_id, $confirm, $remove_data); $success = false; if ($customer->id > 0) { $payments_array = explode(',', $customer->payment_ids); $success = EDD()->customers->delete($customer->id); if ($success) { if ($remove_data) { // Remove all payments, logs, etc foreach ($payments_array as $payment_id) { edd_delete_purchase($payment_id, false, true); } } else { // Just set the payments to customer_id of 0 foreach ($payments_array as $payment_id) { edd_update_payment_meta($payment_id, '_edd_payment_customer_id', 0); } } $redirect = admin_url('edit.php?post_type=download&page=edd-customers&edd-message=customer-deleted'); } else { edd_set_error('edd-customer-delete-failed', __('Error deleting customer', 'edd')); $redirect = admin_url('edit.php?post_type=download&page=edd-customers&view=delete&id=' . $customer_id); } } else { edd_set_error('edd-customer-delete-invalid-id', __('Invalid Customer ID', 'edd')); $redirect = admin_url('edit.php?post_type=download&page=edd-customers'); } wp_redirect($redirect); exit; }
/** * Process shortcode submission. * * @since Astoundify Crowdfunding 0.1-alpha * * @param $key The key of the current field. * @param $field The array of field arguments. * @param $atts The shortcoe attribtues. * @param $campaign The current campaign (if editing/previewing). * @return void */ function atcf_shortcode_submit_process() { global $edd_options, $post; if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } if (empty($_POST['action']) || 'atcf-campaign-submit' !== $_POST['action']) { return; } if (!wp_verify_nonce($_POST['_wpnonce'], 'atcf-campaign-submit')) { return; } $action = esc_attr($_POST['submit']); $existing_campaign = isset($_POST['campaign_id']) ? esc_attr($_POST['campaign_id']) : null; $fields = atcf_shortcode_submit_fields(); $status = 'submit' == $action ? 'pending' : 'draft'; /** If we are submitting, but this is a live campaign, keep published */ if ($existing_campaign && ('pending' == $status && get_post($existing_campaign)->post_status == 'publish')) { $status = 'publish'; } foreach ($fields as $key => $field) { $fields[$key]['value'] = isset($_POST[$key]) ? $_POST[$key] : null; $fields[$key]['value'] = apply_filters('atcf_shortcode_submit_validate_' . $key, $fields[$key]['value']); if (isset($field['required']) && true === $field['required'] && !$fields[$key]['value'] && 'publish' != $status) { edd_set_error('required-' . $key, sprintf(__('The <strong>%s</strong> field is required.', 'atcf'), $field['label'])); } } do_action('atcf_campaign_submit_validate', $fields, $_POST); if (edd_get_errors()) { return; } /** Register a new user, or get the current user */ $user = get_user_by('email', $fields['contact_email']['value']); if (!$user) { $user_id = atcf_register_user(array('user_login' => $fields['contact_email']['value'], 'user_email' => $fields['contact_email']['value'], 'display_name' => isset($fields['name']['value']) ? $fields['name']['value'] : $fields['contact_email']['value'])); } else { $user_id = $user->ID; } /** * Create or update a campaign */ $args = apply_filters('atcf_campaign_submit_data', array('post_type' => 'download', 'post_status' => $status, 'post_content' => $fields['description']['value'], 'post_author' => $user_id), $_POST); if ($fields['title']['value']) { $args['post_title'] = $fields['title']['value']; } if ($fields['excerpt']['value']) { $args['post_excerpt'] = $fields['excerpt']['value']; } if (!$existing_campaign) { $campaign = wp_insert_post($args, true); } else { $args['ID'] = $existing_campaign; $campaign = wp_update_post($args); } do_action('atcf_submit_process_after', $campaign, $_POST, $status, $fields); if ('publish' == $status) { wp_safe_redirect(add_query_arg('updated', 'true', get_permalink($campaign))); exit; } elseif ('submit' == $action) { $url = isset($edd_options['submit_success_page']) ? get_permalink($edd_options['submit_success_page']) : home_url(); $redirect = apply_filters('atcf_submit_campaign_success_redirect', $url); wp_safe_redirect(add_query_arg(array('success' => true, 'campaign' => $campaign), $redirect)); exit; } else { wp_safe_redirect(add_query_arg('preview', 'true', get_permalink($campaign))); exit; } }
/** * Process stripe checkout submission * * @access public * @since 1.0 * @return void */ function edds_process_stripe_payment($purchase_data) { global $edd_options; if (!class_exists('Stripe')) { require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php'; } if (edd_is_test_mode()) { $secret_key = trim($edd_options['test_secret_key']); } else { $secret_key = trim($edd_options['live_secret_key']); } $purchase_summary = edd_get_purchase_summary($purchase_data, false); // make sure we don't have any left over errors present edd_clear_errors(); if (!isset($_POST['edd_stripe_token'])) { // check for fallback mode if (isset($edd_options['stripe_js_fallback'])) { if (!isset($_POST['card_name']) || strlen(trim($_POST['card_name'])) == 0) { edd_set_error('no_card_name', __('Please enter a name for the credit card.', 'edds')); } if (!isset($_POST['card_number']) || strlen(trim($_POST['card_number'])) == 0) { edd_set_error('no_card_number', __('Please enter a credit card number.', 'edds')); } if (!isset($_POST['card_cvc']) || strlen(trim($_POST['card_cvc'])) == 0) { edd_set_error('no_card_cvc', __('Please enter a CVC/CVV for the credit card.', 'edds')); } if (!isset($_POST['card_exp_month']) || strlen(trim($_POST['card_exp_month'])) == 0) { edd_set_error('no_card_exp_month', __('Please enter a expiration month.', 'edds')); } if (!isset($_POST['card_exp_year']) || strlen(trim($_POST['card_exp_year'])) == 0) { edd_set_error('no_card_exp_year', __('Please enter a expiration year.', 'edds')); } $card_data = array('number' => $purchase_data['card_info']['card_number'], 'name' => $purchase_data['card_info']['card_name'], 'exp_month' => $purchase_data['card_info']['card_exp_month'], 'exp_year' => $purchase_data['card_info']['card_exp_year'], 'cvc' => $purchase_data['card_info']['card_cvc'], 'address_line1' => $purchase_data['card_info']['card_address'], 'address_line2' => $purchase_data['card_info']['card_address_2'], 'address_city' => $purchase_data['card_info']['card_city'], 'address_zip' => $purchase_data['card_info']['card_zip'], 'address_state' => $purchase_data['card_info']['card_state'], 'address_country' => $purchase_data['card_info']['card_country']); } else { // no Stripe token edd_set_error('no_token', __('Missing Stripe token. Please contact support.', 'edds')); edd_record_gateway_error(__('Missing Stripe Token', 'edds'), __('A Stripe token failed to be generated. Please check Stripe logs for more information', ' edds')); } } else { $card_data = $_POST['edd_stripe_token']; } $errors = edd_get_errors(); if (!$errors) { try { Stripe::setApiKey($secret_key); // setup the payment details $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'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'stripe'); $customer_exists = false; if (is_user_logged_in()) { $user = get_user_by('email', $purchase_data['user_email']); if ($user) { $customer_id = get_user_meta($user->ID, edd_stripe_get_customer_key(), true); if ($customer_id) { $customer_exists = true; try { // Update the customer to ensure their card data is up to date $cu = Stripe_Customer::retrieve($customer_id); if (isset($cu->deleted) && $cu->deleted) { // This customer was deleted $customer_exists = false; } else { $cu->card = $card_data; $cu->save(); } // No customer found } catch (Exception $e) { $customer_exists = false; } } } } if (!$customer_exists) { // Create a customer first so we can retrieve them later for future payments $customer = Stripe_Customer::create(array('description' => $purchase_data['user_email'], 'email' => $purchase_data['user_email'], 'card' => $card_data)); $customer_id = is_array($customer) ? $customer['id'] : $customer->id; if (is_user_logged_in()) { update_user_meta($user->ID, edd_stripe_get_customer_key(), $customer_id); } } if (edds_is_recurring_purchase($purchase_data) && (!empty($customer) || $customer_exists)) { // Process a recurring subscription purchase $cu = Stripe_Customer::retrieve($customer_id); /********************************************************** * Taxes, fees, and discounts have to be handled differently * with recurring subscriptions, so each is added as an * invoice item and then charged as one time items **********************************************************/ $invoice_items = array(); $needs_invoiced = false; if ($purchase_data['tax'] > 0 && !edd_prices_include_tax()) { if (edds_is_zero_decimal_currency()) { $tax = $purchase_data['tax']; } else { $tax = $purchase_data['tax'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $tax, 'currency' => edd_get_currency(), 'description' => sprintf(__('Sales tax for order %s', 'edds'), $purchase_data['purchase_key']))); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } $needs_invoiced = true; } if (!empty($purchase_data['fees'])) { foreach ($purchase_data['fees'] as $fee) { if (edds_is_zero_decimal_currency()) { $fee_amount = $fee['amount']; } else { $fee_amount = $fee['amount'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $fee_amount, 'currency' => edd_get_currency(), 'description' => $fee['label'])); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } } $needs_invoiced = true; } if ($purchase_data['discount'] > 0) { if (edds_is_zero_decimal_currency()) { $discount_amount = $purchase_data['discount']; } else { $discount_amount = $purchase_data['discount'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $discount_amount * -1, 'currency' => edd_get_currency(), 'description' => $purchase_data['user_info']['discount'])); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } $needs_invoiced = true; } try { $plan_id = edds_get_plan_id($purchase_data); // record the pending payment $payment = edd_insert_payment($payment_data); set_transient('_edd_recurring_payment_' . $payment, '1', DAY_IN_SECONDS); // Store the parent payment ID in the user meta EDD_Recurring_Customer::set_customer_payment_id($user->ID, $payment); // Update the customer's subscription in Stripe $customer_response = $cu->updateSubscription(array('plan' => $plan_id)); // 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, $customer_id); // Set the customer status 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, $payment); // Set the customer's new expiration date EDD_Recurring_Customer::set_customer_expiration($user->ID, $new_expiration); } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('payment_error', $err['message']); } else { edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0); } catch (Stripe_ApiConnectionError $e) { $body = $e->getJsonBody(); $err = $body['error']; edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds')); edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0); } catch (Stripe_InvalidRequestError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Bad Request of some sort. Maybe Christoff was here ;) if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message']))); } } catch (Stripe_ApiError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error with Stripe\'s API: ', 'edds'), json_encode($err['message'])), 0); } catch (Stripe_AuthenticationError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Authentication error. Stripe keys in settings are bad. if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds')); } } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; // generic stripe error if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } } catch (Exception $e) { // some sort of other error $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } } if (!empty($err)) { // Delete any invoice items we created for fees, taxes, and other foreach ($invoice_items as $invoice) { $ii = Stripe_InvoiceItem::retrieve($invoice); $ii->delete(); } edd_send_back_to_checkout('?payment-mode=stripe'); } } elseif (!empty($customer) || $customer_exists) { // Process a normal one-time charge purchase if (!isset($edd_options['stripe_preapprove_only'])) { if (edds_is_zero_decimal_currency()) { $amount = $purchase_data['price']; } else { $amount = $purchase_data['price'] * 100; } $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => edd_get_currency(), "customer" => $customer_id, "description" => html_entity_decode($purchase_summary, ENT_COMPAT, 'UTF-8'), 'statement_description' => substr($purchase_summary, 0, 15), 'metadata' => array('email' => $purchase_data['user_info']['email']))); } // record the pending payment $payment = edd_insert_payment($payment_data); } else { edd_record_gateway_error(__('Customer Creation Failed', 'edds'), sprintf(__('Customer creation failed while processing a payment. Payment Data: %s', ' edds'), json_encode($payment_data)), $payment); } if ($payment && (!empty($customer_id) || !empty($charge))) { if (!empty($needs_invoiced)) { try { // Create the invoice containing taxes / discounts / fees $invoice = Stripe_Invoice::create(array('customer' => $customer_id)); $invoice = $invoice->pay(); } catch (Exception $e) { // If there is nothing to pay, it just means the invoice item was taken care of with the subscription payment } } if (isset($edd_options['stripe_preapprove_only'])) { edd_update_payment_status($payment, 'preapproval'); add_post_meta($payment, '_edds_stripe_customer_id', $customer_id); } else { edd_update_payment_status($payment, 'publish'); } // You should be using Stripe's API here to retrieve the invoice then confirming it's been paid if (!empty($charge)) { edd_insert_payment_note($payment, 'Stripe Charge ID: ' . $charge->id); if (function_exists('edd_set_payment_transaction_id')) { edd_set_payment_transaction_id($payment, $charge->id); } } elseif (!empty($customer_id)) { edd_insert_payment_note($payment, 'Stripe Customer ID: ' . $customer_id); } edd_empty_cart(); edd_send_to_success_page(); } else { edd_set_error('payment_not_recorded', __('Your payment could not be recorded, please contact the site administrator.', 'edds')); // if errors are present, send the user back to the purchase page so they can be corrected edd_send_back_to_checkout('?payment-mode=stripe'); } } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('payment_error', $err['message']); } else { edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_ApiConnectionError $e) { $body = $e->getJsonBody(); $err = $body['error']; edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds')); edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_InvalidRequestError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Bad Request of some sort. Maybe Christoff was here ;) if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_ApiError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message']))); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_AuthenticationError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Authentication error. Stripe keys in settings are bad. if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; // generic stripe error if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Exception $e) { // some sort of other error $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } } else { edd_send_back_to_checkout('?payment-mode=stripe'); } }
/** * edd_unset_error seems to be not working * since it's not unsetting what's really inside $_SESSION['edd-errors'] * so this is probably the fix * * Removes a stored error * * Modified From: * EDD 1.4 * includes/error-tracking.php * Modified Part: * unset the error in session variable * * @param $error_id string - the ID of the error being set * @return void */ function edd_unset_error_fix($error_id) { // edd_unset_error fix for version less than 1.4 if (version_compare(EDD_VERSION, '1.5', '<')) { $errors = edd_get_errors(); if ($errors) { if (isset($_SESSION['edd-errors'][$error_id])) { unset($_SESSION['edd-errors'][$error_id]); } } } else { edd_unset_error($error_id); } }
function sagepay_direct_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' => 'sagepay_direct', 'status' => 'pending'); $required = array('edd_first' => __('First Name is not entered.', 'sagepay_direct_patsatech'), 'edd_last' => __('Last Name is not entered.', 'sagepay_direct_patsatech'), 'card_cvc' => __('Card CVV is not entered.', 'sagepay_direct_patsatech'), 'card_name' => __('Card Holder Name is not entered.', 'sagepay_direct_patsatech'), 'card_address' => __('Billing Address is not entered.', 'sagepay_direct_patsatech'), 'card_city' => __('Billing City is not entered.', 'sagepay_direct_patsatech'), 'card_zip' => __('Billing Zip / Postal Code is not entered.', 'sagepay_direct_patsatech')); foreach ($required as $field => $error) { if (!$purchase_data['post_data'][$field]) { edd_set_error('billing_error', $error); } } if (!sagepay_direct_is_credit_card_number($purchase_data['post_data']['card_number'])) { edd_set_error('invalid_card_number', __('Credit Card Number is not valid.', 'sagepay_direct_patsatech')); } if (!sagepay_direct_is_correct_expire_date($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.', 'sagepay_direct_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 { $time_stamp = date("ymdHis"); $orderid = $edd_options['sagepay_direct_vendor_name'] . "-" . $time_stamp . "-" . $payment; $sp_arg['ReferrerID'] = 'CC923B06-40D5-4713-85C1-700D690550BF'; $sp_arg['Amount'] = $purchase_data['price']; $sp_arg['CustomerName'] = substr($purchase_data['post_data']['edd_first'] . ' ' . $purchase_data['post_data']['edd_last'], 0, 100); $sp_arg['CustomerEMail'] = substr($purchase_data['post_data']['edd_email'], 0, 255); $sp_arg['BillingSurname'] = substr($purchase_data['post_data']['edd_last'], 0, 20); $sp_arg['BillingFirstnames'] = substr($purchase_data['post_data']['edd_first'], 0, 20); $sp_arg['BillingAddress1'] = substr($purchase_data['post_data']['card_address'], 0, 100); $sp_arg['BillingAddress2'] = substr($purchase_data['post_data']['card_address_2'], 0, 100); $sp_arg['BillingCity'] = substr($purchase_data['post_data']['card_city'], 0, 40); if ($purchase_data['post_data']['billing_country'] == 'US') { $sp_arg['BillingState'] = $purchase_data['post_data']['card_state']; } else { $sp_arg['BillingState'] = ''; } $sp_arg['BillingPostCode'] = substr($purchase_data['post_data']['card_zip'], 0, 10); $sp_arg['BillingCountry'] = $purchase_data['post_data']['billing_country']; //$sp_arg['BillingPhone'] = substr($purchase_data['post_data']['edd_phone'], 0, 20); $sp_arg['DeliverySurname'] = substr($purchase_data['post_data']['edd_last'], 0, 20); $sp_arg['DeliveryFirstnames'] = substr($purchase_data['post_data']['edd_first'], 0, 20); $sp_arg['DeliveryAddress1'] = substr($purchase_data['post_data']['card_address'], 0, 100); $sp_arg['DeliveryAddress2'] = substr($purchase_data['post_data']['card_address_2'], 0, 100); $sp_arg['DeliveryCity'] = substr($purchase_data['post_data']['card_city'], 0, 40); if ($purchase_data['post_data']['billing_country'] == 'US') { $sp_arg['DeliveryState'] = $purchase_data['post_data']['card_state']; } else { $sp_arg['DeliveryState'] = ''; } $sp_arg['DeliveryPostCode'] = substr($purchase_data['post_data']['card_zip'], 0, 10); $sp_arg['DeliveryCountry'] = $purchase_data['post_data']['billing_country']; //$sp_arg['DeliveryPhone'] = substr($purchase_data['post_data']['edd_phone'], 0, 20); $sp_arg['CardHolder'] = $purchase_data['post_data']['card_name']; $sp_arg['CardNumber'] = $purchase_data['post_data']['card_number']; $sp_arg['StartDate'] = ''; $sp_arg['ExpiryDate'] = sprintf("%02d", $purchase_data['post_data']['card_exp_month']) . date("y", strtotime("01/01/" . $purchase_data['post_data']['card_exp_year'])); $sp_arg['CV2'] = $purchase_data['post_data']['card_cvc']; $sp_arg['CardType'] = $purchase_data['post_data']['card_type']; $sp_arg['VPSProtocol'] = "3.00"; $sp_arg['Vendor'] = $edd_options['sagepay_direct_vendor_name']; $sp_arg['Description'] = sprintf(__('Order #%s', 'sagepay_direct_patsatech'), $payment); $sp_arg['Currency'] = edd_get_currency(); $sp_arg['TxType'] = $edd_options['sagepay_direct_transtype']; $sp_arg['VendorTxCode'] = $orderid; $post_values = ""; foreach ($sp_arg as $key => $value) { $post_values .= "{$key}=" . urlencode($value) . "&"; } $post_values = rtrim($post_values, "& "); if ($edd_options['sagepay_direct_mode'] == 'test') { $gateway_url = 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp'; } else { if ($edd_options['sagepay_direct_mode'] == 'live') { $gateway_url = 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp'; } } $response = wp_remote_post($gateway_url, array('body' => $post_values, 'method' => 'POST', 'sslverify' => FALSE)); EDD()->session->set('sagepay_vtc', $orderid); EDD()->session->set('sagepay_oid', $payment); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $resp = array(); $lines = preg_split('/\\r\\n|\\r|\\n/', $response['body']); foreach ($lines as $line) { $key_value = preg_split('/=/', $line, 2); if (count($key_value) > 1) { $resp[trim($key_value[0])] = trim($key_value[1]); } } if ($resp['Status'] == "OK" || $resp['Status'] == "REGISTERED" || $resp['Status'] == "AUTHENTICATED") { edd_update_payment_status($payment, 'publish'); edd_set_payment_transaction_id($payment, $resp['VPSTxId']); edd_empty_cart(); edd_send_to_success_page(); } else { if ($resp['Status'] == "3DAUTH") { if ($resp['3DSecureStatus'] == 'OK') { if (isset($resp['ACSURL']) && isset($resp['MD'])) { $array = array('PaReq' => $resp['PAReq'], 'MD' => $resp['MD'], 'TermUrl' => trailingslashit(home_url()) . '?sagepay_direct=ipn'); $sagepay_arg_array = array(); foreach ($array as $key => $value) { $sagepay_arg_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />'; } echo '<form action="' . $resp['ACSURL'] . '" method="post" name="sagepay_direct_3dsecure_form" > ' . implode('', $sagepay_arg_array) . ' </form> <b> Please wait while you are being redirected.</b> <script type="text/javascript" event="onload"> document.sagepay_direct_3dsecure_form.submit(); </script>'; } } } else { if (isset($resp['StatusDetail'])) { edd_set_error('error_tranasction_failed', __('Transaction Failed. ' . $resp['StatusDetail'], 'sagepay_direct_patsatech')); edd_send_back_to_checkout('?payment-mode=sagepay_direct'); } else { edd_set_error('error_tranasction_failed', __('Transaction Failed with ' . $resp['Status'] . ' status for Unknown Reason.', 'sagepay_direct_patsatech')); edd_send_back_to_checkout('?payment-mode=sagepay_direct'); } } } } else { edd_set_error('error_tranasction_failed', __('Gateway Error. Please Notify the Store Owner about this error.', 'sagepay_direct_patsatech')); edd_send_back_to_checkout('?payment-mode=sagepay_direct'); } } } }
/** * Register new user * @return Array User array */ function vp_edd_fd_register_user() { // Validate the form $_POST data $valid_data['need_new_user'] = true; $valid_data['new_user_data'] = edd_purchase_form_validate_new_user(); // Allow themes and plugins to hook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); if (edd_get_errors()) { // print error before member registration content add_action('vp_edd_before_member', 'edd_print_errors'); $user = false; } else { $user = edd_get_purchase_form_user($valid_data); // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last']); if (function_exists('eddmc_check_for_email_signup')) { eddmc_check_for_email_signup($_POST, $user_info); } } return $user; }
/** * 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']); } }
/** * Profile Editor Shortcode * * Outputs the EDD Profile Editor to allow users to amend their details from the front-end * * @access public * @since 1.4 * @author Sunny Ratilal */ function edd_profile_editor_shortcode($atts, $content = null) { global $current_user; ob_start(); if (is_user_logged_in()) { $user_id = get_current_user_id(); $first_name = get_user_meta($user_id, 'first_name', true); $last_name = get_user_meta($user_id, 'last_name', true); $display_name = $current_user->display_name; if (isset($_GET['updated']) && $_GET['updated'] == true && !edd_get_errors()) { ?> <p class="edd_success"><strong><?php _e('Success', 'edd'); ?> :</strong> <?php _e('Your profile has been edited successfully.', 'edd'); ?> </p> <?php } edd_print_errors(); ?> <form id="edd_profile_editor_form" class="edd_form" action="<?php echo edd_get_current_page_url(); ?> " method="post"> <fieldset> <legend><?php _e('Change your Name', 'edd'); ?> </legend> <p id="edd_profile_name_wrap"> <label for="edd_first_name"><?php _e('First Name', 'edd'); ?> </label> <input name="edd_first_name" id="edd_first_name" class="text edd-input" type="text" value="<?php echo $first_name; ?> " /> <br /> <label for="edd_last_name"><?php _e('Last Name', 'edd'); ?> </label> <input name="edd_last_name" id="edd_last_name" class="text edd-input" type="text" value="<?php echo $last_name; ?> " /> </p> <p id="edd_profile_display_name_wrap"> <label for="edd_display_name"><?php _e('Display Name', 'edd'); ?> </label> <select name="edd_display_name"> <?php if (!empty($current_user->first_name)) { ?> <option <?php selected($display_name, $current_user->first_name); ?> value="<?php echo $current_user->first_name; ?> "><?php echo $current_user->first_name; ?> </option> <?php } ?> <option <?php selected($display_name, $current_user->user_nicename); ?> value="<?php echo $current_user->user_nicename; ?> "><?php echo $current_user->user_nicename; ?> </option> <?php if (!empty($current_user->last_name)) { ?> <option <?php selected($display_name, $current_user->last_name); ?> value="<?php echo $current_user->last_name; ?> "><?php echo $current_user->last_name; ?> </option> <?php } ?> <?php if (!empty($current_user->first_name) && !empty($current_user->last_name)) { ?> <option <?php selected($display_name, $current_user->first_name . ' ' . $current_user->last_name); ?> value="<?php echo $current_user->first_name . ' ' . $current_user->last_name; ?> "><?php echo $current_user->first_name . ' ' . $current_user->last_name; ?> </option> <option <?php selected($display_name, $current_user->last_name . ' ' . $current_user->first_name); ?> value="<?php echo $current_user->last_name . ' ' . $current_user->first_name; ?> "><?php echo $current_user->last_name . ' ' . $current_user->first_name; ?> </option> <?php } ?> </select> </p> <p> <label for="edd_email"><?php _e('Email Address', 'edd'); ?> </label> <input name="edd_email" id="edd_email" class="text edd-input required" type="email" value="<?php echo $current_user->user_email; ?> " /> </p> <legend><?php _e('Change your Password', 'edd'); ?> </legend> <p id="edd_profile_password_wrap"> <label for="edd_user_pass"><?php _e('New Password', 'edd'); ?> </label> <input name="edd_new_user_pass1" id="edd_new_user_pass1" class="password edd-input" type="password"/> <br /> <label for="edd_user_pass"><?php _e('Re-enter Password', 'edd'); ?> </label> <input name="edd_new_user_pass2" id="edd_new_user_pass2" class="password edd-input" type="password"/> </p> <p class="edd_password_change_notice"><?php _e('Please note after changing your password, you must log back in.', 'edd'); ?> </p> <p id="edd_profile_submit_wrap"> <input type="hidden" name="edd_profile_editor_nonce" value="<?php echo wp_create_nonce('edd-profile-editor-nonce'); ?> "/> <input type="hidden" name="edd_action" value="edit_user_profile" /> <input type="hidden" name="edd_redirect" value="<?php echo esc_url(edd_get_current_page_url()); ?> " /> <input name="edd_profile_editor_submit" id="edd_profile_editor_submit" type="submit" class="edd_submit" value="<?php _e('Save Changes', 'edd'); ?> "/> </p> </fieldset> </form><!-- #edd_profile_editor_form --> <?php } else { echo '<p>' . __('You need to login to edit your profile.', 'edd') . '</p>'; wp_login_form(array('echo' => true, 'redirect' => edd_get_current_page_url(), 'form_id' => 'edd_login_form', 'label_username' => __('Username', 'edd'), 'label_password' => __('Password', 'edd'), 'label_remember' => __('Remember me?', 'edd'), 'label_log_in' => __('Log In', 'edd'), 'id_username' => 'edd_user_login', 'id_password' => 'edd_user_pass', 'id_remember' => 'edd_remember_me', 'id_submit' => 'edd_login_form_submit', 'remember' => true)); } $display = ob_get_clean(); return $display; }
/** * Process Register Form * * @since 2.0 * @param array $data Data sent from the register form * @return void */ function edd_process_register_form($data) { if (is_user_logged_in()) { return; } if (empty($_POST['edd_register_submit'])) { return; } do_action('edd_pre_process_register_form'); if (empty($data['edd_user_login'])) { edd_set_error('empty_username', __('Invalid username', 'edd')); } if (username_exists($data['edd_user_login'])) { edd_set_error('username_unavailable', __('Username already taken', 'edd')); } if (!validate_username($data['edd_user_login'])) { edd_set_error('username_invalid', __('Invalid username', 'edd')); } if (email_exists($data['edd_user_email'])) { edd_set_error('email_unavailable', __('Email address already taken', 'edd')); } if (empty($data['edd_user_email']) || !is_email($data['edd_user_email'])) { edd_set_error('email_invalid', __('Invalid email', 'edd')); } if (!empty($data['edd_payment_email']) && $data['edd_payment_email'] != $data['edd_user_email'] && !is_email($data['edd_payment_email'])) { edd_set_error('payment_email_invalid', __('Invalid payment email', 'edd')); } if (empty($_POST['edd_user_pass'])) { edd_set_error('empty_password', __('Please enter a password', 'edd')); } if (!empty($_POST['edd_user_pass']) && empty($_POST['edd_user_pass2']) || $_POST['edd_user_pass'] !== $_POST['edd_user_pass2']) { edd_set_error('password_mismatch', __('Passwords do not match', 'edd')); } do_action('edd_process_register_form'); // Check for errors and redirect if none present $errors = edd_get_errors(); if (empty($errors)) { $redirect = apply_filters('edd_register_redirect', $data['edd_redirect']); edd_register_and_login_new_user(array('user_login' => $data['edd_user_login'], 'user_pass' => $data['edd_user_pass'], 'user_email' => $data['edd_user_email'], 'user_registered' => date('Y-m-d H:i:s'), 'role' => get_option('default_role'))); wp_redirect($redirect); edd_die(); } }
public function get_s3_url($filename, $expires = 5) { if (false !== strpos($filename, '/')) { $parts = explode('/', $filename); $bucket = $parts[0]; $buckets = $this->get_s3_buckets(); if (empty($buckets)) { $errors = edd_get_errors(); if (array_key_exists('edd-amazon-s3', $errors)) { if (current_user_can('manage_options')) { wp_die($errors['edd-amazon-s3']); } else { wp_die(__('Error retrieving file. Please contact the site administrator.', 'edd_s3')); } } } if (in_array($bucket, $buckets)) { $filename = preg_replace('#^' . $parts[0] . '/#', '', $filename, 1); } else { $bucket = $this->bucket; } } else { $bucket = $this->bucket; } $url = $this->s3->getAuthenticatedURL($bucket, $filename, 60 * $expires, false, is_ssl()); return $url; }
/** * Renders the customer view wrapper * * @since 2.3 * @param string $view The View being requested * @param array $callbacks The Registered views and their callback functions * @return void */ function edd_render_customer_view($view, $callbacks) { $render = true; $customer_view_role = apply_filters('edd_view_customers_role', 'view_shop_reports'); if (!current_user_can($customer_view_role)) { edd_set_error('edd-no-access', __('You are not permitted to view this data.', 'edd')); $render = false; } if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { edd_set_error('edd-invalid_customer', __('Invalid Customer ID Provided.', 'edd')); $render = false; } $customer_id = (int) $_GET['id']; $customer = new EDD_Customer($customer_id); if (empty($customer->id)) { edd_set_error('edd-invalid_customer', __('Invalid Customer ID Provided.', 'edd')); $render = false; } $customer_tabs = edd_customer_tabs(); ?> <div class='wrap'> <h2><?php _e('Customer Details', 'edd'); ?> </h2> <?php if (edd_get_errors()) { ?> <div class="error settings-error"> <?php edd_print_errors(); ?> </div> <?php } ?> <?php if ($customer && $render) { ?> <div id="customer-tab-wrapper"> <ul id="customer-tab-wrapper-list"> <?php foreach ($customer_tabs as $key => $tab) { ?> <?php $active = $key === $view ? true : false; ?> <?php $class = $active ? 'active' : 'inactive'; ?> <?php if (!$active) { ?> <a title="<?php echo esc_attr($tab['title']); ?> " aria-label="<?php echo esc_attr($tab['title']); ?> " href="<?php echo esc_url(admin_url('edit.php?post_type=download&page=edd-customers&view=' . $key . '&id=' . $customer->id)); ?> "> <?php } ?> <li class="<?php echo sanitize_html_class($class); ?> "><span class="dashicons <?php echo sanitize_html_class($tab['dashicon']); ?> "></span></li> <?php if (!$active) { ?> </a> <?php } ?> <?php } ?> </ul> </div> <div id="edd-customer-card-wrapper" style="float: left"> <?php $callbacks[$view]($customer); ?> </div> <?php } ?> </div> <?php }
/** * Process Profile Updater Form * * Processes the profile updater form by updating the necessary fields * * @since 1.4 * @author Sunny Ratilal * @param array $data Data sent from the profile editor * @return void */ function edd_process_profile_editor_updates($data) { // Profile field change request if (empty($_POST['edd_profile_editor_submit']) && !is_user_logged_in()) { return false; } // Pending users can't edit their profile if (edd_user_pending_verification()) { return false; } // Nonce security if (!wp_verify_nonce($data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce')) { return false; } $user_id = get_current_user_id(); $old_user_data = get_userdata($user_id); $display_name = isset($data['edd_display_name']) ? sanitize_text_field($data['edd_display_name']) : $old_user_data->display_name; $first_name = isset($data['edd_first_name']) ? sanitize_text_field($data['edd_first_name']) : $old_user_data->first_name; $last_name = isset($data['edd_last_name']) ? sanitize_text_field($data['edd_last_name']) : $old_user_data->last_name; $email = isset($data['edd_email']) ? sanitize_email($data['edd_email']) : $old_user_data->user_email; $line1 = isset($data['edd_address_line1']) ? sanitize_text_field($data['edd_address_line1']) : ''; $line2 = isset($data['edd_address_line2']) ? sanitize_text_field($data['edd_address_line2']) : ''; $city = isset($data['edd_address_city']) ? sanitize_text_field($data['edd_address_city']) : ''; $state = isset($data['edd_address_state']) ? sanitize_text_field($data['edd_address_state']) : ''; $zip = isset($data['edd_address_zip']) ? sanitize_text_field($data['edd_address_zip']) : ''; $country = isset($data['edd_address_country']) ? sanitize_text_field($data['edd_address_country']) : ''; $userdata = array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email); $address = array('line1' => $line1, 'line2' => $line2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country); do_action('edd_pre_update_user_profile', $user_id, $userdata); // New password if (!empty($data['edd_new_user_pass1'])) { if ($data['edd_new_user_pass1'] !== $data['edd_new_user_pass2']) { edd_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'easy-digital-downloads')); } else { $userdata['user_pass'] = $data['edd_new_user_pass1']; } } // Make sure the new email doesn't belong to another user if ($email != $old_user_data->user_email) { // Make sure the new email is valid if (!is_email($email)) { edd_set_error('email_invalid', __('The email you entered is invalid. Please enter a valid email.', 'easy-digital-downloads')); } // Make sure the new email doesn't belong to another user if (email_exists($email)) { edd_set_error('email_exists', __('The email you entered belongs to another user. Please use another.', 'easy-digital-downloads')); } } // Check for errors $errors = edd_get_errors(); if ($errors) { // Send back to the profile editor if there are errors wp_redirect($data['edd_redirect']); edd_die(); } // Update the user $meta = update_user_meta($user_id, '_edd_user_address', $address); $updated = wp_update_user($userdata); if ($updated) { do_action('edd_user_profile_updated', $user_id, $userdata); wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect'])); edd_die(); } }
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']); } } } }
/** * Checks whether an error is set for $field. * * @param string $field The field to check. * * @return bool */ function has_edd_error($field) { $errors = edd_get_errors(); if (isset($errors[$field])) { return trim($errors[$field]); } return false; }
/** * Displays a payment update form * * @since x.x * @return string */ public function update_payment_form() { global $user_ID; if (!is_user_logged_in()) { return; } if (!EDD_Recurring_Customer::is_customer_active($user_ID)) { return; } if ('cancelled' === EDD_Recurring_Customer::get_customer_status($user_ID)) { return; } // Gateways can choose to show the form or not by using this filter $show_cc_form = apply_filters('edd_recurring_customer_can_update_card', false, $user_ID); if (!$show_cc_form) { $form_fields = array(); $form_fields['cc_number'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-card-number', 'label' => __('Credit Card Number', 'edd-recurring'), 'placeholder' => __('Credit Card Number', 'edd-recurring'), 'autocomplete' => false)); $form_fields['cc_name'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-card-name', 'label' => __('Name on Card', 'edd-recurring'), 'placeholder' => __('Name on Card', 'edd-recurring'), 'autocomplete' => true)); $form_fields['cvc_number'] = array('type' => 'text', 'options' => array('name' => 'edd-recurring-cvc-number', 'class' => 'small-text', 'label' => __('CVC Number', 'edd-recurring'), 'placeholder' => __('###', 'edd-recurring'), 'autocomplete' => false)); $form_fields['exp_head'] = array('type' => 'legend', 'options' => array('text' => __('Card Expiration', 'edd-recurring'))); $form_fields['exp_month'] = array('type' => 'month_dropdown'); $form_fields['exp_year'] = array('type' => 'year_dropdown', 'number_of_years' => 10); $elements = apply_filters('edd_recurring_update_form_elements', $form_fields, $user_ID); } $form_output = ''; if (isset($_GET['updated']) && $_GET['updated'] == true && !edd_get_errors()) { $form_output = '<p class="edd_success"><strong>' . __('Success', 'edd') . ':</strong> ' . __('Your profile has been edited successfully.', 'edd') . '</p>'; } $form_output .= '<div id="edd-recurring-update-wrapper">'; $form_output .= '<form action="' . remove_query_arg('updated', edd_get_current_page_url()) . '" id="edd-recurring-form" method="POST">'; $form_input_html = ''; if (!$show_cc_form) { // Iterate through all the form elements, and add them to the HTML foreach ($elements as $element) { switch ($element['type']) { case 'month_dropdown': $form_input_html .= EDD()->html->{$element}['type'](); break; case 'year_dropdown': $form_input_html .= EDD()->html->{$element}['type']('edd-recurring-exp-year', null, 0, $element['number_of_years']); break; case 'legend': $form_input_html .= '<legend>' . $element['options']['text'] . '</legend>'; break; default: $form_input_html .= EDD()->html->{$element}['type']($element['options']); $form_input_html .= '<br />'; break; } } } ob_start(); edd_print_errors(); $form_output .= ob_get_clean(); $form_output .= apply_filters('edd_recurring_update_form_html', $form_input_html, $user_ID); $recurring_gateway = apply_filters('edd_recurring_update_gateway', '', $user_ID); $form_output .= '<input name="edd-recurring-update-gateway" type="hidden" value="' . $recurring_gateway . '" />'; $form_output .= wp_nonce_field('update-payment', 'edd_recurring_update_nonce', true, false); $form_output .= '<input type="hidden" name="edd_action" value="recurring_update_payment" />'; $form_output .= '<input type="submit" name="edd-recurring-update-submit" id="edd-recurring-update-submit" value="' . esc_attr(__('Update Payment', 'edd-recurring')) . '" />'; $form_output .= '</form>'; $form_output .= '</div>'; return '<div id="edd_checkout_form_wrap">' . $form_output . '</div>'; }
function wppb_check_edd_login_form($auth_cookie, $expire, $expiration, $user_id, $scheme) { $wppb_generalSettings = get_option('wppb_general_settings', 'not_found'); if ($wppb_generalSettings != 'not_found') { if (!empty($wppb_generalSettings['adminApproval']) && $wppb_generalSettings['adminApproval'] == 'yes') { if (isset($_REQUEST['edd_login_nonce'])) { if (wp_get_object_terms($user_id, 'user_status')) { if (isset($_REQUEST['edd_redirect'])) { wp_redirect($_REQUEST['edd_redirect']); edd_set_error('user_unapproved', __('Your account has to be confirmed by an administrator before you can log in.', 'profile-builder')); edd_get_errors(); edd_die(); } } } } } }
*/ global $current_user; if ( is_user_logged_in() ): $user_id = get_current_user_id(); $first_name = get_user_meta( $user_id, 'first_name', true ); $last_name = get_user_meta( $user_id, 'last_name', true ); $display_name = $current_user->display_name; $address = edd_get_customer_address( $user_id ); if ( edd_is_cart_saved() ): ?> <?php $restore_url = add_query_arg( array( 'edd_action' => 'restore_cart', 'edd_cart_token' => edd_get_cart_token() ), edd_get_checkout_uri() ); ?> <div class="edd_success edd-alert edd-alert-success"><strong><?php _e( 'Saved cart', 'edd'); ?>:</strong> <?php printf( __( 'You have a saved cart, <a href="%s">click here</a> to restore it.', 'edd' ), esc_url( $restore_url ) ); ?></div> <?php endif; ?> <?php if ( isset( $_GET['updated'] ) && $_GET['updated'] == true && ! edd_get_errors() ): ?> <div class="edd_success edd-alert edd-alert-success"><strong><?php _e( 'Success', 'edd'); ?>:</strong> <?php _e( 'Your profile has been edited successfully.', 'edd' ); ?></div> <?php endif; ?> <?php edd_print_errors(); ?> <?php do_action( 'edd_profile_editor_before' ); ?> <form id="edd_profile_editor_form" class="edd_form" action="<?php echo edd_get_current_page_url(); ?>" method="post"> <fieldset> <span id="edd_profile_name_label"><legend><?php _e( 'Change your Name', 'edd' ); ?></legend></span> <p id="edd_profile_name_wrap"> <label for="edd_first_name"><?php _e( 'First Name', 'edd' ); ?></label> <input name="edd_first_name" id="edd_first_name" class="text edd-input" type="text" value="<?php echo esc_attr( $first_name ); ?>" /> <br /> <label for="edd_last_name"><?php _e( 'Last Name', 'edd' ); ?></label>