Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
chore(release): v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joaolucasl authored Aug 8, 2017
2 parents df95c6a + bcd308c commit f74e51d
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 8 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<a name="1.3.0"></a>
# [1.3.0](https://github.com/moip/moip-sdk-php/compare/v1.2.0...v1.3.0) (2017-08-08)

## Bug Fixes
- **order:**
- fix adding of installments in checkout preferences
([3dee9fa](https://github.com/moip/moip-sdk-php/commit/3dee9fa7b9a5863ba4828de2f03a5fd7a1254898))
- **refund:**
- fix of bank account refund
([d336f9f](https://github.com/moip/moip-sdk-php/commit/d336f9f04dc92a978e3d67942091b573c9a30643))
- fix method to return HATEOAS links from API
([025bfde](https://github.com/moip/moip-sdk-php/commit/025bfdedde5bfe953264b24daa0ba371e73e43cd))
- fix method to get DateTime from resources
([3d30cbb](https://github.com/moip/moip-sdk-php/pull/152/commits/3d30cbbf49fb9c4ee1b6049dd93cd3487a9fef81))


## New Features
- **escrow:** add escrow resource
([ed99701](https://github.com/moip/moip-sdk-php/commit/ed9970156de1dea88a091fd33b54bcec8f91ce92)),
- **notification preferences:** add notification preferences resource
([e553d8b](https://github.com/moip/moip-sdk-php/commit/e553d8b9c9878009cb2d2e021043f3ebbaeb2dc5))
- **customer credit card:** add resource to add more credit cards to customer
([d327f03](https://github.com/moip/moip-sdk-php/commit/d327f03b5d2449dbac95f3f3cabcd17a19b8853a))

## BREAKING CHANGES
Now tests are runned using OAuth authentication instead Basic Auth, because now there are tests to resources that only uses OAuth authentication.
43 changes: 43 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributing
:clap::tada: Thank you for taking the time to contribute! :tada::clap:

We really value your willingness to contribute to this project. In order to higher the chances of your contribution being accepted, please refer to the following guidelines!

## Steps

1. Fork it!
2. Create your feature branch: `git checkout -b feature/xyz develop`
3. Commit your changes according to our commit message standards: `git commit -am 'feat(xyz) Added new functionality'`
4. Push to your repo: `git push origin feature/xyz`
5. Submit a pull request to `develop`

## Workflow
This repo uses Gitflow as its branch management system. You can learn more about Gitflow [here](https://www.atlassian.com/git/tutorials/comparing-workflows#gitflow-workflow).
A few quick tips:
* All feature branches should be based on `develop` and have the format `feature/branch_name`.
* Minor bug fixes should be based on `master` and have the format `hotfix/branch_name`.

### Commit Conventions
In order to make the changelog generation easier we recommend the use of messages based on [Conventional Commits](https://conventionalcommits.org/).

Examples:
```
feat(orders): added `XYZ` helper function
commit description
footer notes
```

```
refactor(orders): refactored `ABC` helper function
The behaviour of `ABC` was inconsistent and (...)
BREAKING CHANGE: return type of `ABC` is now `String`
```

```
docs: updated documentation in Request.php
```

80 changes: 80 additions & 0 deletions src/Helper/Filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Moip\Helper;

/**
* Class Filters.
*/
class Filters
{
/**
* @var array
**/
private $filters = [];

/**
* Set filter to compare if field is greater than value.
*
* @param string $field field to setup filter.
* @param int|Date $value value to setup filter.
*/
public function greaterThan($field, $value)
{
$this->filters[] = sprintf('%s::gt(%s)', $field, $value);
}

/**
* Set filter to compare if field is greater than or equal value.
*
* @param string $field field to setup filter.
* @param int|Date $value value to setup filter.
*/
public function greaterThanOrEqual($field, $value)
{
$this->filters[] = sprintf('%s::ge(%s)', $field, $value);
}

/**
* Set filter to compare if field is less than value.
*
* @param string $field field to setup filter.
* @param int|Date $value value to setup filter.
*/
public function lessThan($field, $value)
{
$this->filters[] = sprintf('%s::lt(%s)', $field, $value);
}

/**
* Set filter to compare if field is between both values.
*
* @param string $field field to setup filter.
* @param string $value1 first value to setup filter.
* @param string $value2 second value to setup filter.
*/
public function between($field, $value1, $value2)
{
$this->filters[] = sprintf('%s::bt(%s,%s)', $field, $value1, $value2);
}

/**
* Set filter to compare if field is in array.
*
* @param string $field field to setup filter.
* @param array $values value to setup filter.
*/
public function in($field, array $values)
{
$this->filters[] = sprintf('%s::in(%s)', $field, implode(',', $values));
}

/**
* Join filters in one string.
*
* @return string
*/
public function __toString()
{
return implode('|', $this->filters);
}
}
76 changes: 76 additions & 0 deletions src/Helper/Pagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Moip\Helper;

/**
* Class Pagination.
*/
class Pagination
{
/**
* @var int
**/
private $offset = 0;

/**
* @var int
**/
private $limit = 100;

/**
* Pagination constructor.
*
* @param int $limit
* @param int $offset
*/
public function __construct($limit = null, $offset = null)
{
if (!empty($limit)) {
$this->limit = $limit;
}

if (!empty($offset)) {
$this->offset = $offset;
}
}

/**
* Get offset.
*
* @return int
*/
public function getOffset()
{
return $this->offset;
}

/**
* Set offset.
*
* @param int $offset
*/
public function setOffset($offset)
{
$this->offset = $offset;
}

/**
* Get limit.
*
* @return int
*/
public function getLimit()
{
return $this->limit;
}

/**
* Set limit.
*
* @param int $limit
*/
public function setLimit($limit)
{
$this->limit = $limit;
}
}
16 changes: 9 additions & 7 deletions src/Moip.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ class Moip
*
* @const string
* */
const CLIENT = 'Moip SDK';
const CLIENT = 'MoipPhpSDK';

/**
* Client Version.
*
* @const string
*/
const CLIENT_VERSION = '1.3.0';

/**
* Authentication that will be added to the header of request.
Expand Down Expand Up @@ -80,12 +87,7 @@ public function __construct(Authentication $moipAuthentication, $endpoint = self
*/
public function createNewSession($timeout = 30.0, $connect_timeout = 30.0)
{
if (function_exists('posix_uname')) {
$uname = posix_uname();
$user_agent = sprintf('Mozilla/4.0 (compatible; %s; PHP/%s %s; %s; %s)', self::CLIENT, PHP_SAPI, PHP_VERSION, $uname['sysname'], $uname['machine']);
} else {
$user_agent = sprintf('Mozilla/4.0 (compatible; %s; PHP/%s %s; %s)', self::CLIENT, PHP_SAPI, PHP_VERSION, PHP_OS);
}
$user_agent = sprintf('%s/%s (+https://github.com/moip/moip-sdk-php/)', self::CLIENT, self::CLIENT_VERSION);
$sess = new Requests_Session($this->endpoint);
$sess->options['auth'] = $this->moipAuthentication;
$sess->options['timeout'] = $timeout;
Expand Down
44 changes: 43 additions & 1 deletion src/Resource/MoipResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use JsonSerializable;
use Moip\Exceptions;
use Moip\Helper\Filters;
use Moip\Helper\Links;
use Moip\Helper\Pagination;
use Moip\Moip;
use Requests;
use Requests_Exception;
Expand Down Expand Up @@ -129,7 +131,13 @@ protected function getIfSetDate($key, stdClass $data = null)
*/
protected function getIfSetDateTime($key, stdClass $data = null)
{
return $this->getIfSetDateFmt($key, \DateTime::ATOM, $data);
$rawDateTime = $this->getIfSet($key, $data);

if (!empty($rawDateTime)) {
$dateTime = new \DateTime($rawDateTime);
}

return $dateTime;
}

/**
Expand Down Expand Up @@ -159,6 +167,40 @@ public function generatePath($action, $id = null)
return sprintf('%s/%s/%s', self::VERSION, static::PATH, $action);
}

/**
* Generate URL to request a get list.
*
* @param Pagination $pagination
* @param Filters $filters
* @param string $qParam Query a specific value.
*
* @return string
*/
public function generateListPath(Pagination $pagination = null, Filters $filters = null, $qParam = '')
{
$queryParams = [];

if (!is_null($pagination)) {
if ($pagination->getLimit() != 0) {
$queryParams['limit'] = $pagination->getLimit();
}

if ($pagination->getOffset() >= 0) {
$queryParams['offset'] = $pagination->getOffset();
}
}

if (!is_null($filters)) {
$queryParams['filters'] = $filters->__toString();
}

if (!empty($qParam)) {
$queryParams['q'] = $qParam;
}

return sprintf('/%s/%s?%s', self::VERSION, static::PATH, http_build_query($queryParams));
}

/**
* Execute a http request. If payload == null no body will be sent. Empty body ('{}') is supported by sending a
* empty stdClass.
Expand Down
14 changes: 14 additions & 0 deletions src/Resource/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Moip\Resource;

use ArrayIterator;
use Moip\Helper\Filters;
use Moip\Helper\Pagination;
use stdClass;

/**
Expand Down Expand Up @@ -441,6 +443,18 @@ public function getCheckoutPreferences()
return $this->getIfSet('checkoutPreferences');
}

/**
* Create a new Orders list instance.
*
* @return \Moip\Resource\OrdersList
*/
public function getList(Pagination $pagination = null, Filters $filters = null, $qParam = '')
{
$orderList = new OrdersList($this->moip);

return $orderList->get($pagination, $filters, $qParam);
}

/**
* Structure of payment.
*
Expand Down
Loading

0 comments on commit f74e51d

Please sign in to comment.