7 Dollar Script How To Split Sales With Partners
Posted 4th October 2008 at 09:03 AM by dwooding
I have been using the $7 secrets script on my Articletator site with great success. I have another project that I want to be able to split the sales equally with a partner. Will the $7 script be able to split the payments between partners easily?
Of course it will.
For this particular project, I need to be able to split the sales equally between myself and my partner. Whoever has the least amount of sales gets the next sale. What I am about to show can easily be done for any number of partners.
For this to work, you need to make two simple edits to just one file, the settings.php file.
First thing to add is just the line that shows your PayPal e-mail address.
Just below where you have set the $sys_default_email, you want to add an array of email adresses that include your PayPal e-mail address along with your partners. Something that looks like this:
The first new line is for your PayPal e-mail address:
$sys_default_email_array[0] = "my_paypal_email@example.com";
Followed by one or more of your partner's PayPal e-mail addresses.
$sys_default_email_array[1] = "your_partners_paypal_email@example.com";
$sys_default_email_array[2] = "your_other_partners_paypal_email@example.com" ;
$sys_default_email_array[3] = "your_dogs_paypal_email@example.com";
$sys_default_email_array[4] = "the_postmans_paypal_email@example.com";
$sys_default_email_array[5] = "robert_plank_is_a_blank_paypal_email@example.com" ;
$sys_default_email_array[6] = "will_tina_fey_be_vp_paypal_email@example.com" ;
$sys_default_email_array[7] = "excuse_me_I_meant_sarah_palin_email@example.c om";
etc.
Notice that within the square brackets, [ and ], is a number. The important point to note is that each number is unique. There is another way to define this array of email addresses, I did it this way to show that each email address is part of an array.
Don't worry, if you decide to remove an email address in the future, just change the numbering so it remains in order.
Note well, if you ever add a partner's email address in the future, after you have already been making sales, then the newest partner will get sales continously until everyone has an equal number of sales. I would suggest you set this up once at the beginning of a partnership and leave it alone.
The next change you make is to add the following code at the very bottom of the settings.php file, just before the closing tag, ?>.
(I added this to version 2.8 of the $7 script, the line number where you add this code into may be different)
A brief explanation is in order.
The first line is a little safety feature.
if (is_array($sys_default_email_array)) {
This chunk of code says "only do the following stuff if there is an array of sys default email addresses". In other words, if you didn't define the email array previously mentioned, skip over this section that defines the $sys_default_email_array as the person with the least amount of sales. Just keep the default PayPal e-mail address.
The next three lines (240-242) initialize the sales count to 0 for everyone's PayPal e-mail addresses.
foreach ($sys_default_email_array as $tmp_email) {
$partner[$tmp_email] = 0;
}
The next line (243) opens up the sales results file called "ipn.txt" and reads the contents into a variable called $sales.
$sales = @file($sys_template_folder . "ipn.txt");
The next four lines (244-247) goes through each line of the sales results, figures out who made the sales and increments the sales count for each person making a sale.
foreach ($sales as $sale) {
$sale = explode("|", $sale);
$partner[$sale[3]]++;
}
The next line (248) sorts the results such that the person with the lowest amount of sales is the first in line in the array of results.
asort($partner);
The next line (249) changes the array keys around (array_keys) such that when the next command occurs (array_shift), the result is the the $sys_default_email is set to the PayPal e-mail of the partner with the least amount of sales.
$sys_default_email = array_shift(array_keys($partner));
All of this occurs only if there is an array of partner's PayPal e-mail addresses previously defined.
And that's about it. I'm sure there is a solution out there that does something like this. But for a simple way to make your $7 secret script be partner friendly, these changes will do the trick.
Dave Wooding
Of course it will.
For this particular project, I need to be able to split the sales equally between myself and my partner. Whoever has the least amount of sales gets the next sale. What I am about to show can easily be done for any number of partners.
For this to work, you need to make two simple edits to just one file, the settings.php file.
First thing to add is just the line that shows your PayPal e-mail address.
Just below where you have set the $sys_default_email, you want to add an array of email adresses that include your PayPal e-mail address along with your partners. Something that looks like this:
The first new line is for your PayPal e-mail address:
$sys_default_email_array[0] = "my_paypal_email@example.com";
Followed by one or more of your partner's PayPal e-mail addresses.
$sys_default_email_array[1] = "your_partners_paypal_email@example.com";
$sys_default_email_array[2] = "your_other_partners_paypal_email@example.com" ;
$sys_default_email_array[3] = "your_dogs_paypal_email@example.com";
$sys_default_email_array[4] = "the_postmans_paypal_email@example.com";
$sys_default_email_array[5] = "robert_plank_is_a_blank_paypal_email@example.com" ;
$sys_default_email_array[6] = "will_tina_fey_be_vp_paypal_email@example.com" ;
$sys_default_email_array[7] = "excuse_me_I_meant_sarah_palin_email@example.c om";
etc.
Notice that within the square brackets, [ and ], is a number. The important point to note is that each number is unique. There is another way to define this array of email addresses, I did it this way to show that each email address is part of an array.
Don't worry, if you decide to remove an email address in the future, just change the numbering so it remains in order.
Note well, if you ever add a partner's email address in the future, after you have already been making sales, then the newest partner will get sales continously until everyone has an equal number of sales. I would suggest you set this up once at the beginning of a partnership and leave it alone.
The next change you make is to add the following code at the very bottom of the settings.php file, just before the closing tag, ?>.
(I added this to version 2.8 of the $7 script, the line number where you add this code into may be different)
A brief explanation is in order.
The first line is a little safety feature.
if (is_array($sys_default_email_array)) {
This chunk of code says "only do the following stuff if there is an array of sys default email addresses". In other words, if you didn't define the email array previously mentioned, skip over this section that defines the $sys_default_email_array as the person with the least amount of sales. Just keep the default PayPal e-mail address.
The next three lines (240-242) initialize the sales count to 0 for everyone's PayPal e-mail addresses.
foreach ($sys_default_email_array as $tmp_email) {
$partner[$tmp_email] = 0;
}
The next line (243) opens up the sales results file called "ipn.txt" and reads the contents into a variable called $sales.
$sales = @file($sys_template_folder . "ipn.txt");
The next four lines (244-247) goes through each line of the sales results, figures out who made the sales and increments the sales count for each person making a sale.
foreach ($sales as $sale) {
$sale = explode("|", $sale);
$partner[$sale[3]]++;
}
The next line (248) sorts the results such that the person with the lowest amount of sales is the first in line in the array of results.
asort($partner);
The next line (249) changes the array keys around (array_keys) such that when the next command occurs (array_shift), the result is the the $sys_default_email is set to the PayPal e-mail of the partner with the least amount of sales.
$sys_default_email = array_shift(array_keys($partner));
All of this occurs only if there is an array of partner's PayPal e-mail addresses previously defined.
And that's about it. I'm sure there is a solution out there that does something like this. But for a simple way to make your $7 secret script be partner friendly, these changes will do the trick.
Dave Wooding
Total Comments 0