Paypal sandbox error: You have requested an outdated version of PayPal - php

You have requested an outdated version of PayPal. This error often
results from the use of bookmarks.
I get this error when I login via a buyer account in sandbox mode.
my view file:
<html>
<body>
<form method="post" action ="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="return" value="<?php echo $this->config->item('returnurl');?>" />
<input type="hidden" name="cmd" value=" " />
<input type="hidden" name="business" value="<?php echo $this->config->item('business');?>" />
<!--product 1-->
<input type="hidden" name="item_name_1" value="prod 1" />
<input type="hidden" name="item_number_1" value="p1" />
<input type="hidden" name="amount_1" value="2" />
<input type="hidden" name="quantity_1" value="1" />
<input type="submit" name="paypalbtn" value="buy with paypal">
</form>
</body>
</html>
my config file : paypal.php
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
$config['authtoken']='IDENTITY_TOKEN';
$config['posturl']='https://www.sandbox.paypal.com/cgi-bin/webscr';
$config['business']='DUMMY_FACILITATOR_EMAIL_ID';
$config['returnurl']='http://localhost/events/event_pay/success/';
$config['cancel_return']='http://localhost/events/event_pay/pay_fail';
?>
my controller file:
<?php
class event_pay extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('mdl_pay');
}
function index()
{
$this->load->view('demo');
}
function showplans()
{
$this->load->view('vw_header');
$this->load->view('vw_eventplans');
$this->load->view('vw_footer');
}
function check_events_by_user()
{
$u_id=37;
$numberofrows =$this->mdl_pay->has_paid($u_id);
echo $numberofrows;
}
function pay_success($data)
{
echo "return url function";
$this->load->view('success',$data);
}
function pay_fail()
{
echo "payment failed";
}
function success()
{
$res = $this->verifyWithPayPal($_GET['tx']);
$this->load->view('success_pay',$res);
}
function successdemo()
{
$this->load->view('vw_success_pay');
}
public function verifyWithPayPal($tx)
{
$token = $this->config->item('authtoken');
$paypal_url = $this->config->item('posturl').'?cmd=_notify-synch&tx='. $tx.'&at='.$token;
$curl= curl_init($paypal_url);
$data=array(
"cmd"=>"_notify-synch",
"tx"=>$tx,
"at"=>$token
);
$data_string=json_encode($data);
curl_setopt($curl,CURLOPT_HEADER, 0);
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$headers= array(
'Content-Type:application/x-www-form-urlencoded',
'Host: www.sandbox.paypal.com',
'Connection: close'
);
curl_setopt($curl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($curl,CURLOPT_HTTPHEADER, $headers);
$response= curl_exec($curl);
$lines= explode("\n", $response);
$keyarray = array();
if(strcmp($lines[0],"SUCCESS")==0){
for($i=1;$i<count($lines)-1; $i++){
list($key,$val)=explode("=",$lines[$i]);
$keyarray[urldecode($key)]=urldecode($val);
}
$this->getListProducts($keyarray);
}
}
public function getListProducts($result)
{
$i=1;
$data = array();
foreach($result as $key => $value)
{
if(0===strpos($key,'item_number')){
$product = array(
'buyer_firstname' => $result['first_name'],
'buyer_lastname' => $result['last_name'],
'buyer_street' => $result['address_street'],
'buyer_city' => $result['address_city'],
'buyer_zip' => $result['address_zip'],
'buyer_state' => $result['address_state'],
'buyer_country' => $result['address_country'],
'buyer_country_code' => $result['address_country_code'],
'buyer_address_status' => $result['address_status'],
'buyer_pp_email' => $result['payer_email'],
'receiver_pp_email' => $result['receiver_email'],
'transaction_id' => $result['txn_id'],
'transaction_type' => $result['txn_type'],
'buy_date' => $result['payment_date'],
'buyer_pp_id' => $result['payer_id'],
//'address_name' => $result['address_name'],
'receiver_pp_id' => $result['receiver_id'],
'receiver_pp_email' => $result['receiver_email'],
'itemnumber' => $result['item_number'],
'itemname' => $result['item_name'],
'itemquantity' => $result['quantity'],
'mc_currency' => $result['mc_currency'],
'mc_fee' => $result['mc_fee'],
'mc_gross' => $result['mc_gross'],
'payment_gross' => $result['payment_gross'] ,
'paypal_pay_time' => date('Y-m-d H:i:s'),
);
$this->mdl_pay->insert_record($product);
echo "<script>alert('Payment Successful!')</script>";
}
}
echo "return statement:at end of for loop ";
return $product;
}
}
?>

The problem was occuring due to this line:
<input type="hidden" name="cmd" value="" />
I replaced it with:
<input type="hidden" name="cmd" value="_xclick" />

Read: https://github.com/websharks/s2member/issues/826 , if this doesn't work contact paypal support, there's not much we can do here.

Related

Why does the validation for my codeigniter website fail everytime?

