@@ -10,16 +10,16 @@ class Payments:
10
10
A class representing a payment system.
11
11
12
12
Attributes:
13
- session_key (str): The session key for authentication.
13
+ nvm_api_key (str): The nvm api key for authentication.
14
14
environment (Environment): The environment for the payment system.
15
- marketplace_auth_token (str, optional): The marketplace authentication token.
16
15
app_id (str, optional): The application ID.
17
16
version (str, optional): The version of the payment system.
18
17
19
18
Methods:
20
19
create_ubscription: Creates a new subscription.
21
20
create_service: Creates a new service.
22
21
create_file: Creates a new file.
22
+ order_subscription: Orders the subscription.
23
23
get_asset_ddo: Gets the asset DDO.
24
24
get_subscription_balance: Gets the subscription balance.
25
25
get_service_token: Gets the service token.
@@ -31,13 +31,12 @@ class Payments:
31
31
get_checkout_subscription: Gets the checkout subscription.
32
32
"""
33
33
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 ,
35
35
app_id : Optional [str ] = None , version : Optional [str ] = None ):
36
- self .session_key = session_key
36
+ self .nvm_api_key = nvm_api_key
37
37
self .environment = environment
38
38
self .app_id = app_id
39
39
self .version = version
40
- self .marketplace_auth_token = marketplace_auth_token
41
40
42
41
def create_subscription (self , name : str , description : str , price : int , token_address : str ,
43
42
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
57
56
Response: The response from the API call.
58
57
"""
59
58
body = {
60
- "sessionKey" : self .session_key ,
61
59
"name" : name ,
62
60
"description" : description ,
63
61
"price" : price ,
@@ -68,7 +66,8 @@ def create_subscription(self, name: str, description: str, price: int, token_add
68
66
}
69
67
headers = {
70
68
'Accept' : 'application/json' ,
71
- 'Content-Type' : 'application/json'
69
+ 'Content-Type' : 'application/json' ,
70
+ 'Authorization' : f'''Bearer { self .nvm_api_key } '''
72
71
}
73
72
url = f"{ self .environment .value ['backend' ]} /api/v1/payments/subscription"
74
73
response = requests .post (url , headers = headers , json = body )
@@ -114,7 +113,6 @@ def create_service(self, subscription_did: str, name: str, description: str, pri
114
113
Response: The response from the API call.
115
114
"""
116
115
body = {
117
- "sessionKey" : self .session_key ,
118
116
"subscriptionDid" : subscription_did ,
119
117
"name" : name ,
120
118
"description" : description ,
@@ -126,7 +124,8 @@ def create_service(self, subscription_did: str, name: str, description: str, pri
126
124
}
127
125
headers = {
128
126
'Accept' : 'application/json' ,
129
- 'Content-Type' : 'application/json'
127
+ 'Content-Type' : 'application/json' ,
128
+ 'Authorization' : f'Bearer { self .nvm_api_key } '
130
129
}
131
130
url = f"{ self .environment .value ['backend' ]} /api/v1/payments/service"
132
131
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
174
173
Response: The response from the API call.
175
174
"""
176
175
body = {
177
- "sessionKey" : self .session_key ,
178
176
"subscriptionDid" : subscription_did ,
179
177
"assetType" : asset_type ,
180
178
"name" : name ,
@@ -186,7 +184,9 @@ def create_file(self, subscription_did: str, asset_type: str, name: str, descrip
186
184
}
187
185
headers = {
188
186
'Accept' : 'application/json' ,
189
- 'Content-Type' : 'application/json'
187
+ 'Content-Type' : 'application/json' ,
188
+ 'Authorization' : f'Bearer { self .nvm_api_key } '
189
+
190
190
}
191
191
url = f"{ self .environment .value ['backend' ]} /api/v1/payments/file"
192
192
response = requests .post (url , headers = headers , json = body )
@@ -204,13 +204,13 @@ def order_subscription(self, subscription_did: str, agreementId: Optional[str] =
204
204
Response: The response from the API call.
205
205
"""
206
206
body = {
207
- "sessionKey" : self .session_key ,
208
207
"subscriptionDid" : subscription_did ,
209
208
** {snake_to_camel (k ): v for k , v in locals ().items () if v is not None and k != 'self' }
210
209
}
211
210
headers = {
212
211
'Accept' : 'application/json' ,
213
- 'Content-Type' : 'application/json'
212
+ 'Content-Type' : 'application/json' ,
213
+ 'Authorization' : f'Bearer { self .nvm_api_key } '
214
214
}
215
215
url = f"{ self .environment .value ['backend' ]} /api/v1/payments/subscription/order"
216
216
response = requests .post (url , headers = headers , json = body )
@@ -234,20 +234,18 @@ def get_asset_ddo(self, did: str):
234
234
response = requests .get (url , headers = headers )
235
235
return response
236
236
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 ):
238
238
"""
239
239
Gets the subscription balance.
240
240
241
241
Args:
242
242
subscription_did (str): The DID of the subscription.
243
- account_address: Optional[ str] : The account address.
243
+ account_address ( str) : The account address.
244
244
245
245
Returns:
246
246
Response: The response from the API call.
247
247
"""
248
248
body = {
249
- "sessionKey" : self .session_key ,
250
- "subscriptionDid" : subscription_did ,
251
249
** {snake_to_camel (k ): v for k , v in locals ().items () if v is not None and k != 'self' }
252
250
}
253
251
headers = {
@@ -268,16 +266,13 @@ def get_service_token(self, service_did: str):
268
266
Returns:
269
267
Response: The response from the API call.
270
268
"""
271
- body = {
272
- "accessToken" : self .marketplace_auth_token ,
273
- "did" : service_did ,
274
- }
275
269
headers = {
276
270
'Accept' : 'application/json' ,
277
- 'Content-Type' : 'application/json'
271
+ 'Content-Type' : 'application/json' ,
272
+ 'Authorization' : f'Bearer { self .nvm_api_key } '
278
273
}
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 )
281
276
return response
282
277
283
278
def get_subscription_associated_services (self , subscription_did : str ):
0 commit comments