itinerisltd / gf-sagepay
Gravity Forms Add-on for SagePay
Package info
github.com/ItinerisLtd/gf-sagepay
Type:wordpress-plugin
pkg:composer/itinerisltd/gf-sagepay
Requires
- php: ^8.4.1
- ext-bcmath: *
- ext-curl: *
- league/omnipay: ^3.2
- omnipay/common: ^3.5.1
- omnipay/sagepay: ^4.1
Requires (Dev)
- alleyinteractive/pest-plugin-wordpress: ^1.1
- itinerisltd/itineris-wp-coding-standards: ^2.0
- pestphp/pest: ^5.3
- php-http/mock-client: ^1.6
- roave/security-advisories: dev-master
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master / 1.x-dev
- 1.0.0
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.10
- 0.10.9
- 0.10.8
- 0.10.7
- 0.10.6
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-ci/release-please
- dev-ci/pr-metadata-checks
- dev-gh/95/readme-sca
- dev-chore/release-1.0.0
- dev-test/e2e-declined-cancelled
- dev-test/e2e-sandbox-payment
- dev-codepuncher-patch-1
This package is auto-updated.
Last update: 2026-10-23 15:06:25 UTC
README
SagePay payment gateway for GravityForms.
- Goal
- Features
- Not Supported / Not Implemented
- Minimum Requirements
- Upgrading to 1.0
- Installation
- Best Practices
- Test Sandbox
- Common Issues
- Shipping Address
- FAQ
- Developing
- Feedback
- Change Log
- Security
- Credits
- License
Goal
Allow Gravity Forms to accept SagePay (now Opayo by Elavon) one-off payments via SagePay Server.
Features
- SagePay Server
- Gift Aid
- 3D Secure
- Strong Customer Authentication (SCA) is handled on Opayo's hosted payment pages (Server protocol 4.00), so card details and 3D Secure challenges never touch your site. See Fraud Protection for the feed setting
- AVS/CV2
- Gravity Forms Logging
- Gravity Forms Notification Events
- Gravity Forms Confirmation
- Gravity Forms Conditional Logic
- Payment statuses: SagePay's notification sets the entry's payment status and fires the matching Gravity Forms notification events (payment completed, pending or failed)
OKorOK REPEATED→ PaidPENDING→ PendingNOTAUTHED,REJECTED,ABORTorERROR→ Failed- Repeated notifications are ignored, and a Paid entry is never downgraded
Not Supported / Not Implemented
These features are not supported by this plugin, but you might be able to use them via MySagePay:
- Card reference
- Token billing
- Deferred payment
- Recurring payment
- Void
- Refund
- Abort
- Basket
- Surcharges
- Account Type M – for telephone (MOTO) transactions
- Account Type C – for repeat transactions
Pull requests are welcome.
Minimum Requirements
- PHP v8.4.1
- PHP bcmath Extension
- PHP cURL Extension
- WordPress v6.7
- Gravity Forms v3.1
Upgrading to 1.0
1.0.0 is a major release. Before upgrading from 0.12:
- Check the minimum requirements: PHP 8.4.1 with bcmath, WordPress 6.7 and Gravity Forms 3.1.
- If your project pins
config.platform.phpincomposer.json, set it to8.4.1or higher (8.4means 8.4.0 and is refused). - Update the Composer constraint, letting only gf-sagepay's own dependencies move (it needs
omnipay/common3.5.1 or newer):composer require itinerisltd/gf-sagepay:^1.0 --update-with-dependencies
- If you extend any of the plugin's classes or call methods outside the public API, update that code:
- every class is now
final,protectedmembers areprivate, and everything outside the public API is@internal Entry::isTimeout(),Entry::expireConfirmationTokenNow(),Entry::setProperty()andFeed::isActive()are removedGatewayFactory::build()is private (useGatewayFactory::buildFromFeed())Entry::setMeta()requires astringkey, andCallbackHandler::run()now ends the request (never)
- every class is now
Good to know:
- Existing feeds, entries and settings carry over unchanged.
- Gravity Forms only enforces its minimum version in wp-admin. A site still on Gravity Forms 2.x keeps taking payments, but the SagePay settings pages stay hidden until Gravity Forms is updated.
- If a theme or another plugin bundles its own Guzzle, that copy may be the one loaded. Any Guzzle 7 release works.
- The notification URL sent to SagePay is now
?callback=gf-sagepay(previously?callback=gf-sagepay&vendor=<vendor code>&isTest=true|false). Notifications are verified against the vendor code stored when the payment was registered, and anyvendororisTestquery args are ignored.
Installation
Composer (Recommended)
composer require itinerisltd/gf-sagepay
Build from Source (Not Recommended)
# Make sure you use the same PHP version as remote servers. # Building inside docker images is recommended. php -v # Checkout source code git clone https://github.com/ItinerisLtd/gf-sagepay.git cd gf-sagepay git checkout <the-tag-or-the-branch-or-the-commit> # Build the zip file composer release:build
Then, install release/gf-sagepay.zip as usual.
Best Practices
HTTPS Everywhere
Although SagePay accepts insecure HTTP sites, you should always use HTTPS to protect all communication.
Payment Status
Always double check payment status on MySagePay.
Fraud Protection
To prevent chargebacks, enforce 3D Secure and AVS/CV2 rules whenever possible.
Each feed's 3D-Secure setting decides how 3D Secure applies to its payments. New feeds default to "Use MSP Setting", which follows the 3D Secure rules in MySagePay; existing feeds keep their saved value, so check them after upgrading. Avoid "Disable", since card issuers can decline unauthenticated payments under SCA, and note that "Force Ignoring Rules" skips your MySagePay 3D Secure rules.
Test Sandbox
Always test the plugin and your fraud protection rules in the test sandbox before going live.
Your own test account only accepts registrations from IP addresses whitelisted in MySagePay (otherwise error 4020). If you can't whitelist yours, use the shared protxross vendor code, which accepts registrations from any IP.
SagePay must be able to reach the notification URL, so a local site needs a public tunnel. A Cloudflare quick tunnel works without an account, but SagePay only reaches it over plain http://; ngrok is an alternative.
Use one of the test cards, for example Visa 4929000000006 with CVV 123, or 4929602110085639 to simulate a decline.
Common Issues
Missing Gift Aid Acceptance Box
Only registered charities can use Gift Aid through the Sage Pay platform. The gift aid acceptance box only appears if your vendor account is Gift Aid enabled and using Donation as transaction type.
GF SagePay is Missing on Form Settings
Make sure you meet the minimum requirements. Check your environment details at the System Status Page.
Shipping Address
SagePay requires both a billing address and a delivery address, so map both sets of fields in the feed (a missing delivery country fails with error 3140).
Use case: Not delivering any physical goods
Map the shipping address fields to the billing ones.
Use case: Allow ship to billing address
This is similar to the WooCommerce way.
Use Gravity Forms' built-in feature: Display option to use the values submitted in different field
FAQ
Will you add support for older PHP versions?
Never! This plugin will only work on actively supported PHP versions.
Don't use it on end of life or security fixes only PHP versions.
It looks awesome. Where can I find more goodies like this?
- Articles on Itineris' blog
- More projects on Itineris' GitHub profile
- More plugins on Itineris and TangRufus wp.org profiles
- Follow @itineris_ltd and @TangRufus on Twitter
- Hire Itineris to build your next awesome site
Where can I give ⭐⭐⭐⭐⭐ reviews?
Thanks! Glad you like it. It's important to let us know somebody is using this project. Please consider:
- tweet something good with mentioning @itineris_ltd and @TangRufus
- ⭐ star this Github repo
- 👀 watch this Github repo
- write blog posts
- submit pull requests
- hire Itineris
Developing
Public API
These are covered by semantic versioning, so they only change in a major release:
- the
gf_sagepay_redirect_url_failure_wp_dieandgf_sagepay_redirect_url_exception_wp_diefilters ConfirmationHandler::buildUrlFor()Itineris\SagePay\Entry: the constructor andgetId(),getFormId(),getProperty(),getMeta(),toArray()andisPaidOrPending()
Everything else may change in any release.
That includes every other class and method (all classes are final, and internals are marked @internal), the gf_sagepay_terminate action, GFSagePay::VERSION (read the version from the plugin header instead) and the entry meta keys the plugin writes (gf_sagepay_* and transaction_reference).
The failure filter passes omnipay's Omnipay\SagePay\Message\ServerAuthorizeResponse, so a major upgrade of omnipay/sagepay would be a breaking change for this plugin.
Build URL for continuing confirmation
Itineris\SagePay\ConfirmationHandler::buildUrlFor(Itineris\SagePay\Entry $entry, int $ttlInSeconds = 3600): string
Usage:
$entryId = 123; $rawEntry = GFAPI::get_entry($entryId); if (is_wp_error($rawEntry)) { wp_die('Entry not found'); } $url = \Itineris\SagePay\ConfirmationHandler::buildUrlFor( new \Itineris\SagePay\Entry($rawEntry), 86400 // expires in 24 hours (24*3600=86400) ); echo $url; // https://example.com/the-form-page/?entry=123&gf-sagepay-token=XXXXXXXXXXXX (the entry's source page)
Use Case: With "using confirmation query strings to populate a form based on another submission":
- User fills in formA
- User completes the SagePay checkout form
- SagePay notifies
CallbackHandler, which records the payment and replies with a single-use confirmation URL - SagePay sends the user to that URL, where
ConfirmationHandlerruns formA's confirmation and sends the user to formB - User arrives at formB's URL with merged query strings
If the user quits before completing formB, you could use ConfirmationHandler::buildUrlFor to generate a single-use, short-lived url for the user to resume formB.
Note:
- The url continues Gravity Forms confirmation
- Whoever got the url will go on confirmation, no authentication performed
- Each call replaces the entry's previous token, so any earlier url for the same entry (including the one SagePay sends the customer to) stops working
- The confirmation will use latest field values from database which could have changed
- A payment that is not Paid or Pending is sent to the feed's cancel URL when one is set
Redirect URL Retrieval Failure Handling
After form submission, this plugin sends the order to SagePay in exchange for a redirect URL (the SagePay hosted checkout form URL).
By default, when redirect URL retrieval fails:
- Mark entry payment status as
Failed - Log the error
wp_dieimmediately
Common failure reasons:
- Incorrect vendor code
- Server IP not whitelisted (error 4020)
Tips: Check the log.
You can use 'gf_sagepay_redirect_url_failure_wp_die' filter to:
- continue Gravity Forms' feed and confirmation flow
- perform extra operations
- redirect to a different error page
Important: If this filter returns false, normal Gravity Forms' feed and confirmation flow continues.
Improper settings might lead to disasters.
Example:
add_filter('gf_sagepay_redirect_url_failure_wp_die', function(bool $shouldWpDie, \Omnipay\SagePay\Message\ServerAuthorizeResponse $response, \Itineris\SagePay\Entry $entry, \GFPaymentAddOn $addOn): bool { // Do something. return true; // Do `wp_die` return false; // Don't `wp_die`, continue normal flow return $shouldWpDie; // Keep the default }, 10, 4);
When registration ends in an exception instead of a reply from SagePay (for example SagePay cannot be reached, or omnipay cannot build the request), there is no ServerAuthorizeResponse. The entry is still marked as Failed with the exception in its notes, and the 'gf_sagepay_redirect_url_exception_wp_die' filter decides whether to wp_die. It receives the exception instead of the response, and returning false has the same effect as above:
add_filter('gf_sagepay_redirect_url_exception_wp_die', function(bool $shouldWpDie, \Throwable $exception, \Itineris\SagePay\Entry $entry, \GFPaymentAddOn $addOn): bool { return $shouldWpDie; }, 10, 4);
Required Reading List
Read the following before developing:
- SagePay Server: Understanding the process
- SagePay Server integration kits, protocols and documents
- Gravity Forms: GFPaymentAddOn
- Gravity Forms: Entry Object
- Omnipay: Sage Pay
- thephpleague/omnipay-sagepay#45 (comment)
- thephpleague/omnipay#255 (comment)
Gravity Forms
Gravity Forms has undocumented behaviour; read its source code when in doubt.
Testing
composer style:check # coding standards composer test # Pest integration suite (real WordPress, Gravity Forms and MySQL) tests/e2e/run.sh # Playwright payments against Opayo's sandbox (wp-env, Docker and cloudflared)
See CLAUDE.md for the local setup each one needs.
Pull requests without tests will not be accepted!
Feedback
Please provide feedback! We want to make this library useful in as many projects as possible. Please submit an issue and point out what you do and don't like, or fork the project and make suggestions. No issue is too small.
Change Log
Please see CHANGELOG for more information on what has changed recently.
Security
If you discover any security related issues, please email dev@itineris.co.uk instead of using the issue tracker. You can also report it privately through GitHub's private vulnerability reporting.
Credits
GF SagePay is an Itineris Limited project created by Tang Rufus and maintained by Lee Hanbury-Pickett.
Full list of contributors can be found here.
License
GF SagePay is released under the MIT License.