Laravel cashier-paddle Simple Charge The checkout id issue - laravel

Cashier Paddle Version: 1.0#beta
Laravel Version: 7.0
PHP Version: 7.2.5
I am using cashier-paddle for one of my laravel 7 projects. I'm trying to apply a "one off" charge (Simple Charge) against a customer. I've followed the official documentation to integrate the package in my project but I am getting this issue "Simple Charge The checkout id must be a valid checkout id". Here are the steps that I have already completed.
Installed the official laravel cashier-paddle package using composer
require laravel/cashier-paddle
Published necessary migrations and added the necessary API Keys on my
env file
Added the #paddlejs in may master layout blade file and updated the
VerifyCsrfToken middleware so it except routes paddle/*
Added the Billable trait to the User model Configured the webhook
route and controller
// Route example
Route::post('paddle/webhook','WebhookController#handleWebhook')->name('cashier.webhook')
// WebhookController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Paddle\Http\Controllers\WebhookController as CashierController;
class WebhookController extends CashierController
{
public function handleWebhook(Request $request)
{
logger('I can reach here!');
}
public function handlePaymentSucceeded($payload)
{
}
}
Generated the paylink variable using my controller.
// paylink variable from controller
$payLink = auth()->user()->charge(12.99, 'Test Product Title');
Finally used the variable on the paddle-button Blade component
// Blade file
<x-paddle-button :url="$payLink" class="px-8 py-4">
Buy
</x-paddle-button>
Note: The simple charge is not working but the charge for a specific product is working fine. For example this one auth()->user()->chargeProduct(619859) is working fine.
These are the steps that I have already followed to integrate the paddle simple chare on my laravel application. Hope that information may help you. Let me know if I am doing anything wrong or missed any steps. I will be really very thankful if anyone can help me to solve the issue. Thanks in advance.

Thanks for visiting the question. After doing some research I've fixed the issue. Everything was fine. Just need to specify the webhook URL in the charge method. I think it was not mentioned in laravel documentation. I'm posting the answer so anyone can get a solution in the future.
// paylink variable from controller
$payLink = auth()->user()->charge($total, 'Product Title', [
'webhook_url' => 'webhook URL here',
]);

Related

why email notification in laravel doesn't work?

I have a simple dashboard to add companies and their employees, i want to send an email notification to admin if there is a new company added, and send an email to company when new employee added.
how to do this using laravel?
i tried to use laravel notification as documentation, but it didn't work.
Maybe some piece of code from your project would be help us to understand.
I think the answer you looking for is can be boot method in model. If you want to check that is there any new company? Then, go to your Company model and try something like this.
public static function boot(){
static::creating(function ($model) {
/*add code about what do you want to do.
Maybe notify method like this */
$model->notify(new NewMessage($variable ));
});
I am really sorry if I got you wrong, but i am just trying to help you.

Laravel app deployment in Heroku fails with handling the post-autoload-dump event returned with error code 1 [duplicate]

