Skip to content

Commit

Permalink
add more changes 🚀 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
abr4xas committed Feb 22, 2022
1 parent 098a63e commit c78efb1
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 93 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/php-cs-fixer.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ $params = [
'key' => '',
'secret' => '',
'base_currency' => '',
'integrator_id' => '', // optional
];

$mercadopago = PaymentProcessors::resolveService('mercadopago', $params);
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"guzzlehttp/guzzle": "^7.2",
"illuminate/contracts": "^8.0"
},
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/Services/MercadoPagoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MercadoPagoService
protected string $key;
protected string $secret;
protected string $baseCurrency;
protected string $integratorId;

private array $apiKeys;

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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',
Expand Down
30 changes: 18 additions & 12 deletions tests/Feature/MercadoPagoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -24,17 +19,28 @@ 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);

$token = $mercadopago->resolveAccessToken();

$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',
];
}
}
48 changes: 20 additions & 28 deletions tests/Feature/PayPalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -63,18 +45,28 @@ 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);

$arr = $paypal->handleApproval();

$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',
];
}
}
38 changes: 18 additions & 20 deletions tests/Feature/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -88,15 +76,25 @@ 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);

$confirm = $stripe->confirmPayment($intent['id']);

$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',
];
}
}
5 changes: 0 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
*/
}
}

0 comments on commit c78efb1

Please sign in to comment.