latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

One last question – S2 Payment Notificatoin

Home Forums Community Forum One last question – S2 Payment Notificatoin

This topic contains 8 replies, has 2 voices. Last updated by  Horns Illustrated 3 years, 7 months ago.

Topic Author Topic
Posted: Thursday May 16th, 2013 at 6:11 pm #50086

I’m so there but need insight on one last item.

I was able to create a MU Plugin and call it from the S2 Payment Notification. (BTW, pretty cool how S2 validates the php in the MU Plugin)

Anyway, in my php code for the MU plugin, how do I call the URL for the sale.php from with the MU plugin? Do you simple do a redirect?

If I had a page, I would render the

Or, are you suggesting (tell me you didn’t make it just that simple) that I do the exact same thing in my php code and render it just like I would if I was outputting html?

Terry

PS. The MU Plugin works like a charm…

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Tuesday May 21st, 2013 at 4:02 am #50253
Bruce
Username: Bruce
Staff Member

Thank you for your inquiry.

Sorry for the delay in response.

Anyway, in my php code for the MU plugin, how do I call the URL for the sale.php from with the MU plugin? Do you simple do a redirect?

A redirect wouldn’t be the best choice here. You probably want to use this WordPress function.

See: http://codex.wordpress.org/Function_Reference/wp_remote_fopen

Posted: Tuesday May 21st, 2013 at 1:27 pm #50298

Bruce,

Thanks for the direction. I used it and it worked, however the data sent to iDev is not being used by iDev.

I’m sending: https://www.hornsillustrated.com/idevaffiliate/sale.php?profile=xx&idev_saleamt=2.5&idev_ordernum=16903267

I do have the correct profile # and only replaced it here to xx.

Cordially,

Terry

Posted: Wednesday May 22nd, 2013 at 3:56 am #50332
Bruce
Username: Bruce
Staff Member
Posted: Wednesday May 22nd, 2013 at 11:50 am #50374

Bruce,

First, thank you for your reply.

Secondly, I need to apologize. I have been pulling my hair out on this. Here is what I found:

1.) I actually (I know I did this before) did not remove the call in the API Tracking. This was the reason I kept thinking iDev as calling S2Member.

2.) I did remove it this time and double checked so it is gone from there.

3.) Going back to the MU Plugin – I used the $contents = wp_remote_fopen($uri);

This is not working…

I’ve tried it many different ways. I also output everything to a log. I output $contents which does not have anything in when it gets written to the log. This may be fine as I would take it as successful because the documentation suggest I would get false on failure.

I’ve also tried to hardcode the variables that I’m passing with no luck either.

I’m hoping you can help. This is getting extremely frustrating because it seems soooooo simple.

Here is my code:

<?php
add_action('init', 's2_payment_notification'); function s2_payment_notification()
	{
		if(!empty($_GET['s2_payment_notification'])) // In my URL, I have `?horns_affiliate_calc_actual_commission=yes`, that's what I'm looking for here.
			{
				if(!empty($_GET['user_id']) && !empty($_GET['item_number'])) // In my URL, I have `&user_id=%%user_id%%&item_number=%%item_number%%`, that's what I'm looking for here.
					{
						$user_id = (integer)$_GET['user_id']; // I'm expecting an integer in this value.
						$item_number = (string)$_GET['item_number']; // I'm expecting a string in this value.
						
						
						$user = new WP_User($user_id); // Get a WordPress® User object instance so I can work with this customer.
						
						// Here I might perform any number of tasks related to this user. Such as creating a user option value in WordPress.
						update_user_option($user_id, 'my_custom_data_for_this_user', $item_number);
						
						// I could also collect details about this user, by accessing properties of my WP_User object instance.
						$first_name = $user->first_name;
						$last_name = $user->last_name;
						$email = $user->user_email;
						$username = $user->user_login;
						
						$amount_paid = (string)$_GET['amount_paid']; // I'm expecting a string in this value.
						$full_coupon_code = (string)$_GET['coupon_code']; // I'm expecting a string in this value.
						// I can also pull s2Member® option values related to this user.
						$s2member_subscr_id = get_user_option('s2member_subscr_id', $user_id);
						$s2member_custom_fields = get_user_option('s2member_custom_fields', $user_id);
						$s2member_custom = get_user_option('s2member_custom', $user_id);
						$s2member_registration_ip = get_user_option('s2member_registration_ip', $user_id);
						$s2member_paid_registration_times = get_user_option('s2member_paid_registration_times', $user_id);
						$s2member_first_payment_txn_id = get_user_option('s2member_first_payment_txn_id', $user_id);
						$s2member_last_payment_time = get_user_option('s2member_last_payment_time', $user_id);
						$s2member_auto_eot_time = get_user_option('s2member_auto_eot_time', $user_id);
						$s2member_file_download_access_log = get_user_option('s2member_file_download_access_log', $user_id);
	
						
						/*Determine Product, then Transaction amount and then comission
						// Formula [Transaction $$ - Product COG] = Commission
						// Doesn't matter the discount because we will always take COG out and the rest is commissions
						*/
						$commission=0;
						$cog=0;
						
						//Determine what product and set the $commission to be pass to iDev
						Switch ($item_number){
						
						Case "1" : //Print Only 
						$cog = 2.50;
						$commission = number_format($amount_paid-$cog,2,".", "");				
						break;
						Case "2" : // Print & Digital
						$cog = 5.00;
						$commission = number_format($amount_paid-$cog,2,".", "");					
						break;
						}
						
						//if commissions is zero or less dont do anything.
						if ($commission <=0)
						{
						   	$commission=0;
						}
						else
						{
							$uri= "https://www.hornsillustrated.com/idevaffiliate/sale.php?profile=83&idev_saleamt=" . $commission . "&idev_ordernum=" .$s2member_subscr_id ; 
							$contents = wp_remote_fopen($uri);  
						}
						 	
						/*  I could also log this transaction, by creating a log entry in a static text file on-site. */
						
						file_put_contents(WP_CONTENT_DIR.'/plugins/s2member-logs/affiliate-transactions.log', 'IsString: '.is_string($uri). ' Item: ' .$item_number.  ' Commissions: '.$commission. ' Amount paid: ' .$amount_paid. ' cog: ' .$cog. ' Full Coupon Code: ' .$full_coupon_code. 'return from idev: ' .$contents. 'uri: ' .$uri. "\n", FILE_APPEND);
					}
				exit; // We can exit here. There's no reason to continue loading WordPress® or my theme during an API Notification.
			}
	}
