Paypal IPN process more than one custom variable - paypal

So I've implemented paypal IPN in my site and I'm in the middle of the
work process. Now I want to use more than 1 custom variable in the pp form
currently I'm using this one only
<input type="hidden" name="custom" value="<?php echo $user_id; ?>">
So I know the variable with the name 'custom' is allowed. I want to know if
I can pass more variables so I can filter the payments based on their criterias.
So if for example shipping is more than $0.00 I set a variable "shipping_cost" like this:
<input type="hidden" name="shipping_cost" value="<?php echo $cost; ?>">
or for other purposes. Is this allowed? Or paypal has an already defined list of allowed
variables we can use? I really want to solve this problem as there's not always one type
of payment we can process...
Thank you guys.

this way you can pass more parameters
<input type="hidden" name="custom" value="variable1=234&var2=summa&etc=xyz"/>
use the above one on your paypal form.
and process through the following code.
parse_str($_POST['custom'],$_MYVAR);
echo $_MYVAR['variable1'];
echo $_MYVAR['var2'];
echo $_MYVAR['etc'];
i hope this one help you.

As I (and many others I imagine) am also facing this problem, I thought I'd share some solutions I came across.
This one raised in the PayPal Community, suggests the use of the Option Variables which appear to offer a key/value pair implementation to facilitate up to 99 vars (for the record I have not actually tried this).
The most commonly accepted solution (which I also favor) is to add all of your data to a DB record, then use the custom var to store your record ID, which can obviously be used later (e.g. via IPN) to retrieve your data.

PayPal defines what fields you may use here. Any other fields will be ignored.
There is a 'shipping' field defined, and PayPal will use the value of that field to charge an extra amount for shipping. You will also be able to get that value from the IPN or PDT data.
If you need to pass other values, you could consider passing a string formatted in query-string style (var1=value1&var2=value2...) in the 'custom' field. Note that the maximum number of characters permitted in this field is 256. You would then parse this when you get the IPN or PDT response.
If the size of the custom field is too limiting, then you could try what I described in another answer here.

Related

How to add longer "item_name" using a Paypal form?

I'm creating a webpage for a client where the user can select multiple options for an item, and then send that information directly to Paypal with a Buy Now button.
Everything works but I can't put a description longer than 125 characters it seems (in the item_name field).
any ideas on how to send all the info onto paypal? ( I would need around 250 chars )
Thanks!
"item_name" value can only be 127 Character Length, however you can also pass the variable "item_number" (127 Character Length) to track product or service purchased (this value is also visible to buyers).
Example:
<input type="hidden" name="item_name" value="T-shirt AB Black">
<input type="hidden" name="item_number" value="APB9823400f">
Ref. https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
And for internal reference, you can also pass "custom" variable (256 Character Length), Pass-through variable for your own tracking purposes, which buyers do not see.
In alternative, you might consider "Add to Cart" buttons with Upload command, you can find instructions and examples here: https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/cart_upload/

HTML Form "value=[Non-Static]"

Current:
<input type="hidden" name="subject" value="| Website Owners Co. - Web Referral |" />
In a Perfect World, The following is Basically what I want it to do.
<input type="hidden" name="subject" value="| UserInput "Location" , UserInput "Date Set" |" />
IN the form itself, I would like to call upon the "Location" that the user has set, AND the "Event Date" that the user has set.
So you really get the Idea, the Form asks for the . . .
Event Date (Drop Down Values) m/d/y
Event Location (Text Field)
Can the [Subject] Line of the email be non-static in this way?
Can this be done simply? Im not that great with code beyond css/html.
You don't state what language for server side scripting you are using to process your form and it isn't tagged. If using PHP would suggest the following.
So, you want to submit a form, do some processing and then send an email using fields submitted in the form as the subject title?
In your form processing page just use something like the following using you are using method=POST and the field names are event_location and event_date. If you are creating the subject from the two submitted values you really do not need to submit subject as a hidden form field.
After the form is submitted you should be able to grab the contents of the two fields and then concatenate them together to create a new email subject variable.
$email_subject = $_POST['event_location']. ", ". $_POST['event_date'];
In PHP it would be done this way. I guess it depends on how you are processing your form.

CGI Perl - changing action and mode variables

