Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

When can I safely redirect my buyer to a download site?


TechieTW

Recommended Posts

Hi,

I am selling downloadables. I need to redirect my buyer to a download site outside of osCommerce. I am using the Paypal_IPN module. I have my Paypal profile configured with Auto Return and IPN enabled.

 

I need to get the values for item_number and payer_email from the order data and redirect the buyer so that they can download my product from outside of osCommerce.

 

Can anyone tell me where it would be safe during the purchase process to insert my redirect? The name of the php page and line would really be helpful.

Don't give up. I see light ahead...!

Link to comment
Share on other sites

or checkout_success.php

 

That is what I was thinking of because of the redirect at the end of checkout_process.php. I really appreciate the help!

 

I also need to have products_id pass through Paypal as item_number. I believe I can do that from checkout_process.php, but have no clue where to do it at. Plus there may be mulitple items so I believe the products_id_x = item_number_x would apply. Could you help figure out where to place this and what the proper syntax would be? :blush:

Don't give up. I see light ahead...!

Link to comment
Share on other sites

You could just make the model number the same as your products ID, save doing code changes.

 

 

I love that idea! I changed the model number of the product in osCommerce but it's value is not passing through Paypal either. Do you know how I can auto poplulate the value for either variable to = the model# or products_id? :huh:

Don't give up. I see light ahead...!

Link to comment
Share on other sites

I was able to successfully add the redirect script at the bottom of checkout_success.php without messsing up the order (because it has already been processed)

 

Problem is pulling the values of the order that was just placed (I'm not that good with php) .. yet..

 

This is what I tried as far as getting values defined into variables for my redirect.

 

$payers_email='[customers_email_address]';

$item_number='[products_id]';

 

For some reason I feel like I should be pulling off of orders values but have no clue. Anyone? :blush:

Don't give up. I see light ahead...!

Link to comment
Share on other sites

Well, you had it all there at hand in checkout_process.php, but chose checkout_success :huh:

 

In checkout_process.php you have this:

 

  tep_session_unregister('sendto');
 tep_session_unregister('billto');
 tep_session_unregister('shipping');
 tep_session_unregister('payment');
 tep_session_unregister('comments');

 

A whole bunch of information unregistered from the session that you must now retrieve again from the database >_<

 

Why not redirect from checkout_process.php?

 

Sonia

Link to comment
Share on other sites

Sonia, You are absolutely correct. checkout_process.php is where I need to work. I was distracted by the redirect statement on line 276 and didn't even notice the lines right above it clearing the values! :-"

 

Primarily I need to get the value(s) for products_id_x. (x being the product number, per item in the transacton) and the email address of the customer so I can define the variables for the redirect. I am very new to this process but I can see that I would need to define $item_number = $products_id from inside a loop somehow to handle multiple items.

 

Could you help with a suggestion of where to put the statement to get the variable(s) defined or even point me in the right direction to get that help? The customer's email address would be constant so I would only have to get that defined once.

 

At this point I'm pretty much lost on what to do next and any help would be greatly appreciated. :(

Don't give up. I see light ahead...!

Link to comment
Share on other sites

All the products details are right there in the $order object:

 

$order->products

 

 

Just use the values that are there in checkout process - assign them to your post variables before they are unregistered from the session :)

 

 

Sonia

Link to comment
Share on other sites

All the products details are right there in the $order object:

 

$order->products

Just use the values that are there in checkout process - assign them to your post variables before they are unregistered from the session :)

Sonia

 

 

I tried inserting this loop at line 264 of checkout_process.php and I just cant get it to work. I am trying to define the $item_send = the model#, and the customer's email address as $email_send. Then depending on how many items are purchased in the transaction, loop that many times to send an individual email with a download link in it for each item. 5 items ordered = 5 emails, one for each item.

 

I am very new to php but eager to learn. Can you tell me what I am doing wrong? Am using the wrong variables?

 

// -------Send the buyer an email with a download link for each item ordered

$email_send = customer['email_address'];

for ($i=0, $n=sizeof($order_totals); $i<$n; $i++)

{

$item_send = products['model'];

sleep (1);

} include "http://mydomain.com/secretfolder/emailadownloadlink.php?email=$email_send&item=$item_send";

//---------End

Don't give up. I see light ahead...!

Link to comment
Share on other sites

You would do better to register your variables in the session and access them on your other page from that - you cannot post objects :)

 

Sonia

 

 

OK, so register the values in checkout_process.php and do the actual loop in checkout_success.php?

Don't give up. I see light ahead...!

Link to comment
Share on other sites

OK, so register the values in checkout_process.php and do the actual loop in checkout_success.php?

 

 

Perhaps if you better explain exactly what you are trying to achieve - why the redirect? If you are trying to send an email, why not just send it from checkout_process.php? What is on the page the user is redirected to?

You say your download site is 'outside osCommerce'... do you mean a different domain? If so, you will need to post the variables - there is a limit to what you can post and it must be in value pairs (again, you cant post an object). If it is on the same domain, then you are would do better to keep things 'inside osCommerce' (call application_top.php into the new page)

 

 

