From aca6a377f813e126914655f5f0b221a763d6b4f9 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:06:06 -0300 Subject: [PATCH 01/44] create folder for authentications --- src/{ => Auth}/MoipAuthentication.php | 0 src/{ => Auth}/MoipBasicAuth.php | 0 src/{ => Auth}/MoipOAuth.php | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/{ => Auth}/MoipAuthentication.php (100%) rename src/{ => Auth}/MoipBasicAuth.php (100%) rename src/{ => Auth}/MoipOAuth.php (100%) diff --git a/src/MoipAuthentication.php b/src/Auth/MoipAuthentication.php similarity index 100% rename from src/MoipAuthentication.php rename to src/Auth/MoipAuthentication.php diff --git a/src/MoipBasicAuth.php b/src/Auth/MoipBasicAuth.php similarity index 100% rename from src/MoipBasicAuth.php rename to src/Auth/MoipBasicAuth.php diff --git a/src/MoipOAuth.php b/src/Auth/MoipOAuth.php similarity index 100% rename from src/MoipOAuth.php rename to src/Auth/MoipOAuth.php From f55c3830d881fd259bc285cf35f84a32d1b93aeb Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:11:56 -0300 Subject: [PATCH 02/44] namespaces --- src/Auth/MoipAuthentication.php | 2 +- src/Auth/MoipBasicAuth.php | 2 +- src/Auth/MoipOAuth.php | 2 +- src/Moip.php | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Auth/MoipAuthentication.php b/src/Auth/MoipAuthentication.php index 240e923..c8e83d0 100644 --- a/src/Auth/MoipAuthentication.php +++ b/src/Auth/MoipAuthentication.php @@ -1,6 +1,6 @@ Date: Wed, 12 Apr 2017 20:19:25 -0300 Subject: [PATCH 03/44] fixed tests for namespace Auth --- tests/MoipTestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/MoipTestCase.php b/tests/MoipTestCase.php index b49fc13..e794bfd 100644 --- a/tests/MoipTestCase.php +++ b/tests/MoipTestCase.php @@ -3,7 +3,7 @@ namespace Moip\Tests; use Moip\Moip; -use Moip\MoipBasicAuth; +use Moip\Auth\MoipBasicAuth; use Moip\Resource\Customer; use Moip\Resource\Orders; use PHPUnit_Framework_TestCase as TestCase; @@ -90,7 +90,7 @@ public function setUp() $auth = new MoipBasicAuth($moip_token, $moip_key); } else { $this->sandbox_mock = self::MOCK; - $auth = $this->getMock('\Moip\MoipAuthentication'); + $auth = $this->getMock('\Moip\Auth\MoipAuthentication'); } $this->moip = new Moip($auth, Moip::ENDPOINT_SANDBOX); } From 5763c91fa3de73edd6f598c019f4325fd10fa0d7 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:30:09 -0300 Subject: [PATCH 04/44] create contracts --- src/Auth/MoipBasicAuth.php | 1 + src/Auth/MoipOAuth.php | 1 + src/{Auth => Contracts}/MoipAuthentication.php | 2 +- src/Moip.php | 2 +- tests/MoipTestCase.php | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) rename src/{Auth => Contracts}/MoipAuthentication.php (82%) diff --git a/src/Auth/MoipBasicAuth.php b/src/Auth/MoipBasicAuth.php index 52f1435..c0ce60d 100644 --- a/src/Auth/MoipBasicAuth.php +++ b/src/Auth/MoipBasicAuth.php @@ -2,6 +2,7 @@ namespace Moip\Auth; +use Moip\Contracts\MoipAuthentication; use Requests_Hooks; /** diff --git a/src/Auth/MoipOAuth.php b/src/Auth/MoipOAuth.php index 283cec8..86b4e5b 100644 --- a/src/Auth/MoipOAuth.php +++ b/src/Auth/MoipOAuth.php @@ -2,6 +2,7 @@ namespace Moip\Auth; +use Moip\Contracts\MoipAuthentication; use Requests_Hooks; /** diff --git a/src/Auth/MoipAuthentication.php b/src/Contracts/MoipAuthentication.php similarity index 82% rename from src/Auth/MoipAuthentication.php rename to src/Contracts/MoipAuthentication.php index c8e83d0..77f3118 100644 --- a/src/Auth/MoipAuthentication.php +++ b/src/Contracts/MoipAuthentication.php @@ -1,6 +1,6 @@ sandbox_mock = self::MOCK; - $auth = $this->getMock('\Moip\Auth\MoipAuthentication'); + $auth = $this->getMock('\Moip\Contracts\MoipAuthentication'); } $this->moip = new Moip($auth, Moip::ENDPOINT_SANDBOX); } From 9acb4ae6247a6eea9b65b8ef42751ca8a3a062d8 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:31:00 -0300 Subject: [PATCH 05/44] create contracts --- src/Auth/{MoipBasicAuth.php => BasicAuth.php} | 4 ++-- tests/MoipTestCase.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/Auth/{MoipBasicAuth.php => BasicAuth.php} (94%) diff --git a/src/Auth/MoipBasicAuth.php b/src/Auth/BasicAuth.php similarity index 94% rename from src/Auth/MoipBasicAuth.php rename to src/Auth/BasicAuth.php index c0ce60d..dc10384 100644 --- a/src/Auth/MoipBasicAuth.php +++ b/src/Auth/BasicAuth.php @@ -6,9 +6,9 @@ use Requests_Hooks; /** - * Class MoipBasicAuth. + * Class BasicAuth. */ -class MoipBasicAuth implements MoipAuthentication +class BasicAuth implements MoipAuthentication { /** * Token. diff --git a/tests/MoipTestCase.php b/tests/MoipTestCase.php index 90f3ac3..48284aa 100644 --- a/tests/MoipTestCase.php +++ b/tests/MoipTestCase.php @@ -3,7 +3,7 @@ namespace Moip\Tests; use Moip\Moip; -use Moip\Auth\MoipBasicAuth; +use Moip\Auth\BasicAuth; use Moip\Resource\Customer; use Moip\Resource\Orders; use PHPUnit_Framework_TestCase as TestCase; @@ -87,7 +87,7 @@ public function setUp() if ($moip_key && $moip_token) { $this->sandbox_mock = self::SANDBOX; - $auth = new MoipBasicAuth($moip_token, $moip_key); + $auth = new BasicAuth($moip_token, $moip_key); } else { $this->sandbox_mock = self::MOCK; $auth = $this->getMock('\Moip\Contracts\MoipAuthentication'); From 2dee8b52c6559a6db5e572cdbaa9b99f70601ac0 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:34:36 -0300 Subject: [PATCH 06/44] Removing moip as a class prefix --- src/Auth/BasicAuth.php | 4 ++-- src/Auth/{MoipOAuth.php => OAuth.php} | 8 ++++---- src/Contracts/Authentication.php | 12 ++++++++++++ src/Contracts/MoipAuthentication.php | 12 ------------ src/Moip.php | 4 ++-- tests/Resource/CustomerTest.php | 4 ++-- tests/Resource/OrdersTest.php | 4 ++-- tests/Resource/PaymentTest.php | 4 ++-- tests/{MoipTest.php => Test.php} | 4 ++-- tests/{MoipTestCase.php => TestCase.php} | 8 ++++---- 10 files changed, 32 insertions(+), 32 deletions(-) rename src/Auth/{MoipOAuth.php => OAuth.php} (89%) create mode 100644 src/Contracts/Authentication.php delete mode 100644 src/Contracts/MoipAuthentication.php rename tests/{MoipTest.php => Test.php} (99%) rename tests/{MoipTestCase.php => TestCase.php} (98%) diff --git a/src/Auth/BasicAuth.php b/src/Auth/BasicAuth.php index dc10384..5c1ab7b 100644 --- a/src/Auth/BasicAuth.php +++ b/src/Auth/BasicAuth.php @@ -2,13 +2,13 @@ namespace Moip\Auth; -use Moip\Contracts\MoipAuthentication; +use Moip\Contracts\Authentication; use Requests_Hooks; /** * Class BasicAuth. */ -class BasicAuth implements MoipAuthentication +class BasicAuth implements Authentication { /** * Token. diff --git a/src/Auth/MoipOAuth.php b/src/Auth/OAuth.php similarity index 89% rename from src/Auth/MoipOAuth.php rename to src/Auth/OAuth.php index 86b4e5b..3b83b46 100644 --- a/src/Auth/MoipOAuth.php +++ b/src/Auth/OAuth.php @@ -2,13 +2,13 @@ namespace Moip\Auth; -use Moip\Contracts\MoipAuthentication; +use Moip\Contracts\Authentication; use Requests_Hooks; /** - * Class MoipOAuth. + * Class OAuth. */ -class MoipOAuth implements MoipAuthentication +class OAuth implements Authentication { /** * Access Token. @@ -18,7 +18,7 @@ class MoipOAuth implements MoipAuthentication private $accessToken; /** - * Create a new MoipOAuth instance. + * Create a new OAuth instance. * * @param string $accessToken */ diff --git a/src/Contracts/Authentication.php b/src/Contracts/Authentication.php new file mode 100644 index 0000000..21915ec --- /dev/null +++ b/src/Contracts/Authentication.php @@ -0,0 +1,12 @@ +moipAuthentication = $moipAuthentication; $this->endpoint = $endpoint; diff --git a/tests/Resource/CustomerTest.php b/tests/Resource/CustomerTest.php index 45f54a6..83afef1 100644 --- a/tests/Resource/CustomerTest.php +++ b/tests/Resource/CustomerTest.php @@ -3,12 +3,12 @@ namespace Moip\Tests\Resource; use Moip\Resource\Customer; -use Moip\Tests\MoipTestCase; +use Moip\Tests\TestCase; /** * class CustomerTest. */ -class CustomerTest extends MoipTestCase +class CustomerTest extends TestCase { /** * Test if the Customer object accepts a \DateTime object and correctly transforms it. diff --git a/tests/Resource/OrdersTest.php b/tests/Resource/OrdersTest.php index 7577dc6..2de2c45 100644 --- a/tests/Resource/OrdersTest.php +++ b/tests/Resource/OrdersTest.php @@ -3,9 +3,9 @@ namespace Moip\Tests\Resource; use Moip\Resource\Orders; -use Moip\Tests\MoipTestCase; +use Moip\Tests\TestCase; -class OrdersTest extends MoipTestCase +class OrdersTest extends TestCase { /** * Send http request. diff --git a/tests/Resource/PaymentTest.php b/tests/Resource/PaymentTest.php index 1165f71..12e8d83 100644 --- a/tests/Resource/PaymentTest.php +++ b/tests/Resource/PaymentTest.php @@ -2,9 +2,9 @@ namespace Moip\Tests\Resource; -use Moip\Tests\MoipTestCase; +use Moip\Tests\TestCase; -class PaymentTest extends MoipTestCase +class PaymentTest extends TestCase { //todo: credit card hash diff --git a/tests/MoipTest.php b/tests/Test.php similarity index 99% rename from tests/MoipTest.php rename to tests/Test.php index 912f9d7..b021142 100644 --- a/tests/MoipTest.php +++ b/tests/Test.php @@ -8,9 +8,9 @@ use Requests_Exception; /** - * class MoipTest. + * class Test. */ -class MoipTest extends MoipTestCase +class Test extends TestCase { /** * Test should return instance of \Moip\Resource\Customer. diff --git a/tests/MoipTestCase.php b/tests/TestCase.php similarity index 98% rename from tests/MoipTestCase.php rename to tests/TestCase.php index 48284aa..6200169 100644 --- a/tests/MoipTestCase.php +++ b/tests/TestCase.php @@ -6,13 +6,13 @@ use Moip\Auth\BasicAuth; use Moip\Resource\Customer; use Moip\Resource\Orders; -use PHPUnit_Framework_TestCase as TestCase; +use PHPUnit_Framework_TestCase; use Requests_Response; /** - * class MoipTestCase. + * class TestCase. */ -abstract class MoipTestCase extends TestCase +abstract class TestCase extends PHPUnit_Framework_TestCase { /** * Variables representing the test modes. On MOCK mode no http request will be made. @@ -90,7 +90,7 @@ public function setUp() $auth = new BasicAuth($moip_token, $moip_key); } else { $this->sandbox_mock = self::MOCK; - $auth = $this->getMock('\Moip\Contracts\MoipAuthentication'); + $auth = $this->getMock('\Moip\Contracts\Authentication'); } $this->moip = new Moip($auth, Moip::ENDPOINT_SANDBOX); } From f065b452736a368b6c38a97e19d5475cf3c8f026 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:36:10 -0300 Subject: [PATCH 07/44] create folder for helpers --- src/{ => Helper}/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{ => Helper}/Utils.php (98%) diff --git a/src/Utils.php b/src/Helper/Utils.php similarity index 98% rename from src/Utils.php rename to src/Helper/Utils.php index 3ef582c..c403b56 100644 --- a/src/Utils.php +++ b/src/Helper/Utils.php @@ -1,6 +1,6 @@ Date: Wed, 12 Apr 2017 20:37:09 -0300 Subject: [PATCH 08/44] fixed tests --- tests/Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Test.php b/tests/Test.php index b021142..c284c97 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -4,7 +4,7 @@ use Moip\Exceptions; use Moip\Moip; -use Moip\Utils; +use Moip\Helper\Utils; use Requests_Exception; /** From 0a55ddc8278135a2e3c62833c9a9234d2de84068 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:37:39 -0300 Subject: [PATCH 09/44] MoipTeste --- tests/{Test.php => MoipTest.php} | 28 ++++++++++++++-------------- tests/Resource/CustomerTest.php | 8 ++++---- tests/Resource/OrdersTest.php | 6 +++--- tests/Resource/PaymentTest.php | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) rename tests/{Test.php => MoipTest.php} (86%) diff --git a/tests/Test.php b/tests/MoipTest.php similarity index 86% rename from tests/Test.php rename to tests/MoipTest.php index c284c97..72ca30f 100644 --- a/tests/Test.php +++ b/tests/MoipTest.php @@ -8,12 +8,12 @@ use Requests_Exception; /** - * class Test. + * class MoipTest. */ -class Test extends TestCase +class MoipTest extends TestCase { /** - * Test should return instance of \Moip\Resource\Customer. + * MoipTest should return instance of \Moip\Resource\Customer. */ public function testShouldReceiveInstanceOfCustomer() { @@ -23,7 +23,7 @@ public function testShouldReceiveInstanceOfCustomer() } /** - * Test should return instance of \Moip\Resource\Account. + * MoipTest should return instance of \Moip\Resource\Account. */ public function testShouldReceiveInstanceOfAccount() { @@ -33,7 +33,7 @@ public function testShouldReceiveInstanceOfAccount() } /** - * Test should return instance of \Moip\Resource\Entry. + * MoipTest should return instance of \Moip\Resource\Entry. */ public function testShouldReceiveInstanceOfEntry() { @@ -43,7 +43,7 @@ public function testShouldReceiveInstanceOfEntry() } /** - * Test should return instance of \Moip\Resource\Orders. + * MoipTest should return instance of \Moip\Resource\Orders. */ public function testShouldReceiveInstanceOfOrders() { @@ -53,7 +53,7 @@ public function testShouldReceiveInstanceOfOrders() } /** - * Test should return instance of \Moip\Resource\Payment. + * MoipTest should return instance of \Moip\Resource\Payment. */ public function testShouldReceiveInstanceOfPayment() { @@ -63,7 +63,7 @@ public function testShouldReceiveInstanceOfPayment() } /** - * Test should return instance of \Moip\Resource\Multiorders. + * MoipTest should return instance of \Moip\Resource\Multiorders. */ public function testShouldReceiveInstanceOfMultiorders() { @@ -73,7 +73,7 @@ public function testShouldReceiveInstanceOfMultiorders() } /** - * Test if a \Moip\Exceptions\testShouldRaiseValidationException is thrown and is correctly constructed. + * MoipTest if a \Moip\Exceptions\testShouldRaiseValidationException is thrown and is correctly constructed. */ public function testShouldRaiseValidationException() { @@ -106,7 +106,7 @@ public function testShouldRaiseValidationException() } /** - * Test if \Moip\Exceptios\UnautorizedException is thrown. + * MoipTest if \Moip\Exceptios\UnautorizedException is thrown. */ public function testShouldRaiseUnautorizedException() { @@ -122,7 +122,7 @@ public function testShouldRaiseUnautorizedException() } /** - * Test if UnexpectedException is thrown when 500 http status code is returned. + * MoipTest if UnexpectedException is thrown when 500 http status code is returned. */ public function testShouldRaiseUnexpectedException500() { @@ -137,7 +137,7 @@ public function testShouldRaiseUnexpectedException500() } /** - * Test if UnexpectedException is thrown when a Requests_Exception is thrown. + * MoipTest if UnexpectedException is thrown when a Requests_Exception is thrown. */ public function testShouldRaiseUnexpectedExceptionNetworkError() { @@ -162,7 +162,7 @@ public function testShouldRaiseUnexpectedExceptionNetworkError() } /** - * Test if we can connect to the API endpoints. + * MoipTest if we can connect to the API endpoints. * This is primarily to make user we are using HTTPS urls and the certification verification is ok. */ public function testConnectEndPoints() @@ -177,7 +177,7 @@ public function testConnectEndPoints() } /** - * Test the convertion from money to cents using floats. + * MoipTest the convertion from money to cents using floats. */ public function testToCents() { diff --git a/tests/Resource/CustomerTest.php b/tests/Resource/CustomerTest.php index 83afef1..6d2074c 100644 --- a/tests/Resource/CustomerTest.php +++ b/tests/Resource/CustomerTest.php @@ -11,7 +11,7 @@ class CustomerTest extends TestCase { /** - * Test if the Customer object accepts a \DateTime object and correctly transforms it. + * MoipTest if the Customer object accepts a \DateTime object and correctly transforms it. */ public function testSetBirthDateDateTime() { @@ -23,7 +23,7 @@ public function testSetBirthDateDateTime() } /** - * Test if the Customer object accepts a date string as argument. + * MoipTest if the Customer object accepts a date string as argument. */ public function testSetBirthDateString() { @@ -34,7 +34,7 @@ public function testSetBirthDateString() } /** - * Test customer creation. + * MoipTest customer creation. */ public function testCustomerCreate() { @@ -50,7 +50,7 @@ public function testCustomerCreate() } /** - * Test customer shipping address. + * MoipTest customer shipping address. */ public function testShippingAddress() { diff --git a/tests/Resource/OrdersTest.php b/tests/Resource/OrdersTest.php index 2de2c45..1fe2806 100644 --- a/tests/Resource/OrdersTest.php +++ b/tests/Resource/OrdersTest.php @@ -29,7 +29,7 @@ private function executeOrder(Orders $order = null, $body = null) } /** - * Test creating an order. + * MoipTest creating an order. */ public function testCreateOrder() { @@ -51,7 +51,7 @@ public function testItens() } /** - *Test if the total is correct. + *MoipTest if the total is correct. */ public function testTotal() { @@ -62,7 +62,7 @@ public function testTotal() } /** - * Test if the total is equal to the expected total. + * MoipTest if the total is equal to the expected total. */ public function testTotalConstant() { diff --git a/tests/Resource/PaymentTest.php b/tests/Resource/PaymentTest.php index 12e8d83..f039164 100644 --- a/tests/Resource/PaymentTest.php +++ b/tests/Resource/PaymentTest.php @@ -9,7 +9,7 @@ class PaymentTest extends TestCase //todo: credit card hash /** - * Test creating a credit card payment, passing all credit card data. + * MoipTest creating a credit card payment, passing all credit card data. */ public function testCreditCardPCI() { @@ -26,7 +26,7 @@ public function testCreditCardPCI() } /** - * Test creating a billet payment. + * MoipTest creating a billet payment. */ public function testBillet() { From ccdfa615d9d74e7c8103da214f8c79f3eea1e29e Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 20:47:17 -0300 Subject: [PATCH 10/44] create helpers --- composer.json | 5 ++++- src/Helper/helpers.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/Helper/helpers.php diff --git a/composer.json b/composer.json index 59104ae..01e36f5 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,10 @@ "autoload": { "psr-4": { "Moip\\": "src/" - } + }, + "files": [ + "src/Helper/helpers.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php new file mode 100644 index 0000000..aa2656d --- /dev/null +++ b/src/Helper/helpers.php @@ -0,0 +1,15 @@ + Date: Wed, 12 Apr 2017 20:51:39 -0300 Subject: [PATCH 11/44] if function not exists --- src/Helper/helpers.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php index aa2656d..19f6247 100644 --- a/src/Helper/helpers.php +++ b/src/Helper/helpers.php @@ -1,15 +1,17 @@ Date: Wed, 12 Apr 2017 20:52:13 -0300 Subject: [PATCH 12/44] psr --- src/Helper/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php index 19f6247..41e95b3 100644 --- a/src/Helper/helpers.php +++ b/src/Helper/helpers.php @@ -1,6 +1,6 @@ Date: Wed, 12 Apr 2017 20:54:35 -0300 Subject: [PATCH 13/44] create function pr --- src/Helper/helpers.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php index 41e95b3..95d9893 100644 --- a/src/Helper/helpers.php +++ b/src/Helper/helpers.php @@ -15,3 +15,26 @@ function to_cents(float $amount): int return Moip\Helper\Utils::toCents($amount); } } + +if (! function_exists('pr')) { + /** + * print_r() convenience function. + * + * In terminals this will act similar to using print_r() directly, when not run on cli + * print_r() will also wrap
 tags around the output of given variable. Similar to debug().
+     *
+     * This function returns the same variable that was passed.
+     *
+     * @param mixed $var Variable to print out.
+     * @return mixed the same $var that was passed to this function
+     * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#pr
+     * @see debug()
+     */
+    function pr($var)
+    {
+        $template = '
%s
'; + printf($template, trim(print_r($var, true))); + + return $var; + } +} \ No newline at end of file From 3ec5ffa24da3493ae15e277e33f9dd2613ec5df9 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 12 Apr 2017 21:35:22 -0300 Subject: [PATCH 14/44] initialize OAuth Connect --- src/Auth/Connect.php | 102 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/Auth/Connect.php diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php new file mode 100644 index 0000000..8c8732c --- /dev/null +++ b/src/Auth/Connect.php @@ -0,0 +1,102 @@ +client_id; + } + + /** + * @param mixed $client_id + * + * @return \Moip\Auth\Connect + */ + public function setClientId($client_id) + { + $this->client_id = $client_id; + return $this; + } + + /** + * @return mixed + */ + public function getRedirectUri() + { + return $this->redirect_uri; + } + + /** + * @param mixed $redirect_uri + * + * @return \Moip\Auth\Connect + */ + public function setRedirectUri($redirect_uri) + { + $this->redirect_uri = $redirect_uri; + return $this; + } + + /** + * @return mixed + */ + public function getScope() + { + return $this->scope; + } + + /** + * @param mixed $scope + * + * @return \Moip\Auth\Connect + */ + public function setScope($scope) + { + $this->scope = $scope; + + return $this; + } + + /** + * Register hooks as needed + * + * This method is called in {@see Requests::request} when the user has set + * an instance as the 'auth' option. Use this callback to register all the + * hooks you'll need. + * + * @see Requests_Hooks::register + * @param Requests_Hooks $hooks Hook system + */ + public function register(Requests_Hooks &$hooks) + { + // TODO: Implement register() method. + } +} From 8e034204bbf91775e5ce8bb4e58bcdfa39fc8531 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Thu, 13 Apr 2017 12:19:00 -0300 Subject: [PATCH 15/44] removed function setScodeResponseType --- src/Auth/Connect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 8c8732c..bf84e21 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -74,7 +74,7 @@ public function getScope() } /** - * @param mixed $scope + * @param array|string $scope * * @return \Moip\Auth\Connect */ From 3cdc6a2c7b72224624d1aefc17be891a5a9db963 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Thu, 13 Apr 2017 12:44:38 -0300 Subject: [PATCH 16/44] docblock --- src/Auth/Connect.php | 76 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index bf84e21..252d416 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -10,24 +10,80 @@ */ class Connect implements Authentication { + /** + * Define the type of response to be obtained. Possible values: CODE + * @const string + */ const RESPONSE_TYPE = 'code'; + + /** + * Permission for creation and consultation of + * ORDERS, PAYMENTS, MULTI ORDERS, MULTI PAYMENTS, CUSTOMERS and consultation of LAUNCHES. + * + * @const string + */ const RECEIVE_FUNDS = 'RECEIVE_FUNDS'; + + /** + * Permission to create and consult reimbursements of + * ORDERS, PAYMENTS. + * + * @const string + */ const REFUND = 'REFUND'; + + /** + * Permission to consult ACCOUNTS registration information. + * + * @const string + */ const MANAGE_ACCOUNT_INFO = 'MANAGE_ACCOUNT_INFO'; + + /** + * Permission to query balance through the ACCOUNTS endpoint. + * + * @const string + */ const RETRIEVE_FINANCIAL_INFO = 'RETRIEVE_FINANCIAL_INFO'; + + /** + * Permission for bank transfers or for Moip accounts through the TRANSFERS endpoint. + * + * @const string + */ const TRANSFER_FUNDS = 'TRANSFER_FUNDS'; + + /** + * Permission to create, change, and delete notification preferences through the PREFERENCES endpoint. + * + * @const string + */ const DEFINE_PREFERENCES = 'DEFINE_PREFERENCES'; + /** + * Unique identifier of the application that will be carried out the request. + * + * @var string (16) + */ private $client_id; + + /** + * Client Redirect URI + * + * @var string (255) + */ private $redirect_uri; - private $scope = []; - public function __construct() - { - return $this; - } + /** + * Permissions that you want (Possible values depending on the feature.). + * + * @var array + */ + private $scope = []; /** + * Unique identifier of the application that will be carried out the request. + * * @return mixed */ public function getClientId() @@ -36,6 +92,8 @@ public function getClientId() } /** + * Unique identifier of the application that will be carried out the request. + * * @param mixed $client_id * * @return \Moip\Auth\Connect @@ -47,6 +105,8 @@ public function setClientId($client_id) } /** + * Client Redirect URI. + * * @return mixed */ public function getRedirectUri() @@ -55,6 +115,8 @@ public function getRedirectUri() } /** + * Client Redirect URI. + * * @param mixed $redirect_uri * * @return \Moip\Auth\Connect @@ -66,6 +128,8 @@ public function setRedirectUri($redirect_uri) } /** + * Permissions that you want (Possible values depending on the feature.). + * * @return mixed */ public function getScope() @@ -74,6 +138,8 @@ public function getScope() } /** + * Permissions that you want (Possible values depending on the feature.). + * * @param array|string $scope * * @return \Moip\Auth\Connect From 79a210a90a494918970ad2f809bcefcc9317de73 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Thu, 13 Apr 2017 21:31:41 -0300 Subject: [PATCH 17/44] create new exception --- src/Exceptions/InvalidArgumentException.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Exceptions/InvalidArgumentException.php diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php new file mode 100644 index 0000000..c6e9c2b --- /dev/null +++ b/src/Exceptions/InvalidArgumentException.php @@ -0,0 +1,13 @@ + Date: Thu, 13 Apr 2017 21:31:52 -0300 Subject: [PATCH 18/44] set scopes --- src/Auth/Connect.php | 163 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 158 insertions(+), 5 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 252d416..87def32 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -3,6 +3,7 @@ namespace Moip\Auth; use Moip\Contracts\Authentication; +use Moip\Exceptions\InvalidArgumentException; use Requests_Hooks; /** @@ -17,16 +18,14 @@ class Connect implements Authentication const RESPONSE_TYPE = 'code'; /** - * Permission for creation and consultation of - * ORDERS, PAYMENTS, MULTI ORDERS, MULTI PAYMENTS, CUSTOMERS and consultation of LAUNCHES. + * Permission for creation and consultation of ORDERS, PAYMENTS, MULTI ORDERS, MULTI PAYMENTS, CUSTOMERS and consultation of LAUNCHES. * * @const string */ const RECEIVE_FUNDS = 'RECEIVE_FUNDS'; /** - * Permission to create and consult reimbursements of - * ORDERS, PAYMENTS. + * Permission to create and consult reimbursements ofORDERS, PAYMENTS. * * @const string */ @@ -81,6 +80,160 @@ class Connect implements Authentication */ private $scope = []; + /** + * @param bool $scope + */ + public function setScodeAll($scope) + { + if (! is_bool($scope)) { + throw new InvalidArgumentException('$scope deve ser boolean, foi passado ' . gettype($scope)); + } + + if ($scope === false) { + $this->scope = []; + } else { + $this->setReceiveFunds(true) + ->setRefund(true) + ->setManageAccountInfo(true) + ->setRetrieveFinancialInfo(true) + ->setTransferFunds(true) + ->setDefinePreferences(true); + } + + } + + /** + * Permission for creation and consultation of ORDERS, PAYMENTS, MULTI ORDERS, MULTI PAYMENTS, CUSTOMERS and consultation of LAUNCHES. + * + * @param bool $receive_funds + * + * @return \Moip\Auth\Connect $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setReceiveFunds($receive_funds) + { + if (! is_bool($receive_funds)) { + throw new InvalidArgumentException('$receive_funds deve ser boolean, foi passado ' . gettype($receive_funds)); + } + + if ($receive_funds === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + + /** + * Permission to create and consult reimbursements ofORDERS, PAYMENTS. + * + * @param bool $refund + * + * @return \Moip\Auth\Connect $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setRefund($refund) + { + if (! is_bool($refund)) { + throw new InvalidArgumentException('$refund deve ser boolean, foi passado ' . gettype($refund)); + } + + if ($refund === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + + /** + * Permission to consult ACCOUNTS registration information. + * + * @param bool $manage_account_info + * + * @return \Moip\Auth\Connect $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setManageAccountInfo($manage_account_info) + { + if (! is_bool($manage_account_info)) { + throw new InvalidArgumentException('$manage_account_info deve ser boolean, foi passado ' . gettype($manage_account_info)); + } + + if ($manage_account_info === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + + /** + * Permission to query balance through the ACCOUNTS endpoint. + * + * @param bool $retrieve_financial_info + * + * @return \Moip\Auth\Connect $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setRetrieveFinancialInfo($retrieve_financial_info) + { + if (! is_bool($retrieve_financial_info)) { + throw new InvalidArgumentException('$retrieve_financial_info deve ser boolean, foi passado ' . gettype($retrieve_financial_info)); + } + + if ($retrieve_financial_info === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + + /** + * Permission for bank transfers or for Moip accounts through the TRANSFERS endpoint. + * + * @param bool $transfer_funds + * + * @return \Moip\Auth\Connect $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setTransferFunds($transfer_funds) + { + if (! is_bool($transfer_funds)) { + throw new InvalidArgumentException('$transfer_funds deve ser boolean, foi passado ' . gettype($transfer_funds)); + } + + if ($transfer_funds === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + + /** + * Permission to create, change, and delete notification preferences through the PREFERENCES endpoint. + * + * @param bool $define_preferences + * + * @return $this + * + * @throws \Moip\Exceptions\InvalidArgumentException + */ + public function setDefinePreferences($define_preferences) + { + if (! is_bool($define_preferences)) { + throw new InvalidArgumentException('$define_preferences deve ser boolean, foi passado ' . gettype($define_preferences)); + } + + if ($define_preferences === true) { + $this->setScope(self::RECEIVE_FUNDS); + } + + return $this; + } + /** * Unique identifier of the application that will be carried out the request. * @@ -146,7 +299,7 @@ public function getScope() */ public function setScope($scope) { - $this->scope = $scope; + $this->scope[] = $scope; return $this; } From d3a3789964d3f6b9fb7cc79051f3b3d3a2c8a469 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Thu, 13 Apr 2017 21:35:48 -0300 Subject: [PATCH 19/44] docblock --- src/Auth/Connect.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 87def32..d57dd49 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -13,6 +13,7 @@ class Connect implements Authentication { /** * Define the type of response to be obtained. Possible values: CODE + * * @const string */ const RESPONSE_TYPE = 'code'; From c33be6f9226a5f2b390e90a53fad90dd072a19bf Mon Sep 17 00:00:00 2001 From: SOSTheBlack Date: Fri, 14 Apr 2017 13:30:46 +0000 Subject: [PATCH 20/44] Apply fixes from StyleCI --- src/Auth/Connect.php | 76 +++++++++++---------- src/Exceptions/InvalidArgumentException.php | 5 +- src/Helper/helpers.php | 8 ++- src/Moip.php | 2 +- tests/MoipTest.php | 2 +- tests/TestCase.php | 2 +- 6 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index d57dd49..3b2950a 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -7,12 +7,12 @@ use Requests_Hooks; /** - * Class Connect + * Class Connect. */ class Connect implements Authentication { /** - * Define the type of response to be obtained. Possible values: CODE + * Define the type of response to be obtained. Possible values: CODE. * * @const string */ @@ -68,7 +68,7 @@ class Connect implements Authentication private $client_id; /** - * Client Redirect URI + * Client Redirect URI. * * @var string (255) */ @@ -86,8 +86,8 @@ class Connect implements Authentication */ public function setScodeAll($scope) { - if (! is_bool($scope)) { - throw new InvalidArgumentException('$scope deve ser boolean, foi passado ' . gettype($scope)); + if (!is_bool($scope)) { + throw new InvalidArgumentException('$scope deve ser boolean, foi passado '.gettype($scope)); } if ($scope === false) { @@ -100,22 +100,21 @@ public function setScodeAll($scope) ->setTransferFunds(true) ->setDefinePreferences(true); } - } /** * Permission for creation and consultation of ORDERS, PAYMENTS, MULTI ORDERS, MULTI PAYMENTS, CUSTOMERS and consultation of LAUNCHES. * - * @param bool $receive_funds - * - * @return \Moip\Auth\Connect $this + * @param bool $receive_funds * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return \Moip\Auth\Connect $this */ public function setReceiveFunds($receive_funds) { - if (! is_bool($receive_funds)) { - throw new InvalidArgumentException('$receive_funds deve ser boolean, foi passado ' . gettype($receive_funds)); + if (!is_bool($receive_funds)) { + throw new InvalidArgumentException('$receive_funds deve ser boolean, foi passado '.gettype($receive_funds)); } if ($receive_funds === true) { @@ -128,16 +127,16 @@ public function setReceiveFunds($receive_funds) /** * Permission to create and consult reimbursements ofORDERS, PAYMENTS. * - * @param bool $refund - * - * @return \Moip\Auth\Connect $this + * @param bool $refund * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return \Moip\Auth\Connect $this */ public function setRefund($refund) { - if (! is_bool($refund)) { - throw new InvalidArgumentException('$refund deve ser boolean, foi passado ' . gettype($refund)); + if (!is_bool($refund)) { + throw new InvalidArgumentException('$refund deve ser boolean, foi passado '.gettype($refund)); } if ($refund === true) { @@ -150,16 +149,16 @@ public function setRefund($refund) /** * Permission to consult ACCOUNTS registration information. * - * @param bool $manage_account_info - * - * @return \Moip\Auth\Connect $this + * @param bool $manage_account_info * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return \Moip\Auth\Connect $this */ public function setManageAccountInfo($manage_account_info) { - if (! is_bool($manage_account_info)) { - throw new InvalidArgumentException('$manage_account_info deve ser boolean, foi passado ' . gettype($manage_account_info)); + if (!is_bool($manage_account_info)) { + throw new InvalidArgumentException('$manage_account_info deve ser boolean, foi passado '.gettype($manage_account_info)); } if ($manage_account_info === true) { @@ -172,16 +171,16 @@ public function setManageAccountInfo($manage_account_info) /** * Permission to query balance through the ACCOUNTS endpoint. * - * @param bool $retrieve_financial_info - * - * @return \Moip\Auth\Connect $this + * @param bool $retrieve_financial_info * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return \Moip\Auth\Connect $this */ public function setRetrieveFinancialInfo($retrieve_financial_info) { - if (! is_bool($retrieve_financial_info)) { - throw new InvalidArgumentException('$retrieve_financial_info deve ser boolean, foi passado ' . gettype($retrieve_financial_info)); + if (!is_bool($retrieve_financial_info)) { + throw new InvalidArgumentException('$retrieve_financial_info deve ser boolean, foi passado '.gettype($retrieve_financial_info)); } if ($retrieve_financial_info === true) { @@ -194,16 +193,16 @@ public function setRetrieveFinancialInfo($retrieve_financial_info) /** * Permission for bank transfers or for Moip accounts through the TRANSFERS endpoint. * - * @param bool $transfer_funds - * - * @return \Moip\Auth\Connect $this + * @param bool $transfer_funds * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return \Moip\Auth\Connect $this */ public function setTransferFunds($transfer_funds) { - if (! is_bool($transfer_funds)) { - throw new InvalidArgumentException('$transfer_funds deve ser boolean, foi passado ' . gettype($transfer_funds)); + if (!is_bool($transfer_funds)) { + throw new InvalidArgumentException('$transfer_funds deve ser boolean, foi passado '.gettype($transfer_funds)); } if ($transfer_funds === true) { @@ -216,16 +215,16 @@ public function setTransferFunds($transfer_funds) /** * Permission to create, change, and delete notification preferences through the PREFERENCES endpoint. * - * @param bool $define_preferences - * - * @return $this + * @param bool $define_preferences * * @throws \Moip\Exceptions\InvalidArgumentException + * + * @return $this */ public function setDefinePreferences($define_preferences) { - if (! is_bool($define_preferences)) { - throw new InvalidArgumentException('$define_preferences deve ser boolean, foi passado ' . gettype($define_preferences)); + if (!is_bool($define_preferences)) { + throw new InvalidArgumentException('$define_preferences deve ser boolean, foi passado '.gettype($define_preferences)); } if ($define_preferences === true) { @@ -255,6 +254,7 @@ public function getClientId() public function setClientId($client_id) { $this->client_id = $client_id; + return $this; } @@ -278,6 +278,7 @@ public function getRedirectUri() public function setRedirectUri($redirect_uri) { $this->redirect_uri = $redirect_uri; + return $this; } @@ -306,13 +307,14 @@ public function setScope($scope) } /** - * Register hooks as needed + * Register hooks as needed. * * This method is called in {@see Requests::request} when the user has set * an instance as the 'auth' option. Use this callback to register all the * hooks you'll need. * * @see Requests_Hooks::register + * * @param Requests_Hooks $hooks Hook system */ public function register(Requests_Hooks &$hooks) diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php index c6e9c2b..d07076f 100644 --- a/src/Exceptions/InvalidArgumentException.php +++ b/src/Exceptions/InvalidArgumentException.php @@ -5,9 +5,8 @@ use RuntimeException; /** - * Class InvalidArgumentException + * Class InvalidArgumentException. */ class InvalidArgumentException extends RuntimeException { - -} \ No newline at end of file +} diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php index 95d9893..1c28f5d 100644 --- a/src/Helper/helpers.php +++ b/src/Helper/helpers.php @@ -1,6 +1,6 @@ Date: Tue, 18 Apr 2017 19:35:27 -0300 Subject: [PATCH 21/44] doc block --- src/Auth/Connect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index d57dd49..078f31d 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -26,7 +26,7 @@ class Connect implements Authentication const RECEIVE_FUNDS = 'RECEIVE_FUNDS'; /** - * Permission to create and consult reimbursements ofORDERS, PAYMENTS. + * Permission to create and consult reimbursements of ORDERS, PAYMENTS. * * @const string */ From 762f9692032d950972597614047df579a8dda6ee Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Tue, 18 Apr 2017 20:27:33 -0300 Subject: [PATCH 22/44] endpoints --- src/Auth/Connect.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 078f31d..d5b0541 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -8,9 +8,35 @@ /** * Class Connect + * + * For all requests involving more than one Moip Account directly, authentication through an OAuth token is required. + * Using the OAuth 2.0 standard it is possible to authenticate to the Moip APIs and request the use of the APIs on behalf of another user. + * In this way, another Moip user can grant you the most diverse permissions, + * from receiving payments as a secondary receiver to even special actions like repayment of a payment. */ class Connect implements Authentication { + /** + * @const string + */ + const ENDPOINT_SANDBOX = 'https://connect.moip.com.br'; + + /** + * @const string + */ + const ENDPOINT_PRODUCTION = 'https://connect-sandbox.moip.com.br'; + + /** + * @const string + */ + const OAUTH_AUTHORIZE = '/oauth/authorize'; + + /** + * @const string + */ + const OAUTH_TOKEN = '/oauth/token'; + + /** * Define the type of response to be obtained. Possible values: CODE * @@ -100,7 +126,6 @@ public function setScodeAll($scope) ->setTransferFunds(true) ->setDefinePreferences(true); } - } /** From ba6c9bc916f1b99d61724f0b39d412d0efecad0c Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Tue, 18 Apr 2017 21:34:38 -0300 Subject: [PATCH 23/44] getAuthUrl --- src/Auth/Connect.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index d5b0541..0cc689d 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -19,12 +19,12 @@ class Connect implements Authentication /** * @const string */ - const ENDPOINT_SANDBOX = 'https://connect.moip.com.br'; + const ENDPOINT_SANDBOX = 'https://connect-sandbox.moip.com.br'; /** * @const string */ - const ENDPOINT_PRODUCTION = 'https://connect-sandbox.moip.com.br'; + const ENDPOINT_PRODUCTION = 'https://connect.moip.com.br'; /** * @const string @@ -107,6 +107,18 @@ class Connect implements Authentication */ private $scope = []; + public function getAuthUrl($auth_endpoint) + { + $query_string = [ + 'response_type' => self::RESPONSE_TYPE, + 'client_id' => $this->client_id, + 'redirect_uri' => $this->redirect_uri, + 'scope' => implode(',', $this->scope) + ]; + + return $auth_endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; + } + /** * @param bool $scope */ @@ -166,7 +178,7 @@ public function setRefund($refund) } if ($refund === true) { - $this->setScope(self::RECEIVE_FUNDS); + $this->setScope(self::REFUND); } return $this; @@ -188,7 +200,7 @@ public function setManageAccountInfo($manage_account_info) } if ($manage_account_info === true) { - $this->setScope(self::RECEIVE_FUNDS); + $this->setScope(self::MANAGE_ACCOUNT_INFO); } return $this; @@ -210,7 +222,7 @@ public function setRetrieveFinancialInfo($retrieve_financial_info) } if ($retrieve_financial_info === true) { - $this->setScope(self::RECEIVE_FUNDS); + $this->setScope(self::RETRIEVE_FINANCIAL_INFO); } return $this; @@ -232,7 +244,7 @@ public function setTransferFunds($transfer_funds) } if ($transfer_funds === true) { - $this->setScope(self::RECEIVE_FUNDS); + $this->setScope(self::TRANSFER_FUNDS); } return $this; @@ -254,7 +266,7 @@ public function setDefinePreferences($define_preferences) } if ($define_preferences === true) { - $this->setScope(self::RECEIVE_FUNDS); + $this->setScope(self::DEFINE_PREFERENCES); } return $this; From a9635ecaff83fdb5fadd9e40afc750605797087c Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Tue, 18 Apr 2017 21:35:08 -0300 Subject: [PATCH 24/44] docblock --- src/Auth/Connect.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 0cc689d..2197d32 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -107,6 +107,13 @@ class Connect implements Authentication */ private $scope = []; + /** + * URI of oauth. + * + * @param $auth_endpoint + * + * @return string + */ public function getAuthUrl($auth_endpoint) { $query_string = [ From 3095b8b184f7f8edb3ca1a16756b7dae997caa00 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 19 Apr 2017 11:53:06 -0300 Subject: [PATCH 25/44] merge --- src/Auth/Connect.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index aff9b13..f705bf9 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -7,21 +7,16 @@ use Requests_Hooks; /** -<<<<<<< HEAD * Class Connect * * For all requests involving more than one Moip Account directly, authentication through an OAuth token is required. * Using the OAuth 2.0 standard it is possible to authenticate to the Moip APIs and request the use of the APIs on behalf of another user. * In this way, another Moip user can grant you the most diverse permissions, * from receiving payments as a secondary receiver to even special actions like repayment of a payment. -======= - * Class Connect. ->>>>>>> 1736c8b385e75d4282846132de335c9a9cfee7bc */ class Connect implements Authentication { /** -<<<<<<< HEAD * @const string */ const ENDPOINT_SANDBOX = 'https://connect-sandbox.moip.com.br'; @@ -41,12 +36,8 @@ class Connect implements Authentication */ const OAUTH_TOKEN = '/oauth/token'; - /** - * Define the type of response to be obtained. Possible values: CODE -======= * Define the type of response to be obtained. Possible values: CODE. ->>>>>>> 1736c8b385e75d4282846132de335c9a9cfee7bc * * @const string */ From 1fe94c1cfdf0ce89be3c5654ac374e1ce8649eff Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Tue, 25 Apr 2017 19:35:40 -0300 Subject: [PATCH 26/44] session request --- src/Auth/Connect.php | 80 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index f705bf9..cb5cdb1 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -2,9 +2,15 @@ namespace Moip\Auth; +use JsonSerializable; use Moip\Contracts\Authentication; use Moip\Exceptions\InvalidArgumentException; +use Moip\Exceptions\UnexpectedException; +use Moip\Moip; +use Moip\Resource\MoipResource; use Requests_Hooks; +use Requests_Session; +use stdClass; /** * Class Connect @@ -14,7 +20,7 @@ * In this way, another Moip user can grant you the most diverse permissions, * from receiving payments as a secondary receiver to even special actions like repayment of a payment. */ -class Connect implements Authentication +class Connect implements Authentication, JsonSerializable { /** * @const string @@ -99,6 +105,13 @@ class Connect implements Authentication */ private $redirect_uri; + /** + * Endpoint. + * + * @var string + */ + private $endpoint; + /** * Permissions that you want (Possible values depending on the feature.). * @@ -106,6 +119,43 @@ class Connect implements Authentication */ private $scope = []; + /** + * @var Requests_Session HTTP session configured to use the moip API. + */ + private $session; + + /** + * Connect constructor. + */ + public function __construct() + { + $this->createNewSession(); + } + + /** + * Creates a new Request_Session with all the default values. + * A Session is created at construction. + * + * @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). + * @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01) + */ + 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)', + Moip::CLIENT, PHP_SAPI, PHP_VERSION, $uname['sysname'], $uname['machine']); + } else { + $user_agent = sprintf('Mozilla/4.0 (compatible; %s; PHP/%s %s; %s)', + Moip::CLIENT, PHP_SAPI, PHP_VERSION, PHP_OS); + } + $sess = new Requests_Session($this->endpoint); + $sess->options['timeout'] = $timeout; + $sess->options['connect_timeout'] = $connect_timeout; + $sess->options['useragent'] = $user_agent; + $this->session = $sess; + } + /** * URI of oauth. * @@ -365,4 +415,32 @@ public function register(Requests_Hooks &$hooks) { // TODO: Implement register() method. } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + function jsonSerialize() + { + // TODO: Implement jsonSerialize() method. + } + + /** + * @param string $endpoint + * + * @return \Moip\Auth\Connect + */ + public function setEndpoint(string $endpoint) + { + if ($endpoint === self::ENDPOINT_SANDBOX || $endpoint === self::ENDPOINT_PRODUCTION) { + $this->endpoint = $endpoint; + + return $this; + } + + throw new InvalidArgumentException('Endpoint inválido.'); + } } From 36a6261a053d2d6a73f1e4868b0ed3623aa6e2bd Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Tue, 25 Apr 2017 21:15:48 -0300 Subject: [PATCH 27/44] add links --- src/Helper/Links.php | 70 +++++++++++++++++++++++++++++++++++ src/Resource/MoipResource.php | 20 ++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/Helper/Links.php diff --git a/src/Helper/Links.php b/src/Helper/Links.php new file mode 100644 index 0000000..85d535a --- /dev/null +++ b/src/Helper/Links.php @@ -0,0 +1,70 @@ +links = $links; + $this->generateMethods(); + } + + /** + * @return mixed + */ + public function getSelf() + { + return $this->links->self->href; + } + + /** + * @param null|string $pay + * + * @return mixed + */ + public function getCheckout($pay) + { + return $this->links->checkout->$pay->redirectHref; + } + + /** + * @return mixed + */ + public function getAllCheckout() + { + return $this->checkout; + } + + /** + * + */ + private function generateMethods() + { + $this->checkout = new stdClass(); + + foreach ($this->links->checkout as $method => $link) { + $this->checkout->$method = $link->redirectHref; + } + } +} diff --git a/src/Resource/MoipResource.php b/src/Resource/MoipResource.php index d96e405..adadb8e 100644 --- a/src/Resource/MoipResource.php +++ b/src/Resource/MoipResource.php @@ -4,6 +4,7 @@ use JsonSerializable; use Moip\Exceptions; +use Moip\Helper\Links; use Moip\Moip; use Requests; use Requests_Exception; @@ -76,6 +77,25 @@ protected function getIfSet($key, stdClass $data = null) } } + /** + * @return \Moip\Helper\Links + */ + public function getLinks() + { + $links = $this->getIfSet('_links'); + + if ($links !== null) { + return new Links($links); + } + } + + /** + * @param $key + * @param $fmt + * @param stdClass|null $data + * + * @return bool|\DateTime|null + */ protected function getIfSetDateFmt($key, $fmt, stdClass $data = null) { $val = $this->getIfSet($key, $data); From 009481aba5ddbaf81cb06940f59280db893591c8 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 09:26:42 -0300 Subject: [PATCH 28/44] compatibilidade php5 --- src/Helper/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helper/helpers.php b/src/Helper/helpers.php index 1c28f5d..1a8f2b0 100644 --- a/src/Helper/helpers.php +++ b/src/Helper/helpers.php @@ -10,7 +10,7 @@ * * @return int */ - function to_cents(float $amount): int + function to_cents(float $amount) { return Moip\Helper\Utils::toCents($amount); } From 80025ca0bb8d87dea373f31afe791fd49c817d07 Mon Sep 17 00:00:00 2001 From: SOSTheBlack Date: Wed, 26 Apr 2017 12:27:27 +0000 Subject: [PATCH 29/44] Apply fixes from StyleCI --- src/Auth/Connect.php | 22 +++++++++++----------- src/Helper/Links.php | 3 --- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index cb5cdb1..6cbf216 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -5,15 +5,12 @@ use JsonSerializable; use Moip\Contracts\Authentication; use Moip\Exceptions\InvalidArgumentException; -use Moip\Exceptions\UnexpectedException; use Moip\Moip; -use Moip\Resource\MoipResource; use Requests_Hooks; use Requests_Session; -use stdClass; /** - * Class Connect + * Class Connect. * * For all requests involving more than one Moip Account directly, authentication through an OAuth token is required. * Using the OAuth 2.0 standard it is possible to authenticate to the Moip APIs and request the use of the APIs on behalf of another user. @@ -167,12 +164,12 @@ public function getAuthUrl($auth_endpoint) { $query_string = [ 'response_type' => self::RESPONSE_TYPE, - 'client_id' => $this->client_id, - 'redirect_uri' => $this->redirect_uri, - 'scope' => implode(',', $this->scope) + 'client_id' => $this->client_id, + 'redirect_uri' => $this->redirect_uri, + 'scope' => implode(',', $this->scope), ]; - return $auth_endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; + return $auth_endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string); } /** @@ -417,13 +414,16 @@ public function register(Requests_Hooks &$hooks) } /** - * Specify data which should be serialized to JSON + * Specify data which should be serialized to JSON. + * * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. + * which is a value of any type other than a resource. + * * @since 5.4.0 */ - function jsonSerialize() + public function jsonSerialize() { // TODO: Implement jsonSerialize() method. } diff --git a/src/Helper/Links.php b/src/Helper/Links.php index 85d535a..bd3bfe6 100644 --- a/src/Helper/Links.php +++ b/src/Helper/Links.php @@ -56,9 +56,6 @@ public function getAllCheckout() return $this->checkout; } - /** - * - */ private function generateMethods() { $this->checkout = new stdClass(); From 18e5e8087000271cff4cd976db7fd2e111050ab4 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 18:20:45 -0300 Subject: [PATCH 30/44] update scope and construct --- src/Auth/Connect.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index cb5cdb1..8c7648d 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -91,6 +91,20 @@ class Connect implements Authentication, JsonSerializable */ const DEFINE_PREFERENCES = 'DEFINE_PREFERENCES'; + /** + * List all scopes. + * + * @const array + */ + const SCOPE_ALL = [ + self::RECEIVE_FUNDS, + self::REFUND, + self::MANAGE_ACCOUNT_INFO, + self::RETRIEVE_FINANCIAL_INFO, + self::TRANSFER_FUNDS, + self::DEFINE_PREFERENCES, + ]; + /** * Unique identifier of the application that will be carried out the request. * @@ -126,9 +140,19 @@ class Connect implements Authentication, JsonSerializable /** * Connect constructor. + * + * @param string $client_id + * @param string $redirect_uri + * @param array $scope + * @param string $endpoint */ - public function __construct() + public function __construct($client_id = '', $redirect_uri = '', $scope = [], $endpoint = self::ENDPOINT_PRODUCTION) { + $this->client_id = $client_id; + $this->redirect_uri = $redirect_uri; + $this->scope = $this->setScope($endpoint); + $this->endpoint = $endpoint; + $this->createNewSession(); } @@ -395,6 +419,14 @@ public function getScope() */ public function setScope($scope) { + if (! in_array($scope, self::SCOPE_ALL, true)) { + throw new InvalidArgumentException(); + } + + if (is_array($scope)) { + $this->scope = $scope; + } + $this->scope[] = $scope; return $this; From 5f3cdea3057a952217fbc0ab6f3bd0b9f32ba6fa Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 18:46:38 -0300 Subject: [PATCH 31/44] params redirect --- src/Auth/Connect.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 8c7648d..3c09232 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -141,18 +141,23 @@ class Connect implements Authentication, JsonSerializable /** * Connect constructor. * - * @param string $client_id * @param string $redirect_uri - * @param array $scope + * @param string $client_id + * @param array|bool $scope * @param string $endpoint */ - public function __construct($client_id = '', $redirect_uri = '', $scope = [], $endpoint = self::ENDPOINT_PRODUCTION) + public function __construct($redirect_uri = '', $client_id = '', $scope = true, $endpoint = self::ENDPOINT_PRODUCTION) { $this->client_id = $client_id; $this->redirect_uri = $redirect_uri; - $this->scope = $this->setScope($endpoint); - $this->endpoint = $endpoint; + if (is_bool($scope)) { + $this->setScodeAll($scope); + } else { + $this->setScope($endpoint); + } + + $this->setEndpoint($endpoint); $this->createNewSession(); } @@ -201,6 +206,8 @@ public function getAuthUrl($auth_endpoint) /** * @param bool $scope + * + * @return $this */ public function setScodeAll($scope) { @@ -218,6 +225,8 @@ public function setScodeAll($scope) ->setTransferFunds(true) ->setDefinePreferences(true); } + + return $this; } /** @@ -467,12 +476,12 @@ function jsonSerialize() */ public function setEndpoint(string $endpoint) { - if ($endpoint === self::ENDPOINT_SANDBOX || $endpoint === self::ENDPOINT_PRODUCTION) { - $this->endpoint = $endpoint; - - return $this; + if (! in_array($endpoint, [self::ENDPOINT_SANDBOX, self::ENDPOINT_PRODUCTION])) { + throw new InvalidArgumentException('Endpoint inválido.'); } - throw new InvalidArgumentException('Endpoint inválido.'); + $this->endpoint = $endpoint; + + return $this; } } From 9d24479aab04fe304dcc6cf203f053d8311b40ff Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 18:47:37 -0300 Subject: [PATCH 32/44] removed implentations --- src/Auth/Connect.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 3c09232..eb3a951 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -5,12 +5,9 @@ use JsonSerializable; use Moip\Contracts\Authentication; use Moip\Exceptions\InvalidArgumentException; -use Moip\Exceptions\UnexpectedException; use Moip\Moip; -use Moip\Resource\MoipResource; use Requests_Hooks; use Requests_Session; -use stdClass; /** * Class Connect From adc5a22c344ed883782d9414cc31b55d13cf61cf Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 18:52:04 -0300 Subject: [PATCH 33/44] fixed redirect uri --- src/Auth/Connect.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index eb3a951..f89e0b2 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -189,8 +189,11 @@ public function createNewSession($timeout = 30.0, $connect_timeout = 30.0) * * @return string */ - public function getAuthUrl($auth_endpoint) + public function getAuthUrl($auth_endpoint = null) { + if ($auth_endpoint !== null) { + $this->endpoint = $auth_endpoint; + } $query_string = [ 'response_type' => self::RESPONSE_TYPE, 'client_id' => $this->client_id, @@ -198,7 +201,7 @@ public function getAuthUrl($auth_endpoint) 'scope' => implode(',', $this->scope) ]; - return $auth_endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; + return $this->endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; } /** From 526a52e5eab4c967ced4a3528566a6bcb0e9f674 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 18:52:47 -0300 Subject: [PATCH 34/44] rename var --- src/Auth/Connect.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index f89e0b2..80e29c2 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -185,14 +185,14 @@ public function createNewSession($timeout = 30.0, $connect_timeout = 30.0) /** * URI of oauth. * - * @param $auth_endpoint + * @param $endpoint * * @return string */ - public function getAuthUrl($auth_endpoint = null) + public function getAuthUrl($endpoint = null) { - if ($auth_endpoint !== null) { - $this->endpoint = $auth_endpoint; + if ($endpoint !== null) { + $this->endpoint = $endpoint; } $query_string = [ 'response_type' => self::RESPONSE_TYPE, From dff84bb172e6e0f80ced164103019a9dadfe6e4d Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Wed, 26 Apr 2017 19:55:55 -0300 Subject: [PATCH 35/44] resgatando accesstoken --- src/Auth/Connect.php | 101 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 5 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 80e29c2..ce30bf2 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -4,8 +4,13 @@ use JsonSerializable; use Moip\Contracts\Authentication; +use Moip\Exceptions\Error; use Moip\Exceptions\InvalidArgumentException; +use Moip\Exceptions\UnautorizedException; +use Moip\Exceptions\UnexpectedException; +use Moip\Exceptions\ValidationException; use Moip\Moip; +use Requests_Exception; use Requests_Hooks; use Requests_Session; @@ -39,6 +44,13 @@ class Connect implements Authentication, JsonSerializable */ const OAUTH_TOKEN = '/oauth/token'; + /** + * Type of request desired. Possible values: AUTHORIZATION_CODE. + * + * @const string + */ + const GRANT_TYPE = 'authorization_code'; + /** * Define the type of response to be obtained. Possible values: CODE. * @@ -109,6 +121,13 @@ class Connect implements Authentication, JsonSerializable */ private $client_id; + /** + * Classic non-standard authentication and access token for integration with generic SDKs. + * + * @var string (35) + */ + private $client_secret; + /** * Client Redirect URI. * @@ -131,9 +150,11 @@ class Connect implements Authentication, JsonSerializable private $scope = []; /** - * @var Requests_Session HTTP session configured to use the moip API. + * Validation code to retrieve the access token. + * + * @var string (32) */ - private $session; + private $code; /** * Connect constructor. @@ -155,15 +176,16 @@ public function __construct($redirect_uri = '', $client_id = '', $scope = true, } $this->setEndpoint($endpoint); - $this->createNewSession(); } /** * Creates a new Request_Session with all the default values. * A Session is created at construction. * - * @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). + * @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). * @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01) + * + * @return \Requests_Session */ public function createNewSession($timeout = 30.0, $connect_timeout = 30.0) { @@ -179,7 +201,8 @@ public function createNewSession($timeout = 30.0, $connect_timeout = 30.0) $sess->options['timeout'] = $timeout; $sess->options['connect_timeout'] = $connect_timeout; $sess->options['useragent'] = $user_agent; - $this->session = $sess; + + return $sess; } /** @@ -204,6 +227,34 @@ public function getAuthUrl($endpoint = null) return $this->endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; } + public function authorize() + { + $path = $this->endpoint . self::OAUTH_TOKEN; + $headers = ['Content-Type' => 'application/x-www-form-urlencoded']; + $body = [ + 'client_id' => $this->client_id, + 'client_secret' => $this->client_secret, + 'grant_type' => self::GRANT_TYPE, + 'code' => $this->code, + 'redirect_uri' => $this->redirect_uri + ]; + + try { + $http_response = $this->createNewSession()->request($path, $headers, $body, 'POST'); + } catch (Requests_Exception $e) { + throw new UnexpectedException($e); + } + + if ($http_response->status_code >= 200 && $http_response->status_code < 300) { + return json_decode($http_response->body); + } elseif ($http_response->status_code >= 400 && $http_response->status_code <= 499) { + $errors = Error::parseErrors($http_response->body); + throw new ValidationException($http_response->status_code, $errors); + } + + throw new UnexpectedException(); + } + /** * @param bool $scope * @@ -484,4 +535,44 @@ public function setEndpoint(string $endpoint) return $this; } + + /** + * @param mixed $client_secret + * + * @return \Moip\Auth\Connect + */ + public function setClientSecret($client_secret) + { + $this->client_secret = $client_secret; + + return $this; + } + + /** + * @return mixed + */ + public function getClientSecret() + { + return $this->client_secret; + } + + /** + * @param string $code + * + * @return \Moip\Auth\Connect + */ + public function setCode(string $code) + { + $this->code = $code; + + return $this; + } + + /** + * @return string + */ + public function getCode() + { + return $this->code; + } } From 662fff2f022ce40aded75aaf8bebfd8b5bdd576a Mon Sep 17 00:00:00 2001 From: SOSTheBlack Date: Wed, 26 Apr 2017 23:07:52 +0000 Subject: [PATCH 36/44] Apply fixes from StyleCI --- src/Auth/Connect.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index dc69921..84e000d 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -6,7 +6,6 @@ use Moip\Contracts\Authentication; use Moip\Exceptions\Error; use Moip\Exceptions\InvalidArgumentException; -use Moip\Exceptions\UnautorizedException; use Moip\Exceptions\UnexpectedException; use Moip\Exceptions\ValidationException; use Moip\Moip; @@ -105,7 +104,7 @@ class Connect implements Authentication, JsonSerializable * * @const array */ - const SCOPE_ALL = [ + const SCOPE_ALL = [ self::RECEIVE_FUNDS, self::REFUND, self::MANAGE_ACCOUNT_INFO, @@ -159,10 +158,10 @@ class Connect implements Authentication, JsonSerializable /** * Connect constructor. * - * @param string $redirect_uri - * @param string $client_id + * @param string $redirect_uri + * @param string $client_id * @param array|bool $scope - * @param string $endpoint + * @param string $endpoint */ public function __construct($redirect_uri = '', $client_id = '', $scope = true, $endpoint = self::ENDPOINT_PRODUCTION) { @@ -182,7 +181,7 @@ public function __construct($redirect_uri = '', $client_id = '', $scope = true, * Creates a new Request_Session with all the default values. * A Session is created at construction. * - * @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). + * @param float $timeout How long should we wait for a response?(seconds with a millisecond precision, default: 30, example: 0.01). * @param float $connect_timeout How long should we wait while trying to connect? (seconds with a millisecond precision, default: 10, example: 0.01) * * @return \Requests_Session @@ -224,7 +223,7 @@ public function getAuthUrl($endpoint = null) 'scope' => implode(',', $this->scope), ]; - return $this->endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string);; + return $this->endpoint.self::OAUTH_AUTHORIZE.'?'.http_build_query($query_string); } /** @@ -234,14 +233,14 @@ public function getAuthUrl($endpoint = null) */ public function authorize() { - $path = $this->endpoint . self::OAUTH_TOKEN; + $path = $this->endpoint.self::OAUTH_TOKEN; $headers = ['Content-Type' => 'application/x-www-form-urlencoded']; $body = [ - 'client_id' => $this->client_id, + 'client_id' => $this->client_id, 'client_secret' => $this->client_secret, - 'grant_type' => self::GRANT_TYPE, - 'code' => $this->code, - 'redirect_uri' => $this->redirect_uri + 'grant_type' => self::GRANT_TYPE, + 'code' => $this->code, + 'redirect_uri' => $this->redirect_uri, ]; try { @@ -484,7 +483,7 @@ public function getScope() */ public function setScope($scope) { - if (! in_array($scope, self::SCOPE_ALL, true)) { + if (!in_array($scope, self::SCOPE_ALL, true)) { throw new InvalidArgumentException(); } @@ -504,7 +503,7 @@ public function setScope($scope) */ public function setEndpoint(string $endpoint) { - if (! in_array($endpoint, [self::ENDPOINT_SANDBOX, self::ENDPOINT_PRODUCTION])) { + if (!in_array($endpoint, [self::ENDPOINT_SANDBOX, self::ENDPOINT_PRODUCTION])) { throw new InvalidArgumentException('Endpoint inválido.'); } From e48ec748ba4a275710a35c0265a4525f944d8fdb Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Fri, 28 Apr 2017 19:01:00 -0300 Subject: [PATCH 37/44] legth --- src/Auth/Connect.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 84e000d..d16150d 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -116,21 +116,21 @@ class Connect implements Authentication, JsonSerializable /** * Unique identifier of the application that will be carried out the request. * - * @var string (16) + * @var string */ private $client_id; /** * Classic non-standard authentication and access token for integration with generic SDKs. * - * @var string (35) + * @var string */ private $client_secret; /** * Client Redirect URI. * - * @var string (255) + * @var string */ private $redirect_uri; @@ -151,7 +151,7 @@ class Connect implements Authentication, JsonSerializable /** * Validation code to retrieve the access token. * - * @var string (32) + * @var string */ private $code; From a0b87fd6e337c88e7f3e964ed6ad379894071164 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Fri, 28 Apr 2017 19:14:08 -0300 Subject: [PATCH 38/44] fixed scope --- src/Auth/Connect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index d16150d..9e4b3be 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -171,7 +171,7 @@ public function __construct($redirect_uri = '', $client_id = '', $scope = true, if (is_bool($scope)) { $this->setScodeAll($scope); } else { - $this->setScope($endpoint); + $this->setScope($scope); } $this->setEndpoint($endpoint); From 1480c1461dde705c8cbc7ec03227ee1eef28f07a Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Fri, 28 Apr 2017 19:43:52 -0300 Subject: [PATCH 39/44] empty scope --- src/Auth/Connect.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 9e4b3be..59a67ce 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -273,6 +273,7 @@ public function setScodeAll($scope) if ($scope === false) { $this->scope = []; } else { + $this->scope = []; $this->setReceiveFunds(true) ->setRefund(true) ->setManageAccountInfo(true) From 83d2e0b4dac44dd2111c1fd1fac9fb748d78e6f6 Mon Sep 17 00:00:00 2001 From: Aryan Gomes Date: Tue, 16 May 2017 11:39:10 -0300 Subject: [PATCH 40/44] add set redirectUrls & add get CheckoutPreferences add method for set UrlSuccess and UrlFailure and add method for get checkoutPreferences --- src/Resource/Orders.php | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Resource/Orders.php b/src/Resource/Orders.php index 2718cbb..0bec389 100644 --- a/src/Resource/Orders.php +++ b/src/Resource/Orders.php @@ -108,6 +108,8 @@ protected function initialize() $this->data->amount->subtotals = new stdClass(); $this->data->items = []; $this->data->receivers = []; + $this->data->checkoutPreferences = new stdClass(); + $this->data->checkoutPreferences->redirectUrls = new stdClass(); } /** @@ -420,6 +422,22 @@ public function getUpdatedAt() { return $this->getIfSetDateTime('updatedAt'); } + + /** + * Get checkout preferences of the order. + * + * @return string + */ + public function getCheckoutPreferences() + { + return $this->getIfSet('checkoutPreferences'); + } + + + public function getPayments() + { + return $this->getIfSet('payments'); + } /** * Structure of payment. @@ -535,4 +553,33 @@ public function setShippingAmount($value) return $this; } + + /** + * Set URL for redirection in case of success. + * + * @param string $urlSuccess UrlSuccess. + * + * @return $this + */ + public function setUrlSuccess($urlSuccess = "") + { + $this->data->checkoutPreferences->redirectUrls->urlSuccess = $urlSuccess; + + return $this; + } + + + /** + * Set URL for redirection in case of failure. + * + * @param string $urlFailure UrlFailure. + * + * @return $this + */ + public function setUrlFailure($urlFailure = "") + { + $this->data->checkoutPreferences->redirectUrls->urlFailure = $urlFailure; + + return $this; + } } From ec56d34198ef19dd648fa32b287c2fb017c80be9 Mon Sep 17 00:00:00 2001 From: Aryan Gomes Date: Tue, 16 May 2017 11:39:10 -0300 Subject: [PATCH 41/44] Revert "add set redirectUrls & add get CheckoutPreferences" This reverts commit 83d2e0b4dac44dd2111c1fd1fac9fb748d78e6f6. --- src/Resource/Orders.php | 47 ----------------------------------------- 1 file changed, 47 deletions(-) diff --git a/src/Resource/Orders.php b/src/Resource/Orders.php index 0bec389..2718cbb 100644 --- a/src/Resource/Orders.php +++ b/src/Resource/Orders.php @@ -108,8 +108,6 @@ protected function initialize() $this->data->amount->subtotals = new stdClass(); $this->data->items = []; $this->data->receivers = []; - $this->data->checkoutPreferences = new stdClass(); - $this->data->checkoutPreferences->redirectUrls = new stdClass(); } /** @@ -422,22 +420,6 @@ public function getUpdatedAt() { return $this->getIfSetDateTime('updatedAt'); } - - /** - * Get checkout preferences of the order. - * - * @return string - */ - public function getCheckoutPreferences() - { - return $this->getIfSet('checkoutPreferences'); - } - - - public function getPayments() - { - return $this->getIfSet('payments'); - } /** * Structure of payment. @@ -553,33 +535,4 @@ public function setShippingAmount($value) return $this; } - - /** - * Set URL for redirection in case of success. - * - * @param string $urlSuccess UrlSuccess. - * - * @return $this - */ - public function setUrlSuccess($urlSuccess = "") - { - $this->data->checkoutPreferences->redirectUrls->urlSuccess = $urlSuccess; - - return $this; - } - - - /** - * Set URL for redirection in case of failure. - * - * @param string $urlFailure UrlFailure. - * - * @return $this - */ - public function setUrlFailure($urlFailure = "") - { - $this->data->checkoutPreferences->redirectUrls->urlFailure = $urlFailure; - - return $this; - } } From b5f438ec4ef70a450c59cdd0abeddc64a198bba2 Mon Sep 17 00:00:00 2001 From: Aryan Date: Tue, 16 May 2017 11:56:27 -0300 Subject: [PATCH 42/44] add set redirectUrls & add get CheckoutPreferences add method for set UrlSuccess and UrlFailure and add method for get checkoutPreferences --- src/Resource/Orders.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Resource/Orders.php b/src/Resource/Orders.php index 2718cbb..ecd128b 100644 --- a/src/Resource/Orders.php +++ b/src/Resource/Orders.php @@ -108,6 +108,8 @@ protected function initialize() $this->data->amount->subtotals = new stdClass(); $this->data->items = []; $this->data->receivers = []; + $this->data->checkoutPreferences = new stdClass(); + $this->data->checkoutPreferences->redirectUrls = new stdClass(); } /** @@ -421,6 +423,16 @@ public function getUpdatedAt() return $this->getIfSetDateTime('updatedAt'); } + /** + * Get checkout preferences of the order. + * + * @return string + */ + public function getCheckoutPreferences() + { + return $this->getIfSet('checkoutPreferences'); + } + /** * Structure of payment. * @@ -535,4 +547,33 @@ public function setShippingAmount($value) return $this; } + + /** + * Set URL for redirection in case of success. + * + * @param string $urlSuccess UrlSuccess. + * + * @return $this + */ + public function setUrlSuccess($urlSuccess = "") + { + $this->data->checkoutPreferences->redirectUrls->urlSuccess = $urlSuccess; + + return $this; + } + + + /** + * Set URL for redirection in case of failure. + * + * @param string $urlFailure UrlFailure. + * + * @return $this + */ + public function setUrlFailure($urlFailure = "") + { + $this->data->checkoutPreferences->redirectUrls->urlFailure = $urlFailure; + + return $this; + } } From 210744a6b2118a7c96050358c15b7366d70c09ba Mon Sep 17 00:00:00 2001 From: SOSTheBlack Date: Tue, 16 May 2017 18:28:34 +0000 Subject: [PATCH 43/44] Apply fixes from StyleCI --- src/Resource/Orders.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Resource/Orders.php b/src/Resource/Orders.php index ecd128b..8b52224 100644 --- a/src/Resource/Orders.php +++ b/src/Resource/Orders.php @@ -555,14 +555,13 @@ public function setShippingAmount($value) * * @return $this */ - public function setUrlSuccess($urlSuccess = "") + public function setUrlSuccess($urlSuccess = '') { $this->data->checkoutPreferences->redirectUrls->urlSuccess = $urlSuccess; return $this; } - /** * Set URL for redirection in case of failure. * @@ -570,7 +569,7 @@ public function setUrlSuccess($urlSuccess = "") * * @return $this */ - public function setUrlFailure($urlFailure = "") + public function setUrlFailure($urlFailure = '') { $this->data->checkoutPreferences->redirectUrls->urlFailure = $urlFailure; From a30bac51e4ba78d41b1e1ac691e134b928e8a470 Mon Sep 17 00:00:00 2001 From: "Jean C. Garcia" Date: Fri, 2 Jun 2017 11:29:05 -0300 Subject: [PATCH 44/44] fixed error --- src/Auth/Connect.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Auth/Connect.php b/src/Auth/Connect.php index 59a67ce..ce02456 100644 --- a/src/Auth/Connect.php +++ b/src/Auth/Connect.php @@ -4,7 +4,6 @@ use JsonSerializable; use Moip\Contracts\Authentication; -use Moip\Exceptions\Error; use Moip\Exceptions\InvalidArgumentException; use Moip\Exceptions\UnexpectedException; use Moip\Exceptions\ValidationException; @@ -252,8 +251,7 @@ public function authorize() if ($http_response->status_code >= 200 && $http_response->status_code < 300) { return json_decode($http_response->body); } elseif ($http_response->status_code >= 400 && $http_response->status_code <= 499) { - $errors = Error::parseErrors($http_response->body); - throw new ValidationException($http_response->status_code, $errors); + throw new ValidationException($http_response->status_code, $http_response->body); } throw new UnexpectedException();