How do I load the Paypal SDK into Silex? - php

I'm having some trouble. I'm using Silex, and I'm trying to load the Paypal SDK into it. I think my issue is related to my understanding of Silex, which is why I'm posting it here.
My Setup
Paypal's developer website says to add a few lines to the composer file (PHP tab). So, I've done that. My new composer file looks like so (the last four entries were those suggested by Paypal):
{
"require": {
"silex/silex": "1.0.*#dev",
"symfony/browser-kit": "2.1.*",
"symfony/console": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/dom-crawler": "2.1.*",
"symfony/filesystem": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/form": "2.1.*",
"symfony/locale": "2.1.*",
"symfony/process": "2.1.*",
"symfony/security": "2.1.*",
"symfony/serializer": "2.1.*",
"symfony/translation": "2.1.*",
"symfony/validator": "2.1.*",
"symfony/monolog-bridge": "2.1.*",
"symfony/twig-bridge": "2.1.*",
"monolog/monolog": ">=1.0.0,<1.2-dev",
"twig/twig": ">=1.2.0,<2.0-dev",
"doctrine/dbal": ">=2.2.0,<2.4.0-dev",
"swiftmailer/swiftmailer": "4.1.*",
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"paypal/rest-api-sdk-php" : "0.7.*"
}
}
Then, I ran composer update, and it updated everything. I checked in the vendor folder, and a paypal folder had been created and seemed to be good to go.
The Problem
Unfortunately, even though I've done the above steps, it still isn't working. I'm following the beginners steps outlined on Paypal's website, it seems that one of the Paypal classes can't be located.
The line that causes the error is taken directly from the "beginners steps" page linked to above. For quick reference, I'll provide it below as well:
$cred = new OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd","EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", $sdkConfig);
Unfortunately that line causes an error that says:
Fatal error: Class 'OAuthTokenCredential' not found in ...
Summed up...
The problem seems to be that Silex isn't loading--or making available--the class OAuthTokenCredential. What do I do?

Thanks Laurynas MaliĊĦauskas and user2930475 for this answer (in the comments of my post).
Looks like I had neglected to put a line such as:
use PayPal\Auth;
in my app.php file.
Once added, I also needed to change my new class line to this:
$cred = new PayPal\Auth\OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd","EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", $sdkConfig);
Note that I have all of my controllers actually in the app.php file.

Actually, you don't need to add anything to app.php at all. Just do this:
use PayPal\Auth\OAuthTokenCredential.php;
class YourController{
public function myAction(){
// ...
$cred = new OAuthTokenCredential("AQkquB...","EL1tVx...", $sdkConfig);
// ...
}
}
You should never need to modify app.php just to use a class.

Related

Module (Laminas\Crypt) could not be initialized