I have been using Eloquent as a standalone package in Slim Framework 2 successfully.
But now that I want to make use of Illuminate\Support\Facades\DB since I need to show some statistics by getting the info from 2 tables and using a Left Join and a Counter from the database like this:
use Illuminate\Support\Facades\DB;
$projectsbyarea = DB::table('projects AS p')
->select(DB::raw('DISTINCT a.area, COUNT(a.area) AS Quantity'))
->leftJoin('areas AS a','p.area_id','=','a.id')
->where('p.status','in_process')
->where('a.area','<>','NULL')
->orderBy('p.area_id');
I get the following error:
Type: RuntimeException
Message: A facade root has not been set.
File: ...\vendor\illuminate\support\Facades\Facade.php
Line: 206
How can I solve it?
So far I have found out, in this link that I need to create a new app container and then bind it to the Facade. But I haven't found out how to make it work.
This is how I started the rest of my Eloquent and working fine:
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule();
$capsule->addConnection([
'my' => $app->config->get('settings'),
/* more settings ...*/
]);
/*booting Eloquent*/
$capsule->bootEloquent();
How do I fix this?
Fixed
As #user5972059 said, I had to add $capsule->setAsGlobal();//This is important to make work the DB (Capsule) just above $capsule->bootEloquent();
Then, the query is executed like this:
use Illuminate\Database\Capsule\Manager as Capsule;
$projectsbyarea = Capsule::table('projects AS p')
->select(DB::raw('DISTINCT a.area, COUNT(a.area) AS Quantity'))
->leftJoin('areas AS a','p.area_id','=','a.id')
->where('p.status','in_process')
->where('a.area','<>','NULL')
->orderBy('p.area_id')
->get();
You have to change your code to:
$Capsule = new Capsule;
$Capsule->addConnection(config::get('database'));
$Capsule->setAsGlobal(); //this is important
$Capsule->bootEloquent();
And at the beginning of your class file you have to import:
use Illuminate\Database\Capsule\Manager as DB;
I have just solved this problem by uncommenting $app->withFacades(); in bootstrap/app.php
Had the same issue with laravel 8. I replaced
use PHPUnit\Framework\TestCase;
with:
use Tests\TestCase;
Try uncommenting in app.php $app->withFacades();
Do not forget to call parent::setUp(); before.
fails
public function setUp(): void {
Config::set('something', true);
}
works
public function setUp(): void {
parent::setUp();
Config::set('something', true);
}
One random problem using phpUnit tests for laravel is that the laravel facades have not been initialized when testing.
Instead of using the standard PHPUnit TestCase class
class MyTestClass extends PHPUnit\Framework\TestCase
one can use
class UserTest extends Illuminate\Foundation\Testing\TestCase
and this problem is solved.
I got this error after running:
$ php artisan config:cache
The solution for me was to delete the /bootstrap/cache/config.php file. I'm running Laravel 5.5.
The seems to arise in multiple situation, and not just about facades.
I received the following message while running tests using PHPUnit v.9.5.4, PHP v.8.0.3 and Lumen v. 8.2.2:
PHP Fatal error: Uncaught RuntimeException: A facade root has not
been set. in path_to_project/vendor/illuminate/support/Facades/Facade.php:258
And that happened although I had apparently already configured my app.php to enable facades ($app->withFacades();), still I received this error message whenever I tried to run tests using Illuminate\Support\Facades\DB. Unfortunately, none of the other answers helped me.
This error was actually been thrown due to my configs in phpunit.xml, which didn't point to my app.php file, where I actually enabled facades.
I just had to change
<phpunit (...OTHER_PARAMS_HERE) bootstrap="vendor/autoload.php">
to
<phpunit (...OTHER_PARAMS_HERE) bootstrap="bootstrap/app.php">
Hope it helps.
wrong way
public function register()
{
$this->app->bind('Activity', function($app)
{
new Activity;
});
}
right way 👍
public function register()
{
$this->app->bind('Activity', function($app)
{
return new Activity;
});
}
---------------------------------- don't forget return
Upgrade version for php, I encountered this error while calling the interface.
$ php artisan config:cache
Deleting the /bootstrap/cache/config.php file is a very effective way.
In my project, I managed to fix this issue by using Laravel Dependency Injection when instantiating the object. Previously I had it like this:
$class = new MyClass(
new Client(),
env('client_id', 'test'),
Config::get('myapp.client_secret')
);
The same error message happened when I used Laravel env() and Config().
I introduced the Client and env in the AppServiceProvider like this:
$this->app->bind(
MyClass::class,
function () {
return new MyClass(
new Client(),
env('client_id', 'test')),
Config::get('myapp.client_secret')
);
}
and then instantiated the class like this:
$class = app(MyClass::class);
See more from https://laravel.com/docs/5.8/container .
In my case, for a while a ran a PHP project in PHP version 8, and that time I used some PHP 8 features like param definition and method's multiple return type declarations supported by only PHP 8 and above. When I downgraded from PHP 8 to PHP 7.4 I faced this issue. After removing the return types and param hinting the problems are gone.
Tested on Laravel 8.78
tests/bootstrap.php
<?php
use Illuminate\Foundation\Bootstrap\RegisterFacades;
use Illuminate\Foundation\Bootstrap\LoadConfiguration;
require_once __DIR__ . '/../vendor/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
(new LoadConfiguration())->bootstrap($app);// <------- Required for next line
(new RegisterFacades())->bootstrap($app);// <------- Add this line
Here is yet another instance of this error, happened to me after upgrading Laravel 8 to 9.
I had feature tests with a #dataProvider to supply data to those tests. Some of the data supplied by the data provider methods came from an application service. It was being initialised like this:
/**
* #dataProvider myDataProvider
*/
public function testSomeStuff(...)
{
...
}
public function myDataProvider()
{
$myService = app(Service::class); // This is trouble
return [
['test1_data' => $myService::SOME_CONSTANT],
[...],
...
];
}
This worked under Laravel 8, but not in Laravel 9. All other solutions listed in this SO thread were checked and were correctly set up.
The problem is that the application is not being inititialised until after the data provider method is run. It was presumably initialised before this stage in the Laravel 8 install. So app(Service::class) was failing due to it using facades internally.
One workaround could be to force the application to initialise earlier, in the data provider function: $this->createApplication(). I would not recommend this due to potential side effects of the test parts running in the wrong order, though it does appear to work when I tried it.
Best solution is to avoid accessing any part of the application functionality in the data provider methods. In my case it was easy to replace $myService::SOME_CONSTANT with MyService::SOME_CONSTANT after making sure those constants were public.
Hopefully this will help somebody suddenly hitting this problem running feature tests after a Laravel 9 upgrade.
If you recently upgrade Laravel on Homestead & VirtualBox environment or do not find any reason that causing please be sure your Vagrant is up to date.
Referance
I had Taylor lock this thread. The past several replies have restated the solution, which is to Upgrade to Virtualbox 6.x, the thread is locked to prevent other issues that are not related from being dogpiled on here.
#melvin's answer above works correctly.
In case someone is wondering about it, the mistake people do is to choose Yes when VSCode asks them if they are making a Unit Test. Remember, Unit Tests should really be unit tests, independent of other application features (models, factories, routes; basically anything that would require the Laravel app to be fired up). In most scenarios, people really actually want to make Feature Tests and therefore should answer No to the above question. A feature test inherits from Tests\TestCase class (which takes care of firing up Laravel app before running the test) unlike unit tests that inherit from the class PHPUnit\Framework\TestCase which use just PHPUnit and are therefore much faster.
credit with thanks to #Aken Roberts's answer here.
From Laravel Documentation: Generally, most of your tests should be feature tests. These types of tests provide the most confidence that your system as a whole is functioning as intended.

