Paypal: going Live from sandbox - php

I have been brainstorming for a while now on this and finally i decided to put a question here.
I am using PayPal-PHP-SDK (restAPI) for processing payments. And i cannot make it go to the live endpoint (api.paypal.com) and always goes to sandbox (api.sandbox.paypal.com)
Progress: Using the sandbox credentials (clientId and clientSecret) in 'bootstarp.php' and 'mode' set to 'sandbox' in 'sdk_config.ini' i have successfully completed multiple sandbox transactions and completed all other parts of the project. Now the only part is making it live, which is in fact turning out to be the Achilles heel of the project.
What i have tried: I have replaced the sandbox credentials with the live ones from the client. Which he got from https://developer.paypal.com/webapps/developer/applications/myapps then under the app clicking 'show' Live Credentials. I also changed the mode to live in 'sdk_config.ini'. But still it takes me to the sandbox endpoint.
EDIT: while creating the api context in bootstarp.php there is a mode i have also set that to live, code below.
$apiContext->setConfig(
array(
'mode' => 'live',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'FINE',
'validation.level' => 'log'
)
);
Can anyone suggest me what i am missing here as i get no error to debug and look further. For any help or advice, thanks in advance.

Have you changed the mode in bootstrap.php? It seems you can use either the configuration in bootstrap.php or in the sdk_config.ini file but not both. Make sure mode is set to live in the bootstrap.php file if you have the sdk_config.ini path commented out as below (from the bootstrap.php file)
// Register the sdk_config.ini file in current directory
// as the configuration source.
/*
if(!defined("PP_CONFIG_PATH")) {
define("PP_CONFIG_PATH", __DIR__);
}
*/

This is probably more appropriate as a comment on Mike Miller's solution but I don't have enough rep, sorry.
I moved from the Paypal API sandbox to live literally five minutes ago, using your question and Mike's answer for information on how to do so.
The only things I changed were the values of clientId and clientSecret in bootstrap.php, and the mode (from 'sandbox' to 'live'), just like you set out in the question. I didn't edit the 'sdk_config.ini' file at all, and the path is commented out anyway, as per Mike's answer.
I note you're referring to the 'bootstrap.php' file as 'bootstarp.php' - this doesn't have anything to do with it, does it?

I had the same problem that I couldn't fix.
I'm not proud of my solution because it's not elegant at all, but it worked to start selling.
I modified the file PayPalConstants.php (located in ...\PayPal-PHP-SDK\paypal\rest-api-sdk-php\lib\PayPal\Core\PayPalConstants.php)
I just changed sandbox routes for live routes:
const REST_SANDBOX_ENDPOINT = "https://api.paypal.com/";
const OPENID_REDIRECT_SANDBOX_URL = "https://www.paypal.com/webapps/auth/protocol/openidconnect";

Related

Custom MAIL_LOG_CHANNEL is not used

I encountered an issue with the mail system of laravel 5.8. As the documentation says, Mail & Local Development one can change the way of sending emails to let it write them to a log-file.
Therefor, the .env as well as the config/mail.php-file have options for that.
So, I added (the key was not here originally) a MAIL_LOG_CHANNEL-key to my .env-file with the value "mail" and changed the value of the key MAIL_DRIVER to "log".
Obviously, I added a new channel to the config/logging.php:
[...]
'mail' => [
'driver' => 'single',
'path' => storage_path('logs/mail-'.php_sapi_name().'.log'),
'level' => 'info',
],
[...]
What ever I tried, the mail was never written to the seperate log-file. I testet the channel with a normal log-statement without any problem.
I switched from MAIL_LOG_CHANNEL="mail" to MAIL_LOG_CHANNEL=mail added a default value to the section of the config/mail.php:
[before]
'log_channel' => env('MAIL_LOG_CHANNEL'),
[after]
'log_channel' => env('MAIL_LOG_CHANNEL', 'mail'),
not getting the width of a hair near to the log entry.
Only with the absolute basic configuration it actually writes the mail to the log but with this solution into the wrong log file.
Does anyone have an idea? It looks pretty strange to me.
Thanks for your help.
I found out why the logging was not working:
one have to change the level-propertiy to "debug".
After that, everything works fine.
See https://laracasts.com/discuss/channels/laravel/custom-mail-log-channel-breaks-mail-driverlog?page=1#reply=523111
for the original hint for this issue.
May that can helkp someone :)
Have a nice day.

Youtube API v3 missing "creation date" in request

I'm trying to make Youtube v3 Data API work on my website.
I shamelessly copied this code from google's code samples, and it is not working. The error message showed is this:
An client error occurred: All cacheable requests must have creation dates.
I previously had issues with API keys as I forgot almost everything about APIs in general and I just thought this sample would have been useful to remember things. I managed to generate the appropriate key and now I know for sure it isn't the real problem.
Sadly Google didn't find posts related to this issue, except two links to the actual Php Library that I implemented in my site to make everything work. By looking at it closely I noticed a developer comment that could be useful.
$rawDate = $resp->getResponseHeader('date');
$parsedDate = strtotime($rawDate);
if (empty($rawDate) || false == $parsedDate) {
// We can't default this to now, as that means future cache reads
// will always pass with the logic below, so we will require a
// date be injected if not supplied.
throw new Google_Exception("All cacheable requests must have creation dates.");
}
I can understand english pretty well but I really don't know what to do now.
I even tried to add some sort of date in the request in my code, but it isn't working (you can laugh):
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
'date' => strtotime(),
));
An client error occurred: (list) unknown parameter: 'date'
Any tips? Thank you in advance
EDIT: I know, this PHP library is currently in beta, but there must be some workaround.
EDIT 2: I found a temporary work around. I inverted the logic gate of that 'if' in the Php Library and now it works. But I don't like doing this, and I won't mark this as solved. At least if you know the reason of the bug please explain it to me, I'm really interested.

