Exemple #1
0
 public function updateStatus()
 {
     if (!$this->payment) {
         return false;
     }
     $order = Order::getOrder($this->payment->order_id);
     // Retrieve transaction from gateway
     $result = $this->method->getTransaction($this->payment->gateway_id, $this->payment->order_id, $order->total);
     if ($result->success) {
         $this->payment->set('status', Payment::PAYMENT_STATUS_APPROVED);
     } else {
         if ($result->status == 'incompleted') {
             $this->payment->set('status', Payment::PAYMENT_STATUS_INCOMPLETED);
         } else {
             $this->payment->set('status', Payment::PAYMENT_STATUS_REJECTED);
         }
     }
     $this->payment->save();
 }
Exemple #2
0
$content .= "\n\nPOST\n";
$content .= json_encode($_POST);
$content .= "\n\n";
//file_put_contents($file, $content, FILE_APPEND);
// END - ONLY FOR TEST PURPOSES
$token = $app->getRequest()->get('token');
$processResult = 00;
if (empty($token)) {
    $processResult = 99;
} else {
    //TODO falta validar la firma....
    $paymentMethod = new PaymentManager($app, PuntoPagos::PAYMENT_METHOD_TYPE);
    $paymentMethod->loadByGatewayId($token);
    $paymentMethod->updateStatus();
    $orderId = $paymentMethod->getOrderId();
    $order = Order::getOrder($orderId);
    if ($paymentMethod->getStatus() == Payment::PAYMENT_STATUS_APPROVED) {
        $order->set('status', Order::ORDER_STATUS_COMPLETED);
    } else {
        $order->set('status', Order::ORDER_STATUS_FAILED);
    }
    $order->save();
    if ($paymentMethod->getStatus() == Payment::PAYMENT_STATUS_APPROVED) {
        //Sacar order products
        $products = OrderProduct::getProductsByOrderId($order->id);
        if (empty($products)) {
            //TODO correo aqui
            //TODO log
            $processResult = 99;
        }
        foreach ($products as $product) {