public function testUpdateDescriptionNull()
 {
     $customer = self::createTestCustomer(array('description' => 'foo bar'));
     $customer->description = NULL;
     $customer->save();
     $updatedCustomer = Conekta_Customer::retrieve($customer->id);
     $this->assertEqual(NULL, $updatedCustomer->description);
 }
 public function testInvalidCredentials()
 {
     Conekta::setApiKey('invalid');
     try {
         Conekta_Customer::create();
     } catch (Conekta_AuthenticationError $e) {
         $this->assertEqual(401, $e->getHttpStatus());
     }
 }
 public function testInvalidObject()
 {
     authorizeFromEnv();
     try {
         Conekta_Customer::retrieve('invalid');
     } catch (Conekta_InvalidRequestError $e) {
         $this->assertEqual(404, $e->getHttpStatus());
     }
 }
Esempio n. 4
0
 public function testAuthenticationError()
 {
     unsetApiKey();
     try {
         $customer = Conekta_Customer::create(array('cards' => array('tok_test_visa_4242')));
     } catch (Exception $e) {
         $this->assertTrue(strpos(get_class($e), 'Conekta_AuthenticationError') !== false);
     }
     setApiKey();
 }
 public function testDeletion()
 {
     authorizeFromEnv();
     $id = 'test-coupon-' . self::randomString();
     $coupon = Conekta_Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
     $customer = self::createTestCustomer(array('coupon' => $id));
     $this->assertTrue(isset($customer->discount));
     $this->assertTrue(isset($customer->discount->coupon));
     $this->assertEqual($id, $customer->discount->coupon->id);
     $customer->deleteDiscount();
     $this->assertFalse(isset($customer->discount));
     $customer = Conekta_Customer::retrieve($customer->id);
     $this->assertFalse(isset($customer->discount));
 }
 /**
  * Create a valid test customer.
  */
 protected static function createTestCustomer(array $attributes = array())
 {
     authorizeFromEnv();
     return Conekta_Customer::create($attributes + array('card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => date('Y') + 3)));
 }
 public function process_payment($invitado = false, $guardar_tarjeta = false)
 {
     require_once "conekta/Conekta.php";
     Conekta::setApiKey($this->privatekey);
     /*CREAMOS USUARIO*/
     $id_comprador = get_user_meta($this->comprador, '_id_conekta', true);
     if (!$id_comprador) {
         try {
             $comprador = get_user_by('id', $this->comprador);
             $customer = Conekta_Customer::create(array("name" => $comprador->display_name, "email" => $comprador->user_email, "cards" => array($this->token)));
             update_user_meta($this->comprador, '_id_conekta', $customer->id);
             /*COMO ES LA PRIMERA VEZ CONFIGURAMOS EL TOKEN CON LA TARJETA ACTIVA DEL USUARIO*/
             $this->token = reset($customer->cards);
             $this->token = $this->token->id;
         } catch (Conekta_Error $e) {
             //El pago no pudo ser procesado
             $mensaje = $e->getMessage();
             $this->mensajes->add_error($mensaje);
             return;
         }
     } else {
         /*ES UN USUARIO YA CREADO*/
         /*TOCA COMPROBAR QUE EL TOKEN SEA EXISTENTE*/
         $tarjetas = get_tarjetas($this->comprador);
         if (!isset($tarjetas[$this->token]) && $guardar_tarjeta) {
             try {
                 /*añadimos tarjeta al usuario*/
                 $customer = Conekta_Customer::find($id_comprador);
                 $card = $customer->createCard(array('token' => $this->token));
                 $tarjeta = array('token' => $card->id, 'nombre' => $card->name, 'digitos' => $card->last4, 'brand' => $card->brand);
                 if ($guardar_tarjeta) {
                     guardar_tarjeta_en_user($tarjeta, $this->comprador);
                 }
                 $this->token = $tarjeta['token'];
             } catch (Conekta_Error $e) {
                 //El pago no pudo ser procesado
                 $mensaje = $e->getMessage();
                 $this->mensajes->add_error($mensaje);
                 return;
             }
         }
     }
     $data_user = get_user_by('id', $this->comprador);
     /*GENERAMOS DATOS DE TRANSACCION*/
     $transaccion = array("amount" => $this->monto, "currency" => "MXN", "description" => "Compra en Síclo.com", "card" => $this->token, "details" => array("email" => $data_user->user_email, "line_items" => array()));
     /*
      **GENERAREMOS LOS DATOS DE LOS LINE_ITEMS
      **TANTO EN PRODUCTOS COMO EN PAQUETES
      */
     if ($this->paquete_objeto) {
         $transaccion['details']["line_items"][] = array("name" => "Paquete de " . $this->paquete_objeto->data['cantidad'] . " clases", "unit_price" => $this->paquete_objeto->data['precio'], "description" => "Paquete de " . $this->paquete_objeto->data['cantidad'] . " clases", "quantity" => 1, "type" => "paquete-clases");
     }
     if ($this->productos) {
         foreach ($this->productos as $producto) {
             $transaccion['details']["line_items"][] = array("name" => $producto['producto']->titulo, "unit_price" => $producto['producto']->precio, "description" => $producto['producto']->titulo, "quantity" => $producto['cantidad'], "type" => "producto-back");
         }
     }
     //CREAR PEDIDO
     $args = array('post_title' => "", 'post_status' => 'pending', 'post_type' => 'pedido', 'post_author' => $this->comprador);
     $idPedido = wp_insert_post($args);
     if ($idPedido) {
         $this->idPedido = $idPedido;
         /*GUARDAMOS ENVÍO DE DATOS*/
         update_post_meta($idPedido, 'transaccion', $transaccion);
         update_post_meta($idPedido, '_info_paquete', $this->paquete_objeto);
         update_post_meta($idPedido, '_paquete', $this->paquete);
         update_post_meta($idPedido, '_productos', $this->productos);
         update_post_meta($idPedido, '_expiracion', $this->paquete_objeto->fecha_expiracion($this->paquete_objeto->data['expiracion'], true));
         /*SE GUARDA PARA MOSTRARLO EN EL HISTORIAL*/
     } else {
         $this->mensajes->add_error('No se ha podido finalizar la transaccion.');
         return;
     }
     $transaccion["reference_id"] = urlencode($idPedido);
     try {
         $pago = Conekta_Charge::create($transaccion);
         /*GUARDAMOS SIEMPRE RESPUESTA*/
         update_post_meta($idPedido, 'respuesta_transaccion', serialize($pago));
         $tarjeta = array('token' => $this->token, 'nombre' => $pago->payment_method->name, 'digitos' => $pago->payment_method->last4, 'brand' => $pago->payment_method->brand);
         if ($guardar_tarjeta) {
             guardar_tarjeta_en_user($tarjeta, $this->comprador);
         }
         mail_de_compra_clases($idPedido);
         $this->finalizar_compra($invitado);
         return;
     } catch (Conekta_Error $e) {
         //El pago no pudo ser procesado
         $mensaje = $e->getMessage();
         $this->mensajes->add_error($mensaje);
         /*GUARDAMOS SIEMPRE RESPUESTA*/
         update_post_meta($idPedido, 'respuesta_transaccion', $mensaje);
         return;
     }
 }
Esempio n. 8
0
 public function testSuccesfulSubscriptionCancel()
 {
     setApiKey();
     $customer = Conekta_Customer::create(array('cards' => array('tok_test_visa_4242')));
     $subscription = $customer->createSubscription(array('plan' => 'gold-plan'));
     $this->assertTrue(strpos(get_class($subscription), 'Conekta_Subscription') !== false);
     $subscription->cancel();
     $this->assertTrue(strpos($subscription->status, 'canceled') !== false);
 }