Skip to content

Commit 39c0055

Browse files
authored
Merge pull request #3 from nevermined-io/feat/support-nvm-api-keys
feat: NvmApiKeys support
2 parents 4af2106 + 5eb6d2b commit 39c0055

File tree

10 files changed

+87
-104
lines changed

10 files changed

+87
-104
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pip install nevermined/payments-py
1313

1414
```
1515
16-
Payments(session_key=session_key, environment=Environment.appStaging, app_id="your_app_id", version="1.0.0", session_key=your_session_key, marketplace_auth_token=your_marketplace_auth_token)
16+
Payments(nvm_api_key=nvm_api_key, environment=Environment.appStaging, app_id="your_app_id", version="1.0.0")
1717
1818
```
1919

docs/payments.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ A class representing a payment system.
2020

2121
**Attributes:**
2222

23-
- <b>`session_key`</b> (str): The session key for authentication.
23+
- <b>`nvm_api_key`</b> (str): The nvm api key for authentication.
2424
- <b>`environment`</b> (Environment): The environment for the payment system.
25-
- <b>`marketplace_auth_token`</b> (str, optional): The marketplace authentication token.
2625
- <b>`app_id`</b> (str, optional): The application ID.
2726
- <b>`version`</b> (str, optional): The version of the payment system.
2827

@@ -42,15 +41,14 @@ Methods:
4241

4342

4443

45-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L34"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
44+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L33"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
4645

4746
### <kbd>method</kbd> `__init__`
4847

