PHP class for integrating the Litepay Payment API and Merchant API into your project.
Overview
The Litepay PHP class is a wrapper for our Crypto Payment API and Merchant API. Import it into your project and start accepting Bitcoin, Litecoin, Zcash, Bitcoin Cash, Monero and other cryptocurrency payments with a few lines of code.
Download: github.com/litepaych/litepay
Parameters
| Parameter | Description |
|---|---|
| method | Cryptocurrency to use: btc, ltc, zec, bch or xmr |
| receiving_address | Your wallet address where payments will be forwarded |
| callback_url | URL to notify on payment (must be URL-encoded, domain must be valid) |
Payment API Examples
include('litepay_ch.php');
$litepay = new litepay('api');
$_secret = 'my_secret_passphrase';
$invoice_id = '123_order_number';
$callback_url = 'https://your_domain.com/callbacks/litepay/callback.php?id='.$invoice_id.'&secret='.$_secret;
$method = 'btc';
$return_address = '1BDesouFJaHyr7DejtGrq7K14D5gSbS4DT';
$parameters = array(
'address' => $return_address,
'method' => $method,
'callback' => urlencode($callback_url)
);
$new_address = $litepay->receive($parameters);
if ($new_address->status == "success") {
$address = $new_address->address;
}
include('litepay_ch.php');
$litepay = new litepay('api');
$method = 'btc';
$parameters = array(
'address' => $generated_address,
'method' => $method
);
$check_address = $litepay->check($parameters);
if ($check_address->status == "success") {
$address = $check_address->address;
$amount = $check_address->amount;
$confirmations = $check_address->confirmations;
$txids = $check_address->txids;
}
More Payment API examples: github.com/litepaych/litepay/examples/regular_api
Merchant API Example
To use the Merchant API you need a Vendor ID:
- Register for a merchant account
- Go to Vendor and create your Vendor ID - you'll receive the credentials by email
include('litepay_ch.php');
$litepay = new litepay('merchant');
$invoice_id = 22;
$callback_url = 'https://domain.com/callback_url.php?invoice='.$invoice_id;
$return_url = 'https://domain.com/success.php';
$parameters = array(
'vendor' => 'VENDOR_ID',
'invoice' => $invoice_id,
'secret' => 'PASSPHRASE',
'currency' => 'USD',
'email' => urlencode('user@email'),
'price' => '2',
'callbackUrl' => urlencode($callback_url),
'returnUrl' => urlencode($return_url)
);
$data = $litepay->merchant($parameters);
if ($data->status == 'success') {
header("Location: $data->url");
} else {
print $data->message;
}
Tip
Always use valid domains for your callback and return URLs, or the request will be denied.
More Merchant API examples: github.com/litepaych/litepay/examples/merchant