Why is not my url a fully qualified url for paypal? - url

I have this code
<?php
require '..\..\vendor\autoload.php';
define('SITE_URL','https://www.historietas.mx');
$paypal = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'my_redential',
'my_secret'
)
);
?>
And this code
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl(SITE_URL.'\controladores\pagos\pay.php?success=true')
->setCancelUrl(SITE_URL.'\controladores\pagos\pay.php?success=false');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try{
$payment->create($paypal);
}
catch(PayPal\Exception\PayPalConnectionException $e){
echo $e->getCode();
echo $e->getData();
die($e);
}
echo $approvalUrl = $payment->getApprovalLink();
and I have this error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'ReturnUrl is not a fully qualified URL'
I don't know what's hapenning I am not using any special character in the url, why is giving me this error? please help, it is very frustating...

remove space from url from your Url that's the issue
include 'vendor/autoload.php';
$checkUrl = 'https://yourdomein.org/user/registration/paypaypal-ch?approval=true&plan=single&email=dghdg#dfgsdh.com&firstname=dshdh0d&lastname=dhdas';
try {
\PayPal\Validation\UrlValidator::validate($checkUrl);
echo "Validated\n";
} catch (InvalidArgumentException $ex) {
echo $ex->getMessage() . "\n";
}

Remove ?success=true
and
Remove ?success=false
from
$redirectUrls->setReturnUrl(SITE_URL.'\controladores\pagos\pay.php?success=true')
->setCancelUrl(SITE_URL.'\controladores\pagos\pay.php?success=false');
and it will wotk for sure.

I had the same problem and it was resolved by using
route('your route name '['parameter 1','parameter2'])
$redirectUrls->setReturnUrl(route('your route name '['parameter 1','parameter2']));

Related

Graphaware neo4j-php-client | Cannot catch Neo4jException

I'm using Postgresql + Neo4j for my project. I need to rollback postgres queries if neo4j query has failed. So, I need to catch Neo4jException in my code. But couldn't done yet. Thanks for help.
require_once('pgconnect.php');
try{
$conn->beginTransaction();
//some pgsql code
$conn->commit();
require_once('neoconnect.php');
$result = $client->run("a query");
$conn = null;
}
catch(PDOException $e){
require_once('pgrollback.php');
}
this is my working code. But as you can see I don't have a catch block to catch neo4j exception. So I added this but no luck. also tried withNeo4jExceptionInterface as exception class (desperate times). (BTW I'm using wrong typed query to get exception)
catch(Neo4jException $ex){
//done smth
}
Also tried to do this without luck too.
$client->run("a query") or throw new Neo4jException();
I just tested and I have no issues catching an exception, can you maybe provide more code, what is in neoconnect.php for example ?
This is my test :
$client = ClientBuilder::create()
->addConnection('default', 'http://localhost:7474')
->build();
$query = 'INVALID QUERY';
try {
$result = $client->run($query);
} catch (\GraphAware\Neo4j\Client\Exception\Neo4jException $e) {
echo sprintf('Catched exception, message is "%s"', $e->getMessage());
}
-
ikwattro#graphaware ~/d/g/p/neo4j-php-client> php test.php
Catched exception, message is "Invalid input 'I': expected <init> (line 1, column 1 (offset: 0))
"INVALID QUERY"
^"⏎

Unable to print error message in foreach in magento admin

Hi i have added a new mas action in the sales order grid which allow create batch invoices.
For this my controler file is
<?php
class Iclp_Batchupdate_IndexController extends Mage_Adminhtml_Controller_Action
public function batchinvoiceAction ()
{
$already = " already ";
$refererUrl = $this->getRequest()->getServer('HTTP_REFERER');
$this->loadLayout();
$this->renderLayout();
$orderIds = explode(",",$this->getRequest()->getParam('order_ids'));
foreach ($orderIds as $orderIdss) {
$order = Mage::getModel('sales/order')->load($orderIdss);
//echo $orderIdss ."<br/>";
//echo "already ".$order->getStatusLabel();
try
{
if(!$order->canInvoice())
{
echo Mage::getSingleton('core/session')->addError($orderIdss.$already.$order->getStatusLabel());
}
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
if (!$invoice->getTotalQty()) {
Mage::throwException(Mage::helper('core')->__('Cannot create an invoice without products.'));
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();
$transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
$transactionSave->save();
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
//echo "Invoice are created";
}
catch (Mage_Core_Exception $e) {
}
}
//A Success Message
Mage::getSingleton('core/session')->addSuccess("Some success message");
//A Error Message
Mage::getSingleton('core/session')->addError("Some error message");
//A Info Message (See link below)
Mage::getSingleton('core/session')->addNotice("This is just a FYI message...");
//These lines are required to get it to work
session_write_close();
$this->getResponse()->setRedirect($refererUrl);
}
}
every thing is working fine but the problem is it is not printing the error message in foreach in above code
if(!$order->canInvoice())
{
echo Mage::getSingleton('core/session')->addError($orderIdss.$already.$order->getStatusLabel());
}
but the bottom error message are displayed properly. MOreover if i extend the class with front-action than it also prints the foreach messages. Please suggest where i am doing the mistake
You should add your errors and messages to admintml/session and not to core/session when you are in adminhtml. That should display the message correctly. You shouldn't need session_write_close();. There is also no need to echo the message, that should be handled automatically by Magento after the redirect.
There is also no need to call $this->loadLayout(); and $this->renderLayout(); because you are redirecting at the end.
Finally, regarding the redirect, you should not read the referrer yourself, Magento can to that for you more reliably. Just use the $this->_redirectReferer(); method instead of $this->getResponse()->setRedirect($refererUrl);.

