/** * Verify a successful Payment! * */ function check_alphabank_response() { global $woocommerce; global $wpdb; //if (( preg_match( '/success/i', $_SERVER['REQUEST_URI'] ) && preg_match( '/alphabank/i', $_SERVER['REQUEST_URI'] ) )) { // $merchantreference= $_GET['MerchantReference']; $post_data_array = array(); if (isset($_POST['mid'])) { $post_data_array[0] = $_POST['mid']; } if (isset($_POST['orderid'])) { $post_data_array[1] = $_POST['orderid']; } if (isset($_POST['status'])) { $post_data_array[2] = $_POST['status']; } if (isset($_POST['orderAmount'])) { $post_data_array[3] = $_POST['orderAmount']; } if (isset($_POST['currency'])) { $post_data_array[4] = $_POST['currency']; } if (isset($_POST['paymentTotal'])) { $post_data_array[5] = $_POST['paymentTotal']; } if (isset($_POST['message'])) { $post_data_array[6] = $_POST['message']; } if (isset($_POST['riskScore'])) { $post_data_array[7] = $_POST['riskScore']; } if (isset($_POST['payMethod'])) { $post_data_array[8] = $_POST['payMethod']; } if (isset($_POST['txId'])) { $post_data_array[9] = $_POST['txId']; } if (isset($_POST['paymentRef'])) { $post_data_array[10] = $_POST['paymentRef']; } $post_data_array[11] = $_POST['digest']; $post_DIGEST = $_POST['digest']; $post_data = implode("", $post_data_array); $digest = base64_encode(sha1(utf8_encode($post_data), true)); if ($this->mode == "yes") { //test mode $post_url = 'https://alpha.test.modirum.com/vpos/shophandlermpi'; } else { //live mode $post_url = 'https://www.alphaecommerce.gr/vpos/shophandlermpi'; } // $ttquery = 'SELECT * FROM `' . $wpdb->prefix . 'alphabank_transactions` WHERE `orderid` = "' . $_POST['orderid'] . '";'; $ref = $wpdb->get_results($ttquery); $merchantreference = $_GET['MerchantReference']; $orderid = $ref['0']->orderid; $order = new WC_Order($orderid); //$order = $_POST['orderid']; if ($_POST['status'] == 'AUTHORIZED' || $_POST['status'] == 'CAPTURED') { //verified - successful payment //complete order if ($order->status == 'processing') { $order->add_order_note(__('Payment Via alphabank<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-alphabank-payment-gateway'); $message_type = 'success'; } else { if ($order->has_downloadable_item()) { //Update order status $order->update_status('completed', __('Payment received, your order is now complete.', 'woocommerce-alphabank-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via alphabank Payment Gateway<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is now complete.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.', 'woocommerce-alphabank-payment-gateway'); $message_type = 'success'; } else { //Update order status $order->update_status('processing', __('Payment received, your order is currently being processed.', 'woocommerce-alphabank-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via alphabank Payment Gateway<br />Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />alphabank Transaction ID: ', 'woocommerce-alphabank-payment-gateway') . $trans_id, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-alphabank-payment-gateway'); $message_type = 'success'; } $alphabank_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_alphabank_message', $alphabank_message); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); } } elseif ($_POST['status'] == 'CANCELED') { //payment has failed - retry $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-alphabank-payment-gateway'); $message_type = 'error'; $alphabank_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_alphabank_message', $pb_message); //Update the order status $order->update_status('failed', ''); $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } // elseif ($_POST['status'] == 'CANCELED') // {//an error occurred // $message = __('Thank you for shopping with us. <br />However, an error occurred and the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-alphabank-payment-gateway'); // $message_type = 'error'; // $alphabank_message = array( // 'message' => $message, // 'message_type' => $message_type // ); // update_post_meta($order_id, '_alphabank_message', $pb_message); // //Update the order status // $order->update_status('failed', ''); // $checkout_url = $woocommerce->cart->get_checkout_url(); // wp_redirect($checkout_url); // exit; // } //$this->redirect_page_id = "https://donate.ellak.gr/".get_page_link($this->get_option('redirect_page_id')); if ($this->redirect_page_id == "-1") { $redirect_url = $this->get_return_url($order); } else { $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id); //For wooCoomerce 2.0 $redirect_url = add_query_arg(array('msg' => urlencode($this->msg['message']), 'type' => $this->msg['class']), $redirect_url); } wp_redirect($redirect_url); //exit; //} // if(isset($_GET['alphabank'])&& ($_GET['alphabank']==='cancel')) { // $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; // //} }
/** * Translate to the order language, the email heading of completed order email notifications to the customer. * * @param string $heading Email heading in default language * @param WC_Order $order Order object * * @return string Translated heading */ public function translateEmailHeadingCustomerCompletedOrder($heading, $order) { if (!empty($order) && $order->has_downloadable_item()) { return $this->translateEmailStringToOrderLanguage($subject, $order, 'heading_downloadable', 'customer_completed_order'); } else { return $this->translateEmailStringToOrderLanguage($heading, $order, 'heading', 'customer_completed_order'); } }
/** * Test: has_downloadable_item */ function test_has_downloadable_item() { $object = new WC_Order(); $this->assertFalse($object->has_downloadable_item()); $object = WC_Helper_Order::create_order(); $this->assertFalse($object->has_downloadable_item()); }
/** * Completed Order **/ function customer_completed_order($order_id) { $order = new WC_Order($order_id); if ($order->has_downloadable_item()) { $subject = __('[%s] Order Complete/Download Links', 'woocommerce'); $email_heading = __('Order Complete/Download Links', 'woocommerce'); } else { $subject = __('[%s] Order Complete', 'woocommerce'); $email_heading = __('Order Complete', 'woocommerce'); } $email_heading = apply_filters('woocommerce_completed_order_customer_notification_subject', $email_heading); $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = apply_filters('woocommerce_email_subject_customer_completed_order', sprintf($subject, $blogname), $order); // Buffer ob_start(); // Get mail template woocommerce_get_template('emails/customer-completed-order.php', array('order' => $order, 'email_heading' => $email_heading)); // Get contents $message = ob_get_clean(); // CC, BCC, additional headers $headers = apply_filters('woocommerce_email_headers', '', 'customer_completed_order'); // Attachments $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_completed_order'); // Send the mail $this->send($order->billing_email, $subject, $message, $headers, $attachments); }
/** * Verify a successful Payment! * */ function check_piraeusbank_response() { global $woocommerce; global $wpdb; if (isset($_GET['peiraeus']) && $_GET['peiraeus'] == 'success') { $ResultCode = $_GET['ResultCode']; if ($ResultCode != 0) { $message = __('A technical problem occured. <br />The transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'error'; $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); //Update the order status $order->update_status('failed', ''); $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } $ResponseCode = $_GET['ResponseCode']; $StatusFlag = $_GET['StatusFlag']; $HashKey = $_GET['HashKey']; $SupportReferenceID = $_GET['SupportReferenceID']; $ApprovalCode = $_GET['ApprovalCode']; $Parameters = $_GET['Parameters']; $AuthStatus = $_GET['AuthStatus']; $PackageNo = $_GET['PackageNo']; $order_id = $_GET['MerchantReference']; $order = new WC_Order($order_id); $ttquery = 'SELECT trans_ticket FROM `' . $wpdb->prefix . 'piraeusbank_transactions` WHERE `merch_ref` = ' . $order_id . ' ;'; $tt = $wpdb->get_results($ttquery); $transticket = $tt['0']->trans_ticket; //concatenate string $stcon = $transticket . $this->pb_PosId . $this->pb_AcquirerId . $order_id . $ApprovalCode . $Parameters . $ResponseCode . $SupportReferenceID . $AuthStatus . $PackageNo . $StatusFlag; //hash concatenated string $conhash = strtoupper(hash('sha256', $stcon)); if ($conhash != $HashKey) { $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'error'; $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); //Update the order status $order->update_status('failed', ''); $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } else { if ($ResponseCode == 0 || $ResponseCode == 8 || $ResponseCode == 10 || $ResponseCode == 16) { if ($order->status == 'processing') { $order->add_order_note(__('Payment Via Peiraeus Bank<br />Transaction ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Peiraeus Bank ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID, 1); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'success'; } else { if ($order->has_downloadable_item()) { //Update order status $order->update_status('completed', __('Payment received, your order is now complete.', 'woocommerce-piraeusbank-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via Peiraeus Bank<br />Transaction ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is now complete.<br />Peiraeus Transaction ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'success'; } else { //Update order status $order->update_status('processing', __('Payment received, your order is currently being processed.', 'woocommerce-piraeusbank-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via Peiraeus Bank<br />Transaction ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Peiraeus Bank ID: ', 'woocommerce-piraeusbank-payment-gateway') . $SupportReferenceID, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'success'; } $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); } } else { if ($ResponseCode == 11) { $message = __('Thank you for shopping with us.<br />Your transaction was previously received.<br />', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'success'; $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); } else { //Failed Response codes $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'error'; $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); //Update the order status $order->update_status('failed', ''); } } } } if (isset($_GET['peiraeus']) && $_GET['peiraeus'] == 'fail') { if (isset($_GET['MerchantReference'])) { $order_id = $_GET['MerchantReference']; $order = new WC_Order($order_id); $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-piraeusbank-payment-gateway'); $message_type = 'error'; $transaction_id = $_GET['SupportReferenceID']; //Add Customer Order Note $order->add_order_note($message . '<br />Piraeus Bank Transaction ID: ' . $transaction_id, 1); //Add Admin Order Note $order->add_order_note($message . '<br />Piraeus Bank Transaction ID: ' . $transaction_id); //Update the order status $order->update_status('failed', ''); $pb_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_piraeusbank_message', $pb_message); } } if (isset($_GET['peiraeus']) && $_GET['peiraeus'] == 'cancel') { $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } if ($this->redirect_page_id == "-1") { $redirect_url = $this->get_return_url($order); } else { $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id); //For wooCoomerce 2.0 $redirect_url = add_query_arg(array('msg' => urlencode($this->msg['message']), 'type' => $this->msg['class']), $redirect_url); } wp_redirect($redirect_url); exit; }
/** * Verify a successful Payment! * */ function check_nbg_response() { global $woocommerce; global $wpdb; if (isset($_GET['nbg']) && $_GET['nbg'] === 'success') { $merchantreference = $_GET['MerchantReference']; //query DB $ttquery = 'SELECT * FROM `' . $wpdb->prefix . 'nbg_transactions` WHERE `merchantreference` like "' . $merchantreference . '" ;'; $ref = $wpdb->get_results($ttquery); $orderid = $ref['0']->orderid; $xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8"?><Request version="2"/>'); $authentication = $xml->addChild('Authentication'); $authentication->addChild('password', $this->nbg_Password); $authentication->addChild('client', $this->nbg_Username); $transaction = $xml->addChild('Transaction'); $HistoricTxn = $transaction->addChild('HistoricTxn'); $HistoricTxn->addChild('reference', $ref['0']->reference); $HistoricTxn->addChild('method', 'query'); if ($this->mode == "yes") { //test mode $post_url = 'https://accreditation.datacash.com/Transaction/acq_a'; } else { //live mode $post_url = 'https://mars.transaction.datacash.com/Transaction'; } // make CURL request $ch = curl_init($post_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml->asXML()); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_NOPROGRESS, 0); $result = curl_exec($ch); // result will contain XML reply curl_close($ch); if ($result == false) { return __('Could not connect to NBG server, please contact the administrator ', 'woocommerce-nbg-payment-gateway'); } //Response $response = simplexml_load_string($result); $order = new WC_Order($orderid); if ($response->status == 1) { if (strcmp($response->reason, 'ACCEPTED') == 0) { //verified - successful payment //complete order if ($order->status == 'processing') { $order->add_order_note(__('Payment Via NBG<br />Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />NBG Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id, 1); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-nbg-payment-gateway'); $message_type = 'success'; } else { if ($order->has_downloadable_item()) { //Update order status $order->update_status('completed', __('Payment received, your order is now complete.', 'woocommerce-nbg-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via NBG Payment Gateway<br />Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is now complete.<br />NBG Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.', 'woocommerce-nbg-payment-gateway'); $message_type = 'success'; } else { //Update order status $order->update_status('processing', __('Payment received, your order is currently being processed.', 'woocommerce-nbg-payment-gateway')); //Add admin order note $order->add_order_note(__('Payment Via NBG Payment Gateway<br />Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id); //Add customer order note $order->add_order_note(__('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />NBG Transaction ID: ', 'woocommerce-nbg-payment-gateway') . $trans_id, 1); $message = __('Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.', 'woocommerce-nbg-payment-gateway'); $message_type = 'success'; } $nbg_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_nbg_message', $nbg_message); // Reduce stock levels $order->reduce_order_stock(); // Empty cart WC()->cart->empty_cart(); } } else { //payment has failed - retry $message = __('Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-nbg-payment-gateway'); $message_type = 'error'; $nbg_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_nbg_message', $pb_message); //Update the order status $order->update_status('failed', ''); $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } } else { //an error occurred $message = __('Thank you for shopping with us. <br />However, an error occurred and the transaction wasn\'t successful, payment wasn\'t received.', 'woocommerce-nbg-payment-gateway'); $message_type = 'error'; $nbg_message = array('message' => $message, 'message_type' => $message_type); update_post_meta($order_id, '_nbg_message', $pb_message); //Update the order status $order->update_status('failed', ''); $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } if ($this->redirect_page_id == "-1") { $redirect_url = $this->get_return_url($order); } else { $redirect_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id); //For wooCoomerce 2.0 $redirect_url = add_query_arg(array('msg' => urlencode($this->msg['message']), 'type' => $this->msg['class']), $redirect_url); } wp_redirect($redirect_url); exit; } if (isset($_GET['nbg']) && $_GET['nbg'] === 'cancel') { $checkout_url = $woocommerce->cart->get_checkout_url(); wp_redirect($checkout_url); exit; } }
/** * Translate to the order language, the email heading of completed order email notifications to the customer * * @param string $heading Email heading in default language * @param WC_Order $order Order object * * @return string Translated heading */ function translate_email_heading_customer_completed_order($heading, $order) { if (!empty($order) && $order->has_downloadable_item()) { return $this->translate_email_string_to_order_language($subject, $order, 'heading_downloadable', 'customer_completed_order'); } else { return $this->translate_email_string_to_order_language($heading, $order, 'heading', 'customer_completed_order'); } }