Posted: Thursday May 23rd, 2013 at 7:57 am #50439

Bruce,

You know I was thinking…why would I want to use the wp_remote_fopen? This opens a remote file, however the sale.php is located on my domain.

Would I want to just use the include (/sale.php?profile=…)

The wp_remote_fopen is not working so I’m left thinking maybe this is not the correct way to do this.

What are your thougths?

Cordially,
Terry

Posted: Friday May 24th, 2013 at 8:53 am #50552

Bruce Help…

I’m about a week away from launching and really need to figure this out.

Would be highly interested in your thoughts on this.

I’m doing the MU Plugin and it’s triggering, however it’s not triggering the iDev sale.php so the sale gets counted.

My logic in the MU Plugin works because I’m capturing the data in a log, however it’s not registering with iDev.

Can you look at my code above and see what I might be doing wrong.

Please know I would greatly appreciate your help and getting past this…

Cordially,

Terry

Posted: Friday May 24th, 2013 at 11:51 pm #50612
Bruce
Username: Bruce
Staff Member

Thanks for your patience.

I’m very sorry for the delay in response.

You know I was thinking…why would I want to use the wp_remote_fopen? This opens a remote file, however the sale.php is located on my domain.

You can’t use a PHP include() or anything like that here. I’d say the best way to handle this would probably be to create an HTML image tag. So instead of this:

$contents = wp_remote_fopen($uri); 

You could do this:

echo '<img src="' . $uri . '"' alt="iDev Tracking Pixel" style="height: 1px; width: 1px;"/>';
That’s about as far as we can go with custom code. If you need further assistance, we recommend http://jobs.wordpress.net, or another freelance web site where WordPress® experts are offering their expertise through a bid on your project.
Posted: Tuesday May 28th, 2013 at 7:52 am #50740

BRUCE…

Here is what I did. I took out the wp_remote_fopen($uri) and replaced it with the echo

My code looks like this:

$p1 = "<img src=" . chr(34);				
$uri= '...sale.php?profile=83&idev_saleamt=' . $commission . '&idev_ordernum=' .$s2member_subscr_id ; 
$p2 = chr(34) . " style=" . chr(34). "height:1px; width:1px;" . chr(34). "/>";
				
$sendpart =  $p1 . $uri . $p2;
echo $sendpart;

and then I output $sendpart to a log file so I’ll know if code was generated.

The code is generated as I see the data from $sendpart in the log. However, the echo is not triggering the iDev.

I can copy the $sendpart URL into another browser window and it then does trigger it and I see the commission record in iDev.

I can only assume the ECHO is not the solution either. Is there a way I can escalate this up the support chain. I’m even willing to pay for support on this. So far, I’ve done everything that you’ve instructed me and it’s not working.

I know the MU Plugin is working and it’s running through the function fine, but neither solution you are suggest that will trigger the iDev is working.

Cordially,
Terry

Viewing 8 replies - 1 through 8 (of 8 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.