On 6/15/02, Michael Tangorre penned:
>I have a shopping cart on a clients website and he would like to use 
>paypal to process the final transaction.
>The entire cart is stored on the website, and he wishes to use just 
>paypal for the payment regardless of how many items are in the cart, 
>etc...
>Now, can this be done? Is there an API that I can use to do this? 
>Has anyone made any custom tags for this? Basically, I would hope 
>Paypal would return some kind of status and if the transaction went 
>through I would record the order and send the order to the guy 
>making the items, etc...

I don't have a custom tag, but this is pretty easy. Maybe I can save 
you and others some time reading:

<FORM ACTION="https://www.paypal.com/cgi-bin/webscr"; METHOD="POST" 
target="<CFOUTPUT>#target#</CFOUTPUT>">
<INPUT TYPE="hidden" NAME="cmd" VALUE="_ext-enter">
<INPUT TYPE="hidden" NAME="redirect_cmd" VALUE="_xclick">

<CFOUTPUT>
<input type="hidden" name="custom" value="#thisorderid#">
<input type="hidden" name="notify_URL" 
value="http://yourdomain.com/paypal_IPN.cfm";>
<INPUT TYPE="hidden" NAME="business" VALUE="#PayPalID#">
<INPUT TYPE="hidden" NAME="first_name" VALUE="#firstname#">
<INPUT TYPE="hidden" NAME="last_name" VALUE="#lastname#">
<INPUT TYPE="hidden" NAME="address1" VALUE="#address#">
<INPUT TYPE="hidden" NAME="address2" VALUE="#address2#">
<INPUT TYPE="hidden" NAME="city" VALUE="#city#">
<INPUT TYPE="hidden" NAME="state" VALUE="#state#">
<INPUT TYPE="hidden" NAME="zip" VALUE="#zip#">
<INPUT TYPE="hidden" NAME="return" VALUE="#GetSetup.Home#">
<CFIF GetSetup.shipcountry IS NOT "1"><INPUT TYPE="hidden" 
NAME="no_intl" VALUE="1"></CFIF>
<INPUT TYPE="hidden" NAME="item_name" VALUE="XXX Order No. #thisorderid#">
<input type="hidden" name="amount" 
value="#Trim(numberformat(variables.grandtotal, '_____.00'))#">
<INPUT TYPE="image" 
SRC="#GetSetup.Server#ezcart/buttons/x-click-but2.gif" NAME="submit" 
ALT="Make payments with PayPal - it's fast, free and secure!" 
width="72" height="29" border="0"></CFOUTPUT>
</FORM>

This will pass the amount as a single item, called "XXX Order No. 
123" with the order total, including shipping and taxes as the price. 
Obviously you'll replace XXX and 123 with your company name and order 
number.

The first field, "custom", I pass with the order ID. This field will 
be passed back to the Instant Payment Notification page on your 
server.

Here is what I use for the paypal_IPN.cfm page I created (notify_URL 
field), which notifies the merchant when the order is approved and 
flags the order approved in the database. Notes afterward. Note that 
if you use their documentation, there is a typo in the ColdFusion 
example. I don't remember "exactly" what it was, but it was in the 
"str" variable (at the top) that is created to pass back to PayPal. A 
& where the ? should be or a missing & something like that.

<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>
<!--- <CFOUTPUT>#cfhttp.filecontent#</CFOUTPUT> --->
<!--- 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 PayPalID or (form.receiver_email is 
AlternatePayPalID and 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>


<CFIF isDefined('variables.payment_status') and variables.invoice GT 0>

[Update query  flag order number #variables.invoice# as approved in 
database here]

</CFIF>

<CFIF isDefined('variables.approval_notify')>

<cfmail
from="youremailaddress"
to="youremailaddress"
subject="Order #variables.approval_notify# Approved">
Order #variables.approval_notify# Approved
</cfmail>

</CFIF>

The reason I use both PayPalID and AlternatePayPalID (which are the 
merchant's PayPay e-mail addresses) is that some people have multiple 
PayPal IDs. If they are notified at a different address than they use 
for their initial submission,  this will fail.

I tested it pretty thoroughly, and it works good. The one thing I 
haven't tested is whether or not the "custom" field still get's 
passed back a week later if the user pays by check and it's approved. 
I suspect it is though.
-- 

Bud Schneehagen - Tropical Web Creations

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ColdFusion Solutions / eCommerce Development
[EMAIL PROTECTED]
http://www.twcreations.com/
954.721.3452
______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to