CakePHP requestAction catch error when url not exists

I try to catch error when the requested url does not exist in my application when I use requestAction($url);
with try-catch block, requested wrongs url continue to be loaded;
Please tell me if there is an other solution to test if the url exist, or if the file exist in cakephp dir (my url can be composed of a plugin name).
my actual code:
$url = $appliUrl . $cron['Cron']['plugin'] . '/'. $cron['Cron']['controller'] . '/' . $cron['Cron']['action'];
if (!empty($cron['Cron']['params'])) {
$params = explode(',', $cron['Cron']['params']);
foreach ($params as $param)
$url .= '/' . $param;
}
try{
$output = $this->requestAction($url);
}catch (Exception $e){
$output = "error in the url : ".$url;
}
You can use a variety of methods to accomplish this. In this example, use cURL.
function url_exists($url) {
if (!$fp = curl_init($url)) return false;
return true;
}
Then you can wrap your $output in an if block checking for the url.
if (url_exists($url)) {
$output = $this->requestAction($url);
}
EDIT
Make sure you put the function in a lib or your bootstrap for access. Don't just stick it in your controller like that :)
ANOTHER EDIT
<?php
$ch = curl_init('http://yoururl/');
curl_setopt($ch, CURLOPT_NOBODY, 1);
$c = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);

Breadcrumbs Symfony

I'm using an old version of symfony 1.0.11
slot('breadcrumbs');
include_component('page','breadcrumbs',array('past_pages'=>array(
'/module/action/parameter/value'=>'Home ')));
end_slot();
The problem with this code is that parameter and value do not get passed, so If i click on home i get /module/action but the parameters are not being passed. Any suggestions?
Thanks.
There is also a way automatically set the breadcrumbs this is in the breadcrumbs actions:
// Get the full path without get parameters
$fullPath = $request->getPathInfo();
// get the get parameters
$urlParams = $request->getGetParameters();
// set get parameters as string for url
$this->extend = "";
foreach ($urlParams as $key => $urlParam) {
if (empty($this->extend)) {
$this->extend = "?";
}
this->extend .= $key."=".$urlParam;
}
// Get the URL path and Explode by /
$paths = explode('/', $fullPath);;
$this->paths = $paths;
then in the component itself, you can foreach through the paths and if empty just continue. And always give the GET variables with the link if the browser has some.
Home
<?php foreach($paths as $path):
if(empty($path))
continue;
if(empty($fullPath))
$fullPath = "";
$fullPath .= "/".$path.$extend;
$path = str_replace("-", " ", $path);
?>
<?php if(key($paths->getRawValue()) != (count($paths)-1)): ?>
<?php echo ucwords($path); ?>
<?php else: ?>
<span><?php echo ucwords($path); ?></span>
<?php endif; ?>
This way you never have to set your breadcrumbs if you have a correct url structure.
the way i fixed it is
include_component('page','breadcrumbs',array('past_pages'=>array(
'/module/action?parameter=value'=>'Home ')));

SOAP request in iOS

I have this SOAP request that I use in php to get some information, but I can't seem to figure out how to do this in Xcode, hopefully somebody can point me in the right direction
<?php
$wsdl_url = "https://www.service.com/mySoapService.wsdl";
$client = new SoapClient($wsdl_url);
var_dump($client->__getFunctions());
try {
$userName = 'myUsername';
$password = 'myPassword';
$result = $client->retrieveUsage(new SoapParam(array("UserId" => $userName, "Password" => $password), "RetrieveUsageRequestType"));
print '<pre>';
print_r($result);
print '</pre>';
} catch (Exception $e) {
echo $e->getMessage();
}
?>
Add your WSDL, create stubs and off you go, start using your web-service from iOS apps.
http://sudzc.com/
I hope this is what you are looking for.
Enjoy!
I used http://easywsdl.com to generate classes. Works perfect with my WS

Resources