-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d3b22b7
Showing
13 changed files
with
636 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 ALFAcoins | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## Description | ||
|
||
**alfacoins-api-php** is a PHP Library for interacting with [ALFAcoins API](https://www.alfacoins.com/developers). | ||
|
||
**alfacoins-api-php** provides cryptocurrency payment integration on your website via [ALFAcoins](https://www.alfacoins.com). | ||
|
||
**alfacoins-api-php** allows you to integrate payments with the following cryptocurrencies: | ||
* Bitcoin (BTC) | ||
* Ethereum (ETH) | ||
* XRP (XRP) | ||
* Bitcoin Cash (BCH) | ||
* Litecoin (LTC) | ||
* Dash (DASH) | ||
|
||
## Installation | ||
|
||
alfacoins-api-php is available on [Packagist](https://packagist.org/packages/alfacoins/alfacoins-api-php) (using semantic versioning), and installation via [composer](https://getcomposer.org) is the recommended way to install alfacoins-api-php. Just add this line to your `composer.json` file: | ||
|
||
```json | ||
"alfacoins/alfacoins-api-php": "~v1.0" | ||
``` | ||
|
||
or run | ||
|
||
```sh | ||
composer require alfacoins/alfacoins-api-php | ||
``` | ||
|
||
Note that the `vendor` folder and the `vendor/autoload.php` script are generated by composer; they are not part of alfacoins-api-php. | ||
|
||
Alternatively, if you're not using composer, copy the contents of the alfacoins-api-php folder somewhere and load each class file manually: | ||
|
||
```php | ||
<?php | ||
// include once ALFAcoins Private API class | ||
require_once '../src/privateAPI.php'; | ||
require_once '../src/Exception.php'; | ||
use ALFAcoins\ALFAcoins_privateAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
``` | ||
|
||
To work with unstable version simply clone this repository: | ||
|
||
```sh | ||
git clone https://github.com/alfacoins/alfacoins-api-php | ||
cd alfacoins-api-php/ | ||
``` | ||
|
||
## Getting Started | ||
|
||
See the [examples](examples/) directory for examples of how to use this library. | ||
|
||
Additional information and API documentation is here: [ALFAcoins API Reference](https://www.alfacoins.com/developers). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "alfacoins/alfacoins-api-php", | ||
"description": "PHP Library for interacting with the ALFAcoins.com API.", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"ALFAcoins\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">=5.4", | ||
"ext-json": "*", | ||
"ext-curl": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Private API class | ||
require_once '../src/privateAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_privateAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// shop_name is the API name, replace 'ShopName 123' with your API name. Create API entry at https://www.alfacoins.com/user | ||
$shop_name = 'ShopName 123'; | ||
|
||
// shop_password_hash is an uppercase md5 hash of API password, replace 'MyShopPassword' with your actual API password | ||
$shop_password = 'MyShopPassword'; | ||
|
||
// shop_secret_key is your API secret_key, it's shown one time after you created the new API entry, if you didn't write it down you can reset it in your API settings | ||
$shop_secret_key = 'a8a0e3497c8b67b024babc9a4daf5f5c'; | ||
|
||
// initialize ALFAcoins Private API class with your API settings | ||
$api = new ALFAcoins_privateAPI($shop_name, $shop_password, $shop_secret_key); | ||
|
||
// BitSend is used to make payments to your customers (e.g. pay salaries). One BitSend request - one payment, you can't specify multiple addresses in a single BitSend request. | ||
// set options for BitSend XRP request (address and destination_tag), more documentation can be found here: https://www.alfacoins.com/developers#post_requests-bitsend | ||
$options = [ | ||
'address' => 'rKPPJJKE6gC3GqkCpsAew5gp4w3o3hCU4D', | ||
'destination_tag' => '123', | ||
]; | ||
|
||
// send 50 XRP to rKPPJJKE6gC3GqkCpsAew5gp4w3o3hCU4D with destination tag: 123 | ||
try { | ||
echo "Bitsend result:" . PHP_EOL; | ||
var_dump($bitsend = $api->bitsend(0, 50, 'xrp', $options, 'Client Name', 'noreply@alfacoins.com', 'Test Payment 50 XRP')); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Bitsend method failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// get current status of your BitSend operation | ||
try { | ||
echo "Bitsend Status result:" . PHP_EOL; | ||
var_dump($api->bitsend_status($bitsend['id'])); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Bitsend status failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// send 150 USD (depends on your API fiat currency settings, default is USD) XRP equivalent (using current exchange rate) to XRP account rKPPJJKE6gC3GqkCpsAew5gp4w3o3hCU4D with destination tag: 123 | ||
try { | ||
echo "Bitsend result: " . PHP_EOL; | ||
var_dump($api->bitsend(150, 0, 'xrp', $options, 'Client Name', 'noreply@alfacoins.com')); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Bitsend status failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// get current status of your BitSend operation | ||
try { | ||
echo "Bitsend Status result:" . PHP_EOL; | ||
var_dump($api->bitsend_status($bitsend['id'])); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Bitsend status failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Private API class | ||
require_once '../src/privateAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_privateAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// shop_name is the API name, replace 'ShopName 123' with your API name. Create API entry at https://www.alfacoins.com/user | ||
$shop_name = 'ShopName 123'; | ||
|
||
// shop_password_hash is an uppercase md5 hash of API password, replace 'MyShopPassword' with your actual API password | ||
$shop_password = 'MyShopPassword'; | ||
|
||
// shop_secret_key is your API secret_key, it's shown one time after you created the new API entry, if you didn't write it down you can reset it in your API settings | ||
$shop_secret_key = 'a8a0e3497c8b67b024babc9a4daf5f5c'; | ||
|
||
// initialize ALFAcoins Private API class with your API settings | ||
$api = new ALFAcoins_privateAPI($shop_name, $shop_password, $shop_secret_key); | ||
|
||
// prepare options to create a new order, more about it here: https://www.alfacoins.com/developers#post_requests-create | ||
$options = [ | ||
// notificationURL is used for notification about order's status change | ||
// PLEASE NOTE: you can only use verified websites in the websites integration area | ||
'notificationURL' => 'http://example.com/receive.php', | ||
// redirectURL is used to redirect your customer from the payment page | ||
'redirectURL' => 'http://example.com/completed?id=MyOrder123', | ||
// payerName is your customer's name used to notify your customer about order | ||
'payerName' => 'John Smith', | ||
// payerEmail is your customer's e-mail address used to notify your customer about order | ||
'payerEmail' => 'john.smith@test.com', | ||
]; | ||
|
||
// internal order_id which you can use to track this order in your own system, will be also displayed on the payment page | ||
$order_id = '999'; | ||
|
||
// order description (will be displayed on your payment page) | ||
$order_description = 'Payment for Order #999'; | ||
|
||
// cryptocurrency type | ||
$type = 'bitcoin'; | ||
|
||
// amount in fiat currency, 100 USD in our example | ||
$fiat_amount = 100; | ||
|
||
// amount currency type, if you leave this parameter blank default will be used from your API settings | ||
$fiat_currency = 'USD'; | ||
|
||
// create new order, more about it - https://www.alfacoins.com/developers#post_requests-create | ||
try { | ||
echo 'Order create result:' . PHP_EOL; | ||
$order = $api->create($type, $fiat_amount, $fiat_currency, $order_id, $order_description, $options); | ||
var_dump($order); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Order create method failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// get order status, more about it - https://www.alfacoins.com/developers#post_requests-status | ||
try { | ||
echo 'Order status result:' . PHP_EOL; | ||
var_dump($api->status($order['id'])); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Order status method failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Public API class | ||
require_once '../src/publicAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_publicAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// initialize ALFAcoins Public API class | ||
$api = new ALFAcoins_publicAPI(); | ||
|
||
// get BTC/USD exchange rate for 1 BTC (example of response: ["6459.83401257"]), more about it - https://www.alfacoins.com/developers#get_requests-rate | ||
try { | ||
echo 'Rate result:' . PHP_EOL; | ||
var_dump($api->rate('BTC','USD')); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Rate method failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// get exchange rates for all available pairs, more about it - https://www.alfacoins.com/developers#get_requests-rates | ||
try { | ||
echo 'Rates result:' . PHP_EOL; | ||
var_dump($api->rates()); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Rates method failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Public API class | ||
require_once '../src/publicAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_publicAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// initialize ALFAcoins Public API class | ||
$api = new ALFAcoins_publicAPI(); | ||
|
||
// get all service fees for all supported cryptocurrencies, more about it - https://www.alfacoins.com/developers#get_requests-fees | ||
try { | ||
echo 'Fees result:' . PHP_EOL; | ||
var_dump($api->fees()); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Fees method failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Private API class | ||
require_once '../src/privateAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_privateAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// shop_name is the API name, replace 'ShopName 123' with your API name. Create API entry at https://www.alfacoins.com/user | ||
$shop_name = 'ShopName 123'; | ||
|
||
// shop_password_hash is an uppercase md5 hash of API password, replace 'MyShopPassword' with your actual API password | ||
$shop_password = 'MyShopPassword'; | ||
|
||
// shop_secret_key is your API secret_key, it's shown one time after you created the new API entry, if you didn't write it down you can reset it in your API settings | ||
$shop_secret_key = 'a8a0e3497c8b67b024babc9a4daf5f5c'; | ||
|
||
// initialize ALFAcoins Private API class with your API settings | ||
$api = new ALFAcoins_privateAPI($shop_name, $shop_password, $shop_secret_key); | ||
|
||
// prepare options for the refund method | ||
$options = [ | ||
// address where refund to | ||
"address" => "1FE7bSYsXSMrdXTCdRUWUB6jGFFba74fzm", | ||
]; | ||
|
||
// make full refund, more about it - https://www.alfacoins.com/developers#post_requests-refund | ||
try { | ||
echo 'Refund result:' . PHP_EOL; | ||
var_dump($api->refund(409152, 0, $options, true)); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Refund method failed: " . $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
// partial refund (e.g. 10 USD instead of the full order amount), default currency is set in your settings | ||
try { | ||
echo 'Refund result:' . PHP_EOL; | ||
var_dump($api->refund(409152, 10, $options, true)); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Refund method failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
// include once ALFAcoins Private API class | ||
require_once '../src/privateAPI.php'; | ||
require_once '../src/Exception.php'; | ||
|
||
use ALFAcoins\ALFAcoins_privateAPI; | ||
use ALFAcoins\ALFAcoins_Exception; | ||
|
||
// shop_name is the API name, replace 'ShopName 123' with your API name. Create API entry at https://www.alfacoins.com/user | ||
$shop_name = 'ShopName 123'; | ||
|
||
// shop_password_hash is an uppercase md5 hash of API password, replace 'MyShopPassword' with your actual API password | ||
$shop_password = 'MyShopPassword'; | ||
|
||
// shop_secret_key is your API secret_key, it's shown one time after you created the new API entry, if you didn't write it down you can reset it in your API settings | ||
$shop_secret_key = 'a8a0e3497c8b67b024babc9a4daf5f5c'; | ||
|
||
// initialize ALFAcoins Private API class with your API settings | ||
$api = new ALFAcoins_privateAPI($shop_name, $shop_password, $shop_secret_key); | ||
|
||
// get merchant's balances and operations volume - more about it https://www.alfacoins.com/developers#post_requests-stats | ||
try { | ||
echo 'Stats result:' . PHP_EOL; | ||
var_dump($api->stats()); | ||
} catch (ALFAcoins_Exception $e) { | ||
echo "Stats method failed: " . $e->getMessage() . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace ALFAcoins; | ||
|
||
/** | ||
* Class ALFAcoins_Exception | ||
*/ | ||
class ALFAcoins_Exception extends \Exception { | ||
} |
Oops, something went wrong.