public function createOpenpayCustomer()
 {
     $customerData = array('name' => $this->order->billing_first_name, 'last_name' => $this->order->billing_last_name, 'email' => $this->order->billing_email, 'requires_account' => false, 'phone_number' => $this->order->billing_phone, 'address' => array('line1' => substr($this->order->billing_address_1, 0, 200), 'line2' => substr($this->order->billing_address_2, 0, 50), 'line3' => '', 'state' => $this->order->billing_state, 'city' => $this->order->billing_city, 'postal_code' => $this->order->billing_postcode, 'country_code' => $this->order->billing_country));
     $openpay = Openpay::getInstance($this->merchant_id, $this->private_key);
     Openpay::setProductionMode($this->is_sandbox ? false : true);
     try {
         $customer = $openpay->customers->add($customerData);
         if (is_user_logged_in()) {
             update_user_meta(get_current_user_id(), '_openpay_customer_id', $customer->id);
         }
         return $customer;
     } catch (Exception $e) {
         $this->error($e);
         return false;
     }
 }
 public function cargoTienda()
 {
     $openpay = Openpay::getInstance('m7bm553khn5nbyn5fg75', 'sk_80f1cd0745f24af8ae46929496601fa5');
     // Variable de identificación.
     $cliente = array('name' => Input::get('nombre'), 'last_name' => Input::get('apellido'), 'phone' => Input::get('telefono') ?: null, 'email' => Input::get('email'));
     $chargeData = array('method' => 'store', 'amount' => (double) Input::get('monto'), 'description' => 'Cargo a tienda', 'customer' => $cliente);
     $charge = $openpay->charges->create($chargeData);
     return View::make('pago-tienda', array('charge' => $charge, 'email' => Input::get('email')));
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('Intagono\\Openpay\\Openpay', function ($app) {
         $productionMode = config('openpay.production_mode');
         $merchantId = config('openpay.merchant_id');
         $privayeKey = config('openpay.private_key');
         $openpayCore = OpenpayCore::getInstance($merchantId, $privayeKey);
         if ($productionMode) {
             OpenpayCore::setProductionMode(true);
         }
         return new Openpay($openpayCore);
     });
     $this->app->bind('openpay', 'Intagono\\Openpay\\Openpay');
     $this->mergeConfigFrom(__DIR__ . '/config/openpay.php', 'openpay');
 }
 public static function setProductionMode($mode)
 {
     self::$sandboxMode = $mode ? false : true;
 }
/**
 *	Function after change status to 
 */
