On 10/18/02, Chris Montgomery penned:
>I have read over the PayPal Instant Payment Notification (IPN) docs and
>think I have a fairly firm grasp on how this works for payment
>verification, etc. But what I haven't nailed down is if it is possible
>to use PayPal with an *existing* shopping cart written in CF. PayPal
>support hasn't responded to my question about this, so I thought some of
>you might know.
>
>My question: is it possible to integrate an existing CF shopping cart
>with PayPal payment processing? It *appears* to me that to integrate IPN
>with a shopping cart, that shopping cart needs to be a PayPal shopping
>cart (one created on their site). Or am I incorrect?

I use PayPal with mine. I simply use their standard Pay With PayPal 
button. I pass the item_name as "Joe's Tires Order No. 123". I pass 
the amount as the total of the order. All the other fields, 
first_name, last_name, etc. will simply be the customer's info. I 
tell them that their total will show the grand total of the order, 
including shipping charges, and give a message: After logging in or 
creating your account on PayPal, please choose "No Shipping Address 
Required". This information (if applicable) has already been captured.

Now, the IPN. :)

You have to pass 2 additional fields, custom and notify_URL. I have a 
page under the secure URL of the site that I created. The URL to that 
will be the notify_URL field value. I pass the Order ID as the custom 
field value.

Below is the important part of my IPN page. I'm including it because 
maybe others can use it. After the code below, I take the 
variables.invoice I create from the form.custom field and if I find 
"VERIFIED" in cfhttp.filecontent, I update the order as approved in 
the database and e-mail the merchant that the order has been 
approved. Otherwise, if I find "INVALID", I e-mail them the merchant 
that the order was declined and flag the order in the database so no 
further changes can be made.

You may need to take out the URL encoding if using cf 5 or MX. Not 
sure if they automatically encode the cfhttp url or not like they do 
with cfhttpparam (GRRRR!). The only variables you will need to change 
or set are attributes.PayPalID and attributes.AlternatePayPalID, 
which I have in my application.cfm of the cart which are the 
merchant's e-mail address and an alternate e-mail address if they use 
one.

Anyway. Here's the code. Probably not pretty, but it works for me. :)

<CFPARAM NAME="variables.invoice" DEFAULT="0">
<!--- read post from PayPal system and add 'cmd' --->
<CFSET str="cmd=_notify-validate">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
<CFSET str = str & "&#LCase(TheField)#=#URLEncodedFormat(Evaluate(TheField))#">
</CFLOOP>
<CFIF IsDefined("FORM.payment_date")>
<CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#">
</CFIF>
<CFIF IsDefined("FORM.subscr_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.subscr_date)#">
</CFIF>

<!--- post back to PayPal system to validate --->
<CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#"; 
METHOD="GET" RESOLVEURL="false">
</CFHTTP>

<!--- check notification validation --->
<CFIF CFHTTP.FileContent contains "VERIFIED" and 
isDefined('form.payment_status') and isDefined('form.custom') and 
isNumeric(form.custom) and isDefined('form.receiver_email') and 
(form.receiver_email is attributes.PayPalID or (form.receiver_email 
is attributes.AlternatePayPalID and attributes.AlternatePayPalID is 
not ""))>
<cfswitch expression="#form.payment_status#">
<cfcase value = "Completed">
<cfset variables.payment_status = "This charge was authorized">
<cfset variables.approval_notify = form.custom>
</cfcase>
<cfcase value = "Pending">
<cfset variables.payment_status = "Pending - #form.pending_reason#">
</cfcase>
</cfswitch>

<cfset variables.invoice = int(val(form.custom))>

<CFELSEIF #CFHTTP.FileContent# contains "INVALID">
<cfset variables.payment_status = "INVALID PAYPAL TRANSACTION">
<CFIF isDefined('form.custom')><cfset variables.invoice = 
int(form.custom)></CFIF>

<CFELSE>
<!--- error --->
</CFIF>
-- 

Bud Schneehagen - Tropical Web Creations

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com

Reply via email to