Example #1
0
    private function processCardPayment($data)
    {
        switch ($data['order_type']) {
            case "alimentare":
                $order = $this->OrdersModel->alimentareCont($data);
                break;
            case "pachet":
                $order = $this->OrdersModel->buyPachet($data);
                break;
            default:
                echo "<h1>Ooops, eroare. Contactati administratorul helpie.</h1>";
                exit;
                break;
        }
        require_once 'application/libraries/Mobilpay/Payment/Request/Abstract.php';
        require_once 'application/libraries/Mobilpay/Payment/Request/Card.php';
        require_once 'application/libraries/Mobilpay/Payment/Invoice.php';
        require_once 'application/libraries/Mobilpay/Payment/Address.php';
        $paymentUrl = 'http://sandboxsecure.mobilpay.ro';
        //$paymentUrl = 'https://secure.mobilPay.ro';
        $x509FilePath = 'application/libraries/Mobilpay/public.cer';
        try {
            srand((double) microtime() * 1000000);
            $objPmReqCard = new \Mobilpay_Payment_Request_Card();
            $objPmReqCard->signature = 'NVQD-8THN-YH1P-QY3M-D5T9';
            $objPmReqCard->orderId = $order->getOrderNumber();
            $objPmReqCard->confirmUrl = base_url('neocart/payment_confirm');
            $objPmReqCard->returnUrl = base_url('neocart/finalizare_card?code=' . $order->getOrderNumber());
            $objPmReqCard->invoice = new \Mobilpay_Payment_Invoice();
            $objPmReqCard->invoice->currency = 'RON';
            $objPmReqCard->invoice->customer_type = 2;
            $total = $order->getTotal();
            if (!$total) {
                exit("ERROR: 3:31, Please contact administrator !");
            }
            $objPmReqCard->invoice->amount = $total;
            $objPmReqCard->invoice->details = 'Tranzactii Helpie';
            $billingAddress = new \Mobilpay_Payment_Address();
            $billingAddress->type = "person";
            $billingAddress->firstName = $order->getUser()->getFirstname();
            $billingAddress->lastName = $order->getUser()->getLastname();
            $billingAddress->email = $order->getUser()->getEmail();
            $billingAddress->mobilePhone = $order->getUser()->getPhone();
            $objPmReqCard->invoice->setBillingAddress($billingAddress);
            $objPmReqCard->encrypt($x509FilePath);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
        $e = "";
        echo '
        <div class="span-15 prepend-1" style="margin:0 auto; text-align:center; margin-top:100px;">
        <?php if (!($e instanceof Exception)): ?>
                <p>
                <form name="frmPaymentRedirect" method="post" action="' . $paymentUrl . '">
                    <input type="hidden" name="env_key" value="' . $objPmReqCard->getEnvKey() . '"/>
                    <input type="hidden" name="data" value="' . $objPmReqCard->getEncData() . '"/>
                    <p>	

                        Pentru a finaliza plata vei redirectat catre pagina de plati securizata a mobilpay.ro
                    </p>
                    <p>
                        Daca nu esti redirectat in 3 secunde apasa <input type="image" value="Redirect"/>
                    </p>
                </form>
            </p>
            <script type="text/javascript" language="javascript">
               window.setTimeout(document.frmPaymentRedirect.submit(),1000);
            </script>
        <?php else: ?>
            <p><strong><?php echo $e->getMessage(); ?></strong></p>
        <?php endif; ?>
</div>';
    }
 		if (is_file($fisier)) {
 			$ck .= ' e bine <br />';
 			if (file_exists($fisier)) {
 			$ck .= ' exista ';
 			} else {
 			$ck .= ' nu exista ';
 			}
 		} else {
 			$ck .= ' ceva nu este in regula ';
 		}
 		
 		echo '>>>> '.$ck;
 		*/
 try {
     srand((double) microtime() * 1000000);
     $objPmReqCard = new Mobilpay_Payment_Request_Card();
     #merchant account signature - generated by mobilpay.ro for every merchant account
     #semnatura contului de comerciant - mergi pe www.mobilpay.ro Admin -> Conturi de comerciant -> Detalii -> Setari securitate
     $objPmReqCard->signature = 'CVMG-8YLX-UDUH-PD7G-AVYV';
     #you should assign here the transaction ID registered by your application for this commercial operation
     #order_id should be unique for a merchant account
     $objPmReqCard->orderId = md5(uniqid(rand()));
     #below is where mobilPay will send the payment result. This URL will always be called first; mandatory
     $link_confirm = JRoute::_('index.php?option=com_sauto&view=pay&task=cc_confirm');
     $objPmReqCard->confirmUrl = $baza . $link_confirm;
     #below is where mobilPay redirects the client once the payment process is finished. Not to be mistaken for a "successURL" nor "cancelURL"; mandatory
     $link_return = JRoute::_('index.php?option=com_sauto&view=pay&task=cc_return');
     $objPmReqCard->returnUrl = $baza . $link_return;
     $item =& JRequest::getVar('item', '', 'post', 'string');
     $uid =& JRequest::getVar('uid', '', 'post', 'string');
     $valoare =& JRequest::getVar('valoare', '', 'post', 'string');
        public function generate_mobilpay_card_form($order_id)
        {
            global $woocommerce;
            // Get order information
            $order = new WC_Order($order_id);
            // Decide which URL to post to
            $environment_url = $this->environment == "yes" ? 'http://sandboxsecure.mobilpay.ro' : 'https://secure.mobilpay.ro';
            require_once plugin_dir_path(__FILE__) . 'includes/request/class-mobilpay-abstract.php';
            require_once plugin_dir_path(__FILE__) . 'includes/request/class-mobilpay-card.php';
            require_once plugin_dir_path(__FILE__) . 'includes/class-mobilpay-invoice.php';
            require_once plugin_dir_path(__FILE__) . 'includes/class-mobilpay-address.php';
            // Path to your merchant public certificate
            if ($this->environment == "yes") {
                $x509FilePath = plugin_dir_path(__FILE__) . 'certificates/sandbox.' . $this->merchant_id . '.public.cer';
            } else {
                $x509FilePath = plugin_dir_path(__FILE__) . 'certificates/live.' . $this->merchant_id . '.public.cer';
            }
            try {
                srand((double) microtime() * 1000000);
                $objPmReqCard = new Mobilpay_Payment_Request_Card();
                // Merchant account signature - generated by mobilPay for every merchant account
                $objPmReqCard->signature = $this->merchant_id;
                // Order ID
                $objPmReqCard->orderId = str_replace("#", "", $order->get_order_number());
                // Where mobilPay will send the payment result - this URL will always be called first
                $objPmReqCard->confirmUrl = $this->notify_url;
                // Where mobilPay redirects the client once the payment process is finished
                $objPmReqCard->returnUrl = $this->get_return_url($order);
                // Payment information: currency, amount, details
                $objPmReqCard->invoice = new Mobilpay_Payment_Invoice();
                $objPmReqCard->invoice->currency = 'RON';
                // currency accepted by mobilPay
                $objPmReqCard->invoice->amount = $order->order_total;
                $objPmReqCard->invoice->details = __('Credit/debit card payment via mobilPay', 'mobilpay');
                // Billing details
                $billingAddress = new Mobilpay_Payment_Address();
                if (!empty($order->billing_company)) {
                    $billingAddress->type = 'company';
                } else {
                    $billingAddress->type = 'person';
                }
                $billingAddress->firstName = $order->billing_first_name;
                $billingAddress->lastName = $order->billing_last_name;
                $billingAddress->address = $order->billing_address_1 . ', ' . $order->billing_address_2 . ', ' . $order->billing_city . ', ' . $order->billing_state . ', ' . $order->billing_postcode . ', ' . $order->billing_country;
                $billingAddress->email = $order->billing_email;
                $billingAddress->mobilePhone = $order->billing_phone;
                $objPmReqCard->invoice->setBillingAddress($billingAddress);
                // Shipping details
                if (!empty($order->shipping_address_1)) {
                    $shippingAddress = new Mobilpay_Payment_Address();
                    if (!empty($order->shipping_company)) {
                        $shippingAddress->type = 'company';
                    } else {
                        $shippingAddress->type = 'person';
                    }
                    $shippingAddress->firstName = $order->shipping_first_name;
                    $shippingAddress->lastName = $order->shipping_last_name;
                    $shippingAddress->address = $order->shipping_address_1 . ', ' . $order->shipping_address_2 . ', ' . $order->shipping_city . ', ' . $order->shipping_state . ', ' . $order->shipping_postcode . ', ' . $order->shipping_country;
                    $shippingAddress->email = $order->shipping_email;
                    $shippingAddress->mobilePhone = $order->shipping_phone;
                    $objPmReqCard->invoice->setShippingAddress($shippingAddress);
                }
                // Encrypt data
                $objPmReqCard->encrypt($x509FilePath);
            } catch (Exception $e) {
            }
            wc_enqueue_js('
			    $.blockUI({
			        message: "' . esc_js(__('Redirecting to mobilPay 3D Secure payment gateway to make the payment.', 'mobilpay')) . '",
			        baseZ: 99999,
			        overlayCSS:
			        {
			            background: "#fff",
			            opacity: 1,
			            cursor: "wait"
			        },
			        css: {
			            padding:         "30px",
			            zindex:          "9999999",
			            textAlign:       "center",
			            color:           "#333",
			            border:          "3px solid #aaa",
			            backgroundColor: "#fff",
			            cursor:          "wait"
			        }
			    });
			jQuery("#submit_mobilpay_card_payment_form").click();
			');
            ?>
			<form name="frmPaymentRedirect" method="post" action="<?php 
            echo $environment_url;
            ?>
">
				<input type="hidden" name="env_key" value="<?php 
            echo $objPmReqCard->getEnvKey();
            ?>
"/>
				<input type="hidden" name="data" value="<?php 
            echo $objPmReqCard->getEncData();
            ?>
"/>
				<input type="submit" class="button" id="submit_mobilpay_card_payment_form" value="<?php 
            echo __('Pay for order', 'mobilpay');
            ?>
" /> <a class="button" href="<?php 
            echo esc_url($order->get_cancel_order_url());
            ?>
"><?php 
            echo __('Cancel order', 'mobilpay');
            ?>
</a>
				<script type="text/javascript">
					jQuery("#mobilpay_payment_form").hide();
				</script>
			</form>

		<?php 
        }