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

Commit

Permalink
create base connector
Browse files Browse the repository at this point in the history
  • Loading branch information
njoguamos committed Jan 27, 2024
1 parent c943280 commit c33334c
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 21 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
],
"require": {
"php": "^8.1 | ^8.2 | ^8.3",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0"
"illuminate/contracts": "^10.0",
"saloonphp/saloon": "^3.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
6 changes: 0 additions & 6 deletions config/cash-app.php

This file was deleted.

35 changes: 35 additions & 0 deletions config/cashapp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Cash APP Environment
|--------------------------------------------------------------------------
|
| Here, you specify whether your Cash App integration is in production.
| When the value is false, the application uses sandbox a which
| allows Cash App API integration without moving any money.
|
| @see https://developers.cash.app/docs/api/partner-onboarding/integrating-with-cash-app-pay/comparison
|
*/

'production' => env(key: 'CASH_PRODUCTION', default: false),

/*
|--------------------------------------------------------------------------
| Cash APP Base Urls
|--------------------------------------------------------------------------
|
| Here, you specify either "sandbox" or "production." The "sandbox" is used
| for testing API integration without moving any money. The "production"
| means your application is live, using Pay Kit for the production.
|
|
*/

'urls' => [
'sandbox' => env(key: 'CASH_APP_SANDBOX_URL', default: 'https://sandbox.api.cash.app'),
'production' => env(key: 'CASH_APP_PRODUCTION_URL', default: 'https://api.cash.app'),
]
];
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Njogu Amos Test Suite">
<testsuite name="Application Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
12 changes: 11 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
{
"preset": "psr12"
"preset": "psr12",
"rules": {
"binary_operator_spaces": {
"operators": {
"=>": "align_single_space_minimal"
}
},
"array_syntax": {
"syntax": "short"
}
}
}
8 changes: 4 additions & 4 deletions src/CashAppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public function configurePackage(Package $package): void
* More info: https://github.com/spatie/laravel-package-tools
*/
$package
->name('laravel-cash-app')
->hasConfigFile()
->name(name: 'laravel-cashapp')
->hasConfigFile(configFileName: 'cashapp')
->hasViews()
->hasMigration('create_laravel-cash-app_table')
->hasCommand(CashAppCommand::class);
->hasMigration(migrationFileName: 'create_laravel-cash-app_table')
->hasCommand(commandClassName: CashAppCommand::class);
}
}
17 changes: 17 additions & 0 deletions src/Connectors/CashAppBaseConnector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace NjoguAmos\CashApp\Connectors;

use Saloon\Http\Connector;

class CashAppBaseConnector extends Connector
{
public function resolveBaseUrl(): string
{
if (config(key: 'cashapp.production')) {
return config(key: 'cashapp.urls.production') ;
}

return config(key: 'cashapp.urls.sandbox');
}
}
5 changes: 0 additions & 5 deletions tests/ArchTest.php

This file was deleted.

File renamed without changes.
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ protected function setUp(): void
);
}

protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
CashAppServiceProvider::class,
];
}

public function getEnvironmentSetUp($app)
public function getEnvironmentSetUp($app): void
{
config()->set('database.default', 'testing');

Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/ArchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

arch(description: 'it will not use debugging functions')
->expect(value: ['dd', 'dump', 'ray'])
->each->not->toBeUsed();
20 changes: 20 additions & 0 deletions tests/Unit/Connectors/CashAppBaseConnectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Njoguamos\CashApp\Tests;

use NjoguAmos\CashApp\Connectors\CashAppBaseConnector;

it(description: 'resolves to the correct base url', closure: function (bool $isProduction, string $baseUrl) {
config()->set(
key: 'cashapp.production',
value: $isProduction
);

$connector = new CashAppBaseConnector();

expect(value: $connector->resolveBaseUrl())
->toBe(expected: $baseUrl);
})->with([
'production' => [true, 'https://api.cash.app'],
'staging' => [false, 'https://sandbox.api.cash.app']
]);

0 comments on commit c33334c

Please sign in to comment.