sagepay
v0.0.0
Published
Node.js package for Sage Pay's server integration protocol.
Downloads
22
Readme
sagepay
A Node.js package for Sage Pay's server integration protocol.
Install
npm i sagepay
Usage
The docs rely heavily on "Sage Pay Server Integration and Protocol Guidelines 3.00", specifically pages 44+ (Character Sets and Encoding, Transaction Registration, Notification of Transaction Results, URLs).
Refer to these guidelines to build better understanding on registering, verifying, and testing payments from Node.js.
Note: All option and return properties match the casing of the guidelines.
sagepay.registerTransaction(options)
Registers payment with Sage Pay. Uses NotificationURL
option to send a request
back to your server (where you use sagepay.finishTransaction
). See the
guidelines for more required options.
Additional options:
testing
switches to Sage Pay's test server. Defaults tofalse
Returns a promise containing the response data. Use NextURL
to
redirect your client to Sage Pay's transaction portal.
sagepay.registerPayment({
Vendor: 'your vendor name',
NotificationURL: 'your notification endpoint',
TxType: 'payment',
// ...
}).then(result => {
console.log(result.Status)
console.log(result.NextURL)
}, err => {
console.error(err)
})
sagepay.transactionResults(request)
Takes a http.Server
request that comes from Sage Pay's server (after
registering the transaction) and returns a promise of the results. Use
sagepay.finishTransaction
after.
sagepay.transactionResults(request).then(data => {
console.log(data.Status)
console.log(data.VendorTxCode)
// ...
}, err => {
console.error(err)
})
sagepay.finishTransaction(response, options)
Writes a http.Server
response to Sage Pay finishing the transaction.
Uses RedirectURL
option to send the user from the transaction portal back to
your website. See the guidelines for more options.
Returns a promise and resolves when successful.
sagepay.finishTransaction(request, response, {
Status: 'OK',
RedirectURL: 'your finish page',
// ...
}).then(resp => {
console.log('Finished transaction')
}, err => {
console.error(err)
})
sagepay.testCards
A list of different test cards in the format:
{
"method": "Visa",
"number": "4929 0000 0000 6",
"cardtype": "VISA",
"3dsecure": "Y"
}
See the guidelines for more details
sagepay.fields
List of all request and response fields with proper casing.
License
MIT © Jamen Marz