Hello everyone,
I am new to paypal but now the basics of cakephp, rightnow I am making a paypal integration with cakephp but unable to pass the value to the paypal. I'm showing you my code. Please tell me if I'm doing something wrong.
function paypal()
{
if($this->request->is('post'))
{
echo $item_name_1=$this->request->data['Choose']['item_name_1'];
echo"<br>";
echo $amount_1=$this->request->data['Choose']['amount_1'];echo"<br>";
echo $item_name_2=$this->request->data['Choose']['item_name_2'];echo"<br>";
echo $amount_2=$this->request->data['Choose']['amount_2'];echo"<br>";
echo $cmd=$this->request->data['Choose']['cmd'];echo"<br>";
echo $business=$this->request->data['Choose']['business'];echo"<br>";
echo $upload=$this->request->data['Choose']['upload'];echo"<br>";
echo $currency_code=$this->request->data['Choose']['currency_code'];echo"<br>";
echo $item_number_1=$this->request->data['Choose']['item_number_1'];echo"<br>";
echo $item_number_2=$this->request->data['Choose']['item_number_2'];echo"<br>";
$this->redirect('https://www.paypal.com/cgi-bin/webscr?cmd='.$cmd.'&upload='.$upload.'&business='.$business.
'¤cy_code='.$currency_code.'&item_number_1='.$item_number_1.'&item_name_1='.$item_name_1.
'&'.'amount_1='.$amount_1.'&item_number_2='.$item_number_2.'&item_name_2='.$item_name_2.'&'.'amount_2='.$amount_2);
}
}
I'm passing all the view values(including hidden fields) to my controller(all values are displaying correctly) and redirecting it to the paypal site. Here I'm sending multiple values but I'm getting error like this:
This recipient is currently unable to receive money.
If i write the same code in corephp then values are reaching to the paypal and everything working fine, please tell me where I'm getting wrong.
First off, you should prepare your code in the Controller:
function paypal(){
$this->set('paypalData', $this->request->data['Choose']);
}
... and then create a form (in a view) which is POSTed to the PayPal site:
//file: Views/ControllerName/paypal.ctp
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="amount" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="item_name_1" value="<?php echo $paypalData['item_name_1']; ?>">
<input type="hidden" name="item_number_1" value="<?php echo $paypalData['item_number_1']; ?>">
<input type="hidden" name="amount_1" value="<?php echo $paypalData['amount_1']; ?>">
<input type="hidden" name="currency_code" value="<?php echo $paypalData['currency_code']; ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
The user would then click the button to go to PayPal, which is more reliable (and right :D). The url which you are redirecting to might fail in many ways, since your values are not url_encoded, might get too long, etc..
Second: Your error is probably popping up because you are using www.paypal.com instead of www.sandbox.paypal.com
Third: I copied the HTML above to ease the viewing, you should be using the Form helper inside the view to ensure proper HTML formatting.
Fourth: ECHOing inside a Controller action is just wrong. Especially so, if you are redirecting after making output. Redirects will not work if any output is sent to the browser.
Hope this gets you in the right direction.
Related
I couldn't find any similar questions (most dealt with broken form posts) but this is not the case.
I have a paypal form that works flawlessly on desktop/laptop. On mobile devices I successfully get to paypal but there is nothing in the order summary, as if nothing got posted to paypal. A variable dump shows all form variables are in place, so I'm quite confused.
Here is the form I submit:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="myRegister">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="service#obscured.com">
<input type="hidden" name="item_name" value="Some description.">
<input type="hidden" name="amount" value="5.00">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="item_number" value="1248" />
<input type="hidden" name="cbt" value="Click This Button To Register." />
<input type="hidden" name="return" value="http://mydomain/redirect.cfm" />
</form>
And that works on Desktop. I am just trying to get it work within a phone browser at the moment. I'll deal with the Paypal phone app at another time, if needed.
Any help appreciated.
Edit: This is also happening with PayPal hosted Buy It Now buttons as well.
Your code works fine for me on mobile, I can see the order details by tapping the "My total". The details are hidden at the first place though, I have to tap to make it show, seems it's designed this way
Within Android browser settings, clear setting for individual websites: Settings > Content Settings > Website Settings. Select paypal.com. Apparently there was a issue that was not resolved just by clearing the browser cache.
I have a two forms in my application.
In the first one the user sets his data. When submitted the form data gets checked and an entry is made into a database with $http.
The second one is hidden and contains the payment parameters for either paypal or amazon payments.
I need one of two solutions (I can do A but my gut feeling is that B is better):
A)
Trigger the submit function of form B when the promise of form A's http is resolved.
This would be one solution which is not very good I guess:
HTML
<form method="POST" action="{{spendenController.paypal.actionUrl}}" target="_top" id="paypalForm">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="{{spendenController.paypal.accountEmail}}">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="lc" value="DE">
<input type="hidden" name="amount" value="{{spendenController.spenden.amount}}">
<input type="hidden" name="item_name" value="Spende">
<input type="hidden" name="notify_url" value="{{spendenController.paypal.notifyUrl}}">
<input type="hidden" name="return" value="{{spendenController.paypal.successRedirectUrl}}" />
<input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_donateCC_LG.gif" border="0" name="btnSubmit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
Controller
document.getElementById('paypalForm').submit()
B)
Or load a page with POST params directly from the controller/a service when the promise is resolved. In that case I wouldn't even need the second form.
Question: How to open a page with POST from the controller?
I do not just want to send POST data with $http.post I need the user to see the paypal checkout window in order to fulfill the payment.
I have an field where the id is set via php:
<input name="user_id" type="text" value="<?php echo $this->r->user_id; ?>" ng-model="entry.user_id" >
But the value does not appear in the field.
How can I set it from php to angular js?
Set the initial value of the ng-model using ng-init instead:
<input name="user_id" type="text" ng-model="entry.user_id" ng-init="entry.user_id = <?php echo $this->r->user_id; ?>" >
I'm not sure about the php syntax, but this will set value for you as long as the controller has an entry object available.
<input type="text" ng-model="enquiry.companyName" ng-init="enquiry.companyName='<?php echo $_SESSION['COMPANYNAME'] ?>'" name="companyName">
Sigle quote around php block is important.
You might want to try ng-value as well. Might fit your situation better. I didn't come across it until today:
<input name="user_id" type="text" ng-value="<?php echo $this->r->user_id; ?>" ng-model="entry.user_id" >
I am learning word press. I have 2 questions
I have created a page and assigned my template file for it.
1. Question
How to get my form input values in same page or in another page template?
<form id="formId" action="" method="post">
<input style="width:88%" type="text" name="name">
<input type="submit" name="subs" value="Submit" />
</form>
In same file I put:
<?php
if( isset($_POST['subs']) ) {
echo $_POST['name'];
}
?>
I also tried $_SERVER['PHP_SELF']; in action but it's not displayed.
How could I store it in my own table?
When click submit, it refreshes and displays "No Results Found".
2. Question
How to show the submitted values in wp-admin?
Here's the word press code flow I can't solve.
Change Form action to the same page:
<form action="<?php the_permalink(); ?>
try to use
action="<?php echo get_permalink(); ?>"
instead of
action="<?php echo $_SERVER['PHP_SELF']; ?>"
in your form
The Form helper in cakephp
echo $form->input('Firstname', array('class'=>'test','name'=>'Firstname','type'=>'text'));
generates me like the following
<div class="input text">
<label for="Firstname">Frrstname</label>
<input type="text" id="Firstname" value="" class="test" name="Firstname"/>
</div>
is it possible to add a Break between label and input within the DIV .. If so how .. please suggest
I would suggest not adding the break.
Just use css:
label{display:block}
would achieve the same result.
echo $form->input('Firstname', array( 'between'=>'<br />','class'=>'test','name'=>'Firstname','type'=>'text'));