Example #1
0
require_once 'extern/Mobilpay/Payment/Request/Abstract.php';
require_once 'extern/Mobilpay/Payment/Request/Card.php';
require_once 'extern/Mobilpay/Payment/Request/Notify.php';
require_once 'extern/Mobilpay/Payment/Invoice.php';
require_once 'extern/Mobilpay/Payment/Address.php';
$errorCode = 0;
$errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_NONE;
$errorMessage = '';
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
    if (isset($_POST['env_key']) && isset($_POST['data'])) {
        #calea catre cheia privata
        #cheia privata este generata de mobilpay, accesibil in Admin -> Conturi de comerciant -> Detalii -> Setari securitate
        $privateKeyFilePath = getUserConfig('mobilpay_key');
        try {
            global $objPmReq;
            $objPmReq = Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath);
            #uncomment the line below in order to see the content of the request
            print_r($objPmReq);
            $errorCode = $objPmReq->objPmNotify->errorCode;
            // action = status only if the associated error code is zero
            if ($errorCode == "0") {
                switch ($objPmReq->objPmNotify->action) {
                    #orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage;
                    #pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId;
                    case 'confirmed':
                        #cand action este confirmed avem certitudinea ca banii au plecat din contul posesorului de card si facem update al starii comenzii si livrarea produsului
                        //update DB, SET status = "confirmed/captured"
                        $_GET['mobilpayipn'] = true;
                        $_GET['mobilpayipn_post'] = true;
                        require_once "extensions/process_offer_ws.php";
                        global $objPmReq;
Example #2
0
 public function payment_confirm()
 {
     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/Request/Notify.php';
     require_once 'application/libraries/Mobilpay/Payment/Address.php';
     $errorCode = 0;
     $errorType = \Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_NONE;
     if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
         if (isset($_POST['env_key']) && isset($_POST['data'])) {
             $privateKeyFilePath = 'application/libraries/Mobilpay/private.key';
             try {
                 $objPmReq = \Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath);
                 $order = $this->OrdersModel->getOrderByCode($objPmReq->orderId);
                 if ($objPmReq->objPmNotify->errorCode != 0) {
                     $this->OrdersModel->setOrderPaymentStatus(App_constants::$PAYMENT_STATUS_CANCELED, $order);
                 } else {
                     switch ($objPmReq->objPmNotify->action) {
                         #orice action este insotit de un cod de eroare si de un mesaj de eroare. Acestea pot fi citite folosind $cod_eroare = $objPmReq->objPmNotify->errorCode; respectiv $mesaj_eroare = $objPmReq->objPmNotify->errorMessage;
                         #pentru a identifica ID-ul comenzii pentru care primim rezultatul platii folosim $id_comanda = $objPmReq->orderId;
                         case 'confirmed':
                             $this->OrdersModel->setOrderPaymentStatus(App_constants::$PAYMENT_STATUS_CONFIRMED, $order);
                             $email = $order->getUser()->getEmail();
                             $subject = "Confirmare comandă nr. " . $order->getOrderNumber();
                             $email = $order->getUser()->getEmail();
                             $body = "Buna Ziua<br/> Plata dumneavoastra pe Mobilpay.ro a fost finalizata cu success. <br/><br/> Va multumim,<br/> <b>Helpie</b>";
                             \NeoMail::genericMail($body, $subject, $email);
                             break;
                         case 'confirmed_pending':
                             #cand action este confirmed_pending inseamna ca tranzactia este in curs de verificare antifrauda. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare.
                             $this->OrdersModel->setOrderPaymentStatus(App_constants::$PAYMENT_STATUS_PENDING, $order);
                             break;
                         case 'paid_pending':
                             $this->OrdersModel->setOrderPaymentStatus($objPmReq->objPmNotify->action, $order);
                             #cand action este paid_pending inseamna ca tranzactia este in curs de verificare. Nu facem livrare/expediere. In urma trecerii de aceasta verificare se va primi o noua notificare pentru o actiune de confirmare sau anulare.
                             $errorMessage = $objPmReq->objPmNotify->getCrc();
                             break;
                         case 'paid':
                             $this->OrdersModel->setOrderPaymentStatus($objPmReq->objPmNotify->action, $order);
                             #cand action este paid inseamna ca tranzactia este in curs de procesare. Nu facem livrare/expediere. In urma trecerii de aceasta procesare se va primi o noua notificare pentru o actiune de confirmare sau anulare.
                             $errorMessage = $objPmReq->objPmNotify->getCrc();
                             break;
                         case 'canceled':
                             $this->OrdersModel->setOrderPaymentStatus($objPmReq->objPmNotify->action, $order);
                             #cand action este canceled inseamna ca tranzactia este anulata. Nu facem livrare/expediere.
                             $errorMessage = $objPmReq->objPmNotify->getCrc();
                             break;
                         case 'credit':
                             #cand action este credit inseamna ca banii sunt returnati posesorului de card. Daca s-a facut deja livrare, aceasta trebuie oprita sau facut un reverse.
                             $errorMessage = $objPmReq->objPmNotify->getCrc();
                             $this->OrdersModel->setOrderPaymentStatus(App_constants::$PAYMENT_STATUS_CANCELED, $order);
                             break;
                         default:
                             $errorType = \Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
                             $errorCode = \Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_ACTION;
                             $errorMessage = 'mobilpay_refference_action paramaters is invalid';
                             break;
                     }
                 }
             } catch (Exception $e) {
                 $errorType = \Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_TEMPORARY;
                 $errorCode = $e->getCode();
                 $errorMessage = $e->getMessage();
             }
         } else {
             $errorType = \Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
             $errorCode = \Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS;
             $errorMessage = 'mobilpay.ro posted invalid parameters';
         }
     } else {
         $errorType = \Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
         $errorCode = \Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_METHOD;
         $errorMessage = 'invalid request metod for payment confirmation';
     }
     header('Content-type: application/xml');
     echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
     if (isset($errorCode) && isset($errorMessage) && $errorCode == 0) {
         echo "<crc>{$errorMessage}</crc>";
     } else {
         if (!isset($errorMessage)) {
             $errorMessage = "";
         }
         echo "<crc error_type=\"{$errorType}\" error_code=\"{$errorCode}\">{$errorMessage}</crc>";
     }
 }
 function check_mobilpaycard_response()
 {
     global $woocommerce;
     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/request/class-mobilpay-notify.php';
     require_once plugin_dir_path(__FILE__) . 'includes/class-mobilpay-invoice.php';
     require_once plugin_dir_path(__FILE__) . 'includes/class-mobilpay-address.php';
     $errorCode = 0;
     $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_NONE;
     $errorMessage = '';
     if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) {
         if (isset($_POST['env_key']) && isset($_POST['data'])) {
             // Path to your merchant private key
             if ($this->environment == "yes") {
                 $privateKeyFilePath = plugin_dir_path(__FILE__) . 'certificates/sandbox.' . $this->merchant_id . 'private.key';
             } else {
                 $privateKeyFilePath = plugin_dir_path(__FILE__) . 'certificates/live.' . $this->merchant_id . 'private.key';
             }
             try {
                 $objPmReq = Mobilpay_Payment_Request_Abstract::factoryFromEncrypted($_POST['env_key'], $_POST['data'], $privateKeyFilePath);
                 // Get order information
                 $order = new WC_Order($objPmReq->orderId);
                 // action = status only if the associated error code is zero
                 if ($objPmReq->objPmNotify->errorCode == 0) {
                     switch ($objPmReq->objPmNotify->action) {
                         case 'confirmed':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             if ($order->status != 'processing') {
                                 // Mark order as paid
                                 $order->payment_complete();
                                 // Payment has been successful
                                 $order->add_order_note($errorMessage);
                                 // Empty shopping cart
                                 $woocommerce->cart->empty_cart();
                             }
                             break;
                         case 'confirmed_pending':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             break;
                         case 'paid_pending':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             break;
                         case 'paid':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             break;
                         case 'canceled':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             $order->update_status('cancelled');
                             break;
                         case 'credit':
                             $errorMessage = $objPmReq->objPmNotify->errorMessage;
                             $order->update_status('refunded');
                             break;
                         default:
                             $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
                             $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_ACTION;
                             $errorMessage = 'mobilPay refference action paramaters is invalid.';
                             break;
                     }
                 } else {
                     // Rejected transaction error message
                     $errorMessage = $objPmReq->objPmNotify->errorMessage;
                     $order->add_order_note($errorMessage);
                 }
             } catch (Exception $e) {
                 $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_TEMPORARY;
                 $errorCode = $e->getCode();
                 $errorMessage = $e->getMessage();
             }
         } else {
             $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
             $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS;
             $errorMessage = 'mobilPay posted invalid parameters.';
         }
     } else {
         $errorType = Mobilpay_Payment_Request_Abstract::CONFIRM_ERROR_TYPE_PERMANENT;
         $errorCode = Mobilpay_Payment_Request_Abstract::ERROR_CONFIRM_INVALID_POST_METHOD;
         $errorMessage = 'Invalid request method for payment confirmation.';
     }
     // Generate xml response
     ob_start();
     echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
     if ($errorCode == 0) {
         echo "<crc>{$errorMessage}</crc>";
     } else {
         echo "<crc error_type=\"{$errorType}\" error_code=\"{$errorCode}\">{$errorMessage}</crc>";
     }
     ob_flush();
     exit;
 }