Skip to content

Commit

Permalink
Merge pull request #27 from conekta/feature/upgrade-1.1
Browse files Browse the repository at this point in the history
Feature/upgrade 2.0
  • Loading branch information
MauricioMurga authored Feb 2, 2017
2 parents d1a1381 + c282ec5 commit 66e1fc4
Show file tree
Hide file tree
Showing 59 changed files with 4,937 additions and 417 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OS
.DS_Store

*~
# Composer
composer.lock
/vendor
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@

=== 3.0.0 2016-11-16

* Add namespaces to master.
* Add namespaces to master.

=== 3.1.0 2017-01-25

* Order's submodels added. New Order flow
* Supporting now API 2.0
* Check https://www.conekta.io/es/docs/api v1.1 for further information
84 changes: 37 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

![alt tag](https://raw.github.com/conekta/conekta-php/master/readme_files/cover.png)

# Conekta PHP v.3.0.0
# Conekta PHP v.3.1.0

This is a php library that allows interaction with https://api.conekta.io API.

Expand All @@ -17,55 +17,45 @@ To get started, add the following to your PHP script:

You can also install this library with composer:

require: "conekta/conekta-php": "3.0.0"
require: "conekta/conekta-php": "3.1.0"

## Usage
```php
\Conekta\Conekta::setApiKey('1tv5yJp3xnVZ7eK67m4h');
try {
$charge = \Conekta\Charge::create(array(
"amount"=> 51000,
"currency"=> "MXN",
"description"=> "Pizza Delivery",
"reference_id"=> "orden_de_id_interno",
"card"=> $_POST['conektaTokenId']
//"tok_a4Ff0dD2xYZZq82d9"
));
} catch (Conekta_Error $e) {
echo $e->getMessage(); //Dev Message
echo $e->message_to_purchaser;
//El pago no pudo ser procesado
}

{
"id": "5286828b8ee31e64b7001739",
"livemode": false,
"created_at": 1384546955,
"status": "paid",
"currency": "MXN",
"description": "Some desc",
"reference_id": null,
"failure_code": null,
"failure_message": null,
"object": "charge",
"amount": 2000,
"fee": 371,
"payment_method": {
"name": "Mario Moreno",
"exp_month": "05",
"exp_year": "15",
"auth_code": "861491",
"object": "card_payment",
"last4": "4242",
"brand": "visa"
},
"details": {
"name": null,
"phone": null,
"email": null,
"line_items": []
}
}
setApiKey();
$valid_order =
array(
'line_items'=> array(
array(
'name' => 'Box of Cohiba S1s',
'description' => 'Imported From Mex.',
'unit_price' => 20000,
'quantity' => 1,
'sku' => 'cohb_s1',
'category' => 'food',
'type' => 'physical',
'tags' => array('food', 'mexican food')
)
),
'currency' => 'mxn',
'metadata' => array('test' => 'extra info'),
'charges' => array(
array(
'payment_source' => array(
'type' => 'oxxo_cash',
'expires_at' => strtotime(date("Y-m-d H:i:s")) + "36000"
),
'amount' => 20000
)
),
'currency' => 'mxn',
'customer_info' => array(
'name' => 'John Constantine',
'phone' => '+5213353319758',
'email' => '[email protected]'
)
);

$order = \Conekta\Order::create($valid_order);
```

## Documentation
Expand Down
12 changes: 11 additions & 1 deletion lib/Conekta.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
require_once dirname(__FILE__).'/Conekta/Requestor.php';
require_once dirname(__FILE__).'/Conekta/Object.php';
require_once dirname(__FILE__).'/Conekta/Resource.php';

require_once dirname(__FILE__).'/Conekta/Charge.php';
require_once dirname(__FILE__).'/Conekta/PaymentMethod.php';
require_once dirname(__FILE__).'/Conekta/Customer.php';
Expand All @@ -36,3 +35,14 @@
require_once dirname(__FILE__).'/Conekta/Webhook.php';
require_once dirname(__FILE__).'/Conekta/WebhookLog.php';
require_once dirname(__FILE__).'/Conekta/Log.php';
require_once dirname(__FILE__).'/Conekta/Order.php';
require_once dirname(__FILE__).'/Conekta/PaymentSource.php';
require_once dirname(__FILE__).'/Conekta/TaxLine.php';
require_once dirname(__FILE__).'/Conekta/DiscountLine.php';
require_once dirname(__FILE__).'/Conekta/ShippingLine.php';
require_once dirname(__FILE__).'/Conekta/LineItem.php';
require_once dirname(__FILE__).'/Conekta/ErrorList.php';
require_once dirname(__FILE__).'/Conekta/ConektaList.php';
require_once dirname(__FILE__).'/Conekta/ShippingContact.php';
require_once dirname(__FILE__).'/Conekta/FiscalEntity.php';
require_once dirname(__FILE__).'/Conekta/OrderReturn.php';
20 changes: 20 additions & 0 deletions lib/Conekta/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@

class Address extends Resource
{
var $street1 = "";
var $street2 = "";
var $street3 = "";
var $city = "";
var $state = "";
var $zip = "";
var $country = "";

public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}
}

