Skip to content

Commit

Permalink
improve logging to determine sandbox url
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenefvdm committed Oct 5, 2022
1 parent c7fd796 commit d174c71
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
31 changes: 0 additions & 31 deletions LOG.md

This file was deleted.

11 changes: 7 additions & 4 deletions src/Components/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ class Subscriptions extends Component
'billingUpdated' => 'billingWasUpdated',
];

/**
* After billing is updated, that means when PayFast onsite subscription modal goes
* away, the front-end must reflect the changes that could be a new subscription
* or the receipt that was updated when a paying also came in.
*/
public function billingWasUpdated()
{
ray("billingUpdated event fired, refreshing receipts and removing subscription display");

{
$this->emitTo('receipts', 'refreshComponent');

$this->displayingCreateSubscription = false;
Expand All @@ -49,7 +52,7 @@ public function confirmCancelSubscription()

public function cancelSubscription()
{
ray('Cancelling subscription for ' . $this->user->subscriptions()->active()->first()->payfast_token)->orange();
PayFast::debug('Cancelling subscription for ' . $this->user->subscriptions()->active()->first()->payfast_token, 'warning');

$this->user->subscription('default')->cancel2();

Expand Down
52 changes: 43 additions & 9 deletions src/PayFast.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace FintechSystems\PayFast;

use Carbon\Carbon;
use FintechSystems\PayFast\Contracts\BillingProvider;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Http;
use FintechSystems\PayFast\Contracts\BillingProvider;

class PayFast implements BillingProvider
{
Expand Down Expand Up @@ -36,9 +37,9 @@ public function __construct($client)
$this->url = 'https://www.payfast.co.za/onsite/process';
$prependUrl = config('payfast.callback_url');
}

if (config('payfast.debug') == true) {
ray("In PayFast constructor, testmode: $this->testmode, URL: $this->url");
$this->debug("In PayFast API constructor, testmode: $this->testmode, URL: $this->url");
}

$this->returnUrl = $prependUrl . $client['return_url'];
Expand Down Expand Up @@ -68,16 +69,16 @@ public function cancelSubscription($payfast_token)
}

/**
* Create a new subscription using PayFast Onsite Payments
* Create a new subscription using PayFast Onsite Payments. One of the most
* important aspect is ensuring that the correct billing date is sent
* with the order, and also on renewals the initial amount is zero
*/
public function createOnsitePayment($planId, $billingDate = null, $mergeFields = [], $cycles = 0)
{
$plan = config('payfast.plans')[$planId];

$recurringType = Subscription::frequencies($planId);

ray("billingDate in createOnsitePayment: $billingDate");


$data = [
'merchant_id' => $this->merchantId(),
'merchant_key' => $this->merchantKey(),
Expand All @@ -104,8 +105,8 @@ public function createOnsitePayment($planId, $billingDate = null, $mergeFields =

$message = "The PayFast onsite modal was invoked with these merged values and will now wait for user input:";

ray($message)->purple();
ray($data)->green();
$this->debug($message, 'displayPayFastModal');
$this->debug($data, 'notice');

$signature = PayFast::generateApiSignature($data, $this->passphrase());

Expand All @@ -129,6 +130,39 @@ public function dataToString($dataArray)
return substr($pfOutput, 0, -1);
}

/**
* A simple debugger that combines what Ray can do and built-in Laravel logging.
* Defaults to debug and purple if logging is anything except the defaults.
* Won't log to local in the application isn't in production.
*/
function debug($message, $level = 'debug')
{
$color = match($level) {
'debug' => 'gray',
'info' => 'blue',
'notice' => 'green',
'warning' => 'orange',
'error' => 'red',
'critical' => 'red',
'alert' => 'red',
'emergency' => 'red',
default => 'purple',
};
ray($message)->$color();

if ($color == 'purple') {
$level = 'debug';
}

if ($level == 'debug' && config('payfast.debug') == false) {
return;
}

if (config('app.env') == 'production') {
Log::$level($message);
}
}

/**
* Fetch subscription information information from the API.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PayFastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function register()
'passphrase' => config('payfast.passphrase'),

'testmode' => config('payfast.testmode'),

'merchant_id_test' => config('payfast.merchant_id_test'),
'merchant_key_test' => config('payfast.merchant_key_test'),
'passphrase_test' => config('payfast.passphrase_test'),
Expand Down

0 comments on commit d174c71

Please sign in to comment.