Skip to content

Commit

Permalink
wip basic setup, planning resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenebak committed Jan 7, 2024
1 parent feb9f0b commit cdd85e6
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 44 deletions.
32 changes: 7 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ This is where your description should go. Limit it to a paragraph or two. Consid

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-quickpay.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-quickpay)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Installation

You can install the package via composer:
Expand All @@ -23,13 +17,6 @@ You can install the package via composer:
composer require netbums/laravel-quickpay
```

You can publish and run the migrations with:

```bash
php artisan vendor:publish --tag="laravel-quickpay-migrations"
php artisan migrate
```

You can publish the config file with:

```bash
Expand All @@ -40,26 +27,21 @@ This is the contents of the published config file:

```php
return [
'api_key' => env('QUICKPAY_API_KEY'),
'login' => env('QUICKPAY_LOGIN'),
'password' => env('QUICKPAY_PASSWORD'),
'merchant_id' => env('QUICKPAY_MERCHANT_ID'),
];
```

Optionally, you can publish the views using

```bash
php artisan vendor:publish --tag="laravel-quickpay-views"
```

## Usage

```php
$quickpay = new Netbums\Quickpay();
echo $quickpay->echoPhrase('Hello, Netbums!');
```

## Testing
use \Netbums\Quickpay\Quickpay;

$payments = Quickpay::payments()->all();

```bash
composer test
```

## Changelog
Expand Down
Empty file added src/DataObjects/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions src/Exceptions/ConfigNotCorrect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Netbums\Quickpay\Exceptions;

use Exception;

class ConfigNotCorrect extends Exception
{

}
45 changes: 40 additions & 5 deletions src/Quickpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

namespace Netbums\Quickpay;

use QuickPay\QuickPay as QuickPayVendor;
use Netbums\Quickpay\Exceptions\ConfigNotCorrect;
use Netbums\Quickpay\Resources\CardResource;
use Netbums\Quickpay\Resources\FeeResource;
use Netbums\Quickpay\Resources\PaymentResource;
use Netbums\Quickpay\Resources\PayoutResource;
use Netbums\Quickpay\Resources\SubscriptionResource;

class Quickpay
{
protected $client;
protected \QuickPay\QuickPay $client;

public function __construct()
{
$credentials = null;

if (config('quickpay.api_key')) {
$credentials = ":".config('quickpay.api_key');
$credentials = ":" . config('quickpay.api_key');
} else if (config('quickpay.login') && config('quickpay.password')) {
$credentials = sprintf('%s:%s', config('quickpay.login'), config('quickpay.password'));
}
Expand All @@ -22,13 +27,43 @@ public function __construct()
throw new ConfigNotCorrect('You should specify an `api_key` or `login` and `password` in the `quickpay` config file');
}

$this->client = new QuickPayVendor($credentials);
$this->client = new \QuickPay\QuickPay($credentials);

}

public function payments(): PaymentResource
{
return new PaymentResource($this->client);
return new PaymentResource(
client: $this->client
);
}

public function subscriptions(): SubscriptionResource
{
return new SubscriptionResource(
client: $this->client
);
}

public function cards(): CardResource
{
return new CardResource(
client: $this->client
);
}

public function payouts(): PayoutResource
{
return new PayoutResource(
client: $this->client
);
}

public function fees(): FeeResource
{
return new FeeResource(
client: $this->client
);
}

}
10 changes: 10 additions & 0 deletions src/Resources/CardResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Netbums\Quickpay\Resources;

use Netbums\Quickpay\Resources\Concerns\QuickpayApiConsumer;

class CardResource
{
use QuickpayApiConsumer;
}
28 changes: 14 additions & 14 deletions src/Resources/Concerns/QuickpayApiConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
namespace Netbums\Quickpay\Resources\Concerns;

use Netbums\Quickpay\Exceptions\CardNotAccepted;
use Netbums\Quickpay\Exceptions\QuickPayTestNotAllowed;
use Netbums\Quickpay\Exceptions\QuickPayValidationError;
use QuickPay\QuickPay as QuickPayVendor;
use QuickPay\QuickPay;

trait QuickpayApiConsumer
{

public QuickPayVendor $client;
public QuickPay $client;

public string $endpoint;

public string $method;

public array $data;

public function __construct(QuickPayVendor $client)
public function __construct(QuickPay $client)
{
}

/**
* @param string $method
* @param string $endpoint
* @param array $data
* @return object
* @throws CardNotAccepted
* @throws QuickPayValidationError
*/
public function request(string $method, string $endpoint, array $data = []): object
{
$response = $this->client->request->$method($endpoint, $data);

if ($response->isSuccess()) {
$data = $response->asObject();

if (app()->environment('production') && $data->test_mode) {
throw new QuickPayTestNotAllowed(
message: 'You are not allowed to use test cards in production mode',
code: 403
);
}

if (!empty($data->operations) && !$data->accepted) {
// if app is in production mode, and the request is not a test, and the card is not accepted, throw an exception
if (config('app.env') === 'production' && !$data->test_mode && !$data->accepted) {
throw new CardNotAccepted(
message: 'The card was not accepted',
message: 'You cannot use test cards in production mode.',
code: 402
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/FeeResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Netbums\Quickpay\Resources;

use Netbums\Quickpay\Resources\Concerns\QuickpayApiConsumer;

class FeeResource
{
use QuickpayApiConsumer;
}
74 changes: 74 additions & 0 deletions src/Resources/PaymentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,81 @@

namespace Netbums\Quickpay\Resources;

use Netbums\Quickpay\Resources\Concerns\QuickpayApiConsumer;

class PaymentResource
{
use QuickpayApiConsumer;

public function all()
{

}

public function create()
{

}

// Create or update payment link
public function createLink($id)
{

}

// Delete payment link
public function deleteLink($id)
{

}

// Get Payment
public function find($id)
{

}

// Create payment session
public function createPaymentSession($id)
{

}

// authorize payment
public function authorize($id)
{

}

// capture payment
public function capture($id)
{

}

// refund payment
public function refund($id)
{

}

// cancel payment
public function cancel($id)
{

}

// renew authorization
public function renew($id)
{

}

// create fraud confirmation report
public function createFraudConfirmationReport($id)
{

}


}
52 changes: 52 additions & 0 deletions src/Resources/PayoutResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Netbums\Quickpay\Resources;

use Netbums\Quickpay\Resources\Concerns\QuickpayApiConsumer;

class PayoutResource
{
use QuickpayApiConsumer;

// get payouts
public function all()
{

}

// create payout
public function create()
{

}

// create or update payout link
public function createOrUpdateLink($id)
{

}

// delete payout link
public function delete($id)
{

}

// get single payout
public function find($id)
{

}

// update payout
public function update($id)
{

}

// authorize a payout
public function authorize($id)
{

}
}
10 changes: 10 additions & 0 deletions src/Resources/SubscriptionResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Netbums\Quickpay\Resources;

use Netbums\Quickpay\Resources\Concerns\QuickpayApiConsumer;

class SubscriptionResource
{
use QuickpayApiConsumer;
}

0 comments on commit cdd85e6

Please sign in to comment.