OPayo
A Node.js Client for interracting with the OPayo(SagePay) API
Documentation
See SagePay API Reference
Installation
Install the package with
npm install @mhayk/sagepay --save
or
yarn add @mhayk/sagepay
Usage
Create a Client
instance and provide the access_token and environment you want to use.
const sagepay = ;const Client = sagepayClient; // Gets Access Token stored in environment variableconst VENDOR_NAME = processenvVENDOR_NAMEconst SANDBOX_INTEGRATION_KEY = processenvSANDBOX_INTEGRATION_KEYconst SANDBOX_INTEGRATION_PASSWORD = processenvSANDBOX_INTEGRATION_PASSWORD const client = vendor_name: VENDOR_NAME integration_key: SANDBOX_INTEGRATION_KEY integration_password: SANDBOX_INTEGRATION_PASSWORD environment: "sandbox" card: "007" ; console const merchant = await clientmerchant_session_keys;const expiry merchantSessionKey = merchantconsole clientmerchantSessionKey = merchantSessionKey; const card = cardDetails: cardholderName: 'TEST' cardNumber: '4929000005559' expiryDate: '0821' securityCode: '123' const newCardIdentifier = await clientcard_identifiersconst cardIdentifier = newCardIdentifierconsole const payment = transactionType: 'Payment' paymentMethod: card: merchantSessionKey cardIdentifier vendorTxCode: '0102030405-faraan' amount: 100 currency: 'GBP' description: 'MHAYK TEST LIBRARY' customerFirstName: 'MHAYK WHANDSON' customerLastName: 'DA SILVA LIMA' billingAddress: address1: "11, Worton Road" city: 'London' postalCode: "TW7 6HJ" country: "GB" const transaction = await clienttransactionsconsole
Usage with Typescript
; // Gets Access Token stored in environment variable ; console.logclient ;console.log`Expiry: , Merchant Session Key: ` client.merchantSessionKey = merchantSessionKey; console.log`Card Identifier: ` console.logtransaction
Events
The SagePay Client instance emits request
and response
events
const sagepay = ;const Client = sagepayClient; const VENDOR_NAME = processenvVENDOR_NAMEconst SANDBOX_INTEGRATION_KEY = processenvSANDBOX_INTEGRATION_KEYconst SANDBOX_INTEGRATION_PASSWORD = processenvSANDBOX_INTEGRATION_PASSWORD // Gets Access Token stored in environment variableconst access_token = processenvACCESS_TOKEN;const environment = "sandbox"; const client = vendor_name: VENDOR_NAME integration_key: SANDBOX_INTEGRATION_KEY integration_password: SANDBOX_INTEGRATION_PASSWORD environment: "sandbox" card: "007" ; // Add the request event handler function:client; // Add the request event handler function:client;
Avaliable resources
- Merchant Session Keys
- Card Identifiers
- Transactions
Development
Running tests
$ npm install$ npm test
or
$ yarn$ yarn test
To use your Sandbox Access Token to run the tests, you need to set the file .env with the following variables:
VENDOR_NAME=
SANDBOX_INTEGRATION_KEY=
SANDBOX_INTEGRATION_PASSWORD=