I have a controller code like so:
$validation=service('validation');
$validation->reset();
$data = [
'validation' => $validation,
];
if ($this->request->getMethod() === 'post'){
$validation->setRules( [ 'comment' => 'required',] );
if($validation->run()) {
$CommentsModel->save(['Comment' => $this->request->getPost('comment'),]);
return redirect()->to('/someplace...');
}
}
}
return view('templates/header', $data)
. view('templates/menu')
. view('addComment', $data)
. view('templates/footer');
}
Everytime my form is posted, the validation fails... even when I have something in comment! Any idea why this would be?
This is the form:
<form action="/Add/<?= esc($book)?>/<?= esc($chapter) ?>" method="post">
<?= csrf_field() ?>
<label for="comment">Comment</label>
<textarea name="comment" id="comment" ><?= set_value("comment")?></textarea><br />
<?php if($validation->hasError('comment')) echo '<p class="validationError">' . $validation->getError('comment') . '</p>'?>
<input type="submit" name="submit" value="Add Comment" />
</form>

How to call overrider controller from html form

Like in topic. How can I call the overrider controller from html form like this below:
<form method="post" action="index.php?controller=CmsController">
<input name="test" type="text" />
<input name="action" value="getStatus" type="hidden" />
<input value="test" type="submit" />
</form>
This code above I have in my tpl file.
File: /override/controllers/front/CmsController.php
---edit
{$link->getModuleLink('blockcms', 'CmsController')|escape:'html'}
doesn’t work.
---edit
public function initContent() {
parent::initContent();
if (Tools::getValue('action') && Tools::getValue('action') == 'getStatus') {
$id = $this->getIdByCode(Tools::getValue('voucher'));
$obj = new CartRuleCore($id);
$context = Context::getContext();
$response = $obj->checkValidity($context);
if ($response == NULL or $response == 'Koszyk jest pusty'){
$response = 'Kod ';
}
}
if (isset($this->cms)) {
$this->cms->content = str_replace("<!--response-->", $response, "{$this->cms->content}");
}
$this->setTemplate(_PS_THEME_DIR_ . 'cms.tpl');
This is part of initContent function in \override\controllers\front\CmsController.php And in my file tpl I have
<form method="post" action="index.php?controller=CmsController">
<input name="test" type="text" />
<input name="action" value="getStatus" type="hidden" />
<input value="test" type="submit" />

Codeigniter - Displaying page

I'm having a problem displaying my index.php in codeigniter. Can someone help me with this?
Here's my index.php:
<form id="myForm" action="<?php echo baseurl('controller/CreateUser'); ?>" method="post">
Name: <input type="text" name="name"/><br/>
Username: <input type="text" name="username"/><br/>
Password: <input type="password" name="password"/><br/>
<button id="sub">Save</button>
</form>
<span id="result"></span>
And here's my controller:
public function index(){
$this->load->view( 'layouts/header', [ 'title' => 'Never Stop Learning!' ] );
$this->load->view( 'NeverStopLearning/index');
$this->load->view( 'layouts/footer' );
}
public function CreateUser(){
$data = array(
"name" => $this->input->post("name"),
"username" => $this->input->post("username"),
"password" => $this->input->post("password")
);
if($this->model->Insert('table_users', $data)){
echo "Successfully Inserted";
}else{
echo "Insertion Failed";
}
}

Codeigniter insert array into database

I am currently making a registration form where in you could register individually or by many I need a way how to make the multiple register work i cant add the input into db i get an array to string conversion error
i still dont have the model for this
my code is
controller
public function registerbatch(){
for ($i = 0; $i < count($this->input->post('surname','firstname','age','school','course','email')); $i++) {
$this->form_validation->set_rules("surname[$i]", "surname[$i]", "required");
$this->form_validation->set_rules("firstname[$i]", "firstname[$i]", "required");
$this->form_validation->set_rules("age[$i]", "Age[$i]", "required");
$this->form_validation->set_rules("school[$i]", "School[$i]", "required");
$this->form_validation->set_rules("course[$i]", "Course[$i]", "required");
$this->form_validation->set_rules("email[$i]", "Email[$i]", "required");
}
if ($this->form_validation->run() == TRUE) {
$reg_dat = array(
'surname' => $this->input->post('surname'),
'name' => $this->input->post('firstname'),
'age' => $this->input->post('age'),
'school' => $this->input->post('school'),
'course' => ($this->input->post('course')),
'email' => ($this->input->post('email')),
);
$this->user_model->add_user($reg_dat);
$this->load->view('user/home_view');
} else {
$this->load->view('user/batch_register');
}
view:
<html>
<head>
</head>
<body>
<form class="form" action="<?php echo base_url() . 'user/registerbatch'; ?>" method="post" class="form-horizontal" role="form">
<?php for ($i = 0; $i < $num; $i++): ?>
<br>
Surname: <input type="text" name="surname[]">
<br>
Name: <input type="text" name="firstname[]">
<br>
Age:<input type ="int" name ="age[]">
<br>
School: <input type="text" readonly value="<?= $school ?>" name="school[]">
<br>
Course:<input type ="text" name ="course[]">
<br>
Email:<input type ="text" name ="email[]">
<br>
<br>
<?php endfor ?>
<button type="submit" class="btn btn-success">Register</button>
</body>
</html>
Try this below coding ....
if ($this->form_validation->run() == TRUE) {
extract($_POST);
foreach($surname as $key=>$value) {
$reg_dat = array(
'surname' => $value,
'name' => $firstname[$key],
'age' => $age[$key],
'school' => $school[$key],
'course' => $course[$key],
'email' => $email[$key],
);
$this->user_model->add_user($reg_dat);
}
}
$this->load->view('user/home_view');
Seems that your Post can be a multidimensional array. I think the best way to solve your problem is to foreach that post and insert every row
//your controller
if ($this->form_validation->run() == TRUE) {
$reg_dat_multi = $this->input->post();
foreach ($reg_dat_multi as $reg_dat) {
$this->user_model->add_user($reg_dat);
}
);
you didn't show your model but let's think that is something like this
//your model
function add_user($reg_dat){
if ( $this->db->insert('table', $reg_dat) ){
return true;
}
return false;
}
hope that helps

How to submit a form with PHP?

<form style="text-align:center;" id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='business' value='payment#xxx.com'>
<input type='hidden' name='item_name' value='201001114262121'>
<input type='hidden' name='amount' id="amount" value='1.00'>
<input type='hidden' name='currency_code' value='CAD'>
<input type='hidden' name='return' value='http://www.xxx.com/paypal_process.php'>
<input type='hidden' name='invoice' value='82'>
<input type='hidden' name='charset' value='utf-8'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='no_note' value=''>
<input type='hidden' name='notify_url' value='http://www.xxx.com/return.php'>
<input type='hidden' name='rm' value='82'>
<input type='hidden' name='cancel_return' value='http://www.xxx.com/index.html'>
</form>
Anyone knows?
<?php
if(isset($_POST['submit']))
{
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if($optional_headers != null)
{
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = #fopen($url, 'rb', false, $ctx);
if (!$fp)
{
throw new Exception("Problem with $url, $php_errormsg");
}
$response='';
while (!feof($fp))
{
$response = $response.fgets($fp);
}
if ($response === false)
{
throw new Exception("Problem reading data from $url, $php_errormsg");
}
fclose($fp);
return $response;
}
$host = 'http://mydomain.com';
$url = 'http://mydomain.com/formHandler.php';
$username = 'admin';
$password = '123456';
$data = array ('action' => 'login','lgname' => $username, 'lgpassword' => $password, 'format' => 'txt');
$data = http_build_query($data);
$reply = do_post_request($url, $data);
echo "**********Response*********<pre>";
echo var_dump($reply);
#header('location:'.$host);
#exit;
} else {
echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="uname" /><br><input type="password" name="password" /><input type="submit" name="submit"></form>';
}
?>
Try this
If you're wanting this form to submit as soon as the page is loaded, you can add this to the bottom of the page if you're determined in using PHP to submit the form:
<?
echo "<script type=\"text/javascript\">
window.onload=function(){
document.forms['paypalform'].submit();
}
</script>";
?>
But that seems like a long way around it. You could just write the javascript into the page... maybe I'm not sure what you're wanting to do, but I thought I'd throw this out.
Using javascript you can submit the form inside PHP code like this:
(trick is in last line )
$paypalURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
$paypalID = 'xyz-merchant#gmail.com';
$form = "<form id='paypal' action='". $paypalURL."' method='post'>";
$form .='<input type="hidden" name="business" value="'. $paypalID.'">';
$form .='<input type="hidden" name="cmd" value="_xclick">';
$itemDetail = "Detail goes here";
$orderId = 4444;
$totalAmountWithFee = 55;
$form .='<input type="hidden" name="item_name" value=" '.$itemDetail.'">
<input type="hidden" name="item_number" value="'.$orderId.'">
<input type="hidden" name="amount" value="'.$totalAmountWithFee.'">
<input type="hidden" name="currency_code" value="USD">';
$form .="<input type='hidden' name='cancel_return' value='http://localhost/public/cancel.php'> <input type='hidden' name='return' value='http://localhost/success.php'>";
$form.="<script type=\"text/javascript\"> document.forms['paypal'].submit();</script>";
echo $form;
If someone has a good idea pls share.
You can submit an HTML form from php with fsubmit PHP library https://github.com/randomsymbols/fsubmit
require_once 'fsubmit.php';
$html = '<form action="backend.aspx" method="post"><input type="text" name="question"></form>';
$form = new Fsubmit();
$form->url = 'http://the_url_must_contain_action_url_base'; // If form action is a relative link, then url is a required parameter, if form action is an absolute link, then this parameter can be omitted
$form->html = $html;
$form->params = ['question' => 'To code or not to code?', 'extra_question' => 'In what language?'];
$answer = $form->submit();
echo $answer['content'];
You can submit an HTML form from a PHP script with cURL or this library (that is based on cURL and simple html dom).

Categories