Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/devcontainers/base:0-focal

RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository ppa:ondrej/php -y && \
apt-get update && \
apt-get install -y \
php7.4 php7.4-cli php7.4-common php7.4-curl \
php7.4-mysql php7.4-bcmath php7.4-soap php7.4-zip php7.4-intl \
php7.4-gd php7.4-xsl php7.4-dom php7.4-mbstring \
unzip && \
rm -rf /var/lib/apt/lists/*

RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
12 changes: 12 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Ona",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/node:2": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:3.0.1": {}
}
}
16 changes: 16 additions & 0 deletions .github/workflows/artifact-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write

strategy:
matrix:
Expand All @@ -30,6 +32,20 @@ jobs:
id: tag
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"

- name: Inject SigNoz API key
env:
SIGNOZ_API_KEY: ${{ secrets.SIGNOZ_API_KEY }}
run: |
if [ -z "$SIGNOZ_API_KEY" ]; then
echo "::error::SIGNOZ_API_KEY secret is not set"
exit 1
fi
sed -i "s|%%SIGNOZ_API_KEY%%|${SIGNOZ_API_KEY}|g" src/Monitoring/SignozServiceLogger.php
if grep -q '%%SIGNOZ_API_KEY%%' src/Monitoring/SignozServiceLogger.php; then
echo "::error::Placeholder replacement failed"
exit 1
fi

- name: Create release artifact
run: |
mkdir -p build
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/change-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.1, 8.2, 8.3]
php: [7.4, 8.1, 8.2, 8.3, 8.4]

env:
XDEBUG_MODE: coverage
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
ENV: ${{ secrets.ENV }}
SIGNOZ_API_KEY: ${{ secrets.SIGNOZ_API_KEY }}

steps:
- uses: actions/checkout@v3
Expand All @@ -48,14 +49,27 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Inject SigNoz API key
env:
SIGNOZ_API_KEY: ${{ secrets.SIGNOZ_API_KEY }}
run: |
if [ -z "$SIGNOZ_API_KEY" ]; then
echo "::error::SIGNOZ_API_KEY secret is not set"
exit 1
fi
sed -i "s|%%SIGNOZ_API_KEY%%|${SIGNOZ_API_KEY}|g" src/Monitoring/SignozServiceLogger.php
if grep -q '%%SIGNOZ_API_KEY%%' src/Monitoring/SignozServiceLogger.php; then
echo "::error::Placeholder replacement failed"
exit 1
fi

- 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
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/package-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.1, 8.2]
php: [7.4, 8.1, 8.2, 8.3, 8.4]

steps:
- uses: actions/checkout@v2
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/security-scan.yml

This file was deleted.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"mockery/mockery": ">=1.2",
"symfony/var-dumper": "5.4.13",
"phpstan/phpstan": "^1.9",
"pestphp/pest": "^1.22",
"pestphp/pest": "1.22",
"nunomaduro/phpinsights": "^2.6",
"eloquent/liberator": "^3.0",
"squizlabs/php_codesniffer": "3.*",
Expand All @@ -45,6 +45,9 @@
}
],
"config": {
"platform": {
"php": "7.4"
},
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
Expand Down
4 changes: 2 additions & 2 deletions paymentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<!-- Replace the value with the payment button text you prefer (optional) -->
<!-- <input type="hidden" name="tx_ref" value="TEST_TXREF_--><?//= uniqid() ?><!--"/>-->
<!-- Replace the value with your transaction reference. It must be unique per transaction. You can delete this line if you want one to be generated for you. -->
<input type="hidden" name="success_url" value="http://request.lendlot.com/13b9gxc1?status=success">
<input type="hidden" name="success_url" value="https://example.com/success">
<!-- Put your success url here -->
<input type="hidden" name="failure_url" value="http://request.lendlot.com/13b9gxc1?status=failed">
<input type="hidden" name="failure_url" value="https://example.com/failure">
<!-- Put your failure url here -->
<center><input id="btn-of-destiny" class="btn btn-warning" type="submit" value="Pay Now"/></center>
</form>
Expand Down
13 changes: 12 additions & 1 deletion processPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Flutterwave\Library\Modal;
use \Flutterwave\Config\ForkConfig;

// start a session.
// start a session for redirect metadata.
session_start();

// Define custom config.
Expand Down Expand Up @@ -39,9 +39,15 @@
$controller = new PaymentController( $client, $customHandler, $modalType );
} catch(\Exception $e ) {
echo $e->getMessage();
exit();
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {
if ($controller === null) {
echo 'Unable to initialize payment controller.';
exit();
}

$request = $_REQUEST;
$request['redirect_url'] = $_SERVER['HTTP_ORIGIN'] . $_SERVER['REQUEST_URI'];
try {
Expand All @@ -54,6 +60,11 @@
$request = $_GET;
# Confirming Payment.
if(isset($request['tx_ref'])) {
if ($controller === null) {
echo 'Unable to initialize payment controller.';
exit();
}

$controller->callback( $request );
} else {

Expand Down
1 change: 1 addition & 0 deletions src/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Flutterwave\Contract\ConfigInterface;
use Flutterwave\EventHandlers\EventHandlerInterface;
use Flutterwave\Helper\EnvVariables;
use Flutterwave\Monitoring\SignozServiceLogger;
use Flutterwave\Traits\ApiOperations as Api;
use Flutterwave\Traits\PayloadOperations as Payload;
use Psr\Log\LoggerInterface;
Expand Down
15 changes: 14 additions & 1 deletion src/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@
use Flutterwave\EventHandlers\EventHandlerInterface;
use Flutterwave\Flutterwave;
use Flutterwave\Contract\ConfigInterface;
use Flutterwave\Monitoring\SignozServiceLogger;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Flutterwave\Helper\EnvVariables;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

abstract class AbstractConfig
{
public const PUBLIC_KEY = 'PUBLIC_KEY';
public const SECRET_KEY = 'SECRET_KEY';
public const ENCRYPTION_KEY = 'ENCRYPTION_KEY';
public const ENV = 'ENV';
public const DEFAULT_PREFIX = 'FW|PHP';
public const DEFAULT_PREFIX = 'FW_PHP';
public const LOG_FILE_NAME = 'flutterwave-php.log';
public Logger $logger;
protected string $secret;
protected string $public;
public SignozServiceLogger $signoz;

protected static ?ConfigInterface $instance = null;
protected string $env;
Expand Down Expand Up @@ -53,6 +57,10 @@ protected function __construct(string $secret_key, string $public_key, string $e

$log = new Logger('Flutterwave/PHP');
$this->logger = $log;
$cache = new Psr16Cache(new FilesystemAdapter('flutterwave_signoz'));
$this->signoz = new SignozServiceLogger($this->http, $this->getPublicKey(), $this->getEnv(), $cache, EnvVariables::SDK_VERSION);
// Track app initialization once per lifecycle
$this->signoz->trackAppCreated($this->getPublicKey());
}

abstract public static function setUp(
Expand Down Expand Up @@ -84,4 +92,9 @@ public static function getDefaultTransactionPrefix(): string
{
return self::DEFAULT_PREFIX;
}

public function getSignoz(): SignozServiceLogger
{
return $this->signoz;
}
}
1 change: 1 addition & 0 deletions src/Contract/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Flutterwave\Contract;

use Flutterwave\Monitoring\SignozServiceLogger;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;

Expand Down
28 changes: 6 additions & 22 deletions src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Flutterwave\Controller;

use Flutterwave\EventHandlers\ModalEventHandler;
use Flutterwave\EventHandlers\EventHandlerInterface;
use Flutterwave\Flutterwave;
use Flutterwave\Entities\Payload;
use Flutterwave\Library\Modal;
use Flutterwave\Service\Transactions;

Expand Down Expand Up @@ -43,14 +41,14 @@ private function getRequestMethod(): string

public function __call(string $name, array $args)
{
if ($this->routes[$name] !== $this->$requestMethod) {
if ($this->routes[$name] !== $this->requestMethod) {
// Todo: 404();
echo "Unauthorized page!";
}
call_user_method_array($name, $this, $args);
call_user_func_array([$this, $name], $args);
}

private function handleSessionData( array $request )
private function handleSessionData(array $request): void
{
$_SESSION['success_url'] = $request['success_url'];
$_SESSION['failure_url'] = $request['failure_url'];
Expand All @@ -61,10 +59,8 @@ private function handleSessionData( array $request )
public function process(array $request)
{
$this->handleSessionData($request);

try {
$_SESSION['p'] = $this->client;

try {
if('inline' === $this->modalType ) {
echo $this->client
->eventHandler($this->handler)
Expand All @@ -87,23 +83,11 @@ public function callback(array $request)
$status = $request['status'];

if (empty($tx_ref)) {
session_destroy();
}

if (!isset($_SESSION['p'])) {
echo "session expired!. please refresh you browser.";
echo 'Missing transaction reference.';
exit();
}

$payment = $_SESSION['p'];

// $payment::setUp([
// 'secret_key' => 'FLWSECK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
// 'public_key' => 'FLWPUBK_TEST-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X',
// 'encryption_key' => 'FLWSECK_XXXXXXXXXXXXXXXX',
// 'environment' => 'staging'
// ]);

$payment = $this->client;
$payment::bootstrap();

if ('cancelled' === $status) {
Expand Down
Loading
Loading