4948
```python
5049
__init__(
51-
session_key: str,
50+
nvm_api_key: str,
5251
environment: Environment,
53-
marketplace_auth_token: Optional[str] = None,
5452
app_id: Optional[str] = None,
5553
version: Optional[str] = None
5654
)
@@ -65,7 +63,7 @@ __init__(
6563

6664
---
6765

68-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L135"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
66+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L133"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
6967

7068
### <kbd>method</kbd> `create_file`
7169

@@ -135,7 +133,7 @@ Creates a new file.
135133

136134
---
137135

138-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L77"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
136+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
139137

140138
### <kbd>method</kbd> `create_service`
141139

@@ -203,7 +201,7 @@ Creates a new service.
203201

204202
---
205203

206-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L42"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
204+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L40"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
207205

208206
### <kbd>method</kbd> `create_subscription`
209207

@@ -241,7 +239,7 @@ Creates a new subscription.
241239

242240
---
243241

244-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L219"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
242+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L218"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
245243

246244
### <kbd>method</kbd> `get_asset_ddo`
247245

@@ -265,7 +263,7 @@ Gets the asset DDO.
265263

266264
---
267265

268-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L358"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
266+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L352"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
269267

270268
### <kbd>method</kbd> `get_checkout_subscription`
271269

@@ -289,7 +287,7 @@ Gets the checkout subscription.
289287

290288
---
291289

292-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L345"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
290+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L339"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
293291

294292
### <kbd>method</kbd> `get_file_details`
295293

@@ -313,7 +311,7 @@ Gets the file details.
313311

314312
---
315313

316-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L332"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
314+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L326"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
317315

318316
### <kbd>method</kbd> `get_service_details`
319317

@@ -337,7 +335,7 @@ Gets the service details.
337335

338336
---
339337

340-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L261"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
338+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L258"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
341339

342340
### <kbd>method</kbd> `get_service_token`
343341

@@ -361,7 +359,7 @@ Gets the service token.
361359

362360
---
363361

364-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L301"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
362+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L295"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
365363

366364
### <kbd>method</kbd> `get_subscription_associated_files`
367365

@@ -385,7 +383,7 @@ Gets the subscription associated files.
385383

386384
---
387385

388-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L283"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
386+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L277"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
389387

390388
### <kbd>method</kbd> `get_subscription_associated_services`
391389

@@ -409,15 +407,12 @@ Gets the subscription associated services.
409407

410408
---
411409

412-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L237"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
410+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L236"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
413411

414412
### <kbd>method</kbd> `get_subscription_balance`
415413

416414
```python
417-
get_subscription_balance(
418-
subscription_did: str,
419-
account_address: Optional[str] = None
420-
)
415+
get_subscription_balance(subscription_did: str, account_address: str)
421416
```
422417

423418
Gets the subscription balance.
@@ -437,7 +432,7 @@ Gets the subscription balance.
437432

438433
---
439434

440-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L319"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
435+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L313"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
441436

442437
### <kbd>method</kbd> `get_subscription_details`
443438

@@ -461,7 +456,7 @@ Gets the subscription details.
461456

462457
---
463458

464-
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L195"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
459+
<a href="https://github.com/nevermined-io/payments-py/blob/main/payments_py/payments.py#L194"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
465460

466461
### <kbd>method</kbd> `order_subscription`
467462

payments_py/payments.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class Payments:
1010
A class representing a payment system.
1111
1212
Attributes:
13-
session_key (str): The session key for authentication.
13+
nvm_api_key (str): The nvm api key for authentication.
1414
environment (Environment): The environment for the payment system.
15-
marketplace_auth_token (str, optional): The marketplace authentication token.
1615
app_id (str, optional): The application ID.
1716
version (str, optional): The version of the payment system.
1817
1918
Methods:
2019
create_ubscription: Creates a new subscription.
2120
create_service: Creates a new service.
2221
create_file: Creates a new file.
22+
order_subscription: Orders the subscription.
2323
get_asset_ddo: Gets the asset DDO.
2424
get_subscription_balance: Gets the subscription balance.
2525
get_service_token: Gets the service token.
@@ -31,13 +31,12 @@ class Payments:
3131
get_checkout_subscription: Gets the checkout subscription.
3232
"""
3333

34-
def __init__(self, session_key: str, environment: Environment, marketplace_auth_token: Optional[str] = None,
34+
def __init__(self, nvm_api_key: str, environment: Environment,
3535
app_id: Optional[str] = None, version: Optional[str] = None):
36-
self.session_key = session_key
36+
self.nvm_api_key = nvm_api_key
3737
self.environment = environment
3838
self.app_id = app_id
3939
self.version = version
40-
self.marketplace_auth_token = marketplace_auth_token
4140

4241
def create_subscription(self, name: str, description: str, price: int, token_address: str,
4342
amount_of_credits: Optional[int], duration: Optional[int], tags: Optional[List[str]]):
@@ -57,7 +56,6 @@ def create_subscription(self, name: str, description: str, price: int, token_add
5756
Response: The response from the API call.
5857
"""
5958
body = {
60-
"sessionKey": self.session_key,
6159
"name": name,
6260
"description": description,
6361
"price": price,
@@ -68,7 +66,8 @@ def create_subscription(self, name: str, description: str, price: int, token_add
6866
}
6967
headers = {
7068
'Accept': 'application/json',
71-
'Content-Type': 'application/json'
69+
'Content-Type': 'application/json',
70+
'Authorization': f'''Bearer {self.nvm_api_key}'''
7271
}
7372
url = f"{self.environment.value['backend']}/api/v1/payments/subscription"
7473
response = requests.post(url, headers=headers, json=body)
@@ -114,7 +113,6 @@ def create_service(self, subscription_did: str, name: str, description: str, pri
114113
Response: The response from the API call.
115114
"""
116115
body = {
117-
"sessionKey": self.session_key,
118116
"subscriptionDid": subscription_did,
119117
"name": name,
120118
"description": description,
@@ -126,7 +124,8 @@ def create_service(self, subscription_did: str, name: str, description: str, pri
126124
}
127125
headers = {
128126
'Accept': 'application/json',
129-
'Content-Type': 'application/json'
127+
'Content-Type': 'application/json',
128+
'Authorization': f'Bearer {self.nvm_api_key}'
130129
}
131130
url = f"{self.environment.value['backend']}/api/v1/payments/service"
132131
response = requests.post(url, headers=headers, json=body)
@@ -174,7 +173,6 @@ def create_file(self, subscription_did: str, asset_type: str, name: str, descrip
174173
Response: The response from the API call.
175174
"""
176175
body = {
177-
"sessionKey": self.session_key,
178176
"subscriptionDid": subscription_did,
179177
"assetType": asset_type,
180178
"name": name,
@@ -186,7 +184,9 @@ def create_file(self, subscription_did: str, asset_type: str, name: str, descrip
186184
}
187185
headers = {
188186
'Accept': 'application/json',
189-
'Content-Type': 'application/json'
187+
'Content-Type': 'application/json',
188+
'Authorization': f'Bearer {self.nvm_api_key}'
189+
190190
}
191191
url = f"{self.environment.value['backend']}/api/v1/payments/file"
192192
response = requests.post(url, headers=headers, json=body)
@@ -204,13 +204,13 @@ def order_subscription(self, subscription_did: str, agreementId: Optional[str] =
204204
Response: The response from the API call.
205205
"""
206206
body = {
207-
"sessionKey": self.session_key,
208207
"subscriptionDid": subscription_did,
209208
**{snake_to_camel(k): v for k, v in locals().items() if v is not None and k != 'self'}
210209
}
211210
headers = {
212211
'Accept': 'application/json',
213-
'Content-Type': 'application/json'
212+
'Content-Type': 'application/json',
213+
'Authorization': f'Bearer {self.nvm_api_key}'
214214
}
215215
url = f"{self.environment.value['backend']}/api/v1/payments/subscription/order"
216216
response = requests.post(url, headers=headers, json=body)
@@ -234,20 +234,18 @@ def get_asset_ddo(self, did: str):
234234
response = requests.get(url, headers=headers)
235235
return response
236236

237-
def get_subscription_balance(self, subscription_did: str, account_address: Optional[str] = None):
237+
def get_subscription_balance(self, subscription_did: str, account_address: str):
238238
"""
239239
Gets the subscription balance.
240240
241241
Args:
242242
subscription_did (str): The DID of the subscription.
243-
account_address: Optional[str]: The account address.
243+
account_address (str): The account address.
244244
245245
Returns:
246246
Response: The response from the API call.
247247
"""
248248
body = {
249-
"sessionKey": self.session_key,
250-
"subscriptionDid": subscription_did,
251249
**{snake_to_camel(k): v for k, v in locals().items() if v is not None and k != 'self'}
252250
}
253251
headers = {
@@ -268,16 +266,13 @@ def get_service_token(self, service_did: str):
268266
Returns:
269267
Response: The response from the API call.
270268
"""
271-
body = {
272-
"accessToken": self.marketplace_auth_token,
273-
"did": service_did,
274-
}
275269
headers = {
276270
'Accept': 'application/json',
277-
'Content-Type': 'application/json'
271+
'Content-Type': 'application/json',
272+
'Authorization': f'Bearer {self.nvm_api_key}'
278273
}
279-
url = f"{self.environment.value['backend']}/api/v1/payments/service/token"
280-
response = requests.post(url, headers=headers, json=body)
274+
url = f"{self.environment.value['backend']}/api/v1/payments/service/token/{service_did}"
275+
response = requests.get(url, headers=headers)
281276
return response
282277

283278
def get_subscription_associated_services(self, subscription_did: str):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "payments-py"
3-
version = "0.1.3"
3+
version = "0.2.0"
44
description = ""
55
authors = ["enrique <enrique@nevermined.io>"]
66
readme = "README.md"

site/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ <h2 id="functions">Functions</h2>
154154

155155
<!--
156156
MkDocs version : 1.5.3
157-
Build Date UTC : 2024-05-06 14:21:42.594385+00:00
157+
Build Date UTC : 2024-05-17 14:29:59.059152+00:00
158158
-->

0 commit comments

Comments
 (0)