// Get your keys in https://www.coinpayments.net/index.php?cmd=acct_api_keys
Libs.CoinPayments.setPrivateKey("YOUR KEY");
Libs.CoinPayments.setPublicKey('YOUR KEY');
// for Receiving Payments
// Get your BB Api Key from Bots.Business App in Profile
Libs.CoinPayments.setBBApiKey('YOUR API KEY');
let amount = 0.0001; // amount in BTC
options = {
fields: {
amount: amount, // amount in BTC
currency: "BTC", // currency1 = currency2 = BTC
// currency1: "BTC", // The original currency of the transaction
// currency2: "LTC" //The currency the buyer will be sending
// buyer_email: "[email protected]",
// you can use another fields also
// except custom and ipn_url (it used by Lib)
// See https://www.coinpayments.net/apidoc-create-transaction
},
// generated wallet, QR code, payment page
// will be available in this command
onSuccess: '/onCreatePayment',
// on successful payment this command
// will be executed
onPaymentCompleted: "/onPaymentCompleted",
// it is not necessary
// onIPN: "/onIPN"
// if you want customize error messages
// onError: "/onError"
}
Libs.CoinPayments.createTransaction(options);
// You can inspect all options:
// Bot.sendMessage(inspect(options));
let result = options.result;
let msg = "*Need pay:*\n `" + result.amount + "`" +
"\n\n*to address:*\n" +
"`" + result.address + "`" +
"\n\n [Checkout](" + result.checkout_url +
") | [Status](" + result.status_url +
")" // you can uncomment this for manual status checking
// + "\n\nCheck status manually: /check" + options.payment_index;
Bot.sendMessage(msg);
Api.sendPhoto({ photo: result.qrcode_url });
// you can inspect all options
// Bot.sendMessage(inspect(options));
if(!options){
// for security we need to check that this command runned only by lib
// user can not run command with options
return
}
Bot.sendMessage("Payment completed");
let amount = options.amount1;
let res = Libs.ResourcesLib.userRes("balance");
res.add(amount)
Bot.sendMessage("added to balance, BTC: " + amount);
Libs.CoinPayments.getTxInfo({
payment_index: payment_index, // see /onCreatePayment command.
// Need pass this payment_index to this command
onSuccess: '/on_txn_id'
})
// You can inspect all options:
// Bot.sendMessage(inspect(options));
Bot.sendMessage(options.result.status_text);
// Do not finish payment here.
// Use /onPaymentCompleted for this
// You can inspect all fields:
// Bot.sendMessage(inspect(options))
// IPN is not needed
// Use - onPaymentCompleted
Bot.sendMessage("IPN: Payment status: " + options.status_text );
// You can inspect all fields:
Bot.sendMessage(inspect(options))
Libs.CoinPayments.createPermanentWallet({
currency: "BTC",
//label: "myLabel",
onSuccess: "/onWalletCreate",
// onIPN - not necessary
//onIPN: "/onPermanentWalletIPN",
onIncome: "/onIncome"
// if you want customize error messages
// onError: "/onError"
});
//Bot.sendMessage(inspect(options));
let wallet = options.result.address;
Bot.sendMessage("Your permanent wallet address is:\n`" + wallet + "`")
// You can save wallet
//User.setProperty("wallet", wallet, "string");
// anybody can run /onIncome command!
if(!options){
// for security we need to check that this command runned only by lib
// user can not run command with options
return
}
let wallet = options.address;
let currency = options.currency;
let amount = options.amount;
let fiat_amount = options.fiat_amount;
let fiat_currency = options.fiat_coin;
let fee = options.fee;
let txn_id = options.txn_id
// see another fields by
// Bot.sendMessage(inspect(options));
Bot.sendMessage(
"*Income to wallet:*" +
"\n`"+ wallet + "`" +
"\n\n*Amount*:\n" +
amount + " " + currency + " (" + fiat_amount + " " + fiat_currency + ")" +
"\n*Fee*: " + fee +
"\n\nTXN: `" + txn_id + "`"
);
// You can inspect all fields:
Bot.sendMessage(inspect(options))
options = {
// onIPN: "/onPermanentWalletIPN", // if you need IPN also
onIncome: "/onIncome",
// not necessary options
// you can pass amount
//amount: 0.5
// txn_id: YOUR_TXN_ID
}
Libs.CoinPayments.callTestPermanentWalletIncome(options);
if(!options){
// for security we need to check that this command runned only by lib
// user can not run command with options
return
}
// your secure code
...