Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Macedo committed May 14, 2019
0 parents commit dbe8859
Show file tree
Hide file tree
Showing 17 changed files with 647 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/vendor
composer.lock
composer.phar
phpunit.xml
.idea/

.directory
dirlist.app
dirlist.vendor
dirlist.cache
documents/
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Contributing Guidelines

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files.
* Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
style and that all tests pass.
* Send the pull request.
* Check that the Travis CI build passed. If not, rinse and repeat.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Victor Ximenis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Omnipay: MercadoPago

**MercadoPago driver for the Omnipay PHP payment processing library**

[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
processing library for PHP 5.3+. This package implements MercadoPago support for Omnipay.

## Installation

Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
to your `composer.json` file:

```json
{
"require": {
"victorximenis/omnipay-mercadopago": "~1.0"
}
}
```

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

## Basic Usage

The following gateways are provided by this package:

* MercadoPago

For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.

## Support

If you are having general issues with Omnipay, we suggest posting on
[Stack Overflow](http://stackoverflow.com/). Be sure to add the
[omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project,
or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which
you can subscribe to.

If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/victorximenis/omnipay-mercadopago/issues),
or better yet, fork the library and submit a pull request.
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "lucassmacedo/omnipay-mercadopago",
"type": "library",
"description": "MercadoPago gateway for OmniPay",
"keywords": [
"mercadopago",
"mp",
"gateway",
"merchant",
"omnipay",
"pay",
"payment",
"PHPeste"
],
"homepage": "https://github.com/lucassmacedo/omnipay-mercadopago",
"license": "MIT",
"authors": [
{
"name": "Lucas Macedo",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": { "Omnipay\\MercadoPago\\" : "src/" }
},
"require": {
"omnipay/common": "^3.0"
},
"require-dev": {
"omnipay/tests": "^3.0"
}
}
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Omnipay Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" />
</listeners>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
86 changes: 86 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Omnipay\MercadoPago;

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\ItemBag;

class Gateway extends AbstractGateway
{
public function getName()
{
return 'MercadoPago';
}

public function getClientId()
{
return $this->getParameter('client_id');
}

public function setClientId($value)
{
return $this->setParameter('client_id', $value);
}

public function getClientSecret()
{
return $this->getParameter('client_secret');
}

public function setClientSecret($value)
{
return $this->setParameter('client_secret', $value);
}

public function getGrantType()
{
return $this->getParameter('grant_type');
}

public function setGrantType($value)
{
return $this->setParameter('grant_type', $value);
}

public function setAccessToken($value)
{
return $this->setParameter('access_token', $value);
}

public function getAccessToken()
{
return $this->getParameter('access_token');
}

public function setExternalReference($value)
{
return $this->setParameter('external_reference', $value);
}

public function getExternalReference()
{
return $this->getParameter('external_reference');
}

public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\MercadoPago\Message\PurchaseRequest', $parameters);
}

public function requestToken(array $parameters = array())
{
return $this->createRequest('\Omnipay\MercadoPago\Message\TokenRequest', $parameters);
}

/**
* @param array $parameters
* @return \Omnipay\MercadoPago\Message\CompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\MercadoPago\Message\CompletePurchaseRequest', $parameters);
}

}

?>
27 changes: 27 additions & 0 deletions src/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Omnipay\MercadoPago;

use Omnipay\Common\Item as BaseItem;

class Item extends BaseItem
{
public function getCategoryId()
{
return $this->getParameter('category_id');
}
public function setCategoryId($value)
{
return $this->setParameter('category_id', $value);
}
public function getCurrencyId()
{
return $this->getParameter('currency_id');
}
public function setCurrencyId($value)
{
return $this->setParameter('currency_id', $value);
}
}

?>
66 changes: 66 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Omnipay\MercadoPago\Message;

abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
protected $liveEndpoint = 'https://api.mercadopago.com';
protected $testEndpoint = 'https://api.mercadopago.com';

public function getData()
{
$data = $this->getExternalReference();
return $data;
}

public function sendData($data)
{
$url = $this->getEndpoint() . '?access_token=' . $this->getAccessToken();
$httpRequest = $this->httpClient->createRequest(
'POST',
$url,
array(
'Content-type' => 'application/json',
),
$this->toJSON($data)
);
$httpResponse = $httpRequest->send();
return $this->createResponse($httpResponse->json());
}

public function setExternalReference($value)
{
return $this->setParameter('external_reference', $value);
}

public function getExternalReference()
{
return $this->getParameter('external_reference');
}

public function setAccessToken($value)
{
return $this->setParameter('access_token', $value);
}

public function getAccessToken()
{
return $this->getParameter('access_token');
}

protected function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}

public function toJSON($data, $options = 0)
{
if (version_compare(phpversion(), '5.4.0', '>=') === true) {
return json_encode($data, $options | 64);
}
return str_replace('\\/', '/', json_encode($data, $options));
}

}

?>
41 changes: 41 additions & 0 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Omnipay\MercadoPago\Message;

class CompletePurchaseRequest extends AbstractRequest
{
protected $liveEndpoint = 'https://api.mercadopago.com/collections/notifications/';
/** @var this option is unavailable */
protected $testEndpoint = 'https://api.mercadolibre.com/sandbox/collections/notifications/';


public function getData()
{
//get information about collection
$id = $this->httpRequest->query->get('collection_id');
$url = $this->getEndpoint() . "$id?access_token=" . $this->getAccessToken();
$httpRequest = $this->httpClient->createRequest(
'GET',
$url,
array(
'Content-type' => 'application/json',
)
);
$httpResponse = $httpRequest->send();
$response = $httpResponse->json();
return isset($response['collection']) ? $response['collection'] : null;
}

public function sendData($data)
{
return $this->createResponse($data);
}

protected function createResponse($data)
{
return $this->response = new CompletePurchaseResponse($this, $data);
}

}

?>
Loading

0 comments on commit dbe8859

Please sign in to comment.