diff --git a/LOG.md b/LOG.md deleted file mode 100644 index 82991bd..0000000 --- a/LOG.md +++ /dev/null @@ -1,31 +0,0 @@ -2022-06-02 - -- Moved WHMCS to Payfast and did some cleaning up and stripping down - -2021-12-04 - -- Removed Pest -- Added autoload and autoload-dev section in `composer.json` - -Sample configure.php some caveats: - -fintechsystems not hypenated - -``` -php configure.php -Author name (Eugene): Eugene van der Merwe -Author email (eugenevdm@gmail.com): -Author username (fintech-systems): -Vendor name (fintech-systems): FintechSystems -Vendor namespace (FintechSystems): -Package name (laravel-payfast): -Class name (LaravelPayfast): PayFast -Package description (This is my package laravel-payfast): ------- -Author : Eugene van der Merwe (fintech-systems, eugenevdm@gmail.com) -Vendor : FintechSystems (fintechsystems) -Package : laravel-payfast -Namespace : FintechSystems\PayFast -Class name : PayFast ------- -``` diff --git a/src/Components/Subscriptions.php b/src/Components/Subscriptions.php index 0044e9f..599f1df 100644 --- a/src/Components/Subscriptions.php +++ b/src/Components/Subscriptions.php @@ -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; @@ -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(); diff --git a/src/PayFast.php b/src/PayFast.php index 8c255b1..7339bb2 100644 --- a/src/PayFast.php +++ b/src/PayFast.php @@ -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 { @@ -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']; @@ -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(), @@ -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()); @@ -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. */ diff --git a/src/PayFastServiceProvider.php b/src/PayFastServiceProvider.php index 7d842ea..6e44362 100644 --- a/src/PayFastServiceProvider.php +++ b/src/PayFastServiceProvider.php @@ -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'),