Processing Online Donations Through the NGP API

April 13, 2010
Development

UPDATE: This article is outdated. We have since updated the code we use to accept online donations with the NGP contribution API, and we have written about it in our newer article "Accept campaign donations with the NGP contribution API".

Many of our political clients request that we integrate their website with NGP's fundraising and contact management service. Although NGP boasts powerful tools for keeping track of donors and maintaining mailing lists, their third-party API is sadly lacking in both functionality and documentation. After much trial-and-error (and some last-minute help from Josh), I was finally able to successfully interface with NGP's server to process donations directly from a client's website. To save you the same hassle, here is our solution:

NGP only accepts data in the form of an XML fragment passed via a SOAP transaction. We are going to use the NuSOAP library to handle the actual API call (PHP5's built-in SOAP library should work, too, but I had some strange errors when I tried it). Put the NuSOAP folder and the proxy file at the end of this post somewhere publicly-accessible on your server—I put it in the web root. Open up ngp_proxy.php and change the Credential String at the top to your own string, which you will need to get from NGP.

Now you need to create your donation form. This part is up to you, depending on what particular information you want to store and what donation options you want to provide. See below for a list of all possible fields. Just make sure to set the action of the form to the ngp_proxy.php file you just uploaded and the method to post. You can include a hidden input to specify a page to redirect to after a donation is successfully processed: <input type="hidden" name="success" value="http://mydomain.com/thank_you.html" />.

Disclaimer: Processing donations is serious business! Make sure you have SSL enabled on your server, so you aren't transferring credit card information in clear text. New Media Campaigns takes no responsibility for any security issues that occur as a result of using this code.

That's all there is to it. If you have any suggestions of improvements, please share in the comments.

Download the Proxy File

All Supported Fields

Fields with a * are required by NGP.

  • last_name*
  • first_name*
  • middle_name
  • salutation
  • prefix
  • suffix
  • address1*
  • address2
  • address3
  • city
  • state
  • zip*
  • email
  • home_phone
  • work_phone
  • work_phone_ext
  • fax
  • employer
  • occupation
  • cycle* - Election year the donation is for
  • member
  • attribution
  • source
  • recurring_period- Frequency of the donation. One of:
    • MONT
    • WEEK
    • BIWK
    • FRWK
    • QTER
    • SMYR
    • YEAR
  • recurring_term - Number of times to make the donation
  • amount*
  • cc_number*
  • cc_exp_year*
  • cc_exp_month*
  • cvv

UPDATE: This article is outdated. We have since updated the code we use to accept online donations with the NGP contribution API, and we have written about it in our newer article "Accept campaign donations with the NGP contribution API".

Comments

ian johnson's avatar
ian johnson


Thanks for posting this. I used your demo as a starting point for getting a simple newsletter signup class. Details here:

http://www.moiagroup.com/archives/using-the-ngp-api-to-add-email-addresses/664

Eli Van Zoeren's avatar
Eli Van Zoeren

The EmailSignup method should do what you want through that url. I haven't actually experimented with that functionality yet, thought, so I'm not sure why it isn't working for you. Take a look at section 2.3 of the PDF http://www.myngp.com/ngpapi/docs/CWP.API.pdf for example code that may help.

LC's avatar
LC

Well, Ive gone in and modified the file, uploaded everything to the server. I fill out the form, hit submit, and it doesnt give me an error, it gives me the success message, but the contact also doesnt end up in the database :( One thing i noticed in the API...your code uses https://services.myngp.com/ngponlineservices/onlinecontribservice.asmx?wsdl, and it looks like this URL is good for volunteers and contributions, but i dont see that in the documentation for newsletter. Im going to keep working at it, but hopefully somebody over at NGP can help me out.

LC's avatar
LC

Excellent, thanks. I'm going to see if I can figure this out :-) If i manage to get it working, I'll definitely come back and share the file.

Eli Van Zoeren's avatar
Eli Van Zoeren

LC-

It should be possible, using the EmailSignUp method in their API. See the EmailSignUp section of this document for more details, but essentially you would need to change the XML to only include those fields (LastName, FirstName, Email, and Zip), and then change "PostVerisignTransaction" to "EmailSignUp" on line 102 of the proxy script.

If you get it working and would like to contribute that function to the proxy script for everyone to use, send it my way. Thanks.

LC's avatar
LC

Great post, thanks for the info! Im trying to implement something similar, with very limited knowledge in this area. Im wondering how I might adapt this file to work with the NGP Newsletter signup form? From the API documentation I was sent, I believe the fields are a little different, ie LastName, FirstName....any thoughts would be appreciated.

sadsad's avatar
sadsad

sdfsf

Clay Schossow's avatar
Clay Schossow NMC team member

Sean,

Thanks for reading the post in weighing in! Those seem like they could be very helpful resources to developers using Drupal. Thanks for sharing and feel free to check out our implementation and let us know if you have any other thoughts.

Clay

Sean Robertson's avatar
Sean Robertson

It should be noted that if you're using Drupal, we have a collection of open source modules already available to handle this. Here are the two base modules required to get the basic forms set up:

http://drupal.org/project/crmapi
http://drupal.org/project/crmngp

These modules will also integrate with the two above to help capture more data:

http://drupal.org/project/forward (field code only for registered users)
http://drupal.org/project/letters
http://drupal.org/project/petition

Leave a comment