Exemplo n.º 1
0
function ctala_log_me_both($param)
{
    ctala_log_me($param);
    ctala_log_me_screen($param);
}
Exemplo n.º 2
0
 function process_response()
 {
     $SUFIJO = __FUNCTION__;
     $id = $_REQUEST['id'];
     $topic = $_REQUEST['topic'];
     if (isset($id) && isset($topic)) {
         ctala_log_me("TOPIC : " . $topic, __FUNCTION__);
         ctala_log_me($_REQUEST, __FUNCTION__);
         $mp = new \MP($this->get_option('clientid'), $this->get_option('secretkey'));
         /*
          * Creamos el merchant info dependiendo del request.
          */
         if ($topic == "payment") {
             $payment_info = $mp->get("/collections/notifications/" . $id);
             $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"]);
         } elseif ($topic == 'merchant_order') {
             $merchant_order_info = $mp->get("/merchant_orders/" . $_GET["id"]);
         }
         /*
          * Logeamos los datos.
          */
         ctala_log_me($merchant_order_info, __FUNCTION__);
         if ($merchant_order_info["status"] == 200) {
             //Usamos la variabel [external_reference] para el order_id
             $order_id = $merchant_order_info["response"]["external_reference"];
             $TrxId = $merchant_order_info["response"]["id"];
             $PreferenceId = $merchant_order_info["response"]["preference_id"];
             add_post_meta($order_id, self::MP_META_KEY_ID, $TrxId, true);
             add_post_meta($order_id, self::MP_META_KEY_PREFERENCE_ID, $PreferenceId, true);
             //Creamos la OC para agregar las notas y completar en caso de que sea necesario.
             global $woocommerce;
             $order = new \WC_Order($order_id);
             $paid_amount = 0;
             foreach ($merchant_order_info["response"]["payments"] as $payment) {
                 if ($payment['status'] == 'approved') {
                     $paid_amount += $payment['transaction_amount'];
                 }
             }
             if ($paid_amount >= $merchant_order_info["response"]["total_amount"]) {
                 if (count($merchant_order_info["response"]["shipments"]) > 0) {
                     // The merchant_order has shipments
                     if ($merchant_order_info["response"]["shipments"][0]["status"] == "ready_to_ship") {
                         $mensaje = "Pago total completado. Puedes entregar el pedido  : {$TrxId}";
                         $order->add_order_note($mensaje);
                         $order->add_order_note("PREF ID : {$PreferenceId}");
                         ctala_log_me($mensaje);
                         $order->update_status('processing', "Pago recibido, se procesa la orden : {$TrxId}");
                     }
                 } else {
                     // The merchant_order don't has any shipments
                     $mensaje = "PAGO COMPLETADO {$TrxId}";
                     ctala_log_me($mensaje);
                     $order->update_status('processing', "Pago recibido, se procesa la orden : {$TrxId}");
                     $order->add_order_note($mensaje);
                     $order->add_order_note("PREF ID : {$PreferenceId}");
                 }
             } else {
                 $mensaje = "Aun no pagado.";
                 $order->add_order_note($mensaje);
                 ctala_log_me($mensaje);
                 //                    $order->update_status('pending', "pago aun no recibido");
             }
         }
     }
 }