Skip to content

Commit

Permalink
addressed some issues and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Mujhtech committed Feb 21, 2024
1 parent f35e346 commit 56e4a0e
Show file tree
Hide file tree
Showing 34 changed files with 709 additions and 527 deletions.
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"Swyftpay",
"Swervpay",
"Card",
"Identity",
"Payout",
"Payin",
"Issuing"
],
"license": "MIT",
Expand All @@ -13,7 +16,13 @@
"autoload": {
"psr-4": {
"Swervpaydev\\SDK\\": "src/"
}
},
"files": [
"src/Swervpay.php"
]
},
"autoload-dev": {
"psr-4": {}
},
"authors": [
{
Expand All @@ -22,8 +31,8 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^8.1.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.8"
"guzzlehttp/guzzle": "^6.5.7|^7.4.4"
}
}
42 changes: 42 additions & 0 deletions example/card.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Swervpaydev\SDK\Swervpay;
use Swervpaydev\SDK\Enums\CardProvider;
use Swervpaydev\SDK\Enums\Currency;
use Swervpaydev\SDK\Enums\CardType;


$swervpay = new Swervpay([
'business_id' => 'bsn_fAYcWSUXz3TogChv7BgH',
'secret_key' => 'sk_dev_MfTiTSC31IZrz7DOBEow',
'base_uri' => 'http://localhost:8888/api/v1/'
]);


// Get all cards
$cards = $swervpay->card()->gets([
'limit' => 10,
'page' => 1,
])->toArray();

print_r($cards);


// Get a card
$card = $swervpay->card()->get('<CARD_ID>');

print_r($card);


// Create a card
$newCard = $swervpay->card()->create([
'customer_id' => 'cus_5f3e5e3e5e3e5e3e5e3e5e3e',
'amount' => 1000,
'currency' => Currency::USD,
'provider' => CardProvider::Mastercard,
'type' => CardType::Default,
// Optional only mandatory on when card type is lite
'name_on_card' => 'User Ten',
]);
38 changes: 38 additions & 0 deletions example/customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Swervpaydev\SDK\Swervpay;


$swervpay = new Swervpay([
'business_id' => '<BUSINESS_ID>',
'secret_key' => '<SECRET_ID>',
]);

// Create a customer
$newCustomer = $swervpay->customer()->create([
'first_name' => 'User',
'last_name' => 'Ten',
'email' => 'user10@mailinator.com',
'country' => 'Nigeria',
'middle_name' => 'Middle',
]);

print_r($newCustomer);

// Get a customer

$customers = $swervpay->customer()->gets([
'limit' => 10,
'page' => 1,
])->toArray();

print_r($customers);


// Get a customer

$customer = $swervpay->customer()->get('<CUSTOMER_ID>');

print_r($customer);
24 changes: 24 additions & 0 deletions src/Enums/CardProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Swervpaydev\SDK\Enums;

/**
* Enum CardProvider
*
* This enum represents the different card providers that are supported.
* Currently, it includes Mastercard and Visa.
*
* @package Swervpaydev\SDK\Enums
*/
enum CardProvider: string
{
/**
* Represents a Mastercard card provider.
*/
case Mastercard = 'MASTERCARD';

/**
* Represents a Visa card provider.
*/
case Visa = 'VISA';
}
29 changes: 29 additions & 0 deletions src/Enums/CardType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Swervpaydev\SDK\Enums;

/**
* Enum CardType
*
* This enum represents the different types of cards that are supported.
* Currently, it includes Lite, Default, and Cooperate.
*
* @package Swervpaydev\SDK\Enums
*/
enum CardType: string
{
/**
* Represents a Lite card type.
*/
case Lite = 'LITE';

/**
* Represents a Default card type.
*/
case Default = 'DEFAULT';

/**
* Represents a Cooperate card type.
*/
case Cooperate = 'COORPERATE';
}
24 changes: 24 additions & 0 deletions src/Enums/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Swervpaydev\SDK\Enums;

/**
* Enum Currency
*
* This enum represents the different types of currencies that are supported.
* Currently, it includes Nigerian Naira (NGN) and United States Dollar (USD).
*
* @package Swervpaydev\SDK\Enums
*/
enum Currency: string
{
/**
* Represents Nigerian Naira (NGN).
*/
case NGN = 'NGN';

/**
* Represents United States Dollar (USD).
*/
case USD = 'USD';
}
8 changes: 8 additions & 0 deletions src/Exceptions/FailedAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

use Exception;

/**
* Class FailedAction
*
* This class represents a custom exception that is thrown when an action fails.
* It extends the base Exception class provided by PHP.
*
* @package Swervpaydev\SDK\Exceptions
*/
final class FailedAction extends Exception
{
//
Expand Down
13 changes: 12 additions & 1 deletion src/Exceptions/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

use Exception;

/**
* Class NotFound
*
* This class represents a custom exception that is thrown when an endpoint could not be found.
* It extends the base Exception class provided by PHP.
*
* @package Swervpaydev\SDK\Exceptions
*/
final class NotFound extends Exception
{
/**
* Create a new exception instance.
*
* The constructor method is overridden from the parent Exception class.
* It sets a default message for the exception: 'The endpoint you are looking for could not be found.'
*
* @return void
*/
public function __construct()
{
parent::__construct('The endpoint you are looking for could not be found.');
}
}
}
22 changes: 18 additions & 4 deletions src/Exceptions/Timeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

use Exception;

/**
* Class Timeout
*
* This class represents a custom exception that is thrown when an operation times out.
* It extends the base Exception class provided by PHP.
*
* @package Swervpaydev\SDK\Exceptions
*/
class Timeout extends Exception
{
/**
Expand All @@ -16,7 +24,11 @@ class Timeout extends Exception
/**
* Create a new exception instance.
*
* @param array $output
* The constructor method is overridden from the parent Exception class.
* It sets a default message for the exception: 'The operation has timed out.'
* It also accepts an array of output from the operation that caused the timeout.
*
* @param array $output The output from the operation that caused the timeout.
* @return void
*/
public function __construct(array $output)
Expand All @@ -27,12 +39,14 @@ public function __construct(array $output)
}

/**
* The output returned from the operation.
* Get the output returned from the operation.
*
* This method returns the output from the operation that caused the timeout.
*
* @return array
* @return array The output from the operation that caused the timeout.
*/
public function output()
{
return $this->output;
}
}
}
Loading

0 comments on commit 56e4a0e

Please sign in to comment.