Reputation: 2087
This is the flow of customers:
Visit Website -> Fill Out Form With Their Info -> Click "Buy Now" and Checkout with PayPal -> Be Returned Back To The Website -> Use Information Passed From Checkout From to Run PHP
script on server via ajax
(assuming the checkout was successful). Well, that's the plan anyways. The problem I am having is figuring out how to actually pass the variables (there are 8 total... array???. I currently have a quick checkout button on the website, which redirects the user away to PayPal to complete the transaction. I've been searching for a good tutorial on YouTube or here at S.O., but have been unsuccessful. Any ideas how I may accomplish this?
Thanks
Upvotes: 0
Views: 778
Reputation: 755
You can use json to pass multiple values via the custom
variable in PayPal..
Create your values:
$custom = array();
$custom['value1'] = "foo";
$custom['value2'] = "bar";
$custom = json_encode($custom);
Then you can POST
this data to somewhere:
<input type="hidden" name="custom" value="<?php echo htmlentities($custom) ?>"/>
then get the data from somewhere like this:
$data = json_decode($_POST['custom']);
echo $data->value2;
The output should be bar
Upvotes: 0
Reputation: 676
In your PayPal form, simply use something like the following for your custom field..
Example:
<input type="hidden" name="custom" value="<?php echo $custom1.','.$custom2.','.$custom3; ?>">
or;
<input type="hidden" name="custom" value="custom1,custom2,custom3">
In short the custom name is accepted by PayPal, and you would use commas to separate the variables.
PayPal will pass the custom field back to you, in the IPN.
EDIT:
Here's an example of what you might do with custom:
$custom = $_POST['custom'];
$pattern = ",";
$pieces = explode($pattern,$custom, 3);
// 3 is how many custom fields there are
$custom1 = $pieces[0];
$custom2 = $pieces[1];
if (isset($pieces[2])) {
//an example checking to see if there is a third custom variable
$custom3 = $pieces[2];
}
Upvotes: 1