forked from pouriya73/CoinPayment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoinpaymentsAPI.php
1021 lines (973 loc) · 37.3 KB
/
CoinpaymentsAPI.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require('CoinpaymentsCurlRequest.php');
/**
* CoinPayments.net PHP API Wrapper
*
* @link https://www.coinpayments.net/apidoc Official CoinPayments.net API Documentation.
* @copyright (c) 2018, CoinPayments.net
*
* Many API commands require a currency or currencies values to be passed. These are always in the
* format of a currency ticker code. See https://www.coinpayments.net/supported-coins for these ticker codes,
* located in the CODE column.
*
* LTCT (Litecoin Testnet) is a test currency with no value and should be used for development purposes when possible
* in order to save on real currency network transaction fees.
*
* The commands for converting coins and getting coin conversion information rely on mainnet transactions of a
* non-testing currency and are excluded from the capabilities of LTCT in the CoinPayments API.
*
* $PayByName tag commands also rely on having available or claimed tags on the production CoinPayments.net website to
* manipulate.
*/
class CoinpaymentsAPI
{
private $private_key = '';
private $public_key = '';
private $request_handler;
private $format;
/**
* CoinpaymentsAPI constructor.
* @param $private_key
* @param $public_key
* @param $format
*/
public function __construct($private_key, $public_key, $format)
{
// Set the default format to json if a value was not passed
if (empty($format)) {
$format = 'json';
}
// Set keys and format passed to class
$this->private_key = $private_key;
$this->public_key = $public_key;
$this->format = $format;
// Throw an error if the keys are not both passed
try {
if (empty($this->private_key) || empty($this->public_key)) {
throw new Exception("Your private and public keys are not both set!");
}
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
// Initiate a cURL request object
$this->request_handler = new CoinpaymentsCurlRequest($this->private_key, $this->public_key, $format);
}
/** ------------------------------------------------ **/
/** ------------ Informational Commands ------------ **/
/** ------------------------------------------------ **/
/**
* function GetBasicInfo
* Get basic account information.
*
* @return array|object
* Successful result includes the following values:
* - username (string)
* - merchant_id (string)
* - email (string)
* - public_name (string)
*
* @throws Exception
*/
public function GetBasicInfo()
{
return $this->request_handler->execute('get_basic_info');
}
/**
* function GetRates
* Basic call to get rates, with full currency names and no reference to if the coin is enabled.
*
* @return array|object
* Successful result includes the following values (sample):
* - Currency ticker (example string: BTC)
* - is_fiat (integer)
* - rate_btc (string)
* - last_update (string)
* - tx_fee (string)
* - status (string)
* - name (string)
* - confirms (string)
* - can_convert (integer)
* - capabilities (array)
* - [payments, wallet, transfers, dest_tag, convert] (each a string)
*
* @throws Exception
*/
public function GetRates()
{
return $this->request_handler->execute('rates');
}
/**
* function GetRatesWithAccepted
* Call to get rates, with full currency names and reference to if the coin is enabled.
*
* @return array|object
* Successful result includes the following values (sample):
* - Currency ticker (example string: BTC)
* - is_fiat (integer)
* - rate_btc (string)
* - last_update (string)
* - tx_fee (string)
* - status (string)
* - name (string)
* - confirms (string)
* - can_convert (integer)
* - capabilities (array)
* - [payments, wallet, transfers, dest_tag, convert] (each a string)
* - accepted
*
* @throws Exception
*/
public function GetRatesWithAccepted()
{
$fields = [
'accepted' => 1
];
return $this->request_handler->execute('rates', $fields);
}
/**
* function GetShortRates
* Call to get short rates, without full currency names or confirms and no reference to if the coin is enabled.
*
* @return array|object
* Successful result includes the following values (sample):
* - Currency ticker (example string: BTC)
* - is_fiat (integer)
* - rate_btc (string)
* - last_update (string)
* - tx_fee (string)
* - status (string)
* - capabilities (array)
* - [payments, wallet, transfers, dest_tag, convert] (each a string)
*
* @throws Exception
*/
public function GetShortRates()
{
$fields = [
'short' => 1
];
return $this->request_handler->execute('rates', $fields);
}
/**
* function GetShortRatesWithAccepted
* Call to get short rates, without full currency names or confirms and with reference to if the coin is enabled.
*
* @return array|object
* Successful result includes the following values (sample):
* - Currency ticker (example string: BTC)
* - is_fiat (integer)
* - rate_btc (string)
* - last_update (string)
* - tx_fee (string)
* - status (string)
* - capabilities (array)
* - [payments, wallet, transfers, dest_tag, convert] (each a string)
* - accepted (integer)
*
* @throws Exception
*/
public function GetShortRatesWithAccepted()
{
$fields = [
'short' => 1,
'accepted' => 1
];
return $this->request_handler->execute('rates', $fields);
}
/**
* function GetCoinBalances
* Get balances of only coins with a positive balance.
*
* @return array|object
* Successful result includes the following values (sample) for each coin.
* - Currency ticker (example string: BTC)
* - balance (10000000) | The coin balance as an integer in Satoshis. (integer)
* - balancef (0.10000000) | The coin balance as a floating point number. (string)
* - status (string) | If the coin is locked in the vault or available.
* - coin_status (string) | If the coin is online or offline for maintenance.
*
* @throws Exception
*/
public function GetCoinBalances()
{
return $this->request_handler->execute('balances');
}
/**
* function GetAllCoinBalances
* Get balances of all coins, even those with a 0 balance.
*
* @return array|object
* Successful result includes the following values (sample) for each coin.
* - Currency ticker (example string: BTC)
* - balance (10000000) | The coin balance as an integer in Satoshis. (integer)
* - balancef (0.10000000) | The coin balance as a floating point number. (string)
* - status (string) | If the coin is locked in the vault or available.
* - coin_status (string) | If the coin is online or offline for maintenance.
*
* @throws Exception
*/
public function GetAllCoinBalances()
{
$fields = [
'all' => 1
];
return $this->request_handler->execute('balances', $fields);
}
/**
* function GetDepositAddress
* Get addresses for personal use deposits.
* Deposits to these addresses don't send IPNs!
* For commercial-use addresses and/or ones that send IPNs see GetCallBackAddresses function.
*
* @param string $currency The ticker of currency the buyer will be sending.
*
* @return array|object
* Successful result includes the following values.
* - address (string)
* - pubkey | (string) NXT Only: The pubkey to attach the 1st time you send to the address to activate it.
* - dest_tag | (string|integer) For coins needing a destination tag, example: XRP (Ripple)
*
* @throws Exception
*/
public function GetDepositAddress($currency)
{
$fields = [
'currency' => $currency
];
return $this->request_handler->execute('get_deposit_address', $fields);
}
/** ------------------------------------------------ **/
/** -------------- Receiving Payments -------------- **/
/** ------------------------------------------------ **/
/**
* function CreateSimpleTransaction
* Use this function to create a transaction when you only want to specify the minimum fields
* and do not require a currency conversion.
*
* @param integer $amount The amount for the transaction in the $currency.
* @param string $currency The ticker of the currency for the transaction.
* @param string $buyer_email Email address for the buyer of the transaction.
*
* @return array|object
* Successful result includes the following values.
* - amount (string)
* - address (string)
* - txn_id (string)
* - confirms_needed (string)
* - timeout (integer)
* - status_url (string)
* - qrcode_url (string)
*
* @throws Exception
*/
public function CreateSimpleTransaction($amount, $currency, $buyer_email)
{
$fields = [
'amount' => $amount,
'currency1' => $currency,
'currency2' => $currency,
'buyer_email' => $buyer_email
];
return $this->request_handler->execute('create_transaction', $fields);
}
/**
* function CreateSimpleTransactionWithConversion
* Use this function to create a transaction when you only want to specify the minimum fields
* and require a currency conversion. For example if your products are priced in USD but you
* are receiving BTC, you would use currency1 = USD and currency2 = BTC.
*
* @param integer $amount The amount in the original currency (currency1)
* @param string $currency1 Original currency ticker for the transaction.
* @param string $currency2 Actual currency ticker the buyer will send.
* @param string $buyer_email Email address for the buyer of the transaction.
*
* @return array|object
* Successful result includes the following values.
* - amount (string)
* - address (string)
* - txn_id (string)
* - confirms_needed (string)
* - timeout (integer)
* - status_url (string)
* - qrcode_url (string)
*
* @throws Exception
*/
public function CreateSimpleTransactionWithConversion($amount, $currency1, $currency2, $buyer_email)
{
$fields = [
'amount' => $amount,
'currency1' => $currency1,
'currency2' => $currency2,
'buyer_email' => $buyer_email
];
return $this->request_handler->execute('create_transaction', $fields);
}
/**
* function CreateComplexTransaction
* Use this function to create a transaction when you only want to specify all optional fields
* and require a currency conversion. For example if your products are priced in USD but you
* are receiving BTC, you would use currency1 = USD and currency2 = BTC. To use this function
* without a currency conversion, simply set currency1 and currency2 to the same value.
*
* @param integer $amount The amount in the original currency (currency1)
* @param string $currency1 Original currency ticker for the transaction.
* @param string $currency2 Actual currency ticker the buyer will send.
* @param string $buyer_email Email address for the buyer of the transaction.
* @param string $address An address in currency2's network.
* @param string $buyer_name A buyer name for the seller's reference.
* @param string $item_name An item name to associate with the transaction.
* @param integer $item_number An item number to associate with the transaction.
* @param string $invoice An invoice identifying string to associate with the transaction.
* @param string $custom A custom field for the seller to populate with extra information.
* @param string $ipn_url The URL for instant payment notifications to be sent to regarding this transaction.
*
* @return array|object
* Successful result includes the following values.
* - amount (string)
* - address (string)
* - txn_id (string)
* - confirms_needed (string)
* - timeout (integer)
* - status_url (string)
* - qrcode_url (string)
*
* @throws Exception
*/
public function CreateComplexTransaction($amount, $currency1, $currency2, $buyer_email, $address, $buyer_name, $item_name, $item_number, $invoice, $custom, $ipn_url)
{
$fields = [
'amount' => $amount,
'currency1' => $currency1,
'currency2' => $currency2,
'buyer_email' => $buyer_email,
'address' => $address,
'buyer_name' => $buyer_name,
'item_name' => $item_name,
'item_number' => $item_number,
'invoice' => $invoice,
'custom' => $custom,
'ipn_url' => $ipn_url
];
return $this->request_handler->execute('create_transaction', $fields);
}
/**
* function CreateCustomTransaction
* Use this function when you want to specify some but not all of the optional fields.
*
* @param array $fields The following required fields, with your chosen combination of optional fields.
* - field_name (required)
* -----------------------
* - amount (Yes)
* - currency1 (Yes)
* - currency2 (Yes)
* - buyer_email (Yes)
* - address (No)
* - buyer_name (No)
* - item_name (No)
* - item_number (No)
* - invoice (No)
* - custom (No)
* - ipn_url (No)
*
* @return array|object
* Successful result includes the following values.
* - amount (string)
* - address (string)
* - txn_id (string)
* - confirms_needed (string)
* - timeout (integer)
* - status_url (string)
* - qrcode_url (string)
*
* @throws Exception
*/
public function CreateCustomTransaction($fields)
{
return $this->request_handler->execute('create_transaction', $fields);
}
/**
* function GetOnlyCallbackAddress
* Since callback addresses are designed for commercial use they incur the same 0.5% fee on deposits as
* transactions created with 'create_transaction' command. For personal use deposits that reuse the same personal
* address(es) in your wallet that have no fee but don't send IPNs see GetDepositAddress function.
*
* Note: Will default to using IPN URL if there is one set on your Edit Settings page.
*
* @param string $currency The ticker of the currency for the callback address.
*
* @return array|object
* Successful result includes the following values.
* - address (string)
* - pubkey | (string) NXT Only: The pubkey to attach the 1st time you send to the address to activate it.
* - dest_tag | (string|integer) For coins needing a destination tag, example: XRP (Ripple)
*
* @throws Exception
*/
public function GetOnlyCallbackAddress($currency)
{
$fields = [
'currency' => $currency
];
return $this->request_handler->execute('get_callback_address', $fields);
}
/**
* function GetCallbackAddressWithIpn
* Same as GetOnlyCallbackAddress function but includes an IPN url for your callbacks.
*
* @param string $currency The ticker of the currency for the callback address.
* @param string $ipn_url Your Instant Payment Notifications server URL to be associated with the address.
* @param string $label Optionally set an address label
*
* @return array|object
* Successful result includes the following values.
* - address (string)
* - pubkey | (string) NXT Only: The pubkey to attach the 1st time you send to the address to activate it.
* - dest_tag | (string|integer) For coins needing a destination tag, example: XRP (Ripple)
*
* @throws Exception
*/
public function GetCallbackAddressWithIpn($currency, $ipn_url, $label='')
{
$fields = [
'currency' => $currency,
'ipn_url' => $ipn_url,
];
if(!empty($label)) $fields['label'] = $label;
return $this->request_handler->execute('get_callback_address', $fields);
}
/**
* function GetTxInfoMulti
* Retrieves transaction information for up to 25 individual transaction IDs.
* The API key being used must belong to the seller of the transaction(s).
*
* Important note: It is recommended to handle IPNs instead of using this command when possible,
* it is more efficient and places less load on our servers.
*
*
* @param string $transaction_ids Multiple transaction IDs separated with a pipe symbol: |
* example: aFakeTxId1|aFakeTxId2|aFakeTxId3
*
* @return array|object
* See GetTxInfoSingle result values.
*
* @throws Exception
*/
public function GetTxInfoMulti($transaction_ids)
{
$fields = [
'txid' => $transaction_ids
];
return $this->request_handler->execute('get_tx_info_multi', $fields);
}
/**
* function GetTxInfoSingle
* Retrieves transaction information for a single transaction.
*
* Important note: It is recommended to handle IPNs instead of using this command when possible,
* it is more efficient and places less load on our servers.
*
* @param string $transaction_id The transaction ID for which you want to retrieve information.
*
* @return array|object
* Successful result includes the following values.
* - error (string)
* - time_created (integer)
* - time_expires (integer)
* - status (integer)
* - status_text (string)
* - type (string)
* - coin (string)
* - amount (integer)
* - amountf (string)
* - received (integer)
* - receivedf (string)
* - recv_confirms (integer)
* - payment_address (string)
* - time_completed (integer)
*
* @throws Exception
*/
public function GetTxInfoSingle($transaction_id)
{
$fields = [
'txid' => $transaction_id
];
return $this->request_handler->execute('get_tx_info', $fields);
}
/**
* function GetTxInfoSingleWithRaw
* Retrieves transaction information for a single transaction including raw checkout and shipping data.
*
* Important note: It is recommended to handle IPNs instead of using this command when possible,
* it is more efficient and places less load on our servers.
*
* @param string $transaction_id The transaction ID for which you want to retrieve information.
*
* @return array|object
* Successful result includes the following values.
* - time_created (integer)
* - time_expires (integer)
* - status (integer)
* - status_text (string)
* - type (string)
* - coin (string)
* - amount (integer)
* - amountf (string)
* - received (integer)
* - receivedf (string)
* - recv_confirms (integer)
* - payment_address (string)
* - time_completed (integer)
* - checkout (array)
* - subtotal (integer)
* - tax (integer)
* - shipping (integer)
* - total (integer)
* - currency (string)
* - amount (integer)
* - item_name (string)
* - item_number (string)
* - invoice (string)
* - custom (string)
* - ipn_url (string)
* - amountf (double/float)
* - shipping (array)
* - first_name (string)
* - last_name (string)
* - company (string)
* - address1 (string)
* - address2 (string)
* - city (string)
* - state (string)
* - zip (string)
* - country (string)
* - phone (string)
*
* @throws Exception
*/
public function GetTxInfoSingleWithRaw($transaction_id)
{
$fields = [
'txid' => $transaction_id,
'full' => 1
];
return $this->request_handler->execute('get_tx_info', $fields);
}
/**
* function GetSellerTransactionList
* Retrieves a list of transaction IDs only where you are the seller.
*
* Important note: It is recommended to handle IPNs instead of using this command when possible,
* it is more efficient and places less load on our servers.
*
* @param int $limit The maximum number of transaction IDs to return from 1-100.
* @param int $start The transaction number to start from.
* @param int $newer A Unix timestamp that when defined will return transactions from that time or later.
*
* @return array|object The transaction IDs (string) found in the given range.
*
* @throws Exception
*/
public function GetSellerTransactionList($limit = 25, $start = 0, $newer = 0)
{
$fields = [
'limit' => $limit,
'start' => $start,
'newer' => $newer
];
return $this->request_handler->execute('get_tx_ids', $fields);
}
/**
* function GetFullTransactionList
* Retrieves a list of transaction IDs where you are the seller or buyer.
*
* Important note: It is recommended to handle IPNs instead of using this command when possible,
* it is more efficient and places less load on our servers.
*
* @param int $limit The maximum number of transaction IDs to return from 1-100.
* @param int $start The transaction number to start from.
* @param int $newer A Unix timestamp that when defined will return transactions from that time or later.
*
* @return array|object Contains an array for each transaction ID
* - txid (string)
* - user_is (string) If the user is the seller or buyer.
*
* @throws Exception
*/
public function GetFullTransactionList($limit = 25, $start = 0, $newer = 0)
{
$fields = [
'limit' => $limit,
'start' => $start,
'newer' => $newer,
'all' => 1
];
return $this->request_handler->execute('get_tx_ids', $fields);
}
/** ------------------------------------------------ **/
/** ------------ Withdrawals/Transfers ------------- **/
/** ------------------------------------------------ **/
/**
* function CreateMerchantTransfer
*
* @param int $amount The amount of the transfer in the given $currency.
* @param string $currency The currency for the transfer.
* @param string $merchant The merchant ID (not a username) for the user that will receive the transfer.
* @param int $autoconfirm Set to 1 to withdraw without an email confirmation.
*
* @return array|object
* Successful result includes the following values.
* - id (string)
* - status (integer)
* - amount (string)
*
* @throws Exception
*/
public function CreateMerchantTransfer($amount, $currency, $merchant, $autoconfirm = 0)
{
$fields = [
'amount' => $amount,
'currency' => $currency,
'merchant' => $merchant,
'auto_confirm' => $autoconfirm
];
return $this->request_handler->execute('create_transfer', $fields);
}
/**
* function CreatePayByNameTransfer
*
* @param int $amount The amount of the transfer in the given $currency.
* @param string $currency The currency for the transfer.
* @param string $paybyname The $PayByName tag that will recieve the transfer.
* @param int $autoconfirm Set to 1 to withdraw without an email confirmation.
*
* @return array|object
* Successful result includes the following values.
* - id (string)
* - status (integer)
* - amount (string)
*
* @throws Exception
*/
public function CreatePayByNameTransfer($amount, $currency, $paybyname, $autoconfirm = 0)
{
$fields = [
'amount' => $amount,
'currency' => $currency,
'pbntag' => $paybyname,
'auto_confirm' => $autoconfirm
];
return $this->request_handler->execute('create_transfer', $fields);
}
/**
* function CreateWithdrawal
* Withdrawals send coins to a specified address or $PayByName tag over the coin networks and optionally send
* an IPN when complete. If you are sending to another CoinPayments user and you have their $PayByName tag or
* merchant ID you can also use 'create_transfer' for faster sends that don't go over the coin networks when possible.
*
* @param array $fields Parameters to pass with the withdrawal command. See below.
* - amount (integer) The amount of the withdrawal.
* - currency (string) The ticker of the currency to withdraw.
* - add_tx_fee (integer) Set to 1 to add the coin TX fee to the withdrawal amount, so that the sender pays the TX fee
* instead of the receiver.
*
* - currency2 (string) Optional currency to use to to withdraw 'amount' worth of 'currency2' in 'currency' coin.
* This is for exchange rate calculation only and will not convert coins or change which
* currency is withdrawn. For example, to withdraw 1.00 USD worth of BTC you would specify
* currency1=BTC, currency2=USD, and amount=1.00.
*
* - address (string) The address to send the funds to, either this OR paybyname must be specified. Must be an
* address in currency1's network.
*
* - pbntag (string) A $PayByName tag to send the withdrawal to, either this OR address must be specified.
* - dest_tag (string|integer) The extra tag to use if applicable to $currency1 (destination tag).
* This could be a Destination Tag for Ripple, Payment ID for Monero, Message for XEM, etc.
*
* - ipn_url (string) URL for your IPN callbacks. If not set it will use the IPN URL in your Edit Settings page if you have one set.
* - auto_confirm (integer) If set to 1, withdrawal will complete without email confirmation.
* - note (string) This lets you set the note for the withdrawal.
*
* @return array|object
* Successful result includes the following values.
* - id (string)
* - status (integer)
* - amount (string)
*
* @throws Exception
*/
public function CreateWithdrawal($fields)
{
if (!empty($fields['address']) && !empty($fields['paybyname'])) {
throw new Exception('You must specify either an address or a $PayByName tag, but not both!');
}
return $this->request_handler->execute('create_withdrawal', $fields);
}
/**
* function CreateMassWithdrawal
* Execute multiple withdrawals with one command.
* The withdrawals are passed in an associative array of $withdrawals, each having it's own array of fields from the
* CreateWithdrawal function except auto_confirm which is always 1 in mass withdrawals. The key of each withdrawal
* is used to return the result (same as CreateWithdrawal again.) The key can contain ONLY a-z, A-Z, and 0-9.
* Withdrawals with empty keys or containing other characters will be silently ignored.
*
* @param array $withdrawals The associative array of withdrawals.
*
* @return array|object
* Successful result is an associative array with matching keys from the given $withdrawals parameter.
* Each withdrawal key is associated with an array containing the following values.
* - id (string)
* - status (integer)
* - amount (string)
*
* @throws Exception
*/
public function CreateMassWithdrawal($withdrawals)
{
$fields = [
'wd' => $withdrawals
];
return $this->request_handler->execute('create_mass_withdrawal', $fields);
}
/**
* function ConvertCoins
* Convert a given amount of one currency to a different currency.
*
* @param int $amount The amount of the $from currency to convert.
* @param string $from The ticker of the currency to convert from.
* @param string $to The ticker of the currency to conver to.
* @param string $address The address to send funds to. If blank or not included the coins will go to your CoinPayments Wallet.
* @param string $dest_tag The destination tag to use for the withdrawal (for Ripple.) If 'address' is not included this has no effect.
*
* @return array|object Contains only one value, the ID of the conversion (string).
*
* @throws Exception
*/
public function ConvertCoins($amount, $from, $to, $address = null, $dest_tag = null)
{
$fields = [
'amount' => $amount,
'from' => $from,
'to' => $to
];
if (!is_null($address)) {
$fields['address'] = $address;
}
if (!is_null($dest_tag) && !is_null($address)) {
$fields['dest_tag'] = $dest_tag;
}
return $this->request_handler->execute('convert', $fields);
}
/**
* function GetConversionLimits
* Check the amount limits for conversions between two currencies.
* Notes:
* - A 'max' value of 0.00000000 is valid and means there is no known upper limit available.
* - Due to provider fluctuation limits do vary often.
*
*
* @param string $from The ticker of the currency to convert from.
* @param string $to The ticker of the currency to convert to.
*
* @return array|object
* Successful result includes the following values.
* - min (string)
* - max (string)
*
* @throws Exception
*/
public function GetConversionLimits($from, $to)
{
$fields = [
'from' => $from,
'to' => $to
];
return $this->request_handler->execute('convert_limits', $fields);
}
/**
* function GetWithdrawalHistory
* Retrieve historical information for multiple withdrawals.
*
* @param int $limit The maximum number of withdrawals to return from 1-100.
* @param int $start The withdrawal number to start from.
* @param int $newer Return withdrawals submitted at the given Unix timestamp or later.
*
* @return array|object
* Successful result includes the following values for each withdrawal.
* - id (string)
* - time_created (integer)
* - status (integer)
* - status_text (string)
* - coin (string)
* - amount (integer)
* - amountf (string)
* - send_address (string)
* - send_dest_tag (string|integer) Applicable coins only.
* - send_txid (string)
*
*
* @throws Exception
*/
public function GetWithdrawalHistory($limit = 25, $start = 0, $newer = 0)
{
$fields = [
'limit' => $limit,
'start' => $start,
'newer' => $newer
];
return $this->request_handler->execute('get_withdrawal_history', $fields);
}
/**
* function GetWithdrawalInformation
* Retrieve information for a single withdrawal.
*
* @param string $id The withdrawal ID to query.
*
* @return array|object
* Successful result includes the following values:
* - time_created (integer)
* - status (integer)
* - status_text (string)
* - coin (string)
* - amount (integer)
* - amountf (string)
* - send_address (string)
* - send_txid (string)
*
* @throws Exception
*/
public function GetWithdrawalInformation($id)
{
$fields = [
'id' => $id
];
return $this->request_handler->execute('get_withdrawal_info', $fields);
}
/**
* function GetConversionInformation
* Retrieve information for a currency conversion.
*
* @param string $id The conversion ID to query.
*
* @return array|object
* Successful result includes the following values:
* - time_created
* - status
* - status_text
* - coin1
* - coin2
* - amount_sent
* - amount_sentf
* - received
* - receivedf
*
* @throws Exception
*/
public function GetConversionInformation($id)
{
$fields = [
'id' => $id
];
return $this->request_handler->execute('get_conversion_info', $fields);
}
/** ------------------------------------------------ **/
/** ------------------ $PayByName ------------------ **/
/** ------------------------------------------------ **/
/**
* function GetProfileInformation
* Retrieve information on a given $PayByName tag.
*
* @param string $pbntag The $PayByName tag to lookup, with or without a $ at the beginning.
*
* @return array|object
* Successful result includes the following values:
* - pbntag (string)
* - merchant (string)
* - profile_name (string)
* - profile_url (string)
* - profile_email (string)
* - profile_image (string)
* - member_since (integer)
* - feedback (array)
* - pos (integer)
* - neg (integer)
* - neut (integer)
* - total (integer)
* - percent (string)
* - percent_str (string)
*
* @throws Exception
*/
public function GetProfileInformation($pbntag)
{
$fields = [
'pbntag' => $pbntag
];
return $this->request_handler->execute('get_pbn_info', $fields);
}
/**
* function GetTagList
* Retrieve a list of $PayByName tags and tag IDs associated with your account (claimed & unclaimed).
*
* @return array|object
* Successful result includes an array for each tag with the following values:
* - tagid (string)
* - pbntag (string)
* - time_expires (integer)
*
* @throws Exception
*/
public function GetTagList()
{
return $this->request_handler->execute('get_pbn_list');
}
/**
* function UpdateTagProfile
* Use to update profile information associated with a $PayByName tag.
*
* @param int $tagid The tag ID of the profile you wish to update. Use GetTagList function to see tag list with IDs.
* @param string $name A new name for the profile.
* @param string $email A new email for the profile.
* @param string $url A new website URL for the profile.
* @param string $image HTTP POST with a JPG or PNG image 250KB or smaller.
* This is an actual "multipart/form-data" file POST and not a URL to a file.
*
* @return array|object
* Successful result includes only an "error" equal to "ok" value.
* The result array inside the response will be empty regardless of success.
*
* @throws Exception
*/
public function UpdateTagProfile($tagid, $name, $email, $url, $image)
{
$fields = [
'tagid' => $tagid,
'name' => $name,
'email' => $email,
'url' => $url,
'image' => $image
];
return $this->request_handler->execute('update_pbn_tag', $fields);
}
/**
* function ClaimPayByNameTag