1. Go to this page and download the library: Download niush/laravel-nano-to library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niush / laravel-nano-to example snippets
Route::get('/order/success/{id}', [OrderController::class, 'success'])->name('nano-to-success'); // E.g. Shows a static order success page.
Route::get('/order/cancel/{id}', [OrderController::class, 'cancel'])->name('nano-to-cancel'); // E.g. Redirects back to Cart Page
// PERFORM PAYMENT CONFIRMED BUSINESS LOGIC
Route::post('/order/webhook/{id}', [OrderController::class, 'webhook'])->name('nano-to-webhook');
// 1) With Specific Amount
return NanoTo::amount(10)->create($order->id, function($checkout_url) {
// Do Something with $checkout_url if To::info("Payment for Subscription", "<i>Also accepts HTML</i>")
->amount(9.99)
->create($order->id)->send();
// 3) With Additional Metadata (Can be received in Webhook)
return NanoTo::amount(9.99)->metadata([
"user_id" => $user->id,
"order_id" => $order->id
])->create($order->id)->send();
// 4) For Suggest based payment. Useful in cases like Donation.
return NanoTo::info("Donate Us")
->suggest([
["name" => "Coffee", "price" => "10"],
["name" => "Meal", "price" => "50"]
])
->create($uuid)->send();
// 5) Use RAW friendly Amount in QR Codes (e.g. for Natrium)
return NanoTo::asRaw()->amount(9.99)->create($order->id)->send();
// 6) With Custom Image in Checkout page
return NanoTo::withImage("full_url_of_image")->amount(9.99)->create($order->id)->send();
// 7) Or Simply, if no need to track anything. And,
// You can get the Header and compare with your config secret. In Webhook Controller:
$request->header('Webhook-Secret') == config("nano-to.webhook_secret") // Valid
// Compare the body, store == $order->amount_in_usd;
$request->input('status') == "complete";
$request->input('block.type') == "receive";
// You can also compare receiver address is in config or not.
$order->via = "nano";
$order->hash = $request->input('block.hash');
$order->status = "complete";
$order-save();
public function webhook(Request $request, Order $order) {
if($request->header('Webhook-Secret') != config("nano-to.webhook_secret")) {
$order->status = "failed"; // Webhook Secret is MALFORMED
$order->remarks = "Payment Verification Malformed";
}
else {
if(
$request->input('amount') == $order->amount_in_usd &&
$request->input('status') == "complete" &&
$request->input('block.type') == "receive" &&
$request->input('block.hash')
) {
$order->status = "complete";
$order->hash = $request->input('block.hash');
$order->remarks = "Payment Complete from Address: " . $request->input('block.account') . " , with Amount: " . $request->input('method.amount');
$order->save();
}
else {
$order->status = "failed"; // Payment Amount is not correct or not complete etc.
$order->remarks = "Payment Was Not Fully Completed";
}
}
// You can also utilize Metadata for verification:
// $request->input('metadata.user_id') == $order->user_id;
$order->save();
return ["success" => true];
}
use Niush\NanoTo\NanoToApi;
// 1) Get CoinMarketCap conversion rate
NanoToApi::getPrice("NANO", "USD");
NanoToApi::getPrice("XMR", "NPR");
NanoToApi::getPrice("NANO", "XMR");
// 2) Get Nano.to Custom Username alias information
NanoToApi::getUsername("moon");
// 3) Get Nano Address Information (OR Nano.to alias info)
NanoToApi::getNanoAddressInfo("nano_3xxxx");
// 4) Get Total Nano Balance from all nano address provided in config file
NanoToApi::getTotalNanoBalance();
// 5) Get Pending Nano Blocks
NanoToApi::getPendingNanoBlocks("nano_3xxxx");
// 6) Get Last 50+ Block History
NanoToApi::getNanoAddressHistory("nano_3xxxx");
// 7) Get Nano Transaction by specific Amount (Amount must be in Nano decimal format)
NanoToApi::getNanoTransactionByAmount("nano_3xxxx", "2.101");
// 8) Get Nano Transaction by block HASH
NanoToApi::getNanoTransactionByHash("NANO_HASH");
// 9) Get JSON Representation of given checkout URL. Only has 12 hour lifespan.
NanoToApi::getCheckoutUrlAsJson("https://nano.to/checkout/xxx");
// 10) Get List Of Public Representatives for Nano. And, Search by first parameter.
NanoToApi::getListOfPublicRepresentatives("ninja");
// 11) Get List Of Nano.to known Usernames. And, Search by first parameter.
NanoToApi::getListOfNanoUsernames("esteban");
// 12) Check if nanocrawler is down or unreachable. Returns boolean true if down.
NanoToApi::isNanoCrawlerDown();
// 13) Check if Nano.to base_url is down or unreachable. Returns boolean true if down.
NanoToApi::isNanoToDown();