paga-python 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paga/__init__.py +28 -4
- paga/actions.py +25 -241
- paga/airtime.py +150 -0
- paga/bill_payment.py +203 -0
- paga/business.py +33 -596
- paga/checkout.py +19 -180
- paga/client.py +33 -9
- paga/collection.py +305 -0
- paga/direct_debit.py +2 -2
- paga/money_transfer.py +391 -0
- paga/persistent.py +50 -31
- paga/refunds.py +90 -0
- paga/status.py +60 -0
- paga/subsidiary.py +459 -0
- {paga_python-0.1.0.dist-info → paga_python-0.1.2.dist-info}/METADATA +12 -3
- paga_python-0.1.2.dist-info/RECORD +25 -0
- paga/directory.py +0 -523
- paga_python-0.1.0.dist-info/RECORD +0 -19
- {paga_python-0.1.0.dist-info → paga_python-0.1.2.dist-info}/WHEEL +0 -0
- {paga_python-0.1.0.dist-info → paga_python-0.1.2.dist-info}/licenses/LICENSE +0 -0
paga/__init__.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"""Async Python SDK for the Paga Engine API."""
|
|
2
2
|
|
|
3
|
+
from .airtime import AirtimeMixin
|
|
3
4
|
from .auth import PAYMENT_REQUEST_FULL_HASH_FIELDS
|
|
5
|
+
from .bill_payment import BillPaymentMixin
|
|
6
|
+
from .business import BusinessMixin
|
|
7
|
+
from .checkout import CheckoutMixin
|
|
4
8
|
from .client import (
|
|
5
9
|
DEFAULT_CHECKOUT_LIVE_BASE_URL,
|
|
6
10
|
DEFAULT_CHECKOUT_TEST_BASE_URL,
|
|
@@ -16,6 +20,9 @@ from .codes import (
|
|
|
16
20
|
MandateStatusCode,
|
|
17
21
|
PaymentRequestState,
|
|
18
22
|
)
|
|
23
|
+
from .collection import CollectionMixin
|
|
24
|
+
from .customer import CustomerMixin
|
|
25
|
+
from .direct_debit import DirectDebitMixin
|
|
19
26
|
from .exceptions import (
|
|
20
27
|
PagaAPIError,
|
|
21
28
|
PagaAuthenticationError,
|
|
@@ -87,6 +94,11 @@ from .models import (
|
|
|
87
94
|
ValidateMoneyTransferResponse,
|
|
88
95
|
)
|
|
89
96
|
from .outcome import OperationOutcome, classify, is_unknown_outcome
|
|
97
|
+
from .money_transfer import MoneyTransferMixin
|
|
98
|
+
from .persistent import PersistentPaymentAccountMixin
|
|
99
|
+
from .refunds import RefundsMixin
|
|
100
|
+
from .status import StatusMixin
|
|
101
|
+
from .subsidiary import SubsidiaryMixin
|
|
90
102
|
from .webhooks import (
|
|
91
103
|
parse_hash_parameters,
|
|
92
104
|
parse_money_transfer_notification,
|
|
@@ -104,12 +116,15 @@ from .webhooks import (
|
|
|
104
116
|
verify_subsidiary_operation,
|
|
105
117
|
)
|
|
106
118
|
|
|
107
|
-
__version__ = "0.1.
|
|
119
|
+
__version__ = "0.1.2"
|
|
108
120
|
|
|
109
121
|
__all__ = [
|
|
110
122
|
"AccountBalanceResponse",
|
|
123
|
+
"AirtimeMixin",
|
|
111
124
|
"Bank",
|
|
112
125
|
"BanksResponse",
|
|
126
|
+
"BillPaymentMixin",
|
|
127
|
+
"BusinessMixin",
|
|
113
128
|
"BulkMoneyTransferResponse",
|
|
114
129
|
"BulkTransferResult",
|
|
115
130
|
"BusinessErrorCode",
|
|
@@ -117,9 +132,15 @@ __all__ = [
|
|
|
117
132
|
"ChargeMandateStatusData",
|
|
118
133
|
"ChargeMandateStatusResponse",
|
|
119
134
|
"ChargeStatusCode",
|
|
135
|
+
"CheckoutMixin",
|
|
136
|
+
"CheckoutVerifyChargeResponse",
|
|
120
137
|
"CollectBank",
|
|
121
138
|
"CollectBanksResponse",
|
|
139
|
+
"CollectPaymentMethodResult",
|
|
140
|
+
"CollectPaymentRequestResponse",
|
|
122
141
|
"CollectStatusCode",
|
|
142
|
+
"CollectionMixin",
|
|
143
|
+
"CustomerMixin",
|
|
123
144
|
"CustomerResponse",
|
|
124
145
|
"DataBundle",
|
|
125
146
|
"DataBundlesResponse",
|
|
@@ -127,11 +148,9 @@ __all__ = [
|
|
|
127
148
|
"DEFAULT_CHECKOUT_TEST_BASE_URL",
|
|
128
149
|
"DEFAULT_COLLECT_LIVE_BASE_URL",
|
|
129
150
|
"DEFAULT_COLLECT_TEST_BASE_URL",
|
|
130
|
-
"CheckoutVerifyChargeResponse",
|
|
131
|
-
"CollectPaymentMethodResult",
|
|
132
|
-
"CollectPaymentRequestResponse",
|
|
133
151
|
"DepositToBankResponse",
|
|
134
152
|
"DisableMandateResponse",
|
|
153
|
+
"DirectDebitMixin",
|
|
135
154
|
"DirectDebitSessionData",
|
|
136
155
|
"DirectDebitSessionMetadata",
|
|
137
156
|
"DirectDebitSessionResponse",
|
|
@@ -151,6 +170,7 @@ __all__ = [
|
|
|
151
170
|
"MobileOperator",
|
|
152
171
|
"MobileOperatorsResponse",
|
|
153
172
|
"MoneyTransferItem",
|
|
173
|
+
"MoneyTransferMixin",
|
|
154
174
|
"MoneyTransferNotification",
|
|
155
175
|
"MoneyTransferResponse",
|
|
156
176
|
"OnboardMerchantCredentials",
|
|
@@ -169,15 +189,19 @@ __all__ = [
|
|
|
169
189
|
"PaymentRequestState",
|
|
170
190
|
"PaymentStatusData",
|
|
171
191
|
"PaymentStatusResponse",
|
|
192
|
+
"PersistentPaymentAccountMixin",
|
|
172
193
|
"PersistentPaymentAccountResponse",
|
|
173
194
|
"PurchaseResponse",
|
|
174
195
|
"RecentTransaction",
|
|
175
196
|
"RecentTransactionsResponse",
|
|
176
197
|
"RefundResponse",
|
|
177
198
|
"RefundStatusResponse",
|
|
199
|
+
"RefundsMixin",
|
|
200
|
+
"StatusMixin",
|
|
178
201
|
"SubsidiaryAccountResponse",
|
|
179
202
|
"SubsidiaryBalanceResponse",
|
|
180
203
|
"SubsidiaryHistoryResponse",
|
|
204
|
+
"SubsidiaryMixin",
|
|
181
205
|
"SubsidiaryMoneyResponse",
|
|
182
206
|
"SubsidiaryTransferResponse",
|
|
183
207
|
"TransactionHistoryResponse",
|
paga/actions.py
CHANGED
|
@@ -1,246 +1,30 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Compatibility shim for the old, section-less layout.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from typing import Any, Dict, List, Optional
|
|
6
|
-
|
|
7
|
-
from .auth import (
|
|
8
|
-
AIRTIME_HASH_FIELDS,
|
|
9
|
-
BILL_PAYMENT_HASH_FIELDS,
|
|
10
|
-
MONEY_TRANSFER_HASH_FIELDS,
|
|
11
|
-
REFUND_HASH_FIELDS,
|
|
12
|
-
)
|
|
13
|
-
from .models import (
|
|
14
|
-
DepositToBankResponse,
|
|
15
|
-
MerchantPaymentResponse,
|
|
16
|
-
PagaResponse,
|
|
17
|
-
PurchaseResponse,
|
|
18
|
-
RefundResponse,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ActionMixin:
|
|
23
|
-
"""Action operations: refunds, money transfers, airtime and bill payments."""
|
|
24
|
-
|
|
25
|
-
async def refund_payment(
|
|
26
|
-
self,
|
|
27
|
-
*,
|
|
28
|
-
reference_number: str,
|
|
29
|
-
payment_request_reference: str,
|
|
30
|
-
refund_amount: float,
|
|
31
|
-
currency: str = "NGN",
|
|
32
|
-
reason: Optional[str] = None,
|
|
33
|
-
) -> RefundResponse:
|
|
34
|
-
"""Refund or cancel a payment request.
|
|
35
|
-
|
|
36
|
-
Operation: Refunds - Refund or cancel a payment request.
|
|
37
|
-
|
|
38
|
-
Refunds a paid payment request in full or in part, or cancels one that
|
|
39
|
-
has not been paid. Send one request per partial refund, each with its
|
|
40
|
-
own ``reference_number``. Reusing a ``reference_number`` returns status
|
|
41
|
-
code ``102`` and never refunds twice.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
reference_number: Your unique reference for this refund.
|
|
45
|
-
payment_request_reference: The ``reference_number`` of the original
|
|
46
|
-
payment request.
|
|
47
|
-
refund_amount: Amount to refund.
|
|
48
|
-
currency: Transaction currency. Defaults to ``"NGN"``.
|
|
49
|
-
reason: Optional refund reason.
|
|
50
|
-
|
|
51
|
-
Returns:
|
|
52
|
-
The parsed :class:`RefundResponse`.
|
|
53
|
-
"""
|
|
54
|
-
payload: Dict[str, Any] = {
|
|
55
|
-
"referenceNumber": reference_number,
|
|
56
|
-
"paymentRequestReference": payment_request_reference,
|
|
57
|
-
"refundAmount": refund_amount,
|
|
58
|
-
"currency": currency,
|
|
59
|
-
}
|
|
60
|
-
if reason is not None:
|
|
61
|
-
payload["reason"] = reason
|
|
62
|
-
response = await self._request(
|
|
63
|
-
"POST",
|
|
64
|
-
"/refund/v2",
|
|
65
|
-
payload,
|
|
66
|
-
use_hash=True,
|
|
67
|
-
use_basic=True,
|
|
68
|
-
hash_fields=REFUND_HASH_FIELDS,
|
|
69
|
-
)
|
|
70
|
-
return RefundResponse.model_validate(response.model_dump())
|
|
71
|
-
|
|
72
|
-
async def send_money(
|
|
73
|
-
self,
|
|
74
|
-
*,
|
|
75
|
-
reference_number: str,
|
|
76
|
-
amount: str,
|
|
77
|
-
destination_bank_uuid: str,
|
|
78
|
-
destination_bank_account_number: str,
|
|
79
|
-
currency: str = "NGN",
|
|
80
|
-
remarks: Optional[str] = None,
|
|
81
|
-
status_callback_url: Optional[str] = None,
|
|
82
|
-
) -> DepositToBankResponse:
|
|
83
|
-
"""Send money from the business balance to a bank account or Paga wallet.
|
|
84
|
-
|
|
85
|
-
Operation: Money transfer - Send the money.
|
|
3
|
+
The operations that used to live here are now split by the section of Paga's
|
|
4
|
+
documentation they belong to:
|
|
86
5
|
|
|
87
|
-
|
|
88
|
-
|
|
6
|
+
- :mod:`paga.money_transfer` — Money Transfer
|
|
7
|
+
- :mod:`paga.airtime` — Airtime and data
|
|
8
|
+
- :mod:`paga.bill_payment` — Bill payment (VAS)
|
|
9
|
+
- :mod:`paga.refunds` — Refunds
|
|
10
|
+
- :mod:`paga.status` — Check the transaction status
|
|
89
11
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
destination_bank_uuid: The bank's UUID from get banks, or Paga's UUID
|
|
94
|
-
for a wallet.
|
|
95
|
-
destination_bank_account_number: Destination bank account number.
|
|
96
|
-
currency: Transaction currency. Defaults to ``"NGN"``.
|
|
97
|
-
remarks: Optional transfer remarks.
|
|
98
|
-
status_callback_url: Where Paga notifies once the transfer is processed. Optional.
|
|
12
|
+
This module re-exports them so that ``from paga.actions import ...`` keeps
|
|
13
|
+
working. It will be removed in a future release.
|
|
14
|
+
"""
|
|
99
15
|
|
|
100
|
-
|
|
101
|
-
The parsed :class:`DepositToBankResponse`.
|
|
102
|
-
"""
|
|
103
|
-
payload: Dict[str, Any] = {
|
|
104
|
-
"referenceNumber": reference_number,
|
|
105
|
-
"amount": amount,
|
|
106
|
-
"currency": currency,
|
|
107
|
-
"destinationBankUUID": destination_bank_uuid,
|
|
108
|
-
"destinationBankAccountNumber": destination_bank_account_number,
|
|
109
|
-
}
|
|
110
|
-
if remarks is not None:
|
|
111
|
-
payload["remarks"] = remarks
|
|
112
|
-
if status_callback_url is not None:
|
|
113
|
-
payload["statusCallbackUrl"] = status_callback_url
|
|
114
|
-
response = await self._request(
|
|
115
|
-
"POST",
|
|
116
|
-
"/depositToBank",
|
|
117
|
-
payload,
|
|
118
|
-
use_hash=True,
|
|
119
|
-
use_basic=False,
|
|
120
|
-
base_url=self.business_base_url,
|
|
121
|
-
hash_fields=MONEY_TRANSFER_HASH_FIELDS,
|
|
122
|
-
raise_on_error=False,
|
|
123
|
-
)
|
|
124
|
-
return DepositToBankResponse.model_validate(response.model_dump())
|
|
125
|
-
|
|
126
|
-
async def buy_airtime(
|
|
127
|
-
self,
|
|
128
|
-
*,
|
|
129
|
-
reference_number: str,
|
|
130
|
-
amount: str,
|
|
131
|
-
destination_phone_number: str,
|
|
132
|
-
mobile_operator_public_id: str,
|
|
133
|
-
currency: str = "NGN",
|
|
134
|
-
is_data_bundle: bool = False,
|
|
135
|
-
mobile_operator_service_id: Optional[str] = None,
|
|
136
|
-
is_suppress_recipient_messages: bool = False,
|
|
137
|
-
) -> PurchaseResponse:
|
|
138
|
-
"""Buy airtime or data.
|
|
139
|
-
|
|
140
|
-
Operation: Airtime and data - Buy the airtime or data.
|
|
141
|
-
|
|
142
|
-
Tops up a phone with airtime or data from the business balance. There
|
|
143
|
-
is no callback: decide on ``responseCode``, and check the transaction
|
|
144
|
-
status if needed.
|
|
145
|
-
|
|
146
|
-
Args:
|
|
147
|
-
reference_number: Your unique airtime purchase reference.
|
|
148
|
-
amount: Airtime value, or exactly the bundle's ``servicePrice`` for data.
|
|
149
|
-
destination_phone_number: Phone number to credit.
|
|
150
|
-
mobile_operator_public_id: The network's mobile operator public id.
|
|
151
|
-
currency: Transaction currency. Defaults to ``"NGN"``.
|
|
152
|
-
is_data_bundle: Whether this is a data bundle purchase. Defaults to ``False``.
|
|
153
|
-
mobile_operator_service_id: Data only. The bundle's ``serviceId``.
|
|
154
|
-
is_suppress_recipient_messages: Whether to suppress recipient messages.
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
The parsed :class:`PurchaseResponse`.
|
|
158
|
-
"""
|
|
159
|
-
payload: Dict[str, Any] = {
|
|
160
|
-
"referenceNumber": reference_number,
|
|
161
|
-
"amount": amount,
|
|
162
|
-
"destinationPhoneNumber": destination_phone_number,
|
|
163
|
-
"mobileOperatorPublicId": mobile_operator_public_id,
|
|
164
|
-
"currency": currency,
|
|
165
|
-
"isDataBundle": is_data_bundle,
|
|
166
|
-
}
|
|
167
|
-
if mobile_operator_service_id is not None:
|
|
168
|
-
payload["mobileOperatorServiceId"] = mobile_operator_service_id
|
|
169
|
-
if is_suppress_recipient_messages:
|
|
170
|
-
payload["isSuppressRecipientMessages"] = True
|
|
171
|
-
|
|
172
|
-
response = await self._request(
|
|
173
|
-
"POST",
|
|
174
|
-
"/airtimePurchase",
|
|
175
|
-
payload,
|
|
176
|
-
use_hash=True,
|
|
177
|
-
use_basic=False,
|
|
178
|
-
base_url=self.business_base_url,
|
|
179
|
-
hash_fields=AIRTIME_HASH_FIELDS,
|
|
180
|
-
raise_on_error=False,
|
|
181
|
-
)
|
|
182
|
-
return PurchaseResponse.model_validate(response.model_dump())
|
|
183
|
-
|
|
184
|
-
async def pay_bill(
|
|
185
|
-
self,
|
|
186
|
-
*,
|
|
187
|
-
reference_number: str,
|
|
188
|
-
amount: float,
|
|
189
|
-
merchant_account: str,
|
|
190
|
-
merchant_reference_number: str,
|
|
191
|
-
merchant_service: Optional[List[str]] = None,
|
|
192
|
-
currency: str = "NGN",
|
|
193
|
-
payment_channel: Optional[str] = None,
|
|
194
|
-
locale: Optional[str] = None,
|
|
195
|
-
merchant_service_product_code: Optional[str] = None,
|
|
196
|
-
) -> MerchantPaymentResponse:
|
|
197
|
-
"""Pay a bill from the business balance.
|
|
198
|
-
|
|
199
|
-
Operation: Bill payment - Pay the bill.
|
|
200
|
-
|
|
201
|
-
Pays a bill from the business balance. There is no callback: decide on
|
|
202
|
-
``responseCode``. ``integrationStatus`` is for information only.
|
|
203
|
-
|
|
204
|
-
Args:
|
|
205
|
-
reference_number: Your unique bill payment reference.
|
|
206
|
-
amount: Bill amount.
|
|
207
|
-
merchant_account: The biller's UUID. From the biller lookup.
|
|
208
|
-
merchant_reference_number: The customer's account / meter /
|
|
209
|
-
smart card / account number at the biller.
|
|
210
|
-
merchant_service: Optional chosen service code. Leave out for
|
|
211
|
-
billers with no services.
|
|
212
|
-
currency: Transaction currency. Defaults to ``"NGN"``.
|
|
213
|
-
payment_channel: Optional payment channel.
|
|
214
|
-
locale: Optional locale.
|
|
215
|
-
merchant_service_product_code: Optional chosen service code, as
|
|
216
|
-
returned by :meth:`get_merchant_services`.
|
|
16
|
+
from __future__ import annotations
|
|
217
17
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
payload["paymentChannel"] = payment_channel
|
|
232
|
-
if locale is not None:
|
|
233
|
-
payload["locale"] = locale
|
|
234
|
-
if merchant_service_product_code is not None:
|
|
235
|
-
payload["merchantServiceProductCode"] = merchant_service_product_code
|
|
236
|
-
response = await self._request(
|
|
237
|
-
"POST",
|
|
238
|
-
"/merchantPayment",
|
|
239
|
-
payload,
|
|
240
|
-
use_hash=True,
|
|
241
|
-
use_basic=False,
|
|
242
|
-
base_url=self.business_base_url,
|
|
243
|
-
hash_fields=BILL_PAYMENT_HASH_FIELDS,
|
|
244
|
-
raise_on_error=False,
|
|
245
|
-
)
|
|
246
|
-
return MerchantPaymentResponse.model_validate(response.model_dump())
|
|
18
|
+
from .airtime import AirtimeMixin
|
|
19
|
+
from .bill_payment import BillPaymentMixin
|
|
20
|
+
from .money_transfer import MoneyTransferMixin
|
|
21
|
+
from .refunds import RefundsMixin
|
|
22
|
+
from .status import StatusMixin
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"AirtimeMixin",
|
|
26
|
+
"BillPaymentMixin",
|
|
27
|
+
"MoneyTransferMixin",
|
|
28
|
+
"RefundsMixin",
|
|
29
|
+
"StatusMixin",
|
|
30
|
+
]
|
paga/airtime.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Airtime and data purchase operations for the Paga Engine API.
|
|
2
|
+
|
|
3
|
+
Covers the **Make payments → Airtime and data** section of Paga's
|
|
4
|
+
documentation.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, Dict, Optional
|
|
10
|
+
|
|
11
|
+
from .auth import AIRTIME_HASH_FIELDS, DATA_BUNDLE_HASH_FIELDS, MOBILE_OPERATORS_HASH_FIELDS
|
|
12
|
+
from .models import DataBundlesResponse, MobileOperatorsResponse, PurchaseResponse
|
|
13
|
+
|
|
14
|
+
__all__ = ["AirtimeMixin"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AirtimeMixin:
|
|
18
|
+
"""Airtime and data operations."""
|
|
19
|
+
|
|
20
|
+
async def get_mobile_operators(
|
|
21
|
+
self,
|
|
22
|
+
*,
|
|
23
|
+
reference_number: str,
|
|
24
|
+
locale: Optional[str] = None,
|
|
25
|
+
) -> MobileOperatorsResponse:
|
|
26
|
+
"""List the mobile networks you can top up.
|
|
27
|
+
|
|
28
|
+
Operation: Airtime and data - Get the mobile operator.
|
|
29
|
+
|
|
30
|
+
Send a network's ``mobileOperatorCode`` as ``mobileOperatorPublicId``
|
|
31
|
+
when buying airtime, and as ``operatorPublicId`` when listing data
|
|
32
|
+
bundles. Cache the list.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
reference_number: Your unique reference for this request.
|
|
36
|
+
locale: Optional locale. Paga defaults to the empty string.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
The parsed :class:`MobileOperatorsResponse`.
|
|
40
|
+
"""
|
|
41
|
+
payload: Dict[str, Any] = {"referenceNumber": reference_number}
|
|
42
|
+
if locale is not None:
|
|
43
|
+
payload["locale"] = locale
|
|
44
|
+
|
|
45
|
+
response = await self._request(
|
|
46
|
+
"POST",
|
|
47
|
+
"/getMobileOperators",
|
|
48
|
+
payload,
|
|
49
|
+
use_hash=True,
|
|
50
|
+
use_basic=False,
|
|
51
|
+
base_url=self.business_base_url,
|
|
52
|
+
hash_fields=MOBILE_OPERATORS_HASH_FIELDS,
|
|
53
|
+
raise_on_error=False,
|
|
54
|
+
)
|
|
55
|
+
return MobileOperatorsResponse.model_validate(response.model_dump())
|
|
56
|
+
|
|
57
|
+
async def get_data_bundles(
|
|
58
|
+
self,
|
|
59
|
+
*,
|
|
60
|
+
reference_number: str,
|
|
61
|
+
operator_public_id: str,
|
|
62
|
+
) -> DataBundlesResponse:
|
|
63
|
+
"""List a network's data bundles.
|
|
64
|
+
|
|
65
|
+
Operation: Airtime and data - For data, pick a bundle.
|
|
66
|
+
|
|
67
|
+
Send a bundle's ``serviceId`` as ``mobileOperatorServiceId`` and
|
|
68
|
+
**exactly** its ``servicePrice`` as ``amount`` — the two must match
|
|
69
|
+
byte for byte or Paga rejects the purchase. Bundles rarely change, so
|
|
70
|
+
cache the list and refresh it monthly.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
reference_number: Your unique reference for this request.
|
|
74
|
+
operator_public_id: The operator's ``mobileOperatorCode``.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
The parsed :class:`DataBundlesResponse`.
|
|
78
|
+
"""
|
|
79
|
+
response = await self._request(
|
|
80
|
+
"POST",
|
|
81
|
+
"/getDataBundleByOperator",
|
|
82
|
+
{
|
|
83
|
+
"referenceNumber": reference_number,
|
|
84
|
+
"operatorPublicId": operator_public_id,
|
|
85
|
+
},
|
|
86
|
+
use_hash=True,
|
|
87
|
+
use_basic=False,
|
|
88
|
+
base_url=self.business_base_url,
|
|
89
|
+
hash_fields=DATA_BUNDLE_HASH_FIELDS,
|
|
90
|
+
raise_on_error=False,
|
|
91
|
+
)
|
|
92
|
+
return DataBundlesResponse.model_validate(response.model_dump())
|
|
93
|
+
|
|
94
|
+
async def buy_airtime(
|
|
95
|
+
self,
|
|
96
|
+
*,
|
|
97
|
+
reference_number: str,
|
|
98
|
+
amount: str,
|
|
99
|
+
destination_phone_number: str,
|
|
100
|
+
mobile_operator_public_id: str,
|
|
101
|
+
currency: str = "NGN",
|
|
102
|
+
is_data_bundle: bool = False,
|
|
103
|
+
mobile_operator_service_id: Optional[str] = None,
|
|
104
|
+
is_suppress_recipient_messages: bool = False,
|
|
105
|
+
) -> PurchaseResponse:
|
|
106
|
+
"""Buy airtime or data.
|
|
107
|
+
|
|
108
|
+
Operation: Airtime and data - Buy the airtime or data.
|
|
109
|
+
|
|
110
|
+
Tops up a phone with airtime or data from the business balance. There
|
|
111
|
+
is no callback: decide on ``responseCode``, and check the transaction
|
|
112
|
+
status if needed.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
reference_number: Your unique airtime purchase reference.
|
|
116
|
+
amount: Airtime value, or exactly the bundle's ``servicePrice`` for data.
|
|
117
|
+
destination_phone_number: Phone number to credit.
|
|
118
|
+
mobile_operator_public_id: The network's mobile operator public id.
|
|
119
|
+
currency: Transaction currency. Defaults to ``"NGN"``.
|
|
120
|
+
is_data_bundle: Whether this is a data bundle purchase. Defaults to ``False``.
|
|
121
|
+
mobile_operator_service_id: Data only. The bundle's ``serviceId``.
|
|
122
|
+
is_suppress_recipient_messages: Whether to suppress recipient messages.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
The parsed :class:`PurchaseResponse`.
|
|
126
|
+
"""
|
|
127
|
+
payload: Dict[str, Any] = {
|
|
128
|
+
"referenceNumber": reference_number,
|
|
129
|
+
"amount": amount,
|
|
130
|
+
"destinationPhoneNumber": destination_phone_number,
|
|
131
|
+
"mobileOperatorPublicId": mobile_operator_public_id,
|
|
132
|
+
"currency": currency,
|
|
133
|
+
"isDataBundle": is_data_bundle,
|
|
134
|
+
}
|
|
135
|
+
if mobile_operator_service_id is not None:
|
|
136
|
+
payload["mobileOperatorServiceId"] = mobile_operator_service_id
|
|
137
|
+
if is_suppress_recipient_messages:
|
|
138
|
+
payload["isSuppressRecipientMessages"] = True
|
|
139
|
+
|
|
140
|
+
response = await self._request(
|
|
141
|
+
"POST",
|
|
142
|
+
"/airtimePurchase",
|
|
143
|
+
payload,
|
|
144
|
+
use_hash=True,
|
|
145
|
+
use_basic=False,
|
|
146
|
+
base_url=self.business_base_url,
|
|
147
|
+
hash_fields=AIRTIME_HASH_FIELDS,
|
|
148
|
+
raise_on_error=False,
|
|
149
|
+
)
|
|
150
|
+
return PurchaseResponse.model_validate(response.model_dump())
|