This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayment_method_definitions.py
62 lines (47 loc) · 2.29 KB
/
payment_method_definitions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
import json
import requests
SYSTEM_API_URL = "https://system.beyondshop.cloud/api"
PAYMENT_METHOD_DEFINITION_ID = ""
def read_json_file(file_path):
data = {}
with open(file_path) as f:
data = json.load(f)
return data
def system_token(client_id, client_secret):
return requests.post('%s/oauth/token' % SYSTEM_API_URL, auth=(client_id, client_secret), data={"grant_type": "client_credentials"}) \
.json() \
.get("access_token", "")
def get_payment_method_definitions(system_token):
payment_method_definitions = \
requests.get('%s/payment-method-definitions' % SYSTEM_API_URL, \
headers={
"Accept": "application/hal+json",
"Authorization": "Bearer %s" % system_token
}).json().get("_embedded", {}).get("payment-method-definitions", [])
return payment_method_definitions
def create_payment_method_definition(system_token, file_path):
payment_method_definition_create_payload = read_json_file(file_path)
created_payment_method_definition = \
requests.post('%s/payment-method-definitions' % SYSTEM_API_URL, \
headers= {
"Accept": "application/hal+json",
"Content-Type": "application/json",
"Authorization": "Bearer %s" % system_token
}, \
json=payment_method_definition_create_payload).json()
return created_payment_method_definition
def get_payment_method_definition(installation, payment_method_definition_name):
payment_method_definition = \
requests.get('%s/payment-method-definitions/%s' % (installation.api_url, payment_method_definition_name), \
headers={
"Accept": "application/hal+json",
"Authorization": "Bearer %s" % installation.access_token
}).json()
return payment_method_definition
def create_payment_method(installation, payment_method_definition_name):
return requests.post('%s/payment-method-definitions/%s/payment-method' % (installation.api_url, payment_method_definition_name), \
headers= {
"Accept": "application/hal+json",
"Authorization": "Bearer %s" % installation.access_token
}).status_code