|
12 | 12 | from .tokens import Tokens |
13 | 13 | from .models.facade import Facade |
14 | 14 | from .models.bill.bill import Bill |
| 15 | +from .models.Rate.rate import Rate |
15 | 16 | from .utils.rest_cli import RESTcli |
| 17 | +from .models.Rate.rates import Rates |
| 18 | +from .models.currency import Currency |
16 | 19 | from .models.ledger.ledger import Ledger |
17 | 20 | from .models.wallet.wallet import Wallet |
18 | 21 | from .models.payout.payout import Payout |
19 | 22 | from .models.invoice.refund import Refund |
20 | 23 | from .models.invoice.invoice import Invoice |
21 | 24 | from .models.payout.payout_batch import PayoutBatch |
22 | 25 | from .models.ledger.ledger_entry import LedgerEntry |
| 26 | +from .models.settlement.settlement import Settlement |
23 | 27 | from .exceptions.bitpay_exception import BitPayException |
| 28 | +from .models.subscription.subscription import Subscription |
24 | 29 | from .models.payout.payout_recipient import PayoutRecipient |
25 | 30 | from .models.payout.payout_recipients import PayoutRecipients |
26 | 31 | from .exceptions.bill_query_exception import BillQueryException |
| 32 | +from .exceptions.rate_query_exception import RateQueryException |
27 | 33 | from .exceptions.bill_update_exception import BillUpdateException |
28 | 34 | from .exceptions.ledger_query_exception import LedgerQueryException |
29 | 35 | from .exceptions.wallet_query_exception import WalletQueryException |
|
34 | 40 | from .exceptions.refund_update_exception import RefundUpdateException |
35 | 41 | from .exceptions.invoice_query_exception import InvoiceQueryException |
36 | 42 | from .exceptions.invoice_update_exception import InvoiceUpdateException |
| 43 | +from .exceptions.currency_query_exception import CurrencyQueryException |
37 | 44 | from .exceptions.refund_creation_exception import RefundCreationException |
38 | 45 | from .exceptions.payout_creation_exception import PayoutCreationException |
| 46 | +from .exceptions.settlement_query_exception import SettlementQueryException |
39 | 47 | from .exceptions.invoice_creation_exception import InvoiceCreationException |
40 | 48 | from .exceptions.payoutbatch_query_exception import PayoutBatchQueryException |
| 49 | +from .exceptions.subscription_query_exception import SubscriptionQueryException |
| 50 | +from .exceptions.subscription_update_exception import SubscriptionUpdateException |
41 | 51 | from .exceptions.refund_notification_exception import RefundNotificationException |
42 | 52 | from .exceptions.refund_cancellation_exception import RefundCancellationException |
43 | 53 | from .exceptions.payout_cancellation_exception import PayoutCancellationException |
44 | 54 | from .exceptions.payout_notification_exception import PayoutNotificationException |
45 | 55 | from .exceptions.invoice_cancellation_exception import InvoiceCancellationException |
46 | 56 | from .exceptions.invoice_notification_exception import InvoiceNotificationException |
47 | 57 | from .exceptions.payoutbatch_creation_exception import PayoutBatchCreationException |
| 58 | +from .exceptions.subscription_creation_exception import SubscriptionCreationException |
48 | 59 | from .exceptions.payout_recipient_query_exception import PayoutRecipientQueryException |
49 | 60 | from .exceptions.payout_recipient_update_exception import PayoutRecipientUpdateException |
50 | 61 | from .exceptions.payoutbatch_cancellation_exception import PayoutBatchCancellationException |
@@ -1062,3 +1073,187 @@ def request_payout_batch_notification(self, payout_batch_id: str): |
1062 | 1073 | raise PayoutBatchNotificationException("failed to deserialize BitPay server response " |
1063 | 1074 | " (PayoutBatch) : %s" % str(exe)) |
1064 | 1075 | return payout_batch |
| 1076 | + |
| 1077 | + def get_settlements(self, currency: str, date_start, date_end, status: str, |
| 1078 | + limit: int = 100, offset: int = 0) -> [Settlement]: |
| 1079 | + try: |
| 1080 | + params = {"token": self.get_access_token(Facade.Merchant), |
| 1081 | + "startDate": date_start, "endDate": date_end, |
| 1082 | + "currency": currency, "status": status, "limit": limit, |
| 1083 | + "offset": offset} |
| 1084 | + response_json = self.__restcli.get("settlements", params) |
| 1085 | + except BitPayException as exe: |
| 1086 | + raise SettlementQueryException("failed to serialize Settlement object : %s" % str(exe), |
| 1087 | + exe.get_api_code()) |
| 1088 | + |
| 1089 | + try: |
| 1090 | + settlements = [] |
| 1091 | + for settlement in response_json: |
| 1092 | + settlements.append(Settlement(**settlement)) |
| 1093 | + except Exception as exe: |
| 1094 | + raise SettlementQueryException("failed to deserialize BitPay server response " |
| 1095 | + " (Settlement) : %s" % str(exe)) |
| 1096 | + return settlements |
| 1097 | + |
| 1098 | + def get_settlement(self, settlement_id: str) -> Settlement: |
| 1099 | + try: |
| 1100 | + params = {"token": self.get_access_token(Facade.Merchant)} |
| 1101 | + response_json = self.__restcli.get("settlements/%s" % settlement_id, params) |
| 1102 | + except BitPayException as exe: |
| 1103 | + raise SettlementQueryException("failed to serialize Settlement object : %s" % str(exe), |
| 1104 | + exe.get_api_code()) |
| 1105 | + |
| 1106 | + try: |
| 1107 | + settlement = Settlement(**response_json) |
| 1108 | + except Exception as exe: |
| 1109 | + raise SettlementQueryException("failed to deserialize BitPay server response " |
| 1110 | + " (Settlement) : %s" % str(exe)) |
| 1111 | + return settlement |
| 1112 | + |
| 1113 | + def get_settlement_reconciliation_report(self, settlement: Settlement) -> Settlement: |
| 1114 | + try: |
| 1115 | + params = {"token": self.get_access_token(Facade.Merchant)} |
| 1116 | + response_json = self.__restcli.get("settlements/%s" % settlement.get_id() + "/reconciliationReport", |
| 1117 | + params) |
| 1118 | + except BitPayException as exe: |
| 1119 | + raise SettlementQueryException("failed to serialize Settlement object : %s" % str(exe), |
| 1120 | + exe.get_api_code()) |
| 1121 | + |
| 1122 | + try: |
| 1123 | + settlement = Settlement(**response_json) |
| 1124 | + except Exception as exe: |
| 1125 | + raise SettlementQueryException("failed to deserialize BitPay server response " |
| 1126 | + " (Settlement) : %s" % str(exe)) |
| 1127 | + return settlement |
| 1128 | + |
| 1129 | + def create_subscription(self, subscription: Subscription) -> Subscription: |
| 1130 | + try: |
| 1131 | + subscription.set_token(self.get_access_token(Facade.Merchant)) |
| 1132 | + subscription.to_json() |
| 1133 | + |
| 1134 | + response_json = self.__restcli.post("subscriptions", subscription, True) |
| 1135 | + except BitPayException as exe: |
| 1136 | + raise SubscriptionCreationException("failed to serialize Subscription object : %s" % str(exe), |
| 1137 | + exe.get_api_code()) |
| 1138 | + |
| 1139 | + try: |
| 1140 | + subscription = Subscription(**response_json) |
| 1141 | + except Exception as exe: |
| 1142 | + raise SubscriptionCreationException("failed to deserialize BitPay server response " |
| 1143 | + " (Subscription) : %s" % str(exe)) |
| 1144 | + return subscription |
| 1145 | + |
| 1146 | + def get_subscription(self, subscription_id: str) -> Subscription: |
| 1147 | + try: |
| 1148 | + params = {"token": self.get_access_token(Facade.Merchant)} |
| 1149 | + response_json = self.__restcli.get("subscriptions/%s" % subscription_id, params) |
| 1150 | + except BitPayException as exe: |
| 1151 | + raise SubscriptionQueryException("failed to serialize Subscription object : %s" % str(exe), |
| 1152 | + exe.get_api_code()) |
| 1153 | + |
| 1154 | + try: |
| 1155 | + subscription = Subscription(**response_json) |
| 1156 | + except Exception as exe: |
| 1157 | + raise SubscriptionQueryException("failed to deserialize BitPay server response " |
| 1158 | + " (Subscription) : %s" % str(exe)) |
| 1159 | + return subscription |
| 1160 | + |
| 1161 | + def get_subscriptions(self, status: str = None) -> [Subscription]: |
| 1162 | + try: |
| 1163 | + params = {"token": self.get_access_token(Facade.Merchant)} |
| 1164 | + if status: |
| 1165 | + params["status"] = status |
| 1166 | + response_json = self.__restcli.get("subscriptions", params) |
| 1167 | + except BitPayException as exe: |
| 1168 | + raise SubscriptionQueryException("failed to serialize Subscription object : %s" % str(exe), |
| 1169 | + exe.get_api_code()) |
| 1170 | + |
| 1171 | + try: |
| 1172 | + subscriptions = [] |
| 1173 | + for subscription in response_json: |
| 1174 | + subscriptions.append(Subscription(**subscription)) |
| 1175 | + except Exception as exe: |
| 1176 | + raise SubscriptionQueryException("failed to deserialize BitPay server response " |
| 1177 | + " (Subscription) : %s" % str(exe)) |
| 1178 | + return subscriptions |
| 1179 | + |
| 1180 | + def update_subscription(self, subscription: Subscription, subscription_id) -> Subscription: |
| 1181 | + try: |
| 1182 | + subscription_token = self.get_subscription(subscription.get_id()).get_token() |
| 1183 | + subscription.set_token(subscription_token) |
| 1184 | + subscription.to_json() |
| 1185 | + |
| 1186 | + response_json = self.__restcli.update("subscriptions/%s" % subscription_id, subscription) |
| 1187 | + except BitPayException as exe: |
| 1188 | + raise SubscriptionUpdateException("failed to serialize Subscription object : %s" % str(exe), |
| 1189 | + exe.get_api_code()) |
| 1190 | + |
| 1191 | + try: |
| 1192 | + subscription = Subscription(**response_json) |
| 1193 | + except Exception as exe: |
| 1194 | + raise SubscriptionUpdateException("failed to deserialize BitPay server response " |
| 1195 | + " (Subscription) : %s" % str(exe)) |
| 1196 | + return subscription |
| 1197 | + |
| 1198 | + def get_currencies(self) -> [Currency]: |
| 1199 | + try: |
| 1200 | + response_json = self.__restcli.get("currencies", None, False) |
| 1201 | + except BitPayException as exe: |
| 1202 | + raise CurrencyQueryException("failed to serialize Currency object : %s" % str(exe), |
| 1203 | + exe.get_api_code()) |
| 1204 | + |
| 1205 | + try: |
| 1206 | + subscriptions = [] |
| 1207 | + for subscription in response_json: |
| 1208 | + subscriptions.append(Subscription(**subscription)) |
| 1209 | + except Exception as exe: |
| 1210 | + raise CurrencyQueryException("failed to deserialize BitPay server response " |
| 1211 | + " (Currency) : %s" % str(exe)) |
| 1212 | + return subscriptions |
| 1213 | + |
| 1214 | + def get_rates(self) -> [Rates]: |
| 1215 | + try: |
| 1216 | + response_json = self.__restcli.get("rates", None, False) |
| 1217 | + except BitPayException as exe: |
| 1218 | + raise RateQueryException("failed to serialize Rates object : %s" % str(exe), |
| 1219 | + exe.get_api_code()) |
| 1220 | + |
| 1221 | + try: |
| 1222 | + rates = [] |
| 1223 | + for rate in response_json: |
| 1224 | + rates.append(Rates(**rate)) |
| 1225 | + except Exception as exe: |
| 1226 | + raise RateQueryException("failed to deserialize BitPay server response " |
| 1227 | + " (Rates) : %s" % str(exe)) |
| 1228 | + return rates |
| 1229 | + |
| 1230 | + def get_currency_rates(self, base_currency: str) -> [Rates]: |
| 1231 | + try: |
| 1232 | + response_json = self.__restcli.get("rates/%s" % base_currency, None, False) |
| 1233 | + except BitPayException as exe: |
| 1234 | + raise RateQueryException("failed to serialize Rates object : %s" % str(exe), |
| 1235 | + exe.get_api_code()) |
| 1236 | + |
| 1237 | + try: |
| 1238 | + rates = [] |
| 1239 | + for rate in response_json: |
| 1240 | + rates.append(Rates(**rate)) |
| 1241 | + except Exception as exe: |
| 1242 | + raise RateQueryException("failed to deserialize BitPay server response " |
| 1243 | + " (Rates) : %s" % str(exe)) |
| 1244 | + return rates |
| 1245 | + |
| 1246 | + def get_currency_pair_rate(self, base_currency, currency) -> Rate: |
| 1247 | + try: |
| 1248 | + response_json = self.__restcli.get("rates/%s" % base_currency + "/%s" % currency, |
| 1249 | + None, False) |
| 1250 | + except BitPayException as exe: |
| 1251 | + raise RateQueryException("failed to serialize Rates object : %s" % str(exe), |
| 1252 | + exe.get_api_code()) |
| 1253 | + |
| 1254 | + try: |
| 1255 | + rate = Rate(**response_json) |
| 1256 | + except Exception as exe: |
| 1257 | + raise RateQueryException("failed to deserialize BitPay server response " |
| 1258 | + " (Rate) : %s" % str(exe)) |
| 1259 | + return rate |
0 commit comments