Stripe billing class not found - Laravel - php

I have added the Stripe library to my composer.json file, ran all commands just to check... update, dump-autoload etc.
In my classmap file the library is shown:
'Stripe\\Account' => $vendorDir . '/stripe/stripe-php/lib/Account.php',
and so on...
In my app folder i have my classes folder etc:
app
motivate
Billing
BillingInterface.php
StripeBilling.php
In my StripeBilling file I reference Stripe like so:
<?php
namespace Motivate\Billing;
class StripeBilling implements BillingInterface
{
public function __construct()
{
Stripe::setApiKey(Config::get('stripe.secret_key'));
}
This throws the error:
Class 'Motivate\Billing\Stripe' not found
So my next thought was:
use \Stripe as Stripe;
Which returns class Stripe not found.
Where is this going wrong? Thanks :)

According to the documentation:
To use your API key, you need only call \Stripe\Stripe::setApiKey()
with your key. The PHP library will automatically send this key in
each request.
So, just try using use \Stripe\Stripe as Stripe; instead.

Related

new laravel package not recognized

I was writing my first laravel package, so I could use it and understand how packages work and learn how to write packages and etc.
But my project didn't recognize the package that I wrote.
Here is my package Github link: https://github.com/IIIphr/Shamsi_Calendar
And this is my main project: https://github.com/IIIphr/aimeos_shamsi
I use this command to add my package to the app: composer require iiiphr/shamsi_calendar
And it'll be added successfully (at least I guess). Then in the temp Controller, I wrote this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use iiiphr\shamsi_calendar;
class temp extends Controller
{
public function index(){
return shamsi_calendar::get_date();
}
}
And a route:
Route::get('/date','temp#index');
But in the http://localhost:8000/date, I will face this error:
Before, I have tried other ways and the result was anything but success.
Another thing, I have this error in visual studio code in the temp controller:
Undefined type 'iiiphr\shamsi_calendar'.intelephense(1009)
I will appreciate any kind of help :)
You import the library perfectly but you don't use the Calendar Controller that the package gives you. The package haves a controller called CalendarController, you have two ways, extends from this controller or create an instance of this controller, if you extend the controller from this:
<?php
namespace App\Http\Controllers;
use iiiphr\shamsi_calendar\CalendarController;
class temp extends CalendarController
{
public function index(){
return $this->get_date();
}
}
What do you think about it?

Laravel use vendor directory php class

