diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index 02d870b..0000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check & fix styling - -on: [pull_request] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php_cs.dist --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fix styling diff --git a/README.md b/README.md index e794b43..df9875f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ $params = [ 'key' => '', 'secret' => '', 'base_currency' => '', + 'integrator_id' => '', // optional ]; $mercadopago = PaymentProcessors::resolveService('mercadopago', $params); diff --git a/composer.json b/composer.json index efc4db5..201407a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "guzzlehttp/guzzle": "^7.2", "illuminate/contracts": "^8.0" }, @@ -43,9 +43,7 @@ "scripts": { "psalm": "vendor/bin/psalm", "test": "vendor/bin/phpunit --colors=always", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage", - "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes", - "all" : "composer psalm && composer test && composer test-coverage && composer format" + "test-coverage": "vendor/bin/phpunit --coverage-html coverage" }, "config": { "sort-packages": true diff --git a/src/Services/MercadoPagoService.php b/src/Services/MercadoPagoService.php index 50b0729..0da9363 100644 --- a/src/Services/MercadoPagoService.php +++ b/src/Services/MercadoPagoService.php @@ -12,6 +12,7 @@ class MercadoPagoService protected string $key; protected string $secret; protected string $baseCurrency; + protected string $integratorId; private array $apiKeys; @@ -21,6 +22,7 @@ final public function __construct(array $apiKeys) $this->key = $apiKeys['key']; $this->secret = $apiKeys['secret']; $this->baseCurrency = $apiKeys['base_currency']; + $this->integratorId = $apiKeys['integrator_id'] ?? ''; } public static function paymentService(array $apiKeys): self @@ -33,6 +35,10 @@ public function resolveAuthorization(array &$queryParams, array &$formParams, ar $queryParams['access_token'] = $this->resolveAccessToken(); $headers['Content-Type'] = 'application/json'; $headers['Accept'] = 'application/json'; + + if (!empty($this->integratorId)) { + $headers['integrator_id'] = $this->integratorId; + } } public function decodeResponse(string $response): array @@ -84,7 +90,7 @@ public function handleApproval(): void * @param int $installments * @return \Psr\Http\Message\StreamInterface|array */ - public function createPayment(int $amount, string $cardNetwork, string $cardToken, string $email, int $installments = 1) + private function createPayment(int $amount, string $cardNetwork, string $cardToken, string $email, int $installments = 1) { return $this->makeRequest( 'POST', diff --git a/tests/Feature/MercadoPagoTest.php b/tests/Feature/MercadoPagoTest.php index 43bfdae..fecbda0 100644 --- a/tests/Feature/MercadoPagoTest.php +++ b/tests/Feature/MercadoPagoTest.php @@ -9,12 +9,7 @@ class MercadoPagoTest extends TestCase /** @test */ public function test_it_can_resolve_class() { - $params = [ - 'base_uri' => 'https://api.mercadopago.com', - 'key' => 'TEST-529cf55e-ccfa-4422-82f2-42f48528ae99', - 'secret' => 'TEST-1434195171484499-110822-9a6e612973312079b2f46e446e7b8bf4-310393912', - 'base_currency' => 'UYU', - ]; + $params = $this->params(); $mercadopago = PaymentProcessors::resolveService('mercadopago', $params); @@ -24,12 +19,8 @@ public function test_it_can_resolve_class() /** @test */ public function test_it_can_resolve_access_token() { - $params = [ - 'base_uri' => 'https://api.mercadopago.com', - 'key' => 'TEST-529cf55e-ccfa-4422-82f2-42f48528ae99', - 'secret' => 'TEST-1434195171484499-110822-9a6e612973312079b2f46e446e7b8bf4-310393912', - 'base_currency' => 'UYU', - ]; + + $params = $this->params(); $mercadopago = PaymentProcessors::resolveService('mercadopago', $params); @@ -37,4 +28,19 @@ public function test_it_can_resolve_access_token() $this->assertIsString($token); } + + /** + * Undocumented function + * + * @return array + */ + private function params(): array + { + return [ + 'base_uri' => 'https://api.mercadopago.com', + 'key' => 'TEST-529cf55e-ccfa-4422-82f2-42f48528ae99', + 'secret' => 'TEST-1434195171484499-110822-9a6e612973312079b2f46e446e7b8bf4-310393912', + 'base_currency' => 'UYU', + ]; + } } diff --git a/tests/Feature/PayPalTest.php b/tests/Feature/PayPalTest.php index e2b67c6..08fb654 100644 --- a/tests/Feature/PayPalTest.php +++ b/tests/Feature/PayPalTest.php @@ -9,13 +9,7 @@ class PayPalTest extends TestCase /** @test */ public function test_it_can_resolve_class() { - $params = [ - 'base_uri' => 'https://api.sandbox.paypal.com', - 'client_id' => 'ARt435S0DIjl2rljuro1TIOQkeKvNSykbp34DBZIQBUxwqccrMZavTE0r-v7QDFtNQcMU-5SIwBf7B-n', - 'client_secret' => 'EPhL66hqSoMjfWT3FQpuZPxQFnFCh-Llpf9qBb3UkXX33bjyLBE4Qu1d2dx8s3y-qeI-ycmA5kVbdmJ6', - 'return_url' => 'http://localhost/return_url', - 'cancel_url' => 'http://localhost/cancel_url', - ]; + $params = $this->params(); $paypal = PaymentProcessors::resolveService('paypal', $params); @@ -25,13 +19,7 @@ public function test_it_can_resolve_class() /** @test */ public function test_it_can_resolve_access_token() { - $params = [ - 'base_uri' => 'https://api.sandbox.paypal.com', - 'client_id' => 'ARt435S0DIjl2rljuro1TIOQkeKvNSykbp34DBZIQBUxwqccrMZavTE0r-v7QDFtNQcMU-5SIwBf7B-n', - 'client_secret' => 'EPhL66hqSoMjfWT3FQpuZPxQFnFCh-Llpf9qBb3UkXX33bjyLBE4Qu1d2dx8s3y-qeI-ycmA5kVbdmJ6', - 'return_url' => 'http://localhost/return_url', - 'cancel_url' => 'http://localhost/cancel_url', - ]; + $params = $this->params(); $paypal = PaymentProcessors::resolveService('paypal', $params); @@ -43,13 +31,7 @@ public function test_it_can_resolve_access_token() /** @test */ public function test_is_can_handle_a_payment() { - $params = [ - 'base_uri' => 'https://api.sandbox.paypal.com', - 'client_id' => 'ARt435S0DIjl2rljuro1TIOQkeKvNSykbp34DBZIQBUxwqccrMZavTE0r-v7QDFtNQcMU-5SIwBf7B-n', - 'client_secret' => 'EPhL66hqSoMjfWT3FQpuZPxQFnFCh-Llpf9qBb3UkXX33bjyLBE4Qu1d2dx8s3y-qeI-ycmA5kVbdmJ6', - 'return_url' => 'http://localhost/return_url', - 'cancel_url' => 'http://localhost/cancel_url', - ]; + $params = $this->params(); $paypal = PaymentProcessors::resolveService('paypal', $params); @@ -63,13 +45,7 @@ public function test_is_can_handle_a_payment() */ public function test_it_can_return_array() { - $params = [ - 'base_uri' => 'https://api.sandbox.paypal.com', - 'client_id' => 'ARt435S0DIjl2rljuro1TIOQkeKvNSykbp34DBZIQBUxwqccrMZavTE0r-v7QDFtNQcMU-5SIwBf7B-n', - 'client_secret' => 'EPhL66hqSoMjfWT3FQpuZPxQFnFCh-Llpf9qBb3UkXX33bjyLBE4Qu1d2dx8s3y-qeI-ycmA5kVbdmJ6', - 'return_url' => 'http://localhost/return_url', - 'cancel_url' => 'http://localhost/cancel_url', - ]; + $params = $this->params(); $paypal = PaymentProcessors::resolveService('paypal', $params); @@ -77,4 +53,20 @@ public function test_it_can_return_array() $this->assertIsArray($arr, 'assert variable is array or not'); } + + /** + * Undocumented function + * + * @return array + */ + private function params(): array + { + return [ + 'base_uri' => 'https://api.sandbox.paypal.com', + 'client_id' => 'ARt435S0DIjl2rljuro1TIOQkeKvNSykbp34DBZIQBUxwqccrMZavTE0r-v7QDFtNQcMU-5SIwBf7B-n', + 'client_secret' => 'EPhL66hqSoMjfWT3FQpuZPxQFnFCh-Llpf9qBb3UkXX33bjyLBE4Qu1d2dx8s3y-qeI-ycmA5kVbdmJ6', + 'return_url' => 'http://localhost/return_url', + 'cancel_url' => 'http://localhost/cancel_url', + ]; + } } diff --git a/tests/Feature/StripeTest.php b/tests/Feature/StripeTest.php index c800243..2ae8a2e 100644 --- a/tests/Feature/StripeTest.php +++ b/tests/Feature/StripeTest.php @@ -10,10 +10,7 @@ class StripeTest extends TestCase /** @test */ public function test_it_can_resolve_class() { - $params = [ - 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', - 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', - ]; + $params = $this->params(); $stripe = PaymentProcessors::resolveService('stripe', $params); @@ -23,10 +20,7 @@ public function test_it_can_resolve_class() /** @test */ public function test_it_can_get_balance() { - $params = [ - 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', - 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', - ]; + $params = $this->params(); $stripe = PaymentProcessors::resolveService('stripe', $params); @@ -38,10 +32,7 @@ public function test_it_can_get_balance() /** @test */ public function test_it_can_generate_a_payment_method_id() { - $params = [ - 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', - 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', - ]; + $params = $this->params(); $stripe = PaymentProcessors::resolveService('stripe', $params); @@ -66,10 +57,7 @@ public function test_it_can_generate_a_payment_method_id() /** @depends test_it_can_generate_a_payment_method_id */ public function test_it_can_handle_a_payment($paymentMethodId) { - $params = [ - 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', - 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', - ]; + $params = $this->params(); $stripe = PaymentProcessors::resolveService('stripe', $params); @@ -88,10 +76,7 @@ public function test_it_can_handle_a_payment($paymentMethodId) /** @depends test_it_can_handle_a_payment */ public function test_it_can_confirm_a_payment($intent) { - $params = [ - 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', - 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', - ]; + $params = $this->params(); $stripe = PaymentProcessors::resolveService('stripe', $params); @@ -99,4 +84,17 @@ public function test_it_can_confirm_a_payment($intent) $this->assertEquals('succeeded', $confirm['status'], 'actual value is not equals to expected'); } + + /** + * Undocumented function + * + * @return array + */ + private function params(): array + { + return [ + 'key' => 'pk_test_51IMzM0JcoyM5FfOypXlbYcOcg9EsrAwfhLikFrK436CqIGIRxysFz1G45NtJJik4NCVAje8xUddeeD0KjVeNe5Rf00JyWoyvEi', + 'secret' => 'sk_test_51IMzM0JcoyM5FfOyoV47UeCAMpHFvkrPOrVRM0B83tE6NEffMlLJCuX09jh6Gv6nXKwx5pR3nWaBp5z4TPP08zIY00z3CLwJJw', + ]; + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index e217c99..269444c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,10 +27,5 @@ public function getEnvironmentSetUp($app) 'database' => ':memory:', 'prefix' => '', ]); - - /* - include_once __DIR__.'/../database/migrations/create_payment_processors_table.php.stub'; - (new \CreatePackageTable())->up(); - */ } }