I am somewhat of a novice with CGI Perl and am working on a web app that uses 'mode' and 'action' variables to determine which pages load.
$mode = param('mode');
$action = param('action');
if ($mode eq 'page1') {
if ($action 'eq') {
&performAction;
}
displayPage1;
}
elsif ($mode eq 'page2') {
&displayPage2
}
During development I have been having trouble figuring out the best way to set these variables when trying to navigate to different modes/actions after a form submit.
In some cases, putting a hidden value in the form will work
hidden(-name=>'action',-value=>'save')
but sometimes it will not. In case of the latter, putting param('action',"save") before the form will make the action change when the form is submitted.
I am unable to figure out why this happens though, are there factors that affect these two variables that I am unaware of?
What I now need to do is have two buttons on the same form, one which will just set the action to save the form data, and another which will save the form data but navigate to another mode/page with that form data.
If anyone could at least point me in the right direction for what I should be researching I would be greatly appreciative.
By default the CGI module implements a state-preserving behavior called "sticky" fields. The way this works is that if you are regenerating a form, the methods that generate the form field values will interrogate param() to see if similarly-named parameters are present in the query string. If they find a like-named parameter, they will use it to set their default values.
You want
hidden(-name=>'action', -value=>$new_value, -override=>1)
or
hidden(-name=>'action', -value=>'default_value')
param('hidden_name', $new_value);
This is a try , not sure if it would work.
Try setting hidden variable before button and changing it before every button, so the new value should be taken.
For ex:
<input type='hidden' name='op' value='save'/>
<input type='submit' name='Save Form' value='SaveForm'/>
<input type='hidden' name='op' value='submit'/>
<input type='submit' name='Submit Form' value='SubmitForm'/>
<input type='hidden' name='op' value='cancel'/>
<input type='submit' name='Cancel Form' value='CancelForm'/>
You can check for hidden variable 'op' in perl script.

Play 2.0 Nested forms: generate <input id="email"> instead of <input id="user_email">

Posted this to Play user group; I account for the sole view, so hoping to get a view, or perhaps even an answer ;-)
Nested forms are great, but there's one glitch that adds boilerplate to either javascript or scala templates.
For example, given:
#inputText(field = _form("user.email"),
'_label-> "Email Address*",
'class-> "required email",
'placeholder-> "jdoe#gmail.com"
)
the generated input field is something like:
<input id="user_email" name="user.email" ...>
Now, when you want to validate the email address client-side you then have to reference DOM id: $('#user_email')
Where $('#email') would be more natural.
I know I can set the id attrib manually in the template but would prefer to, by default, have the nested name (user in this case) stripped out from the id attrib.
Looking in github views helper directory, I am not finding where I can get access to the generated id (i.e. which file I need to overload and how).
Anyone know how to pull this off and/or have a better approach?
Here is where the field's ID is auto-generated:
https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/data/Form.scala#L274
There's not really any way you can override that behaviour, but you could write your own #inputText helper that strips the "user_" part from the ID when generating the HTML.
Basically copy-paste the default helper and replace
<input type="text" id="#id" ...
with your own code, e.g.
<input type="text" id="#processFieldId(id)" ...
or (untested!):
<input type="text" id="#(id.split('_').last)" ...
Then just import your custom helper in your template, and use it just like you would use #inputText.

Add logic to a form when Javascript is disabled

I'd like my form to include a certain value if the quantity is equal to 1 (via a text box).
I've managed to show what the total cost is using JavaScript and I could submit it with this value but I'm worried that when JavaScript is turned off the user will be able to submit the form without the extra fee being added. Therefor escaping the fee.
<form>
<label>Qunatity</label>
<input type="text" name="qyt" />
<input type="text" name="fee" value="250" />
<div class="total">[whatever the total is]</div>
<input type="submit" value="submit" />
</form>
Is there a way I can submit this form so that it submits 250 only if a quantity of 1 is added to the form? I'd like to avoid using a select input.
Will I need to split my form out into two stages to achieve this?
You need to check your logic in server-side code.
Most people have Javascript enabled, so you should do it in Javascript to provide a better experience, but you must always reproduce the logic on the server.
If you need to validate your input without JavaScript, have a server-side component (PHP?) to do the job and return the same form with an error message if no quantity was given. That way you don't have to split your form into two steps.
The best/safest way to handle this would be to do your total calculation on the server side. That way the data you store will always be correct.