Recently I learn Laravel and try to implement BingAds SDK to grab some reports to my database but failed.
I have a controller named BingAdController.php in app/http/Controllers/BingAdController.php
BingAds SDK is installed via composer, they are in vendor/microsoft/bingads/samples/V12/ReportRequests.php
BingAdController.php
namespace App\Http\Controllers;
use SoapVar;
use SoapFault;
use Exception;
use SoapClient;
use Illuminate\Http\Request;
use App\BingAd;
use App\Http\Controllers\Controller;
use Microsoft\BingAds\V12\Reporting\ReportRequestStatusType;
use Microsoft\BingAds\Auth\ServiceClient;
use Microsoft\BingAds\Auth\ServiceClientType;
use Microsoft\BingAds\Samples\V12\AuthHelper;
use Microsoft\BingAds\Samples\V12\ReportRequestLibrary;
include("/Applications/MAMP/htdocs/laravel/vendor/microsoft/bingads/samples/V12/ReportRequests.php");
class BingAdController extends Controller {
public function bingadsReporting(){
ReportRequests.php
namespace Microsoft\BingAds\Samples\V12;
// require_once __DIR__ . "/vendor/autoload.php";
require_once "/Applications/MAMP/htdocs/laravel/vendor/autoload.php";
include __DIR__ . "/AuthHelper.php";
include __DIR__ . "/ReportRequestLibrary.php";
use SoapVar;
use SoapFault;
use Exception;
use Microsoft\BingAds\V12\Reporting\ReportRequestStatusType;
use Microsoft\BingAds\Auth\ServiceClient;
use Microsoft\BingAds\Auth\ServiceClientType;
use Microsoft\BingAds\Samples\V12\AuthHelper;
use Microsoft\BingAds\Samples\V12\ReportRequestLibrary;
$GLOBALS['AuthorizationData'] = null;
$GLOBALS['Proxy'] = null;
$GLOBALS['CampaignManagementProxy'] = null;
class ReportRequests {
public $DownloadPath, $length, $folder;
Laravel keep saying the class not found...
I have been stuck in this problem for 2 days... please help
You shouldn't be manually calling include or require_once in your code - Laravel uses Composer's autoloader out of the box, so you should just be able to refer to the classes you need and it will do the rest.
First, ensure that you have installed Bing's SDK through Composer - i.e. it's added in your composer.json and it was installed through the command line tool. If you just downloaded it yourself and dropped it in the vendor directory it's not going to work.
Then you should be able to call new Microsoft\BindAds\Auth\ServiceClient or whichever class you want - Composer will know where and how to find this class for you.
If you have installed it through Composer and are still having issues you'll need to provide the exact code you're having issues with as well as the full error and stacktrace you're seeing so that we can assist debugging it.
Finally I found the solution.
Add "vendor/microsoft/bingads" into vendor/composer.json -> classmap
Don't know why BingAds didn't auto update composer.json even via composer install.

Class 'App\Http\Controllers\Saml2' not found

I'm on Laravel 5, I'm trying to integrate SAML 2.0 with it. I've found this package = https://github.com/aacotroneo/laravel-saml2
I tried follow their steps, but at the end when I use
<?php
namespace App\Http\Controllers;
class SAMLController extends Controller {
public function adminSignIn(){
return Saml2::login(URL::full());
}
}
I've already added
provider
'Aacotroneo\Saml2\Saml2ServiceProvider',
aliases
'Saml2' => 'Aacotroneo\Saml2\Facades\Saml2Auth',
Why do I still get this error?
Class 'App\Http\Controllers\Saml2' not found
Note : I've even retry after sudo composer dumpauto, same result.
You need to use full namespace for the facade:
\Saml2::login(URL::full());
Or add this to the top of the class:
use Saml2;
you need to explicitly write "use" on top
use Saml2;
This might work.

How to call models methods from helper function in Laravel 5.3?

I've created a helper file using the following method:
Created file in app/Http/helpers.php
Added file path in composer.json
Run this command: composer dumpautoload
Everything worked well but I want to use my models here so that I don't have to write code for getting data from database every time, but it's giving an error that model class not found.
function productImagePath($image_name) {
$generalSettings = \GeneralSettingsModel::GetGeneralSettings();
return $generalSettings;
}
My requirement is that I want to call some model's functions to get frontend (header/footer) design settings from database. So I've to write that code again and again in each controller. I'm very new in Laravel so if it's not a good approach to use helpers for such things, please guide me how it's possible then.
As your GeneralSettingModel class is in the App namespace you will need to include that:
function productImagePath($image_name)
{
$generalSettings = App\GeneralSettingsModel::GetGeneralSettings();
return $generalSettings;
}
Hope this helps!

Attempted to load class "ClassName" from namespace (...). Even though namespace is imported

I have a Symfony project to which I added some non-symfony php files containing various classes. But for some reason the classes are not loaded when loading the website, even though the IDE sees them properly.
So, I have a class that needs other classes:
namespace rootspace\FrontBundle\Controller;
use rootspace\FrontBundle\Networks\TwitterOAuth;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class TwitterController extends Controller
{
public function connectAction(){
// The TwitterOAuth instance
$connection = new TwitterOAuth('abc', '123');
}
}
And then the class which fails to load (that needs yet another file)
namespace rootspace\FrontBundle\Networks;
/* Load OAuth lib. You can find it at http://oauth.net */
//require_once('OAuth.php'); -- should this be commented out?
/**
* Twitter OAuth class
*/
class TwitterOAuth {
/* Contains the last HTTP status code returned. */
}
Lastly, the third file
namespace rootspace\FrontBundle\Networks;
use Symfony\Component\Config\Definition\Exception\Exception;
class OAuthConsumer
{
public $key;
public $secret;
}
(...)
I assume the actual filenames don't matter, right? Nor their structure? PhpStorm sees all the classes properly, I can right-click through them, but it fails when deployed.
Thanks for help
Edit - the whole error message says
Attempted to load class "TwitterOAuth" from namespace "rootspace\FrontBundle\Networks" in D:\Dropbox\project\src\rootspace\FrontBundle\Controller\TwitterController.php line 15. Do you need to "use" it from another namespace?
This is because Symfony's autoloader follows PSR standards (PSR-0, PSR-4) which says that fully qualified (with namespace) class name translates to file location and name. So in fact file names does matter.
So in your case rootspace\FrontBundle\Networks\TwitterOAuth class should be located in rootspace/FrontBundle/Networks directory in file called TwitterOAuth.php
If classes you are using does not follow PSR standards you can also register them manually in app/autoloader.php file
Check these for more info:
How can I add a namespace to Symfony 2.1?:
How to autoload class
And check this answer
I forgot to add a .php extension to my filename

Categories