Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General Update: Enhanced Features and Improved Performance #69

Open
wants to merge 29 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a3dfa35
feat(http-client): Set User-Agent header dynamically
Abraham-Flutterwave Oct 15, 2023
a9128db
fix: Transaction Service Event Tracker
Abraham-Flutterwave Oct 15, 2023
2b8541d
test: Handle PHPSAPI requests
Abraham-Flutterwave Oct 15, 2023
38f6cd4
Update CardTest.php
Abraham-Flutterwave Oct 15, 2023
efc50ae
add SDK_VERSION to environment variables
Abraham-Flutterwave Oct 15, 2023
ad40977
test: New Test cards
Abraham-Flutterwave Oct 15, 2023
d51801f
fix: handle vbssecure auth modes in the card charge service
Abraham-Flutterwave Oct 15, 2023
c0ef792
test: create test provider for TransactionTest
Abraham-Flutterwave Oct 15, 2023
563d04f
example: update card sample with config
Abraham-Flutterwave Oct 15, 2023
b94aed1
dev: update makefile and .gitpod.yml config
Abraham-Flutterwave Oct 15, 2023
dd6b9de
update: change-review workflow
Abraham-Flutterwave Oct 15, 2023
caf302f
update: change-review workflow
Abraham-Flutterwave Oct 15, 2023
367b67b
update: change-review workflow
Abraham-Flutterwave Oct 15, 2023
35713ff
update: change-review workflow
Abraham-Flutterwave Oct 15, 2023
3a747c5
update: change-review workflow include php8.3
Abraham-Flutterwave Oct 15, 2023
24f766f
test: remove dirs from bypass whitelist
Abraham-Flutterwave Oct 15, 2023
23fc6e1
dev: gitpod workspace setup
Abraham-Flutterwave Oct 15, 2023
3bb2015
dev: complete gitpod workspace settings
Abraham-Flutterwave Oct 15, 2023
df276a7
update makefile
Abraham-Flutterwave Oct 15, 2023
2aeab42
test: move bypass finals to checkout test
Abraham-Flutterwave Oct 19, 2023
5f17ac6
remove bypass finals
Abraham-Flutterwave Oct 19, 2023
cc738b3
replace the Config -> PackageConfig
Abraham-Flutterwave Feb 21, 2024
662222c
test: separate checkout test
Abraham-Flutterwave Feb 21, 2024
3de93c7
fix: curlClient namespace
Abraham-Flutterwave Feb 21, 2024
1358abb
update: set default the default modal to standard on checkout
Abraham-Flutterwave Feb 21, 2024
65c6c2a
update setup script
Abraham-Flutterwave Feb 21, 2024
238e83e
fix: handle config override
Abraham-Flutterwave Feb 21, 2024
4305433
tests: exclude vendor folder files
Abraham-Flutterwave Feb 21, 2024
cba7079
refact: update card service
Abraham-Flutterwave Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .docker/.gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gitpod/workspace-full

RUN sudo install-packages php-xdebug
16 changes: 6 additions & 10 deletions .github/workflows/change-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.1, 8.2]
php: [7.4, 8.1, 8.2, 8.3]

env:
XDEBUG_MODE: coverage
Expand Down Expand Up @@ -48,17 +48,13 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: 'Create env file'
run: |
touch .env
echo PUBLIC_KEY=${PUBLIC_KEY} >> .env
echo SECRET_KEY=${SECRET_KEY} >> .env
echo ENCRYPTION_KEY=${ENCRYPTION_KEY} >> .env
echo ENV=${ENV} >> .env
ls -a ${{ github.workspace }}

- name: run unit tests and coverage scan
run: ./vendor/bin/pest --coverage --min=20 --coverage-clover ./coverage.xml
env:
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
ENV: ${{ secrets.ENV }}

- name: Upload to Codecov
uses: codecov/codecov-action@v2
Expand Down
15 changes: 15 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

image:
file: .docker/.gitpod.Dockerfile

tasks:
- init: make

vscode:
extensions:
- felixfbecker.php-debug
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
.PHONY: init
test:
check:
@echo "Installing dependencies..."
@composer install
@echo "Installing dependencies... Done"
@./vendor/bin/pest --coverage --min=0 --coverage-clover ./coverage.xml


test:
@./vendor/bin/pest --coverage --min=0 --coverage-clover ./coverage.xml

debug:
XDEBUG_MODE=coverage ./vendor/bin/pest --coverage --coverage-html .log


25 changes: 23 additions & 2 deletions examples/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@

