5 / 11
May 2008

can anyone supply their php code file to load an e-junkie notification into a mysql database.



maybe it is already on the site somehwere and if no tthen maybe e-junkie can add it for reference.



how do most handle errors. do they have an email sent to site admin?



do most of you have an email sent on successful ad as well?



thank you

  • created

    May '08
  • last reply

    Jun '12
  • 10

    replies

  • 1.6k

    views

  • 5

    users

  • 3

    links

where is the entire list of codes/values we have access to?



does the notification list we get not always display all values? maybe due to being null?



what is the address field name? i only see city, state, zip listed on the site. is it 'address_street' ?

The values we can pass along to your own script (or to a 3rd-party service's URL) are listed here: 6http://www.e-junkie.com/ej/help.integration.php6

(BTW, the street address variable would indeed be "address_street" -- looks like we missed that one in the documentation :^).



Notice at the very end of that page our "Passthru" instructions, which would just dump all the data we collect for each transaction to your URL, so you could capture that and sift thru everything to see what's useful or just grab what you need and ignore the rest.



Getting your own custom scripts to work is of course entirely up to you and your personal expertise with PHP or Perl or whatever you're scripting in; we cannot help develop or troubleshoot or bugfix your own scripting.

I already finished my script after I posted the message.



However, I still think you guys would want to put a 'complete' php script there or a link to some robust examples (even better) or ones the manipulate the datebase.



It just makes it easier for more people to use your service.



Having a section on your site where code example are placed would be a cool thing as well.

Also, there is a TON of items missing which leads to great confusion for new people trialing your service. I pointing this, and many many other things out right at the start when I joined...



Funny how people that pay me to improve their business listen but when its free advice it is disgarded. I have always laughed at that. I tell people all the time that they really do need to pay me to help them or it won't work lol.

A sample PHP script would be great. I got everything I needed but it was a big trial and error effort.

2 months later

could you share the code you developed? I'm having the same issue right now. Thanks.

16 days later

Sadly, nobody has chose to help me get started with the script to send transaction data to my url. The integration page is no help at all getting started. I don't want the whole script, all I need is a good start. Thanks to anyone who cares to help.

I set some defaults in case the parameters don't come in correctly



<cfparam name="payer_email" default="john@doe.com">

<cfparam name="txn_id" default="999999">

<cfparam name="first_name" default="firstname">

<cfparam name="last_name" default="lastname">

<cfparam name="mc_gross" default="0.00">

<cfparam name="address_city" default="novalue">

<cfparam name="address_state" default="novalue">

<cfparam name="address_zip" default="novalue">

<cfparam name="key" default="novalue">

<cfparam name="item_name1" default="novalue">

<cfparam name="item_number1" default="novalue">

<cfparam name="quantity1" default="novalue">

<cfparam name="mc_gross_1" default="mc_gross_1">



Based on our own configuration, we only really sell one product



<cfparam name="item_name2" default="novalue">

<cfparam name="item_number2" default="novalue">

<cfparam name="quantity2" default="novalue">

<cfparam name="mc_gross_2" default="mc_gross_2">



The parameters some in via a form



<cfset email='#Form.payer_email#'>

<cfset txn_id='#Form.txn_id#'>

<cfset first='#Form.first_name#'>

<cfset last='#Form.last_name#'>

<cfset mc_gross='#Form.mc_gross#'>

<cfset address_city='#Form.address_city#'>

<cfset address_state='#Form.address_state#'>

<cfset address_zip='#Form.address_zip#'>

<cfset key='#key#'>



<cfset item_name1='#Form.item_name1#'>

<cfset item_number1='#Form.item_number1#'>

<cfset quantity1='#Form.quantity1#'>

<cfset mc_gross_1='#Form.mc_gross_1#'>



<!-- only if it exists? -->

<CFIF IsDefined("FORM.quantity2")>

<cfset item_name2='#Form.item_name2#'>

<cfset item_number2='#Form.item_number2#'>

<cfset quantity2='#Form.quantity2#'>

<cfset mc_gross_2='#Form.mc_gross_2#'>

</CFIF>



<!-- Serial Numbers (Product Keys) are published with a Carraige Return/Line Feed, for simplicity I replace that with a "+" sign so I can stick them into one database field -->

<cfset key = Replace(key, Chr(13), "+", "ALL")>

<cfset key = Replace(key, Chr(10), "+", "ALL")>



Here is the real code



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>eJunkie Processing</title>

</head>

<body>



<!-- Here I'm creating an email as a backup mechanism -->

<CFMAIL TO="me@mydomain.com"

SERVER="mail.mydomain.com"

FROM="ejunkie@mydomain.com"

SUBJECT="eJunkie Purchase from #email#">

User Information

email: #payer_email#

txn_id: #txn_id#

First: #first#

Last: #last#

Payment: #mc_gross#

address_city=#address_city#

address_state=#address_state#

address_zip=#address_zip#



Serial Number

serialnumber=#key#



Item 1

item_name1=#item_name1#

item_number1=#item_number1#

quantity1=#quantity1#

mc_gross_1=#mc_gross_2#



Item 2

item_name2=#item_name2#

item_number2=#item_number2#

quantity2=#quantity2#

mc_gross_2=#mc_gross_2#



</CFMAIL>

<!-- now do the SQL Insert Statement -->

<cfquery name="qeJunkieInsert" datasource="mydatabase">

Insert into eJunkie (transactdate, txn_id, email, firstname, lastname, grossamount, city, state, zip, serialnumber)

values

(#CreateODBCDate(now())#, '#txn_id#', '#payer_email#', '#first#', '#last#', #mc_gross#, '#address_city#', '#address_state#', '#address_zip#', '#key#')

</cfquery>

Thanks

</body>

</html>



And that's it. Works for me, pretty simple.

3 years later

Let me help you PHP friends out. After all, what's a community for?



First, I've created a DB table called 'purchases' with the following vars:

first_name

last_name

payer_email

payment_date

custom

invoice

item_name

item_number



Why? Because these are the only items I want to know about a purchase. Feel free to add your own.



Now for the PHP code.



<?php

//since all this happens invisibly between servers, we can't see errors, so email myself all the bugs that happen

function emailOnFail($var)

{

mail ("YOUR_EMAIL_ADDRESS_HERE","post from e-junkie", print_r($_POST) . $var);

}



//First, check if the server that triggered this page to load is sending the right handshake

if ($POST['handshake']!==md5("YOUREJUNKIE_EMAIL_HERE".md5("YOUR_EJUNKIE_PASSWORD_HERE")))

{

//The server is not legit, so exit to prevent this fraud from happening.

die();

}



//Connect to the MySQL database

mysql_connect("DB_HOST_HERE", "DB_USER_HERE", "DB_PASSWORD_HERE") or die(emailOnFail("MYSQL ERROR! ".mysql_error()));

mysql_select_db("DB_NAME_HERE") or die(emailOnFail("DB-SELECT ERROR! ".mysql_error()));



//Multiple items could have been purchased so go through the list to see how many items have been purchased; I'm capping it at 1000

$i = 1000;

$count = 1;

while ($i>$count)

{

if($POST['itemnumber'.$count])

{



//We need to know the following variables (left: e-junkie var, right: database var):

/*

first_name = first_name

last_name = last_name

payer_email = payer_email

payment_date = payment_date

custom = YouTubeChannel

invoice = invoice

item_name = item_name

item_number = item_number

*/



//set the vars to a database array (left: db var, right: e-junkie var)

//WARNING: You should probably check if these post-vars actually exist!

$db['first_name'] = $POST['firstname'];

$db['last_name'] = $POST['lastname'];

$db['payer_email'] = $POST['payeremail'];

$db['payment_date'] = $POST['paymentdate'];

$db['YouTubeChannel'] = $_POST['custom'];

$db['invoice'] = $_POST['invoice'];

$db['item_name'] = $POST['itemname'.$count.''];

$db['item_number'] = $POST['itemnumber'.$count.''];



//extract the database array into a query

$string = "INSERT INTO purchases (first_name, last_name, payer_email, payment_date, YouTubeChannel, invoice, item_name, item_number)

VALUES('".$db['first_name']."',

'".$db['last_name']."',

'".$db['payer_email']."',

'".$db['payment_date']."',

'".$db['YouTubeChannel']."',

'".$db['invoice']."',

'".$db['item_name']."',

'".$db['item_number']."'

)";



//fire it into the db or die with an email notification

mysql_query($string) or die(emailOnFail("DB-INSERT ERROR! ".mysql_error()));



}

else

{

//there are no items left in the cart, so kill this script. All done!

$finalcount = $count;

$count = 1001;

break;

die();

}

//There are more items left in the script so go back and do some more!

$count++;

}

?>