Skip to content

Commit

Permalink
Revert "Revert "Merge remote-tracking branch 'origin/f/orders'""
Browse files Browse the repository at this point in the history
This reverts commit 394603a.
  • Loading branch information
Brayan Cruces committed Oct 10, 2018
1 parent 426087b commit fe7e274
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.3.4 10-10-2018
* Se agrega recurso de Orders

### 1.3.3 17-03-2017
* Actualización de composer.json

Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Esta biblioteca trabaja con la [v2.0](https://culqi.com/api/) de Culqi API.
```json
{
"require": {
"culqi/culqi-php": "1.3.3"
"culqi/culqi-php": "1.3.4"
}
}
```
Expand Down Expand Up @@ -160,6 +160,30 @@ $subscription = $culqi->Subscriptions->create(
print_r($subscription);
```

### Crear un Order

[Ver ejemplo completo](/examples/08-create-order.php)

```php
// Creando orden (con 1 dia de duracion)
$order = $culqi->Orders->create(
array(
"amount" => 1000,
"currency_code" => "PEN",
"description" => 'Venta de prueba',
"order_number" => 'pedido-9999',
"client_details" => array(
"first_name"=> "Brayan",
"last_name" => "Cruces",
"email" => "micorreo@gmail.com",
"phone_number" => "51945145222"
),
"expiration_date" => time() + 24*60*60 // Orden con un dia de validez
)
);
print_r($order);
```

## Probar ejemplos
```bash
git clone https://github.com/culqi/culqi-php.git
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.3
1.3.4
37 changes: 37 additions & 0 deletions examples/08-create-order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Ejemplo 8
* Como crear una orden usando Culqi PHP.
*/

try {
// Usando Composer (o puedes incluir las dependencias manualmente)
require '../vendor/autoload.php';

// Configurar tu API Key y autenticación
$SECRET_KEY = "{SECRET KEY}";
$culqi = new Culqi\Culqi(array('api_key' => $SECRET_KEY));

// Creando Cargo a una tarjeta
$order = $culqi->Orders->create(
array(
"amount" => 1000,
"currency_code" => "PEN",
"description" => 'Venta de prueba',
"order_number" => 'pedido-9999',
"client_details" => array(
"first_name"=> "Brayan",
"last_name" => "Cruces",
"email" => "micorreo@gmail.com",
"phone_number" => "51945145222"
),
"expiration_date" => time() + 24*60*60, // Orden con un dia de validez
"metadata" => array("dni" => "71702935")
)
);
// Respuesta
echo json_encode($order);

} catch (Exception $e) {
echo json_encode($e->getMessage());
}
3 changes: 2 additions & 1 deletion lib/Culqi/Culqi.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct($options)
$this->Iins = new Iins($this);
$this->Cards = new Cards($this);
$this->Events = new Events($this);
$this->Customers = new Customers($this);
$this->Customers = new Customers($this);
$this->Orders = new Orders($this);
}
}
4 changes: 2 additions & 2 deletions lib/Culqi/Error/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CulqiException extends \Exception {
namespace Culqi\Error;

class InputValidationError extends CulqiException {
protected $message = "Input validation error. Error en alguno de los campos";
protected $message = "Error de validacion en los campos";
}
/**
* Authentication error
Expand All @@ -33,7 +33,7 @@ class AuthenticationError extends CulqiException {
namespace Culqi\Error;

class NotFound extends CulqiException {
protected $message = "Resource not found";
protected $message = "Recurso no encontrado";
}
/**
* Method not allowed
Expand Down
70 changes: 70 additions & 0 deletions lib/Culqi/Orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Culqi;

/**
* Class Orders
*
* @package Culqi
*/
class Orders extends Resource {

const URL_ORDERS = "/orders/";

/**
* @param array|null $options
*
* @return Get all Orders
*/
public function all($options) {
return $this->request("GET", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options);
}

/**
* @param array|null $options
*
* @return create Order
*/
public function create($options = NULL) {
return $this->request("POST", self::URL_ORDERS, $api_key = $this->culqi->api_key, $options);
}


/**
* @param array|null $options
*
* @return confirm Order
*/
public function confirm($id = NULL) {
return $this->request("POST", self::URL_ORDERS . $id . "/confirm/", $api_key = $this->culqi->api_key);
}

/**
* @param string|null $id
*
* @return get a Order
*/
public function get($id) {
return $this->request("GET", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key);
}

/**
* @param string|null $id
*
* @return delete a Order
*/
public function delete($id) {
return $this->request("DELETE", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key);
}

/**
* @param string|null $id
* @param array|null $options
*
* @return update Order
*/
public function update($id = NULL, $options = NULL) {
return $this->request("PATCH", self::URL_ORDERS . $id . "/", $api_key = $this->culqi->api_key, $options);
}

}
1 change: 1 addition & 0 deletions lib/culqi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
include_once dirname(__FILE__).'/Culqi/Subscriptions.php';
include_once dirname(__FILE__).'/Culqi/Plans.php';
include_once dirname(__FILE__).'/Culqi/Iins.php';
include_once dirname(__FILE__).'/Culqi/Orders.php';
include_once dirname(__FILE__).'/Culqi/Culqi.php';

0 comments on commit fe7e274

Please sign in to comment.