Yii: Creating a Demo Site Without Replicating the Code Base

I need to set up a demo site for users to try a web app before signing up. The demo would be based on production code, however, it would require minor code changes: connection to a demo database, automatic creation/login of a new guest account for each user, etc.
The obvious solution is to replicate my code base as a second demo website and edit as necessary. Keeping the demo code in sync with production code is easy enough by adding a branch in subversion. I'm less than thrilled, however, at the prospect of having to do two updates on my server (production and then demo) every time I push code from development to production.
Initially I thought I might be able to replicate the website through a module. It's unclear if this is possible, however.
Is there a mechanic in Yii to execute an altered version of a website (config file and selected controllers)?
Never do before, so just an idea
solution with few files in other dir
create a separate a demo dir and map it on your demo URL
In this dir put this index.php (may be your .htaccess too)
<?php
$yii=_PRODUCTION_PATH_.'/framework/yii.php';
$config_prod=_PRODUCTION_PATH_.'/protected/config/main.php';
$config_demo=dirname(__FILE__).'/demo_main.php';
require_once($yii);
$config = CMap::mergeArray($config_prod,$config_demo);
Yii::createWebApplication($config)->run();
the demo_main.php override the classes (user, db) to manage a better demo experience:
<?php
return array(
'basePath'=>_PRODUCTION_DIR_.DIRECTORY_SEPARATOR.'..',
'components'=>array(
'user' => array(
// here you override the user class with a DEMO only user
'class'=>'DemoUser',
)
),
solution with all files of prduction site in a different dir
Here follows the index.php in root dir
<?php
$yii='../framework/yii.php';
$configMain = include dirname(__FILE__).'/protected/config/main.php';
$configProd = include dirname(__FILE__).'/protected/config/production.php';
$configDemo = include dirname(__FILE__) . '/protected/config/demo.php';
require_once($yii);
// for the demo version
// instead of the comment can be an *if* or any solution to manage 2 configs
//$config = CMap::mergeArray($configMain,$configProd);
$config = CMap::mergeArray($configMain,$configDemo);
Yii::createWebApplication($config)->run();
demo.php is analogue to "demo_main.php" overridig classes and configs for the demo version of the site.
The testdrive demo app is configured for this - after you install, note the separate index-test.php, and protected/config/test.php.
Unlike #IvanButtinoni's suggestion, you'll need to access index-test.php, instead of index.php, so you may need to modify your .htaccess if you're using clean URLs to allow access to index-test.php.
When I do this, I usually write a custom init in the base controller.php:
public function init() {
// use test layout if using test config
if (isset(Yii::app()->params['test'])) {
$this->layout='//layouts/test';
}
parent::init();
}
Obviously, I have a test parameter in my test.php . . .
The only difference in my two layouts is that one sets the background color to be a bright yellow, just so it's very clear you're on a test site.
If I have understood well (according to the comment answers to original post) then There are several ways. Here is a link that I think can help great deal. It helped me set up and may be will help you!
In Yii 2 it will be inherently supported
http://www.yiiframework.com/wiki/33/

facing cache issue in activecollab routers

I am developing activecollab custom module; facing an issue related to Routers.
I by mistake type wrong action name in Router's action where we need to define in router, but after getting error I updated that action name but activecollabs still reading a previous action i removed files from cache and complie folders but reading previous action.
please share if you ever face this problem in development of activecollab module..
By mistake I did this: (action=>'views')
Router::map('mymodule_view', 'mymodule/view/:request_id', array('controller' => 'mymodule', 'action' => 'views' ), array('req_id' => Router::MATCH_ID) );
but after getting error i update above code by this: (action=>'views')
Router::map('mymodule_view', 'mymodule/view/:request_id', array('controller' => 'mymodule', 'action' => 'view' ), array('req_id' => Router::MATCH_ID) );
First, make sure that your system is in development mode. Open config/config.php and confirm that APPLICATION_MODE is set to in_development:
define('APPLICATION_MODE', 'in_development');
Now that you have that covered, go to activeCollab and you'll have Developer toolbar available in the lower right corner of the application interface, next to activeCollab powered button (it has a red bug icon). Use this tool to clear cache, rebuild images etc.
PS: You can also clear all files from /cache folder, just in case.

Cucumber, webrat mechanize testing php/drupal application on MAMP, authentication issue

I've got cucumber testing my drupal application with passing tests like so:
Given /^I am authenticated as a "([^"]*)" user$/ do |role|
visit('/user')
fill_in "name", :with => "user_#{role.downcase}"
fill_in "pass", :with => "password"
click_button
visit('/') #gets around a 302 redirect issue
response_body.should contain("Log out")
end
My env.rb is like so:
require 'rspec/expectations'
require 'webrat'
require 'test/unit/assertions'
World(Test::Unit::Assertions)
Webrat.configure do |config|
config.mode = :mechanize
end
World do
session = Webrat::Session.new
session.extend(Webrat::Methods)
session.extend(Webrat::Matchers)
session.visit('http://localhost')
session
end
This passes just fine when my virtual host on MAMP is the default localhost. But when I create another virtual host, with the same document (and update the session.visit to use the new root) this test fails. It seems the session is lost.
Does anyone know how to debug this? I've looked at the html output and it shows the content as an unauthenticated user which is why I think the session is being reset.
Edit
I checked the virtual hosts and they are exactly the same. The one with failing tests tends to be an order of magnitude slower.
I eventually moved to capybara. There were versions of mechanize that had a few bugs around posting form data etc. Capybara works much better.

Categories