Sonia

Link to comment
Share on other sites

Perhaps if you better explain exactly what you are trying to achieve - why the redirect? If you are trying to send an email, why not just send it from checkout_process.php? What is on the page the user is redirected to?

You say your download site is 'outside osCommerce'... do you mean a different domain? If so, you will need to post the variables - there is a limit to what you can post and it must be in value pairs (again, you cant post an object). If it is on the same domain, then you are would do better to keep things 'inside osCommerce' (call application_top.php into the new page)

Sonia

 

 

I'm sorry for the confusinon. I sell downloadables. I validate the purchase during the installation process using an external processor to unlock my products.

 

The download data and links are processed outside of osCommerce. I need to send the customer's email address and item number(s) they purchased to this outside source after paying. (to other site) The other site generates an email (per item) that contains a download link. The purchase information is stored for later use when the customer registers their download at installation.

 

So, as you can see, I don't need to "send an email", I need to send two specific values per item to another processor so IT can send the email that contains the link to download and store the data for validation.

 

There may be more than one item number purchased during the payment session. I need to define a static variable '$email_send' = the buyer's email address and a array variable '$item_number(x) = each item purchased. I need to send this information from inside a loop, per item number as the external processor handles each item one item at a time.

 

I also need to define (prepopulate) the Paypal variable $item_number using the osCommerce product's 'model' value so it will 'pass through' Paypal and be used in the loop as $item_number(x)

 

The Basic Flow: Buyer checks out of osCommerce, pays using PayPal_IPN, is Auto returned back to the store (checkout_process.php), purchse is verified and the order is processed without the buyer's interaction, behind the scenes, I need to send the data, the customer ends up at checkout_success.php then checks email and gets a seperate email for each item purchased (contains a download link), customer downloads and installs.(there are no downloads from the store directly)

 

During installation, the purchase is verified with the information stored from the looped process and the product is unlocked.

 

1. Where and how can I prepopulate the value for Paypal variable $item_number(x) so it passes through using either the products_id value or better yet 'model'.

 

2. Where and how do I define the variables I need to send outside of osCommerce. (what .php page and how) <<buyer's email address and the item numbers they purchased.>>

 

3. Where and how do I utilize the loop to send the newly defined variable data? (what .php page and how)

 

Again, I apologize for any misunderstanding or confusion. I am really trying my best to get the right syntax to this process but am new to PHP. Any help would not only be extremely helpful, but educational for me as well. I just need a little help. :blush:

Don't give up. I see light ahead...!

Link to comment
Share on other sites

Number 1. I already answered :)

 

2 & 3 also in some detail. Now that you have been a little more specific it becomes quite simple. You wish to post variables to another server, so use curl.

 

The loop is already there in checkout_process.php, so we'll use it.

 

Find the products loop that begins like this:

 

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

 

At the end of the loop, before the closing bracket } (just before the email part) place the following:

 

$prod = $order->products[$i]['model'];
$email = $order->customer['email_address']; 

$url="yoursite.com/script.php";
$so = curl_init();	
curl_setopt($so, CURLOPT_URL,"http://$url");  
curl_setopt($so, CURLOPT_POST, 1);
curl_setopt($so, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($so, CURLOPT_POSTFIELDS, "value1=$prod&value2=$email");
curl_exec ($so);	 
curl_close ($so);

 

Change the $url value to the remote site/script you are connecting to

Change 'value1' and 'value2' to whatever your post variables must be named

 

This will connect to the remote server for each product in the order

 

Thats it!!

 

 

Sonia

Link to comment
Share on other sites

I did as you recommended and it does not work. I checked the syntax for the curl routine against my PHP manual and everything looks absolutely perfect. But it does not work for some reason.

 

I noticed that the value for $order->products[$i]['model']; isn't defined that early in the page where you suggested to put the routine, so I moved the process down below where it was defined, after the loop ending around line 240. Then I defined my own loop for the routine using the same parameters as the existing loop you suggested, (removed the $url and just hard coded it as it is constant anyhow) and still nothing. Is there a way to halt the process so I can see the values of the variables? I tried using a javascript alert window but it does not work after the <?php statement at the begining of the page. Only outside of the php section. I'm firstly interested to confirm that the variables are in fact being defined properly, if they are not, this would be why the external processor is not generating emails.

 

Here is what I have: (as you can see I defined everything the way you advised.)

 

for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

$email = $order->customer['email_address'];

$item = $order->products[$i]['model'];

$so = curl_init();

curl_setopt($so, CURLOPT_URL,"http://mydomain.com/myfolder/externalprocessor.php");

curl_setopt($so, CURLOPT_POST, 1);

curl_setopt($so, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($so, CURLOPT_POSTFIELDS, "email=$email&item=$item");

curl_exec ($so);

curl_close ($so);

}

 

 

I am totally stumped with this whole process. I don't understand why it does not work! It has to be the variables, right? :'(

Don't give up. I see light ahead...!

Link to comment
Share on other sites

It definitely works because I have tested it :)

 

I actually said to place the code just before the closing bracket of the loop - after the loop is the section where the emails are constructed and sent..... looks like this:

 

 

 <put the code here>
 }