I want to use Bcrypt of Laminas-Crypt package in one of my files. After running
composer require laminas/laminas-crypt,
composer dump-autoload,
composer update
I declared a use statement in my controller:
use Laminas\Crypt\Password\Bcrypt;
The application loaded without any errors, but as far as I am concerned, all namespaces should be registered in config/modules.config.php for the autoloader to load the namespaces accordingly. After adding Laminas\Crypt namespace to the folder the application threw an exception:
Uncaught Laminas\ModuleManager\Exception\RuntimeException: Module (Laminas\Crypt) could not be initialized. in C:\xampp\htdocs\phpLessons\Shortly\vendor\laminas\laminas-modulemanager\src\ModuleManager.php:180
My question is:
Can the application function properly without the namespace of the used package being defined in the config/modules.config.php of root directory?
How can the exception be handled?
Edit:
Here is the relevant part of composer.json
"require": {
"php": ">=8.1.0",
"laminas/laminas-component-installer": "^3.0",
"laminas/laminas-development-mode": "^3.2",
"laminas/laminas-skeleton-installer": "^1.0",
"laminas/laminas-mvc": "^3.3.4",
"laminas/laminas-db": "^2.12.0",
"laminas/laminas-mvc-form": "^2.0.0",
"laminas/laminas-json": "^3.2",
"laminas/laminas-log": "^2.13.1",
"laminas/laminas-cli": "^1.1.1",
"laminas/laminas-mvc-i18n": "^1.2.0",
"laminas/laminas-mvc-plugins": "^1.1.0",
"laminas/laminas-mvc-middleware": "^2.0.0",
"laminas/laminas-session": "^2.10.0",
"laminas/laminas-di": "^3.2.2",
"laminas/laminas-view": "^2.25",
"laminas/laminas-form": "3.7",
"laminas/laminas-crypt": "^3.9",
"ext-pdo": "*",
"laminas/laminas-mail": "^2.20",
"doctrine/orm": "^2.14",
"doctrine/dbal": "^3.2",
"symfony/yaml": "^5.4",
"symfony/cache": "^5.4",
"doctrine/common": "^3.4",
"doctrine/doctrine-orm-module": "^5.3"
},
and modules.config.php from config/autoload:
return [
'Laminas\Cache',
'Laminas\Paginator',
'Laminas\Mail',
'Laminas\Mvc\Plugin\FilePrg',
'Laminas\Mvc\Plugin\FlashMessenger',
'Laminas\Mvc\Plugin\Identity',
'Laminas\Mvc\Plugin\Prg',
'Laminas\Session',
'Laminas\Mvc\Middleware',
'Laminas\Mvc\I18n',
'Laminas\Form',
'Laminas\I18n',
'Laminas\Log',
'Laminas\InputFilter',
'Laminas\Filter',
'Laminas\Hydrator',
'Laminas\Di',
'Laminas\Db',
'Laminas\Router',
'Laminas\Validator',
'Laminas\DeveloperTools',
'Laminas\Diactoros',
'DoctrineModule',
'DoctrineORMModule',
'Application',
'User',
'Pages',
];

Adding a composer package to Laravel 5

"require": {
"infusionsoft/php-sdk": "^1.2",
"laravel/lumen-framework": "5.1.*",
"vlucas/phpdotenv": "~1.0",
"barryvdh/laravel-debugbar": "^2.2",
"goaop/framework": "^2.0",
"php-http/httplug": "^1.1",
"infusionsoft/old-php-isdk": "*"
},
I'm trying to use the "infusionsoft/old-php-isdk" which is in the packagist composer repository but it's not specific to Laravel. I'm using an order controller and it's code that I picked up from another developer so he references the current (and working) "infusionsoft/php-sdk" as the following
"use infusionsoft\infusionsoft;"
What namespace do I call it if it has no namespace from the package?
Here's the original link to the composer package.
https://packagist.org/packages/infusionsoft/old-php-isdk
Am I missing something? Do I need to assign it a namespace? What and where would I put it?

laravel 5,am I including too much libraries?

I am new to Laravel, and I have started working on Laravel 5.x( the current version on the question date). My app uses bunch of libraries, including Amazon MWS library, a parser and many more, see this image for an idea
these seems to be a lot of folder, and including Laravel Framework folder...
many of these built in options would never by used by me directly and intentionally..Also, say from a library, I would use only one method (tojson method from a lib for example)
Already admitted, I am new to Laravel, and from my native understanding, only parts of libraries are included when called..
So, my basic question is,
When and HOW do you know you are including too much ?
How you people manage this??
thanks...and sorry if my question seems offensive to anyone, I believe its directly relating to programming and will help many others like me too..
There's no problem with including many libraries.
Requiring and installing libraries doesn't create overhead in itself, as that code is executed only when you use it. Also most of the libraries in the vendor directory are Laravel dependencies.
If you look at the framework's composer.json file and you'll see that Laravel already has a lot of dependencies as it uses a lot of Symfony components for the core, Monolog for logging, SwiftMailer for sending emails, and the list goes on:
"require": {
"php": ">=5.5.9",
"ext-mbstring": "*",
"ext-openssl": "*",
"classpreloader/classpreloader": "~3.0",
"doctrine/inflector": "~1.0",
"jeremeamia/superclosure": "~2.2",
"league/flysystem": "~1.0",
"monolog/monolog": "~1.11",
"mtdowling/cron-expression": "~1.0",
"nesbot/carbon": "~1.20",
"paragonie/random_compat": "~1.4",
"psy/psysh": "0.7.*",
"swiftmailer/swiftmailer": "~5.1",
"symfony/console": "2.8.*|3.0.*",
"symfony/debug": "2.8.*|3.0.*",
"symfony/finder": "2.8.*|3.0.*",
"symfony/http-foundation": "2.8.*|3.0.*",
"symfony/http-kernel": "2.8.*|3.0.*",
"symfony/polyfill-php56": "~1.0",
"symfony/process": "2.8.*|3.0.*",
"symfony/routing": "2.8.*|3.0.*",
"symfony/translation": "2.8.*|3.0.*",
"symfony/var-dumper": "2.8.*|3.0.*",
"vlucas/phpdotenv": "~2.2"
},
Just install whatever you need, there's no limit to how many libraries you use as long as your code is written properly.

