Over the past several years, we have implemented PayPal into our websites and many
of our customer websites. Since PayPal created their
Developer Program, the methods to access PayPal shopping carts and checkout
has continued to grow. There are easy a half dozen ways to do it today
[Learn More]. One popular method is the
Payment Data Transfer (PDT) program. Back on 1/28/2006, I blogged about
how to easily implement PDT into your website.
Problem: Throughout the life of the PDF program, several versions
of the PayPal WebControls have been released. The most recent version is v1.0.22.19341.
But there's a problem with the release that PayPal never resolved. When using the
DLLs and .NET Web Controls to test in the Sandbox environment, the UseSandbox property
is always ignored and the Postaction is always set to the Production environment.
This makes it impossible to test in their Sandbox environment.
Solution
We created a very simple class to override the PostAction property. See code below.
Download code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PayPal.Web.Controls;
namespace PayPalCustom
{
public class CustomUploadCompleteCartButton : UploadCompleteCartButton
{
public override string PostAction
{
get
{
return
this.UseSandbox ?
"https://www.sandbox.paypal.com/cgi-bin/webscr"
:
"https://www.paypal.com/cgi-bin/webscr";
}
}
}
}
To implement into your website:
1. Add PayPalCustom.dll as a Reference in your application.
2. Change the "Register" tag at the top of your page to:
<%@ Register TagPrefix="cc1" Namespace="PayPalCustom" Assembly="PayPalCustom" %>
3. Change the UploadCompleteCartButton WebControl tag to
<cc1:CustomUploadCompleteCartButton id="btnCheckout" runat="server" OnClick="btnCheckout_Click"></cc1:CustomUploadCompleteCartButton>
Comments
Leave a Comment