/** * Generate the Piraeus Payment button link * */ function generate_piraeusbank_form($order_id) { global $woocommerce; global $wpdb; $order = new WC_Order($order_id); //echo $this->pb_authorize; if ($this->pb_authorize == "yes") { $requestType = '00'; $ExpirePreauth = '30'; } else { $requestType = '02'; $ExpirePreauth = '0'; } $installments = 1; if ($this->pb_installments > 1) { $installments = intval($order->get_total() / 30); $installments = min($installments, $this->pb_installments); } try { $soap = new SoapClient("https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx?WSDL"); $ticketRequest = array('Username' => $this->pb_Username, 'Password' => hash('md5', $this->pb_Password), 'MerchantId' => $this->pb_PayMerchantId, 'PosId' => $this->pb_PosId, 'AcquirerId' => $this->pb_AcquirerId, 'MerchantReference' => $order_id, 'RequestType' => $requestType, 'ExpirePreauth' => $ExpirePreauth, 'Amount' => $order->get_total(), 'CurrencyCode' => '978', 'Installments' => $installments, 'Bnpl' => '0', 'Parameters' => ''); $xml = array('Request' => $ticketRequest); $oResult = $soap->IssueNewTicket($xml); if ($oResult->IssueNewTicketResult->ResultCode == 0) { // store TranTicket in table $wpdb->insert($wpdb->prefix . 'piraeusbank_transactions', array('trans_ticket' => $oResult->IssueNewTicketResult->TranTicket, 'merch_ref' => $order_id, 'timestamp' => current_time('mysql', 1))); //redirect to payment wc_enqueue_js(' $.blockUI({ message: "' . esc_js(__('Thank you for your order. We are now redirecting you to Piraeus Bank to make payment.', 'woocommerce-piraeusbank-payment-gateway')) . '", baseZ: 99999, overlayCSS: { background: "#fff", opacity: 0.6 }, css: { padding: "20px", zindex: "9999999", textAlign: "center", color: "#555", border: "3px solid #aaa", backgroundColor:"#fff", cursor: "wait", lineHeight: "24px", } }); jQuery("#submit_pb_payment_form").click(); '); $LanCode = "el-GR"; /* Other available Language codes en-US: English ru-RU: Russian de-DE: German */ return '<form action="' . esc_url("https://paycenter.piraeusbank.gr/redirection/pay.aspx") . '" method="post" id="pb_payment_form" target="_top"> <input type="hidden" id="AcquirerId" name="AcquirerId" value="' . esc_attr($this->pb_AcquirerId) . '"/> <input type="hidden" id="MerchantId" name="MerchantId" value="' . esc_attr($this->pb_PayMerchantId) . '"/> <input type="hidden" id="PosID" name="PosID" value="' . esc_attr($this->pb_PosId) . '"/> <input type="hidden" id="User" name="User" value="' . esc_attr($this->pb_Username) . '"/> <input type="hidden" id="LanguageCode" name="LanguageCode" value="' . $LanCode . '"/> <input type="hidden" id="MerchantReference" name="MerchantReference" value="' . esc_attr($order_id) . '"/> <!-- Button Fallback --> <div class="payment_buttons"> <input type="submit" class="button alt" id="submit_pb_payment_form" value="' . __('Pay via Pireaus Bank', 'woocommerce-piraeusbank-payment-gateway') . '" /> <a class="button cancel" href="' . esc_url($order->get_cancel_order_url()) . '">' . __('Cancel order & restore cart', 'woocommerce-piraeusbank-payment-gateway') . '</a> </div> <script type="text/javascript"> jQuery(".payment_buttons").hide(); </script> </form>'; } else { echo __('An error occured, please contact the Administrator', 'woocommerce-piraeusbank-payment-gateway'); } } catch (SoapFault $fault) { $order->add_order_note(__('Error' . $fault, '')); } }
function process_order($order = null, $user = null, $params = null) { global $wpcoDb, $Order, $Item, $Javascript; $errors = array(); $wpcoDb->model = $Item->model; $items = $wpcoDb->find_all(array('order_id' => $order->id)); // Use ticketing system to report the transaction // https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx $wsdl = "https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx?WSDL"; $options = array('trace' => true, 'cache_wsdl' => WSDL_CACHE_NONE); $client = new SoapClient($wsdl, $options); $parameters = array('Request' => array('Username' => $this->get_option('piraeus_Username'), 'Password' => md5($this->get_option('piraeus_Password')), 'AcquirerId' => $this->get_option('piraeus_AcquirerId'), 'MerchantId' => $this->get_option('piraeus_MerchantId'), 'PosId' => $this->get_option('piraeus_PosId'), 'MerchantReference' => $order->id, 'CurrencyCode' => '978', 'RequestType' => '02', 'ExpirePreauth' => '0', 'Amount' => $order->total, 'Installments' => "0", 'Bnpl' => "0")); $result = $client->IssueNewTicket($parameters); if (!empty($result->IssueNewTicketResult)) { if ($result->IssueNewTicketResult->ResultCode == 0) { $wpcoDb->model = $Order->model; $wpcoDb->save_field('transid', $result->IssueNewTicketResult->TranTicket, array('id' => $order->id)); } else { $errors[] = $result->IssueNewTicketResult->ResultDescription; } } else { $errors[] = __('Communication failed, please contact the merchant', $this->extension_name); } // Render the payment form $this->render('views' . DS . 'form', array('order' => $order, 'items' => $items, 'user' => $user, 'params' => $params, 'request' => $parameters['Request'], 'errors' => $errors), true, false, 'piraeus'); }