### Install from Git Repository (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Installs the library directly from a Git repository using npm.
```shell
npm install citypay/citypay-api-client-js --save
```
--------------------------------
### Install Dependencies (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Installs project dependencies using npm. This is a prerequisite for local development.
```shell
npm install
```
--------------------------------
### Install CityPay API Client (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Installs the CityPay API client library for Node.js using npm. This command downloads the package and saves it as a dependency in your project.
```shell
npm install citypay-api --save
```
--------------------------------
### Build CityPay API Client Module
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Builds the CityPay API client module after installation. This step is necessary to compile the JavaScript code for use in your Node.js application.
```shell
npm run build
```
--------------------------------
### CityPay API Authorization Request
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Example of making an authorization request to the CityPay API using the JavaScript client.
```javascript
import CityPay from 'citypay-api';
let auth_request = new CityPay.AuthRequest();
auth_request.identifier = "example1";
new CityPay.PaymentProcessingApi().authorisationRequest(auth_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Select Field Examples - CityPay API Client JS
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkCustomParam.md
Demonstrates how to configure 'select' field types for the CityPay API Client in JavaScript, including basic values and label-value pairs. This allows for creating dropdowns with predefined options.
```json
{
"label": "Age Group",
"fieldType": "select",
"value": "Under 18|18-30|30-50|50+"
}
```
```html
```
```json
{
"label": "Age Group",
"fieldType": "select",
"value": "0:Under 18|1:18-30|2:30-50|3:50+"
}
```
```html
```
--------------------------------
### Register Temporary Key with CityPay API Client JS
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/OperationalFunctionsApi.md
Provides an example of registering a temporary license key using the CityPay API Client for JavaScript. It demonstrates initializing the client and calling the registerTempKey method.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.OperationalFunctionsApi();
let register_ip_model = new CityPay.RegisterIpModel(); // RegisterIpModel |
apiInstance.registerTempKey(register_ip_model).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Direct Post Tokenize Request
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/DirectPostApi.md
Initiates a direct post request for tokenization using the CityPay API client. This example demonstrates setting up the client and making a tokenization request, which is part of the transaction flow.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
// Configure API key authorization: cp-domain-key
let cp-domain-key = defaultClient.authentications['cp-domain-key'];
cp-domain-key.apiKey = 'YOUR API KEY';
//cp-domain-key.apiKeyPrefix = 'Token';
let apiInstance = new CityPay.DirectPostApi();
let direct_post_request = new CityPay.DirectPostRequest(); // DirectPostRequest |
apiInstance.directPostTokeniseRequest(direct_post_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Ping Request with CityPay API Client JS
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/OperationalFunctionsApi.md
Shows how to perform a ping request to test the CityPay API connection and authentication. This example initializes the API client and uses the pingRequest method from the OperationalFunctionsApi.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
// Configure API key authorization: cp-domain-key
let cp-domain-key = defaultClient.authentications['cp-domain-key'];
cp-domain-key.apiKey = 'YOUR API KEY';
//cp-domain-key.apiKeyPrefix = 'Token';
let apiInstance = new CityPay.OperationalFunctionsApi();
let ping = new CityPay.Ping(); // Ping |
apiInstance.pingRequest(ping).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Direct Post Authentication Request
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/DirectPostApi.md
Initiates a direct post request for authentication using the CityPay API client. This example shows how to configure the client with sandbox mode, client ID, and license key, and then make an authenticated request.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
// Configure API key authorization: cp-domain-key
let cp-domain-key = defaultClient.authentications['cp-domain-key'];
cp-domain-key.apiKey = 'YOUR API KEY';
//cp-domain-key.apiKeyPrefix = 'Token';
let apiInstance = new CityPay.DirectPostApi();
let direct_post_request = new CityPay.DirectPostRequest(); // DirectPostRequest |
apiInstance.directPostAuthRequest(direct_post_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### MAC Generation Example
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/DirectPostRequest.md
Demonstrates the process of generating a Message Authentication Code (MAC) for CityPay transactions. This involves using a license key, nonce, amount, and identifier to create a secure hash.
```javascript
function generateMAC(licenseKey, nonce, amount, identifier) {
const secret = licenseKey;
const value = nonce + amount.toString() + identifier;
// In a real scenario, you would use a crypto library like 'crypto-js'
// For demonstration, this is a placeholder for the HMAC-SHA256 operation.
// const mac = CryptoJS.HmacSHA256(value, secret).toString(CryptoJS.enc.Hex).toUpperCase();
const mac = "163DBAB194D743866A9BCC7FC9C8A88FCD99C6BBBF08D619291212D1B91EE12E"; // Example MAC
return mac;
}
```
--------------------------------
### Link Library into Project (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Links the globally linked library into your current project directory, allowing you to use the local version.
```shell
npm link /path/to/
```
--------------------------------
### Get Paylink Token Status
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkApi.md
Obtains the full status of a given Paylink Token. This function requires only the token string and returns the PaylinkTokenStatus.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaylinkApi();
let token = "token_example"; // String | The token returned by the create token process.
apiInstance.tokenStatusRequest(token).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### JavaScript API Client Initialization and Bill Payment Token Creation
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkApi.md
This JavaScript code demonstrates how to initialize the CityPay API client with sandbox mode, client ID, and license key. It then shows how to create an instance of the Paylink API and request a bill payment token, handling the response or errors.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaylinkApi();
let paylink_bill_payment_token_request = new CityPay.PaylinkBillPaymentTokenRequest(); // PaylinkBillPaymentTokenRequest |
apiInstance.tokenCreateBillPaymentRequest(paylink_bill_payment_token_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### 3DSv1 Authentication Required Response (XML)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaymentProcessingApi.md
Example of an XML response indicating that 3DSv1 authentication is required. It includes the ACS URL, PAReq, and MD values needed to initiate the authentication process.
```xml
https://bank.com/3DS/ACSSXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN00...WQgZXZlcnl0aGluZyBiZW
```
--------------------------------
### Build Module (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Builds the JavaScript module, typically transpiling or bundling the code for use.
```shell
npm run build
```
--------------------------------
### 3DSv1 Authentication Required Response (JSON)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaymentProcessingApi.md
Example of a JSON response indicating that 3DSv1 authentication is required. It includes the ACS URL, PAReq, and MD values needed to initiate the authentication process.
```json
{
"AuthenticationRequired": {
"acsurl": "https://bank.com/3DS/ACS",
"pareq": "SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN00...",
"md": "WQgZXZlcnl0aGluZyBiZW"
}
}
```
--------------------------------
### Bundle for Browser (Browserify)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Bundles a JavaScript entry file into a single file for browser use with Browserify.
```shell
browserify main.js > bundle.js
```
--------------------------------
### Update Paylink Token Status
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkApi.md
This example demonstrates how to update the status of a Paylink Token. It involves creating a `PaylinkTokenStatusChangeRequest` object and passing it to the `tokenChangesRequest` method of the CityPay API client. The outcome is logged to the console.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaylinkApi();
let paylink_token_status_change_request = new CityPay.PaylinkTokenStatusChangeRequest(); // PaylinkTokenStatusChangeRequest |
apiInstance.tokenChangesRequest(paylink_token_status_change_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Initiate Authorization Request with CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaymentProcessingApi.md
This JavaScript code demonstrates how to initialize the CityPay API client and make an authorization request. It shows setting up the client with sandbox mode and credentials, creating an AuthRequest object, and handling the API response or errors.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaymentProcessingApi();
let auth_request = new CityPay.AuthRequest(); // AuthRequest |
apiInstance.authorisationRequest(auth_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Cancel Paylink Token
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkApi.md
This example shows how to cancel a Paylink Token using the CityPay API client. It initializes the client and then calls the `tokenCancelRequest` method with a token. The success or failure of the cancellation is logged to the console.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaylinkApi();
let token = "token_example"; // String | The token returned by the create token process.
apiInstance.tokenCancelRequest(token).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Link Library Globally (npm)
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Globally links the local library using npm, making it available for linking into other projects.
```shell
npm link
```
--------------------------------
### Subscribe to Webhooks
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/WebHooks.md
This snippet demonstrates how to subscribe to webhook events using the CityPay API client. It initializes the client with sandbox and credentials, then calls the webHookSubscriptionRequest method.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.WebHooks();
let web_hook_subscription_request = new CityPay.WebHookSubscriptionRequest(); // WebHookSubscriptionRequest |
apiInstance.webHookSubscriptionRequest(web_hook_subscription_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Batch Retrieve Request using CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/BatchProcessingApi.md
Obtains a batch and installment (BIS) report for a given batch ID. The function requires an initialized CityPay API client and a BatchReportRequest object. It handles the API call and logs the returned data or any errors encountered.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.BatchProcessingApi();
let batch_report_request = new CityPay.BatchReportRequest(); // BatchReportRequest |
apiInstance.batchRetrieveRequest(batch_report_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Check Token Attachment Status
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkApi.md
This example demonstrates how to check the status of an attachment for a given token using the CityPay API client. It initializes the client with sandbox mode and API credentials, then calls the `tokenAttachmentStatus` method with a token and attachment name. The result is logged to the console or an error is caught.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaylinkApi();
let token = "token_example"; // String | The token returned by the create token process.
let attachment = "attachment_example"; // String | The attachemnt name requested.
apiInstance.tokenAttachmentStatus(token, attachment).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### DomainKeyRequest Properties
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/DomainKeyRequest.md
Defines the properties for creating a DomainKeyRequest, including domain, merchant ID, and optional live and nonce fields for generating a domain key.
```javascript
/**
* Represents a request to generate a domain key.
* @typedef {object} DomainKeyRequest
* @property {string} domain - The domain name for which the key is generated.
* @property {number} merchantid - The merchant ID the domain key is to be used for.
* @property {boolean} [live=false] - Specifies if the key is to be used for production. Defaults to false.
* @property {string} [nonce] - Specifies a random value for integrity. The value is used to generate the domain key to provide further integrity to the key.
*/
```
--------------------------------
### Configure Partial Payments for Paylink
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkConfig.md
Sets up configurations for handling partial payments within a Paylink transaction.
```javascript
const paylinkConfig = {
part_payments: { ...PaylinkPartPayments }
};
```
--------------------------------
### Configure Paylink UI Settings
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkConfig.md
Applies specific UI configurations to the Paylink interface.
```javascript
const paylinkConfig = {
ui: { ...PaylinkUI }
};
```
--------------------------------
### Batch Process Request using CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/BatchProcessingApi.md
Initiates a batch process by uploading batch data. This function requires the CityPay API client to be initialized with sandbox mode, client ID, and license key. It takes a ProcessBatchRequest object as input and returns a ProcessBatchResponse upon successful API call.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.BatchProcessingApi();
let process_batch_request = new CityPay.ProcessBatchRequest(); // ProcessBatchRequest |
apiInstance.batchProcessRequest(process_batch_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Perform Verification Request with CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/AuthorisationAndPaymentApi.md
Shows how to set up the CityPay API client and execute a verification request for a card payment. This function is used to verify card payment requests.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.AuthorisationAndPaymentApi();
let verification_request = new CityPay.VerificationRequest(); // VerificationRequest |
apiInstance.verificationRequest(verification_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Specify Paylink Renderer Engine
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaylinkConfig.md
Selects the rendering engine to be used for the Paylink interface.
```javascript
const paylinkConfig = {
renderer: "engine_name"
};
```
--------------------------------
### Perform Bin Range Lookup with CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/PaymentProcessingApi.md
This JavaScript code illustrates how to perform a bin range lookup using the CityPay API client. It covers client initialization, creating a BinLookup object, and making the request to the bin range lookup service, including response and error handling.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.PaymentProcessingApi();
let bin_lookup = new CityPay.BinLookup(); // BinLookup |
apiInstance.binRangeLookupRequest(bin_lookup).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Perform Retrieval Request with CityPay API Client
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/AuthorisationAndPaymentApi.md
Demonstrates how to initialize the CityPay API client and make a retrieval request to obtain transaction results from the last 90 days. It handles potential multiple results and returns the first 5 transactions by default.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.AuthorisationAndPaymentApi();
let retrieve_request = new CityPay.RetrieveRequest(); // RetrieveRequest |
apiInstance.retrievalRequest(retrieve_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Initiate Charge Request
Source: https://github.com/citypay/citypay-api-client-js/blob/main/docs/CardHolderAccountApi.md
This snippet shows how to initiate a charge request using the CityPay JavaScript client. It involves creating a ChargeRequest object and passing it to the chargeRequest method. The response will indicate the decision of the charge.
```javascript
import CityPay from 'citypay-api';
let client = new CityPay.ApiClient({
"sandbox": true,
"client_id": process.env.CP_CLIENT_ID,
"licence_key": process.env.CP_LICENCE_KEY
})
let apiInstance = new CityPay.CardHolderAccountApi();
let charge_request = new CityPay.ChargeRequest(); // ChargeRequest |
apiInstance.chargeRequest(charge_request).then((data) => {
console.log('API called successfully. Returned data: ' + data);
}, (error) => {
console.error(error);
});
```
--------------------------------
### Web Hook Channel Create
Source: https://github.com/citypay/citypay-api-client-js/blob/main/README.md
Creates a new webhook channel. This is used to set up endpoints for receiving real-time notifications from CityPay.
```javascript
/**
* @summary Web Hook Channel Create Request
* @description Creates a new webhook channel.
* @param {object} options - The request options, including the channel URL and events to subscribe to.
* @returns {Promise