Symfony2 WebProfiler (500): Variable "app" does not exist in #Doctrine/Collector/db.html.twig at line 1

It's actually the first time for very long that I haven't found a single search result for an error message. On every page load I get a popup message saying:
"An error occurred while loading the web debug toolbar (500: Internal Server Error).
Do you want to open the profiler?" And when I open the profiler / logs:
Variable "app" does not exist in #Doctrine/Collector/db.html.twig at line 1
I made some translations and edits of twig templates - really nothing fancy. Now the profiler fails to load on every page.
my composer.json:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.4.*",
"twig/extensions": "1.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"stof/doctrine-extensions-bundle": "~1.1#dev",
"friendsofsymfony/user-bundle": "1.3.*#dev",
"doctrine/doctrine-fixtures-bundle": "2.2.*",
"doctrine/migrations": "1.0.*#dev",
"doctrine/doctrine-migrations-bundle": "~1.0"
},
caches cleared, etc. I'm not asking for a solution but do you have any clue what the case could be here?
Thank you very much for your help & time!
Moritz
It may still be related to the cache, try to rebuild your bootstrap cache in addition to cache:clear prod & dev.
php ./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
PS: the path may be different in your symfony version.

Sonata, sf2 : Undefined index: context when deleting an image from MediaBundle

I installed all the Bundles of Sonata following the documentation step by step. I still have few errors to fix on some actions such as deleting images. All the errors i'm facing right now seem related.
I submited two issues, one SonataMediaBundle and one in SonataClassificationBundle.
in vendor/sonata-project/media-bundle/Admin/BaseMediaAdmin.php at line
118
if ($filter = $this->getRequest()->get('filter')) {
$context = $filter['context']['value'];
} else {
$context = $this->getRequest()->get('context', $this->pool->getDefaultContext());
}
1 - DEBUG - Router Sonata\PageBundle\Route\CmsPageRouter was not able
to match, message "No site defined"
"No site defined" makes me guess i should do something on that. I did create a default page with the SonataPageBundle (added in database). I don't know if there is a specific parameter to add in the config. As i said i followed the documentation step by step and i don't see anything related to defining a site. However i'm not sure "no site defined" is related to the main error.
Here my composer.json in case it could be usefull.
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.6.",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0.12",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0",
"sonata-project/core-bundle": "~2.2#dev",
"sonata-project/notification-bundle": "~2.3",
"knplabs/knp-markdown-bundle": "~1.2",
"videlalvaro/php-amqplib": "~2.4",
"liip/monitor-bundle": "~2.0",
"symfony-cmf/routing-bundle": "1.4.#dev",
"jms/serializer-bundle": "0.13.*#dev",
"sonata-project/formatter-bundle": "~2.3",
"sonata-project/markitup-bundle": "~2.1",
"sonata-project/intl-bundle": "~2.2",
"sonata-project/cache-bundle": "~2.2",
"sonata-project/seo-bundle": "~1.1",
"sonata-project/easy-extends-bundle": "~2.1",
"sonata-project/admin-bundle": "~2.3",
"sonata-project/doctrine-orm-admin-bundle": "~2.3",
"sonata-project/user-bundle": "~2.2",
"sonata-project/classification-bundle": "dev-master",
"sonata-project/news-bundle": "dev-master",
"sonata-project/timeline-bundle": "~2.2#dev",
"sonata-project/media-bundle": "~2.4#dev",
"sonata-project/page-bundle": "~2.3#dev"
}
Any solutions or hints?
PageBundle is ignoring admin routes, so you get a notice with "No site defined" (Nothing to look more about this). I cannot reproduce the issue you state with the current dev-master code.
Please use stable version of bundles or libs.

Categories