Fingerprint
In certain scenarios, you will need to provide a fingerprint ID generated by our JavaScript library.
After obtaining the fingerprint from our JavaScript, submit it in the fingerprint.session_id field on the Create Charge endpoint.
How to Obtain a Fingerprint
Step 1: Include the Library
Add our library to your checkout page by including the following script:
<script src="https://sandbox-api.pathly.io/js/fingerprint/{MERCHANT_ID}?pk={PUBLISHABLE_KEY}"></script>
Replace {MERCHANT_ID} with your unique merchant ID.
Replace {PUBLISHABLE_KEY} with your own publishable key obtained from the Developers Dashboard.
Step 2: Initialize the Library
Initialize the library to obtain the fingerprint ID using the init method. This method returns a promise that resolves with the fingerprint ID or rejects if an error occurs.
collect
.init()
.then((fingerprint) => {
// Send this fingerprint to your server
fingerprintElement.innerText = `Fingerprint: ${fingerprint}`;
})
.catch((error) => {
fingerprintElement.innerText = `Error: ${error}`;
});
Below is a full example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pathly Fingerprint</title>
<script src="https://sandbox-api.pathly.io/js/fingerprint/{MERCHANT_ID}?pk={PUBLISHABLE_KEY}"></script>
</head>
<body>
<div id="fingerprintElement"></div>
<script>
collect
.init()
.then((fingerprint) => {
document.getElementById(
"fingerprintElement"
).innerText = `Fingerprint: ${fingerprint}`;
})
.catch((error) => {
document.getElementById(
"fingerprintElement"
).innerText = `Error: ${error}`;
});
</script>
</body>
</html>
Step 3: Submit the fingerprint ID
Once you have obtained the fingerprint ID using the JavaScript library, you need to submit it to our server when making a request to the Create Charge endpoint. Include the fingerprint ID in the fingerprint field of your API call.
Here's an example of how to include the fingerprint ID in the API call:
Code Examples
Here are code examples in PHP, Go, Python, and Node.js for submitting the fingerprint ID to the server:
PHP
<?php
$chargeData = [
// other charge data...
'fingerprint' => [
'session_id' => $fingerprint, // Include the fingerprint ID here
],
];
// Make the API call to create a charge
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sandbox-api.pathly.io/charges");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($chargeData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer {YOUR_API_KEY}'
]);
$response = curl_exec($ch);
curl_close($ch);
// Handle the response...
?>
Go
package main
import (
"fmt"
"net/http"
"bytes"
)
func main() {
url := "https://sandbox-api.pathly.io/charges"
payload := []byte(`{
// other charge data...
"fingerprint": {
"session_id": "` + fingerprint + `"
}
}`)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(payload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer {YOUR_API_KEY}")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
Python
import requests
url = 'https://sandbox-api.pathly.io/charges'
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {YOUR_API_KEY}'}
data = {
# other charge data...
'fingerprint': {
'session_id': fingerprint # Include the fingerprint ID here
}
}
response = requests.post(url, json=data, headers=headers)
# Handle the response...
Node.js
const axios = require("axios");
const chargeData = {
// other charge data...
fingerprint: {
session_id: fingerprint, // Include the fingerprint ID here
},
};
// Make the API call to create a charge
axios
.post("https://sandbox-api.pathly.io/charges", chargeData)
.then((response) => {
// Handle the response...
})
.catch((error) => {
// Handle the error...
});
Feel free to use the code example that matches your preferred programming language.
Handling Errors
Be aware that ad-blockers and privacy plugins may prevent the script from loading, resulting in a 'Network error'. If this occurs, advise customers to disable any ad-blockers to proceed.
When making a request to the Create Charge endpoint, you should submit the fingerprint value that was returned by our script.