payumoney payment gateway integration

I want to integrate payumoney with laravel 5.1. I have kept the form in blade . Upon submitting the form I get this error:
method not found
then I tried to put the whole form for payment gateway (payu) in controller. It is still not working. Actually laravel unable to submit form to this url - test.payu.in.
I also used this:
$request = \Illuminate\Http\Request::create('http://localhost/mypro/payu/', 'POST', ['param1' => 'value1', 'param2' => 'value2']);
not working
Please help me solving this.
You might like to use a package for PayU Money. Here is a link it is pretty easy to use.
PayU Package.
Here you don't have to do anything.
Just register 2 route one for request and one for response.
Then you have to do the following.
// Frirst:
return Payment::make($data, function($then) {
$then->redirectTo('your/response/url');
});
// Second:
$payment = Payment::capture();
// And you have the payment here.
It is that simple.
Hope it helps.

google calendar with codeigniter

I'm trying to integrate Google Calendar in my php application (I use CodeIgniter for this).
I have a problem with my controller calendar.php.
<?php
session_start();
Class Calendar extends Controller {
function Calendar(){
echo 'start';
parent::Controller();
echo 'okkkkkkkk';
require_once '/home/me/framework/ZendGdata/library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
}
but there is a problem with parent::Controller() because 'okkkkkk' is not printed.
Could anyone help me please?
Change
parent::Controller();
to
parent::__construct();
parent::Controller() doesn't work in CI because as of CI 2.1.2, the constructors are declared using PHP's __construct() method.
As a sidenote, it seems you are using an older version of CI. CI 2.o onwards, the base controller class is called CI_Controller as opposed to just Controller. You should look into updating your project by replacing the system folder.
You can find the full working code in this following link https://github.com/omerkamcili/ci_google_calendar_api.
After down loading the code create your service account, OAuth client Id's in the following link http://console.developers.google.com.
Then replace the client_id,client_secret,redirect_uri's in your project file in the following path -> /project_folder/application/config/client_secret_846685841138-t0a5b9d2i655e7km54md8j440jcg5rr5.apps.googleusercontent.com.json file
Finally download and replace the google-api-php-client in the following file path /project_folder/application/third_party/google-api-php-client

Setting up Codeigniter HMVC with tank auth

I am having trouble getting a working Codeigniter version 2.0.3 with hmvc and tank auth(set up as a module) setup properly. I have installed CI properlly and then install HMVC with these directions https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
I get to my welcome controller/view as example just fine which means the HMVC is working. Next I try to add tank auth to the project by adding it to a folder in the modules folder. It has the proper controller/view/model etc.. setup within the tank auth. I even added in routes something like
$route["auth"]="auth/login";
I also extended the controller within the auth module to MX_Controller like as directed. Also in the constructor I have :
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security'); <--failing to load this
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
$this->form_validation->CI =& $this;
It seems to be redirecting fine to the module however it comes up with an error saying ::
An Error Was Encountered
Unable to load the requested class: security
What am I doing wrong? Does any one have a working CI installation with HMVC and tank auth as a module so I can see how its done? I'm new to HMVC, thanks
I found the same problem, but i solved by simple adding a comment to the
$this->load->library('security');
so it will look like this:
//$this->load->library('security');
since security its now part of the codeigniter core, i guess its already loaded by default, and everything seems to be working pretty good
it is in Helper now according to CodeIgniter 3.0 user guide
try:
$this->load->helper('security');
I fix this, by creating Security.php file in application/libraries directory with the following code:
require_once(BASEPATH.'core/Security.php');
class Security extends CI_Security { }
I found a solution, I simply took the security.php file from codeigniters system/core folder and dropped it into system/libraries.
move the file security.php from system/core to system/libraries
then edit core/codeigniter.php line number 204 from $SEC =& load_class('Security', 'core'); to $SEC =& load_class('Security', 'libraries');
Security.php is present in "codeigniter/system/core/Security.php"
so provide this path your problem gets solved easily
load->library('../core/security');
I Read CodeIgniter 3.X User Guide and I was found that "Security" is available as a 'helper' Now.
So you need to change this;
$this->load->library('security');
into
$this->load->helper('security');
XSS Filtering
The Input class has the ability to filter input automatically to prevent cross-site scripting attacks. If you want the filter to run automatically every time it encounters POST or COOKIE data you can enable it by opening your application/config/config.php file and setting this:
$config['global_xss_filtering'] = TRUE;
You need to read a CodeIgniter 3.0 User Guide there are so many changes and implementation or please Refer change log.

Resources