// lets start with the email confirmation

 

 

Sonia

Link to comment
Share on other sites

It definitely works because I have tested it :)

 

I actually said to place the code just before the closing bracket of the loop - after the loop is the section where the emails are constructed and sent..... looks like this:

 <put the code here>
 }

// lets start with the email confirmation

Sonia

 

 

I put the code 'exactly' where you told me to. The orders process inside osCommerce, no problem. (they always did) but, I'm not geting any data sent to the processor. How can I confirm that the variables are actually being defined properly? Is there a way that I can echo $email and $item to the screen and pause the process long enough for me to confirm the values are correct? How did you test it?

 

$email = $order->customer['email_address'];

$item = $order->products[$i]['model'];

$so = curl_init();

curl_setopt($so, CURLOPT_URL,"http://mydomain.com/myfolder/externalprocessor.php");

curl_setopt($so, CURLOPT_POST, 1);

curl_setopt($so, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($so, CURLOPT_POSTFIELDS, "email=$email&item=$item");

curl_exec ($so);

curl_close ($so);

}

 

// lets start with the email confirmation

Don't give up. I see light ahead...!

Link to comment
Share on other sites

If you are using the Paypal IPN module the code must go in there also :)

 

I'm sorry, I'm so confused. I have been up all night trying to figure out a solution to this problem. Where is 'in there also'? I am using Paypal IPN v1.3 and the only logical place would be at /catalog/ext/modules/payment/paypal_ipn/ipn.php, this is where the order status is changed to "VERIFIED". It appears the curl process is simply checking the status of the transaction. Can I tap in there to get my variables defined?

line 54   if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
line 55   $result = $res;
line 56
line 57   break;
line 58	  }

 

I don't see any useable order variables like there were in /catalog/checkout_process.php . Do I use the Paypal variables (payers_email) & (item_number) or make my own?

 

If I can define my buyer's email address and item number(s) strings in ipn.php, I could leave checkout_process.php alone completely because I can send from inside of ipn.php, right? I am asking because I am confused about your use of the word 'also' = more than one place.

 

If I am supposed to split the process some how, I have no clue what to do, or where/when. :-"

 

If I were to define and use my own curl loop from inside of ipn.php, how would my variables defined if the order values I need are in another process? ($i), ($order->['email_address']), ($order->products[$i]['model'])

 

	for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$email = $order->customer['email_address']; 
$item = $order->products[$i]['model'];
$send = "email=' . '$email' . "&item=" . '$item'";
$curl = curl_init();	
curl_setopt($curl, CURLOPT_URL,'http://mydomain.com/myfolder/dowloadlinkgenerator.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $send);  
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_exec ($curl);	 
curl_close ($curl);
}

 

BTW, The URL and POSTFIELDS are one way. Outbound. So CURLOPT_RETURNTRANSFER should be false right?

 

I sense resolution is very near ... ;)

Don't give up. I see light ahead...!

Link to comment
Share on other sites

You told me (in an email I think) that the variables were NOT being set with a test code I gave you to put into checkout_process.php - this indicates that your checkout_process is elsewhere - with the official osCommerce Paypal IPN it is within paypal_ipn.php - I am not sure of your particular module (and its associated files), but when you do find where the checkout process is taking place, there you will find an $order->products loop where you can insert the code :)

 

The code DOES work - I have tested it half a dozen times from one server to another (so dont change it) B)

 

 

Sonia

Link to comment
Share on other sites

Yes, this is how we determined that something isn't running right. My Paypal Auto return points straight to /catalog/checkout_process.php. Both the IPN path and the Autoreturn are defined just like the instructions say to.

 

How can the process be anywhere else? Is there a way to change the path to where the checkout process happens? Wouldn't the checkout_process.php file have to be there? Where is the paypal_ipn.php file you are talking about? Are you saying I need to look inside paypal_ipn.php to find the path to where my checkout process is defined? Are you talking about 'pre payment checkout' or 'post payment checkout'? I need to generate the data when payment is 'VERIFIED' and not before.

 

If I understand you correctly, my checkout_processes is happening at different location than what is 'normal' and I need to 'find it' so I can insert my code. I have no clue where to begin looking nor what I am supposed to be looking for.

 

Sorry, I know you are trying to help, and I honestly appreciate your efforts. You have my utmost respect and appreciation. You have been awesome and I have really learned a lot. I just don't know what I am supposed to be looking for at this point.

 

Please understand that I am just extremely frustrated with myself and this situation. I am +3 weeks with this issue and am still 'looking for a file' to edit that I cannot identify. Hence, I have no clue of what I am 'looking' for or what to do next. :devil:

 

I might have to change my signature because honestly, the faith in osCommerce is fading fast....

Don't give up. I see light ahead...!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...