-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path01_Create_Exchange_Order.php
More file actions
88 lines (72 loc) · 3.32 KB
/
Copy path01_Create_Exchange_Order.php
File metadata and controls
88 lines (72 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
// include once ALFAcashier main API class
require_once '../src/Api.php';
require_once '../src/Exception.php';
use ALFAcashier\ALFAcashierAPI;
use ALFAcashier\ALFAcashier_Exception;
// create new ALFAcashierAPI object
$api = new ALFAcashierAPI;
// form parameters for order creation, more about order creation here - https://www.alfacashier.com/developers#post_requests-create
// exchange pair example: BTC_LTC, direction of the exchange, defined in the form [source_currency_code]_[destination_currency_code]
$pair = 'BTC_LTC';
// deposit amount, e.g. 0.02 BTC, if you want to use withdrawal amount instead set this value to 0 or NULL
$deposit_amount = 0.02;
// withdrawal amount, we set this to 0, because earlier we've specified deposit_amount 0.02 BTC
// if you want to use withdrawal amount instead (e.g. 5 LTC, $withdrawal_amount = 5), please set $deposit_amount = 0
// if you specify both withdrawal_amount and deposit_amount non 0, deposit_amount will be used
$withdrawal_amount = 0;
// your e-mail address or your customer's e-mail address
$email = 'noreply@alfacashier.com';
// promo code, if you have one
$promo_code = '';
// your referral uid, you can get it here: https://www.alfacashier.com/referral/overview
$referral_uid = '2f777778';
// Litecoin destination address
/*
For different cryptocurrencies there are different required parameters:
1) Bitcoin, Litecoin, Ethereum, Dash, ZCash, Ethereum Classic:
options = {address: BITCOINADDRESS}
address is your cryptocurrency address.
2) Bitcoin Cash
options = {address: BITCOINCASHADDRESS, legacy_address: LEGACYBITCOINCASHADDRESS}
address is your cryptocurrency address.
3) XRP
options = {account: XRPACCOUNT, destination_tag: DESTTAG}
account is your XRP account and destination_tag is Destination Tag (some exchangers require it).
4) NEM
options = {address: XEMADDRESS, message: MESSAGE}
address is your NEM address and message is an optional parameter if you're using shared NEM wallet.
5) Monero
options = {address: MONEROADDRESS, payment_id: PAYMENTID}
address if your Monero address and payment_id is an optional parameter if you're using shared Monero wallet.
*/
$options = ['address' => 'La9WJGciWq3Sq1pXTRS4wJsDRC8KAREu97'];
// create new exchange order to exchange Bitcoin (0.02 BTC) to Litecoin (LTC)
// exchange rate is determined automatically
try {
echo "Order create result:" . PHP_EOL;
$result = $api->create($pair, $deposit_amount, $withdrawal_amount, $email, $options, $promo_code, $referral_uid);
var_dump($result);
} catch (ALFAcashier_Exception $e) {
echo "Order create method failed: " . $e->getMessage() . PHP_EOL;
}
if (!empty($result['secret_key'])) {
// save secret key of your exchange order to track the order or cancel it
$secret_key = $result['secret_key'];
// check exchange order status, more about it - https://www.alfacashier.com/developers#get_requests-status
try {
echo "Order status result:" . PHP_EOL;
$result = $api->status($secret_key);
var_dump($result);
} catch (ALFAcashier_Exception $e) {
echo "Order status method failed: " . $e->getMessage() . PHP_EOL;
}
// cancel exchange order
try {
echo "Order cancel result:" . PHP_EOL;
$result = $api->cancel($secret_key);
var_dump($result);
} catch (ALFAcashier_Exception $e) {
echo "Order cancel method failed: " . $e->getMessage() . PHP_EOL;
}
}