Building a Payment Gateway for Give WP the Donation Plugin for WordPress

My father runs a non-profit organization and I told him I’d help with some of his online needs.  I’m in the midst of a task for him where I need a very simple, but precise method of donations through Stripe.  While the Stripe Add-On for Give is excellent, it’s more than I need and missing some small features my project requires.  I’m not going to get into that specific project but show you what I’ve learned.

Unless I’m missing something obvious on their site and with some quick googling, there’s no documentation for building Give gateways. I had to reverse engineer a couple that are available to see what is necessary to make it work.  Here it is in its simplest form.

Bare Bones Gateway

When building an extension for a plugin I like to try and build the absolute barest possible version.  What you see at the bottom of this section is just that.  We use just two hooks:

  • add_filter( ‘give_payment_gateways’ )
  • add_action( ‘give_gateway_{gateway_slug}’ )

The filter registers our gateway.  This will then show our gateway as an option in the Give gateway settings.

The action is where we process the submitted form data.  It’s pretty straight forward, the function has a single parameter ($purchase_data) passed to it which contains all data submitted and generated by Give that’s needed to process a donation.

The $payment_data array is created and built to hold all the necessary items for processing a transaction and recording it.  Then we simply call the Give function give_insert_payment( $payment_data).

https://gist.github.com/ChrisFlannagan/e214d5df8843e9125df14501907405b8

Settings

The next feature you will probably want to add is the admin settings for your plugin.  This will allow your users to set api keys and other various options you’d like to have.  You can see a good example of establishing settings here:

https://github.com/WordImpress/Give/blob/master/includes/gateways/offline-donations.php#L281

Pending Status

I tried using ‘publish’ instead of ‘pending’ in the payment data but this caused some php warnings to pop up.  Even though the donation went through, the results were ugly and obviously not to spec with the Give plugin’s functionality.  So after checking if the payment is valid simply run the give_update_payment_status function.  Or, if you need to verify the payment through your payment processor you can have  a separate function that handles this.

Fleshing It Out

This, as stated, is a completely bare bones gateway that does nothing but record a donation.  give_gateway_{plugin_slug} action is a blank canvas for handling processing.  You can do your own verifications, reach out to your processor, manage the response and more.  I would suggest looking at the Give plugin directory give/includes/gateways files offline-donations.php and paypal-standard.php and check out the different hooks and functions you can use to expand your gateway’s user experience and capabilities.

The Give plugin is very powerful and very extendable.

5 thoughts on “Building a Payment Gateway for Give WP the Donation Plugin for WordPress”

  1. I know this post is a little old, though is really the only resource available on this subject.

    I’m creating a payment gateway and am up to the last step where I get stuck.

    The process for this payment vendor is that upon donation, the user is referred to a url which is generated from a number of the donation fields together with a hash. At this url they authenticate and authorise the payment. The vendor then redirects to (any given) page and returns in the url some parameters which I’d then need to rehash and check and at that point can either mark the payment as successful or failed.

    I have it such that it redirects to the correct url to allow the user to authenticate and authorise the payment, though how within Give can I setup a receiver or similar that the vendor can return to where I can verify the return values and complete the payment?

  2. Hi chris,

    I ma new on wordpress plateform but I made some developpments in the past ( php & java).
    I am in the same situation that Dan Smith ( cf comment below ) .
    It means I know what we must do to use payment gateway (
    ” process for this payment vendor is that upon donation, the user is referred to a url on POST which is generated from a number of the donation fields together with a hash. At this url they authenticate and authorise the payment. The vendor then redirects to (any given) page and returns in the url some parameters”
    How can we do that with give, do you some template that reuse and readapt for it ?

    Thanks.Regards Damien

Leave a Reply

Your email address will not be published.