Skip to content

Commit 67fc77b

Browse files
committed
API updated to actual version of docs
API updated to actual version of docs. Comments updated to actual version also.
1 parent 92d8308 commit 67fc77b

3 files changed

Lines changed: 95 additions & 38 deletions

File tree

pyCryptomusAPI/api.py

Lines changed: 76 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
API_URL = "https://api.cryptomus.com/v1/"
99

10-
1110
# noinspection PyPep8Naming
1211
class pyCryptomusAPIException(Exception):
1312
def __init__(self, code, message, full_error = ""):
@@ -121,29 +120,42 @@ def __request(self, method_url, mode, **kwargs):
121120
return resp
122121

123122
def create_invoice(self,
124-
amount, currency, order_id, network = None, url_return = None, url_callback = None,
123+
amount, currency, order_id, network = None,
124+
url_return = None, url_success = None, url_callback = None,
125125
is_payment_multiple = None, lifetime = None, to_currency = None, subtract = None,
126126
accuracy_payment_percent = None, additional_data = None, currencies = None,
127-
except_currencies = None):
127+
except_currencies = None, course_source = None, from_referral_code = None,
128+
discount_percent = None, is_refresh = None):
128129
"""
129130
Creating an invoice
130131
https://doc.cryptomus.com/payments/creating-invoice
131132
Requires PAYMENT API key
132133
133-
amount: (Float) The amount of the invoice
134+
amount: (Float) Amount to be paid. If there are pennies in the amount, then send them with a separator '.' Example: 10.28
134135
currency: (String) Currency code (https://doc.cryptomus.com/reference)
135-
order_id: (String) Order ID in your system
136+
order_id: (String[1..128]) Order ID in your system. The parameter should be a string consisting of alphabetic characters, numbers, underscores, and dashes. It should not contain any spaces or special characters.
136137
network: (String, Optional) Blockchain network code (https://doc.cryptomus.com/reference)
137-
url_return: (String, Optional) Url to which the user will return after payment
138-
url_callback: (String, Optional) Url to which webhooks with payment status will be sent
139-
is_payment_multiple: (Bool, Optional) Whether payment of the remaining amount is possible (true/false)
140-
lifetime: (?Int?, Optional) The lifespan of the issued invoice (?in seconds?)
141-
to_currency: (String, Optional) Currency code for accepting payments
142-
subtract: (?Float?, Optional) Percentage of the payment commission charged to the client. The subtract parameter allows you to specify what percentage of the payment acceptance will be paid by the client. If you have a payment commission 1%, then if you create an invoice for 100 USDT with subtract=100 (the client pays 100% commission), the client will have to pay 101 USDT.
143-
accuracy_payment_percent: (?Float?, Optional) Acceptable inaccuracy in payment (min 0, max 5.00)
144-
additional_data: (?String?, Optional) Additional information
145-
currencies: (List[Currency], Optional) List of allowed currencies for payment Structure
146-
except_currencies: (List[Currency], Optional) List of excluded currencies for payment Structure
138+
url_return: (String[6..255], Optional) Before paying, the user can click on the button on the payment form and return to the store page at this URL.
139+
url_success: (String[6..255], Optional) After successful payment, the user can click on the button on the payment form and return to this URL.
140+
url_callback: (String[6..255], Optional) Url to which webhooks with payment status will be sent.
141+
is_payment_multiple: (Bool, Optional) Whether the user is allowed to pay the remaining amount. This is useful when the user has not paid the entire amount of the invoice for one transaction, and you want to allow him to pay up to the full amount. If you disable this feature, the invoice will finalize after receiving the first payment and you will receive funds to your balance.
142+
lifetime: (Int[300..43200], Optional) The lifespan of the issued invoice (?in seconds?)
143+
to_currency: (String, Optional) The parameter is used to specify the target currency for converting the invoice amount. When creating an invoice, you provide an amount and currency, and the API will convert that amount to the equivalent value in the to_currency. For example, to create an invoice for 20 USD in bitcoin: amount: 20, currency: USD, to_currency: BTC. The API will convert 20 USD amount to its equivalent in BTC based on the current exchange rate and the user will pay in BTC.
144+
subtract: (Int[0..100], Optional) Percentage of the payment commission charged to the client. If you have a rate of 1%, then if you create an invoice for 100 USDT with subtract = 100 (the client pays 100% commission), the client will have to pay 101 USDT.
145+
accuracy_payment_percent: (Float[0..5], Optional) Acceptable inaccuracy in payment. For example, if you pass the value 5, the invoice will be marked as Paid even if the client has paid only 95% of the amount. The actual payment amount will be credited to the balance.
146+
additional_data: (?String?, Optional) Additional information for you (not shown to the client).
147+
currencies: (List[Currency][1..255], Optional) List of allowed currencies for payment. This is useful if you want to limit the list of coins that your customers can use to pay invoices.
148+
except_currencies: (List[Currency], Optional) List of excluded currencies for payment.
149+
course_source: (String[4..20], Optional) The service from which the exchange rates are taken for conversion in the invoice. If not passed, Cryptomus exchange rates are used. Available values: https://doc.cryptomus.com/payments/creating-invoice
150+
from_referral_code: (String, Optional) The merchant who makes the request connects to a referrer by code. For example, you are an application that generates invoices via the Cryptomus API and your customers are other stores. They enter their api key and merchant id in your application, and you send requests with their credentials and passing your referral code. Thus, your clients become referrals on your Cryptomus account and you will receive income from their turnover.
151+
discount_percent: (Int[-99..100], Optional) Positive numbers: allows you to set a discount. To set a 5% discount for the payment, you should pass a value: 5. Negative numbers: allows you to set custom additional commission. To set an additional commission of 10% for the payment, you should pass a value: -10.
152+
is_refresh: (Bool, Optional) Using this parameter, you can update the lifetime and get a new address for the invoice if the lifetime has expired. To do that, you need to pass all required parameters, and the invoice with passed order_id will be refreshed.
153+
154+
* The order_id must be unique within the merchant invoices/static wallets/recurrence payments
155+
* When we find an existing invoice with order_id, we return its details, a new invoice will not be created.
156+
* The to_currency should always be the cryptocurrency code, not a fiat currency code.
157+
* The discount percentage when creating an invoice is taken into account only if the invoice has a specific cryptocurrency.
158+
* Only address, payment_status and expired_at are changed. No other fields are changed, regardless of the parameters passed.
147159
"""
148160
method = "payment"
149161
params = {
@@ -155,6 +167,8 @@ def create_invoice(self,
155167
params["network"] = network
156168
if url_return:
157169
params["url_return"] = url_return
170+
if url_success:
171+
params["url_success"] = url_success
158172
if url_callback:
159173
params["url_callback"] = url_callback
160174
if is_payment_multiple is not None:
@@ -173,20 +187,32 @@ def create_invoice(self,
173187
params["currencies"] = [i.to_dict() for i in currencies]
174188
if except_currencies:
175189
params["except_currencies"] = [i.to_dict() for i in except_currencies]
190+
if course_source:
191+
params["course_source"] = course_source
192+
if from_referral_code:
193+
params["from_referral_code"] = from_referral_code
194+
if discount_percent is not None:
195+
params["discount_percent"] = str(discount_percent)
196+
if is_refresh is not None:
197+
params["is_refresh"] = is_refresh
176198
resp = self.__request(method, 1, **params).get("result")
177199
return Invoice.de_json(resp)
178200

179201
def create_wallet(self,
180-
network, currency, order_id, url_callback = None):
202+
network, currency, order_id, url_callback = None, from_referral_code = None):
181203
"""
182204
Creating a Static wallet
183205
https://doc.cryptomus.com/payments/creating-static
184206
Requires PAYMENT API key
185207
186208
network: (String) Blockchain network code (https://doc.cryptomus.com/reference)
187209
currency: (String) Currency code (https://doc.cryptomus.com/reference)
188-
order_id: (String) Order ID in your system
189-
url_callback: (String, Optional) Url to which webhooks with payment status will be sent
210+
order_id: (String[1..100]) Order ID in your system. The parameter should be a string consisting of alphabetic characters, numbers, underscores, and dashes. It should not contain any spaces or special characters.
211+
url_callback: (String[6..255], Optional) URL, to which the webhook will be sent after each top-up of the wallet.
212+
from_referral_code: (String, Optional) The merchant who makes the request connects to a referrer by code. For example, you are an application that generates invoices via the Cryptomus API and your customers are other stores. They enter their api key and merchant id in your application, and you send requests with their credentials and passing your referral code. Thus, your clients become referrals on your Cryptomus account and you will receive income from their turnover.
213+
214+
* The order_id must be unique within the merchant invoices/static wallets/recurrence payments
215+
* When we find an existing invoice with order_id, we return its details, a new invoice will not be created.
190216
"""
191217
method = "wallet"
192218
params = {
@@ -196,6 +222,8 @@ def create_wallet(self,
196222
}
197223
if url_callback:
198224
params["url_callback"] = url_callback
225+
if from_referral_code:
226+
params["from_referral_code"] = from_referral_code
199227
resp = self.__request(method, 1, **params).get("result")
200228
return Wallet.de_json(resp)
201229

@@ -207,9 +235,11 @@ def block_wallet(self,
207235
You need to pass one of the required parameters, if you pass both, the account will be identified by order_id
208236
Requires PAYMENT API key
209237
210-
wallet_uuid: (String, Optional if order_id set) Wallet UUID
211-
order_id: (String, Optional if wallet_uuid set) Order ID in your system
238+
wallet_uuid: (String, Optional if order_id set) UUID of a static wallet
239+
order_id: (String[1..32], Optional if wallet_uuid set) Order ID of a static wallet
212240
is_force_refund: (Bool, Optional) Refund all incoming payments to sender’s address
241+
242+
* You need to pass one of the required parameters, if you pass both, the account will be identified by order_id
213243
"""
214244
method = "wallet/block-address"
215245
params = {
@@ -233,9 +263,11 @@ def block_wallet_refund(self,
233263
You need to pass one of the required parameters, if you pass both, the account will be identified by order_id
234264
Requires PAYMENT API key
235265
236-
address: (String) Address (wallet addres? refund address?)
237-
wallet_uuid: (String, Optional if order_id set) Wallet UUID
238-
order_id: (String, Optional if wallet_uuid set) Order ID in your system
266+
address: (String[10..128]) Refund all blocked funds to this address
267+
wallet_uuid: (String, Optional if order_id set) UUID of a static wallet
268+
order_id: (String[1..32], Optional if wallet_uuid set) Order ID of a static wallet
269+
270+
* To refund payments you need to pass either uuid or order_id, if you pass both, the static wallet will be identified by uuid
239271
"""
240272
method = "wallet/blocked-address-refund"
241273
params = {
@@ -259,7 +291,9 @@ def payment_information(self,
259291
Requires PAYMENT API key
260292
261293
invoice_uuid: (String, Optional if order_id set) Invoice UUID
262-
order_id: (String, Optional if wallet_uuid set) Order ID in your system
294+
order_id: (String[1..128], Optional if wallet_uuid set) Invoice order ID
295+
296+
* To get the invoice status you need to pass one of the required parameters, if you pass both, the account will be identified by order_id
263297
"""
264298
method = "payment/info"
265299
params = {
@@ -281,10 +315,12 @@ def refund(self,
281315
You need to pass one of the required parameters, if you pass both, the account will be identified by invoice_uuid
282316
Requires PAYMENT API key
283317
284-
address: (String) Refund address
285-
is_subtract: (Bool) Determines whether the commission is to be charged to the merchant or to the client (True - to the merchant, False - to the client)
318+
address: (String) The address to which the refund should be made
319+
is_subtract: (Bool) Whether to take a commission from the merchant's balance or from the refund amount. true - take the commission from merchant balance. false - reduce the refundable amount by the commission amount
286320
invoice_uuid: (String, Optional if order_id set) Invoice UUID
287-
order_id: (String, Optional if wallet_uuid set) Order ID in your system
321+
order_id: (String[1..128], Optional if invoice_uuid set) Invoice order ID
322+
323+
* Invoice is identified by order_id or uuid, if you pass both, the account will be identified by uuid
288324
"""
289325
method = "payment/refund"
290326
params = {
@@ -300,16 +336,22 @@ def refund(self,
300336
resp = self.__request(method, 1, **params).get("result")
301337
return Invoice.de_json(resp)
302338

303-
def payment_history(self, cursor = None):
339+
def payment_history(self, date_from = None, date_to = None, cursor = None):
304340
"""
305341
Payment history
306342
https://doc.cryptomus.com/payments/payment-history
307343
Requires PAYMENT API key
308344
345+
date_from: (String, Optional) Filtering by creation date, from
346+
date_to: (String, Optional) Filtering by creation date, to
309347
cursor: (String, Optional) Page cursor (hash)
310348
"""
311349
params = {
312350
}
351+
if date_from:
352+
params["date_from"] = date_from.strftime(CryptomusDateFormat)
353+
if date_to:
354+
params["date_to"] = date_to.strftime(CryptomusDateFormat)
313355
if cursor:
314356
params["cursor"] = cursor
315357
method = "payment/list"
@@ -320,7 +362,9 @@ def payment_history(self, cursor = None):
320362
return PaymentsHistory.de_json(resp)
321363

322364
def payment_history_filtered(
323-
self, max_results = 15, max_pages = 10,
365+
self,
366+
date_from = None, date_to = None,
367+
max_results = 15, max_pages = 10,
324368
currencies = None, networks = None, addresses = None,
325369
statuses = None, is_final = None, page_delay = 1):
326370
"""
@@ -333,6 +377,8 @@ def payment_history_filtered(
333377
Collects only results under filters.
334378
Process as many pages as needed to collect max_results, but not more than max_pages.
335379
380+
date_from: (String, Optional) Filtering by creation date, from
381+
date_to: (String, Optional) Filtering by creation date, to
336382
max_results: (Int, Optional, default=15) Max number of results to collect
337383
max_pages: (Int, Optional, default=10) Max number of pages to process
338384
currencies: (List of Strings, Optional) List of accepted currencies. Codes: https://doc.cryptomus.com/reference
@@ -349,7 +395,7 @@ def payment_history_filtered(
349395
cursor = None
350396
while page_number < max_pages:
351397
if page_number > 0: sleep(page_delay)
352-
resp = self.payment_history(cursor = cursor)
398+
resp = self.payment_history(date_from = date_from, date_to = date_to, cursor = cursor)
353399

354400
if not resp.items:
355401
# No (more) payments

pyCryptomusAPI/cryto_types.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import datetime
12
import json
23
from abc import ABC
34

5+
CryptomusDateFormat = "%Y-%m-%d %H:%M:%S"
46

57
class Dictionaryable(ABC):
68
"""
@@ -218,19 +220,22 @@ def __init__(self):
218220
self.amount = None
219221
self.payment_amount = None
220222
self.payer_amount = None
223+
self.discount_percent = None
224+
self.discount = None
221225
self.payer_currency = None
222226
self.currency = None
223-
self.comments = None
227+
self.merchant_amount = None
224228
self.network = None
225229
self.address = None
226230
self.from_ = None
227231
self.txid = None
232+
self.payment_status = None
228233
self.url = None
229234
self.expired_at = None
230-
self.payment_status = None
231235
self.is_final = None
232236
self.additional_data = None
233-
self.currencies = None
237+
self.created_at = None
238+
self.updated_at = None
234239

235240
@classmethod
236241
def de_json(cls, json_dict):
@@ -242,10 +247,16 @@ def de_json(cls, json_dict):
242247
instance.payment_amount = float(instance.payment_amount)
243248
if instance.payer_amount is not None:
244249
instance.payer_amount = float(instance.payer_amount)
245-
if instance.expired_at is not None:
246-
instance.expired_at = int(instance.expired_at)
247-
if instance.currencies:
248-
instance.currencies = [Currency.de_json(i) for i in instance.currencies]
250+
if instance.discount_percent is not None:
251+
instance.discount_percent = float(instance.discount_percent)
252+
if instance.discount is not None:
253+
instance.discount = float(instance.discount)
254+
if instance.merchant_amount is not None:
255+
instance.merchant_amount = float(instance.merchant_amount)
256+
# if instance.created_at is not None:
257+
# instance.created_at = datetime.datetime.strptime(instance.created_at, CryptomusDateFormat)
258+
# if instance.updated_at is not None:
259+
# instance.updated_at = datetime.datetime.strptime(instance.updated_at, CryptomusDateFormat)
249260
return instance
250261

251262
# noinspection PyMethodOverriding

pyCryptomusAPI/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Versions should comply with PEP440.
22
# This line is parsed in setup.py:
3-
__version__ = '0.0.7'
3+
__version__ = '0.0.8'

0 commit comments

Comments
 (0)