use Flutterwave\Util\AuthMode;
use Flutterwave\Util\Currency;
\Flutterwave\Flutterwave::bootstrap();
use Flutterwave\Config\ForkConfig;
use Dotenv\Dotenv;
// custom config.

if(!file_exists( '.env' )) {
$dotenv = Dotenv::createImmutable(__DIR__."/../");
} else {
$dotenv = Dotenv::createImmutable(__DIR__."/");
}

$dotenv->safeLoad();

$config = ForkConfig::setUp(
$_ENV['SECRET_KEY'],
$_ENV['PUBLIC_KEY'],
$_ENV['ENV'],
$_ENV['ENCRYPTION_KEY']
);

\Flutterwave\Flutterwave::bootstrap($config);

try {

Expand Down Expand Up @@ -48,6 +67,8 @@
$data['customer'] = $customerObj;
$payload = $cardpayment->payload->create($data);



if(!empty($_REQUEST))
{
$request = $_REQUEST;
Expand All @@ -59,7 +80,7 @@

if(isset($request['make'])){
$result = $cardpayment->initiate($payload);

dd($cardpayment);
if($result['mode'] === AuthMode::PIN){
$instruction = $result['instruction'];
require __DIR__."/view/form/pin.php";
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".js">./vendor</directory>
<directory suffix=".xml">./vendor</directory>
<file>tests/bootstrap.php</file>
</exclude>
<report>
<clover outputFile="coverage.xml" />
</report>
Expand Down
24 changes: 21 additions & 3 deletions processPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@
use Flutterwave\EventHandlers\ModalEventHandler as PaymentHandler;
use Flutterwave\Flutterwave;
use Flutterwave\Library\Modal;
use \Flutterwave\Config\ForkConfig;

# start a session.
// start a session.
session_start();

// Define custom config.
// $myConfig = ForkConfig::setUp(
// 'FLWSECK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X', //Secret key
// 'FLWPUBK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X', // Public key
// 'FLWSECK_TESTXXXXXXXXXXX', //Encryption key
// 'staging' //Environment Variable
// );

// uncomment the block if you just want to pass the keys with a specific configuration.
// $_ENV['SECRET_KEY'] = "FLWSECK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X";
// $_ENV['PUBLIC_KEY'] = "FLWPUBK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X";
// $_ENV['ENCRYPTION_KEY'] = "FLWSECK_TESTXXXXXXXXXXXX";
// $_ENV['ENV'] = "staging";

// controller default
$controller = null;

try {
Flutterwave::bootstrap();
Flutterwave::bootstrap(); // create a .env or Flutterwave::bootstrap($myConfig)
$customHandler = new PaymentHandler();
$client = new Flutterwave();
$modalType = Modal::POPUP; // Modal::POPUP or Modal::STANDARD
$modalType = Modal::STANDARD; // Modal::POPUP or Modal::STANDARD
$controller = new PaymentController( $client, $customHandler, $modalType );
} catch(\Exception $e ) {
echo $e->getMessage();
Expand Down
28 changes: 19 additions & 9 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$flutterwave_installation = 'composer';

if( !file_exists( '.env' )) {
if( !file_exists( '.env' ) && !is_dir('vendor')) {
$dotenv = Dotenv::createImmutable(__DIR__."/../../../"); # on the event that the package is install via composer.
} else {
$flutterwave_installation = "manual";
Expand All @@ -17,7 +17,12 @@
//check if the current version of php is compatible
if(!Helper\CheckCompatibility::isCompatible())
{
echo "Flutterwave: This SDK only support php version ". Helper\CheckCompatibility::MINIMUM_COMPATIBILITY. " or greater.";
if (PHP_SAPI === 'cli') {
echo "❌ Flutterwave: This SDK only support php version ". Helper\CheckCompatibility::MINIMUM_COMPATIBILITY. " or greater.";
} else {
echo "Flutterwave: This SDK only support php version ". Helper\CheckCompatibility::MINIMUM_COMPATIBILITY. " or greater.";
}

exit;
}

Expand All @@ -28,22 +33,27 @@
try{
foreach($flutterwaveKeys as $key)
{
if( empty( $_ENV[ $key ] ) )
if(empty($_ENV[ $key ]) && empty(\getenv($key)))
{
throw new InvalidArgumentException("$key environment variable missing.");
}
}
}catch(\Exception $e)
{
echo "<code>Flutterwave sdk: " .$e->getMessage()."</code>";
if (PHP_SAPI === 'cli') {
echo "❌❌Flutterwave sdk: " .$e->getMessage();
echo "Kindly create a .env in the project root and add the required environment variables. ❌". PHP_EOL;
} else {
echo "<code>Flutterwave sdk: " .$e->getMessage()."</code>";
echo "<br /> Kindly create a <code>.env </code> in the project root and add the required environment variables.";
}

echo "<br /> Kindly create a <code>.env </code> in the project root and add the required environment variables.";
exit;
}

$keys = [
'SECRET_KEY' => $_ENV['SECRET_KEY'],
'PUBLIC_KEY' => $_ENV['PUBLIC_KEY'],
'ENV' => $_ENV['ENV'],
'ENCRYPTION_KEY' => $_ENV['ENCRYPTION_KEY']
'SECRET_KEY' => $_ENV['SECRET_KEY'] ?? \getenv('SECRET_KEY'),
'PUBLIC_KEY' => $_ENV['PUBLIC_KEY'] ?? \getenv('PUBLIC_KEY'),
'ENV' => $_ENV['ENV'] ?? \getenv('ENV'),
'ENCRYPTION_KEY' => $_ENV['ENCRYPTION_KEY'] ?? \getenv('ENCRYPTION_KEY')
];
6 changes: 5 additions & 1 deletion src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ protected function __construct(string $secret_key, string $public_key, string $e
[
'base_uri' => EnvVariables::BASE_URL,
'timeout' => 60,
RequestOptions::VERIFY => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath()
'headers' => ['User-Agent' => sprintf(
'FlutterwavePHP/%d', EnvVariables::SDK_VERSION
)],
RequestOptions::VERIFY =>
\Composer\CaBundle\CaBundle::getSystemCaRootBundlePath()
]
);

Expand Down
18 changes: 18 additions & 0 deletions src/Contract/ControllerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Flutterwave\Contract;

use Flutterwave\EventHandlers\EventHandlerInterface;
use Flutterwave\Flutterwave;

interface ControllerInterface {

public function __construct(
Flutterwave $client,
EventHandlerInterface $handler,
string $modalType
);

}
9 changes: 8 additions & 1 deletion src/EventHandlers/CardEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public function onAuthorization(\stdClass $response, ?array $resource = null): a
{
$logger = null;
$data = [];
$mode = $response->meta->authorization->mode;

$mode = $resource['mode'] ?? $response->meta->authorization->mode;

if (property_exists($response, 'data')) {
$transactionId = $response->data->id;
Expand Down Expand Up @@ -124,6 +125,12 @@ public function onAuthorization(\stdClass $response, ?array $resource = null): a
$data['instruction'] = $response->data->processor_response;
$data['validate'] = true;
break;
default:
$data['data_to_save']['status'] = $response->data->status;
$data['data_to_save']['amount'] = $response->data->amount;
$data['data_to_save']['currency'] = $response->data->currency;
$data['data_to_save']['customer_name'] = $response->data->customer->name;
$data['data_to_save']['customer_email'] = $response->data->customer->email;
}

$data['mode'] = $mode;
Expand Down
1 change: 1 addition & 0 deletions src/Helper/EnvVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class EnvVariables
{
public const VERSION = 'v3';
public const SDK_VERSION = '1.0.7';
public const BASE_URL = 'https://api.flutterwave.com/' . self::VERSION;
public const TIME_OUT = 30;
}
2 changes: 1 addition & 1 deletion src/HttpAdapter/CurlClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Flutterwave\Adapter;
namespace Flutterwave\HttpAdapter;

use Psr\Http\Message\ResponseFactoryInterface;

Expand Down
16 changes: 11 additions & 5 deletions src/Service/CardPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,20 @@ public function encryption(string $params): string
*/
public function handleAuthState(\stdClass $response, $payload): array
{
$mode = $response->meta->authorization->mode;
// dd($response);
$data['request_data'] = null;

$mode = (\property_exists($response, 'meta') ) ?
$response->meta->authorization->mode: $response->data->auth_model;
if ($mode === 'pin') {
$data = $this->eventHandler->onAuthorization($response, ['logger' => $this->logger]);
$data['request_data'] = $payload;
return $data;
}

return $this->eventHandler->onAuthorization($response, ['logger' => $this->logger]);
$extra_data = $this->eventHandler->onAuthorization(
$response,
['logger' => $this->logger, 'mode' => $mode]
);

return array_merge([ 'request_data' => $data['request_data'] ], $extra_data);
}

public function getName(): string
Expand Down
Loading
Loading