Documentation
Installation
Step 1: Generate script from https://1pay.network/crypto-payment-sdk
![](assets/images/generate_script.png)
Enter recipient wallet address to generate script. Example:
Step 2: Insert generated script into your website, inside <body> tag
Step 3: Execute function onepay() when you want to initiate a payment
Excute in Javascript:
onepay(0.05, 'usdt', 'this is payment note')
/*
onepay(
amount: Number, // payment value
token: String, // token name: usdt, usdc, dai
note: String // (optional) you can note anything that can help you identify the buyer and the product
)
*/
Or directly in the button:
<button onclick="onepay(0.1, 'usdt', 'note anything here')">Pay</button>
Try demo on JSFiddle: https://jsfiddle.net/1paynetwork/2ux893ct/1/
Callback
You can declare function onepaySuccess() and onepayFail() to handle payment callbacks
// onepaySuccess will be executed when payment successful
const onepaySuccess = (PaymentResponse) => {
// console.log(PaymentResponse)
// example: {hash: 'Ox1ab...', success: true, network: 'arbitrum', amount: 1, token: 'usdt' note: 'product_2|user_1'}
// (optional)
// here you can send PaymentResponse to your server
// then use API Re-check Transaction of 1PAY to verify payment
// this will improve the security of the payment process
}
// onepayFail will be executed when payment failed
const onepayFail = (PaymentResponse) => {
// console.log(PaymentResponse)
// example: {hash: undefined, success: false, network: 'bsc', amount: 2, token: 'usdc', note: 'buyer_email|[email protected]'}
}
Payment Response
Data structure of PaymentResponse
PaymentResponse : {
hash: String, // transaction hash, maybe undefined if payment failed
success: Boolean, // true if payment success, otherwise false
network: String, // blockchain name
amount: Number, // transaction value
token: String, // token name
note: String // transaction note,
paymentTime: Date // the date time this payment is processed
}
Full Example
<html>
<head></head>
<body>
<button onclick="onepay(0.1, 'usdt', 'Demo onepay')">Pay 0.1 USDT</button>
<script src="https://1pay.network/onepay.js?recipient=0x8d70EC40AAd376aa6fD08e4CFD363EaC0AB2c174&network=ethereum,arbitrum,optimism,bsc&token=usdt,usdc,dai"></script>
<script>
const onepaySuccess = (PaymentResponse) => {
console.log(PaymentResponse)
// (optional)
// here you can send PaymentResponse to your server
// then use API Re-check Transaction of 1PAY to verify payment
// this will improve the security of the payment process
}
</script>
</body>
</html>
Try demo on JSFiddle: https://jsfiddle.net/1paynetwork/2ux893ct/1/
Mobile SDK
Easily to integrate 1PAY with SDK for iOS and Android.
iOS SDK
View on Github
Android SDK
View on Github
Manual Integration
1PAY can be integrated into any application/software platform as long as it supports WebView.
Usage
Step 1: Create a WebView that opens 1PAY url with the following format:
https://1pay.network/app?recipient={recipient_wallet_address}&network={supported_network}&token={supported_token}&paymentAmount={payment_value}&paymentToken={payment_token}&paymentNote={payment_note}
Example:
Step 2: Handle callbacks
In case of successful payment, the WebView url will be changed to:
https://1pay.network/success?hash={transaction_hash}&network={blockchain_network}&amount={payment_value}&token={payment_token}¬e={payment_note}
Note: The parameters on the url are the return data of payment.
In case of failed payment, the WebView url will be changed to:
https://1pay.network/fail?network={blockchain_network}&amount={payment_value}&token={payment_token}¬e={payment_note}
Note: The parameters on the url are the return data of payment.
So you need to catch the webview url changed event to handle the payment status & data, please see the examples below for each application platform.
iOS Example
Writen in Swift and uses WKWebView
View on Github
Android Example
Writen in Kotlin and uses Android WebView
View on Github
ElectronJS Example
Writen in Javascript and HTML
View on Github
WinForms C# Example
Writen in C# and uses WinForms WebView2
View on Github
Python Example
Writen in Python and uses pywebview
View on Github
API
API Re-check Transaction
Use this API to re-check a transaction. This step can improve the security of the payment process
[GET] https://api.1pay.network/check?network={network_name}&hash={transaction_hash}
Example:
Response in case re-check transaction successfully. Status code: 200
{
"success": true,
"data": {
"_id": "655329f56be62bec34eb913b",
"hash": "0x8bfdae41cf1ca7b9cb514eae273759a36547e400f2797304effc509c7fb2a4e7",
"network": "arbitrum",
"amount": 0.1, // Amount in usdt
"blockNumber": 150186511, // The number of the block that validated this transaction on the blockchain
"note": "demo note",
"onePayFee": 0.001,
"paymentTime": "2023-11-14T02:34:46.000Z", // the time transaction was confirmed successfully on blockchain
"recipient": "0xa0df561dd599d210f83c36ffdfaf7112dadade30",
"sender": "0x587df3e27550a792c31bd319881754a68741f1b3",
"status": 1, // 1 - Transaction executed successfully on blockchain
// 0 - Transaction executed failed on blockchain
"token": "usdt",
"createdAt": "2023-11-14T08:04:05.360Z", // 1Pay's internal tracking time
"updatedAt": "2023-11-14T08:04:05.360Z" // 1Pay's internal tracking time
}
}
Response in case transaction not found. Status code: 404
{
"success": false,
"message": "Transaction not found."
}
API Report
Get report of a recipient address.
[GET] https://api.1pay.network/analytics/filter?recipient={recipient_address}
Example:
https://api.1pay.network/analytics/filter?recipient=0xa0df561dd599d210f83c36ffdfaf7112dadade30
Response in case successfully. Status code: 200
{
"success": true,
"data": {
"items": [
{
"_id": "65532c876be62bec34eb92ff",
"hash": "0xe8a2ea73a59df41d95d297b61bd7fe10494b684fc9297cddee90d830b030c793",
"network": "bsc",
"amount": 0.1, // Amount in usdt
"blockNumber": 33331386, // The number of the block that validated this transaction on the blockchain
"note": "test note",
"onePayFee": 0.001,
"paymentTime": "2023-11-09T03:23:22.000Z", // the time transaction was confirmed successfully on blockchain
"recipient": "0xa0df561dd599d210f83c36ffdfaf7112dadade30",
"sender": "0x26634ab74242af10e858fd9d24b795fb1f1bf92b",
"status": 1,
"token": "usdt",
"createdAt": "2023-11-14T08:15:03.982Z", // 1Pay's internal tracking time
"updatedAt": "2023-11-24T03:21:28.059Z" // 1Pay's internal tracking time
},
{
"_id": "655329f56be62bec34eb913b",
"hash": "0x8bfdae41cf1ca7b9cb514eae273759a36547e400f2797304effc509c7fb2a4e7",
"network": "arbitrum",
"amount": 0.1,
"blockNumber": 150186511,
"note": "demo note",
"onePayFee": 0.001,
"paymentTime": "2023-11-14T02:34:46.000Z",
"recipient": "0xa0df561dd599d210f83c36ffdfaf7112dadade30",
"sender": "0x587df3e27550a792c31bd319881754a68741f1b3",
"status": 1,
"token": "usdt",
"createdAt": "2023-11-14T08:04:05.360Z",
"updatedAt": "2023-11-24T03:21:28.059Z"
}
],
"totalItems": 2
}
}
Response in case no transaction are found. Status code: 200
{
"success": true,
"data": {
"items": [],
"totalItems": 0
}
}
Response in case invalid input. Status code: 400
{
"success": false,
"message": "sender is not allowed"
}