public function __isset($property)
{
return isset($this->$property);
}

}
34 changes: 32 additions & 2 deletions lib/Conekta/Card.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

namespace Conekta;

Expand All @@ -9,14 +9,44 @@

class Card extends Resource
{
var $created_at = "";
var $last4 = "";
var $bin = "";
var $name = "";
var $exp_month = "";
var $exp_year = "";
var $brand = "";
var $parent_id = "";
var $default = "";

public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}
}

public function __isset($property)
{
return isset($this->$property);
}


public function instanceUrl()
{
$id = $this->id;
if (!$id) {
throw new Error(
$error = new Error(
Lang::translate('error.resource.id', Lang::EN, array('RESOURCE' => get_class())),
Lang::translate('error.resource.id_purchaser', Conekta::$locale)
);

if($this->apiVersion = '2.0.0'){
$errorList = new ErrorList();
array_push($errorList->details, $error);
throw $errorList;
}
throw $error;
}

$class = get_class($this);
Expand Down
30 changes: 30 additions & 0 deletions lib/Conekta/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@

class Charge extends Resource
{
var $livemode = "";
var $amount = "";
var $created_at = "";
var $currency = "";
var $description = "";
var $reference_id = "";
var $failure_code = "";
var $failure_message = "";
var $fee = "";
var $monthly_installments = "";
var $device_fingerprint = "";
var $status = "";
var $exchange_rate = "";
var $foreign_currency = "";
var $amount_in_foreign_currency = "";
var $checkout_id = "";
var $checkout_order_count = "";

public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}
}

public function __isset($property)
{
return isset($this->$property);
}

public static function find($id)
{
$class = get_called_class();
Expand Down
13 changes: 8 additions & 5 deletions lib/Conekta/Conekta.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<?php
<?php

namespace Conekta;

abstract class Conekta
{
public static $apiKey;
public static $apiBase = 'https://api.conekta.io';
public static $apiVersion = '1.0.0';
public static $apiVersion = '2.0.0';
public static $locale = 'es';
const VERSION = '3.0.0';
public static $plugin = '';
const VERSION = '3.1.0';

public static function setApiKey($apiKey)
{
self::$apiKey = $apiKey;
}

public static function setApiVersion($version)
{
self::$apiVersion = $version;
}

public static function setLocale($locale)
{
self::$locale = $locale;
}
public static function setPlugin($plugin)
{
self::$plugin = $plugin;
}
}
84 changes: 84 additions & 0 deletions lib/Conekta/ConektaList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Conekta;

use \Conekta\Resource;
use \Conekta\Requestor;
use \Conekta\Util;
use \Conekta\Error;
use \Conekta\Conekta;

class ConektaList extends Object
{


public function __construct($elements_type, $params = array())
{
parent::__construct();
$this->elements_type = $elements_type;
$this->params = $params;
$this->total = 0;
}

public function addElement($element)
{
$element = Util::convertToConektaObject($element);
$this[$this->total] = $element;
$this->_values[$this->total] = $element;
$this->total = $this->total + 1;

return $this;
}

public function loadFromArray($values = null)
{
if (isset($values)) {
$this->has_more = $values['has_more'];
$this->total = $values['total'];

foreach ($this as $key => $value) {
$this->_unsetKey($key);
}
}

if (isset($values['data'])) {
return parent::loadFromArray($values['data']);
}
}

public function next($options = array())
{
if (sizeOf($this) > 0) {
$this->params['next'] = end($this)->id;
}

$this->params['previous'] = null;

return $this->_moveCursor($options['limit']);
}

public function previous($options = array())
{
if (sizeOf($this) > 0) {
$this->params['previous'] = $this[0]->id;
}

$this->params['next'] = null;

return $this->_moveCursor($options['limit']);
}

protected function _moveCursor($limit)
{
if (isset($limit)) {
$this->params['limit'] = $limit;
}

$class = Util::$types[strtolower($this->elements_type)];
$url = Resource::classUrl($class);
$requestor = new Requestor();
$response = $requestor->request('get', $url, $this->params);

return $this->loadFromArray($response);
}
}
Loading

0 comments on commit 66e1fc4

Please sign in to comment.