function openpay_pay_refunded($order_id)
{
    global $woocommerce;
    global $wpdb;
    require_once 'lib/Openpay.php';
    $wc = new WC_OpenPay();
    $openpay = Openpay::getInstance($wc->openpay_id, $wc->openpay_private_key);
    Openpay::setSandboxMode($this->openpay_sandbox);
    $order = new WC_Order($order_id);
    $customers_table = $wpdb->prefix . 'woocommerce_openpay_customers';
    $customers_data = $wpdb->get_results('SELECT * FROM ' . $customers_table . ' WHERE ID_USER='******'woocommerce_openpay_pays';
    $pay_data = $wpdb->get_results('SELECT * FROM ' . $customers_pays . " WHERE ID_ORDER='" . $order_id . "' AND METHOD='card' AND STATUS='completed' ");
    $charge = $customer->charges->get($pay_data[0]->ID_OPENPAY_CHARGE);
    $refundData = array('description' => 'devolución');
    $charge->refund($refundData);
    //wp_die( "Openpay IPN Request Verification Code ->".var_dump($charge), "Openpay IPN", array( 'response' => 200 ) );
}
 public function createOpenpayWebhook($webhook_data)
 {
     $result = new stdClass();
     $file = $this->file;
     if (file_exists($file)) {
         require_once $file;
     } else {
         $result->error = 'Openpay library is missing';
         return $result;
     }
     $sk = $this->getSecretApiKey();
     $id = $this->getMerchantId();
     $openpay = Openpay::getInstance($id, $sk);
     Openpay::setProductionMode($this->isProductionMode());
     try {
         $webhook = $openpay->webhooks->add($webhook_data);
         return $webhook;
     } catch (OpenpayApiTransactionError $e) {
         $result->error = $this->error($e);
     } catch (OpenpayApiRequestError $e) {
         $result->error = $this->error($e);
     } catch (OpenpayApiConnectionError $e) {
         $result->error = $this->error($e);
     } catch (OpenpayApiAuthError $e) {
         $result->error = $this->error($e);
     } catch (OpenpayApiError $e) {
         $result->error = $this->error($e);
     } catch (Exception $e) {
         $result->error = $this->error($e);
     }
     return $result;
 }
 public function createWebhook($force_host_ssl = false)
 {
     $protocol = get_option('woocommerce_force_ssl_checkout') == 'no' ? 'http' : 'https';
     $url = site_url('/', $protocol) . 'wc-api/Openpay_Stores';
     $webhook_data = array('url' => $url, 'force_host_ssl' => $force_host_ssl, 'event_types' => array('verification', 'charge.succeeded', 'charge.created', 'charge.cancelled', 'charge.failed', 'payout.created', 'payout.succeeded', 'payout.failed', 'spei.received', 'chargeback.created', 'chargeback.rejected', 'chargeback.accepted'));
     $openpay = Openpay::getInstance($this->merchant_id, $this->private_key);
     Openpay::setProductionMode($this->is_sandbox ? false : true);
     try {
         $webhook = $openpay->webhooks->add($webhook_data);
         if (is_user_logged_in()) {
             update_user_meta(get_current_user_id(), '_openpay_webhook_id', $webhook->id);
         }
         return $webhook;
     } catch (Exception $e) {
         $force_host_ssl = $force_host_ssl == false ? true : false;
         // Si viene con parámtro FALSE, solicito que se force el host SSL
         $this->errorWebhook($e, $force_host_ssl, $url);
         return false;
     }
 }
 protected function _setOpenpayObject()
 {
     /* Create OpenPay object */
     $this->_openpay = Openpay::getInstance(Mage::getStoreConfig('payment/common/merchantid'), Mage::getStoreConfig('payment/common/privatekey'));
     Openpay::setProductionMode(!Mage::getStoreConfig('payment/common/sandbox'));
 }
示例#9
0
 function __construct()
 {
     $this->openpay = Openpay::getInstance($this->apikeyPrivate, $this->apikey);
     $this->app = Slim::getInstance();
     $this->response = $this->__response();
 }
示例#10
0
 public function transaccion()
 {
     //Variables carrito
     $total = $this->cart->total();
     //Open pay-button
     $monto = $total;
     $descripcion = 'Cargo de prueba';
     $token = $this->input->post('token_id');
     $use_points = $this->input->post('use_card_points');
     $device_session_id = $this->input->post('deviceIdHiddenFieldName');
     $openpay = Openpay::getInstance('mbbhthnfoofqpkzdjqyz', 'sk_9c0cda74d8ec44f6884796670593f36c');
     //Guardar cliente
     $correo = $this->input->post('correo-cliente');
     $nombre = $this->input->post('nombre-cliente');
     $ape_paterno = $this->input->post('ape-paterno');
     $ape_materno = $this->input->post('ape-materno');
     $telefono = $this->input->post('telefono');
     $cliente = array('correo' => $correo, 'nombre' => $nombre, 'ape_paterno' => $ape_paterno, 'ape_materno' => $ape_materno, 'telefono' => $telefono, 'fecha_creado' => date('Y-m-d H:i:s'));
     $customer = array('name' => $nombre, 'last_name' => $ape_paterno, 'phone_number' => $telefono, 'email' => $correo);
     $cod_cliente = $this->cliente_m->guardarCliente($cliente);
     if ($cod_cliente) {
         //Guardar Cabecero
         $orden_cab = array('cod_cliente' => $cod_cliente, 'total' => $total, 'fecha_orden' => date('Y-m-d H:i:s'));
         $cod_orden = $this->orden_m->guardarCabOrden($orden_cab);
         if ($cod_orden) {
             //Guardar Detalle
             $caracteres = array('-e', '-m', '-a', '-', 'e', 'm', 'a');
             if ($cart = $this->cart->contents()) {
                 foreach ($cart as $item) {
                     if ($this->cart->has_options($item['rowid']) == TRUE) {
                         foreach ($this->cart->product_options($item['rowid']) as $option_name => $option_value) {
                             if ($option_name == 'Tarifa') {
                                 $tipo_tarifa = $option_value;
                             }
                             if ($option_name == 'Tipo') {
                                 $tipo_orden = $option_value;
                             }
                             if ($option_name == 'Fecha Reservación') {
                                 $fecha_reservacion = $option_value;
                             }
                         }
                     }
                     $id = str_replace($caracteres, "", $item['id']);
                     $orden_det = array('cod_cab' => $cod_orden, 'cod_paquete' => $id, 'tipo_orden' => $tipo_orden, 'tipo_tarifa' => $tipo_tarifa, 'cantidad' => $item['qty'], 'subtotal' => $item['subtotal'], 'fecha_reservacion' => $fecha_reservacion, 'fecha_orden' => date('Y-m-d H:i:s'));
                     $cod_det = $this->orden_m->guardarDetOrden($orden_det);
                 }
             }
             if ($cod_det) {
                 $chargeData = array('method' => 'card', 'source_id' => $token, 'amount' => (double) $monto, 'description' => $descripcion, 'use_card_points' => $use_points, 'device_session_id' => $device_session_id, 'customer' => $customer, 'currency' => 'MXN', 'order_id' => $cod_orden);
                 //$this->cart->destroy();
                 try {
                     $charge = $openpay->charges->create($chargeData);
                     if ($charge) {
                         $id_respuesta = $charge->id;
                         $status_respuesta = $charge->status;
                         $autorizacion_respuesta = $charge->authorization;
                         $error_message = $charge->error_message;
                         $this->actualizar_orden($cod_orden, $id_respuesta, $status_respuesta, $autorizacion_respuesta);
                         if ($status_respuesta == 'completed') {
                             if (!$this->mensaje->EnviarCorreoConfirmacionTransaccion($nombre, $correo, $id_respuesta)) {
                                 $this->session->set_userdata('danger', 'Error al enviar correo de transaccion.');
                             }
                             $this->cart->destroy();
                             $this->session->set_userdata('success', 'Gracias por su preferencia.');
                             redirect('carrito');
                         }
                         $this->cart->destroy();
                         $this->session->set_userdata('danger', 'No se pudo realizar la transaccion.');
                         redirect('carrito');
                     } else {
                         $this->session->set_userdata('danger', 'No se pudo realizar el pago, intentelo de nuevo.');
                         redirect('carrito');
                         $this->cart->destroy();
                     }
                 } catch (Exception $e) {
                     //var_dump($e);
                     $this->session->set_userdata('danger', 'No se pudo realizar la transaccion, intentelo de nuevo.');
                     redirect('carrito');
                 }
             } else {
                 $this->session->set_userdata('danger', 'No se pudo guardar el detalle del pedido, intentelo de nuevo.');
                 redirect('carrito');
             }
         } else {
             $this->session->set_userdata('danger', 'No se pudo guardar el cabecero del pedido, intentelo de nuevo.');
             redirect('carrito');
         }
     } else {
         $this->session->set_userdata('danger', 'No se pudo guardar el cliente, intentelo de nuevo.');
         redirect('carrito');
     }
     //Realizar Transaccion
 }
示例#11
-1
 private function _request($method, $url, $params)
 {
     if (!class_exists('Openpay')) {
         throw new OpenpayApiError("Library install error, there are some missing classes");
     }
     OpenpayConsole::trace('OpenpayApiConnector @_request');
     $myId = Openpay::getId();
     if (!$myId) {
         throw new OpenpayApiAuthError("Empty or no Merchant ID provided");
     } else {
         if (!preg_match('/^[a-z0-9]{20}$/i', $myId)) {
             throw new OpenpayApiAuthError("Invalid Merchant ID '" . $myId . "'");
         }
     }
     $myApiKey = Openpay::getApiKey();
     if (!$myApiKey) {
         throw new OpenpayApiAuthError("Empty or no Private Key provided");
     } else {
         if (!preg_match('/^sk_[a-z0-9]{32}$/i', $myApiKey)) {
             throw new OpenpayApiAuthError("Invalid Private Key '" . $myApiKey . "'");
         }
     }
     $absUrl = Openpay::getEndpointUrl();
     if (!$absUrl) {
         throw new OpenpayApiConnectionError("No API endpoint set");
     }
     $absUrl .= '/' . $myId . $url;
     //$params = self::_encodeObjects($params);
     $headers = array('User-Agent: OpenpayPhp/v1');
     list($rbody, $rcode) = $this->_curlRequest($method, $absUrl, $headers, $params, $myApiKey);
     return $this->interpretResponse($rbody, $rcode);
 }