fix: added saas api's to communicate with frappe cloud
This commit is contained in:
parent
71406a495c
commit
32c4b24a31
56
crm/api/saas_billing.py
Normal file
56
crm/api/saas_billing.py
Normal file
@ -0,0 +1,56 @@
|
||||
import frappe
|
||||
import requests
|
||||
|
||||
def get_base_url():
|
||||
url = "https://frappecloud.com"
|
||||
if frappe.conf.developer_mode and frappe.conf.get("saas_billing_base_url"):
|
||||
url = frappe.conf.get("saas_billing_base_url")
|
||||
return url
|
||||
|
||||
def get_site_name():
|
||||
site_name = frappe.local.site
|
||||
if frappe.conf.developer_mode and frappe.conf.get("saas_billing_site_name"):
|
||||
site_name = frappe.conf.get("saas_billing_site_name")
|
||||
return site_name
|
||||
|
||||
def get_headers():
|
||||
# check if user is system manager
|
||||
if frappe.get_roles(frappe.session.user).count("System Manager") == 0:
|
||||
frappe.throw("You are not allowed to access this resource")
|
||||
|
||||
# check if communication secret is set
|
||||
if not frappe.conf.get("fc_communication_secret"):
|
||||
frappe.throw("Communication secret not set")
|
||||
|
||||
return {
|
||||
"X-Site-Token": frappe.conf.get("fc_communication_secret"),
|
||||
"X-Site": get_site_name()
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def generate_access_token():
|
||||
request = requests.post(f"{get_base_url()}/api/method/press.saas.api.auth.generate_access_token", headers=get_headers())
|
||||
if request.status_code == 200:
|
||||
return request.json()["message"]
|
||||
else:
|
||||
frappe.throw("Failed to generate access token")
|
||||
|
||||
@frappe.whitelist()
|
||||
def is_access_token_valid(token):
|
||||
headers={ 'Content-Type': 'application/json' }
|
||||
request = requests.post(f"{get_base_url()}/api/method/press.saas.api.auth.is_access_token_valid", headers, json={ token })
|
||||
return request.json()["message"]
|
||||
|
||||
@frappe.whitelist()
|
||||
def current_site_info():
|
||||
request = requests.post(f"{get_base_url()}/api/method/press.saas.api.site.info", headers=get_headers())
|
||||
if request.status_code == 200:
|
||||
return request.json().get("message")
|
||||
else:
|
||||
frappe.throw("Failed to get site info")
|
||||
|
||||
@frappe.whitelist()
|
||||
def saas_api(method, data={}):
|
||||
request = requests.post(f"{get_base_url()}/api/method/press.saas.api.{method}", headers=get_headers(), json=data)
|
||||
print(request.json())
|
||||
return request.json().get("message")
|
||||
@ -3,7 +3,6 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.boot import add_subscription_conf
|
||||
from frappe.utils import cint
|
||||
from frappe.utils.telemetry import capture
|
||||
|
||||
@ -34,8 +33,7 @@ def get_boot():
|
||||
"site_name": frappe.local.site,
|
||||
"read_only_mode": frappe.flags.read_only,
|
||||
"csrf_token": frappe.sessions.get_csrf_token(),
|
||||
"telemetry_site_age": frappe.utils.telemetry.site_age(),
|
||||
"subscription_conf": add_subscription_conf(),
|
||||
"fc_communication_secret": frappe.conf.fc_communication_secret,
|
||||
"setup_complete": cint(frappe.get_system_settings("setup_complete"))
|
||||
}
|
||||
)
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit b496da753880dba27223813979f8cee8417bcc90
|
||||
Subproject commit 519cc536e720c4e785432084c04be63f450a2d4e
|
||||
@ -75,6 +75,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<TrialBanner
|
||||
baseAPIPath="crm.api.saas_billing"
|
||||
:isSidebarCollapsed="isSidebarCollapsed"
|
||||
@upgradePlan="showBillingSettingPage"
|
||||
/>
|
||||
|
||||
@ -85,18 +85,21 @@ const tabs = computed(() => {
|
||||
},
|
||||
{
|
||||
label: __('Subscription'),
|
||||
condition: () => window.subscription_conf,
|
||||
condition: () => window.fc_communication_secret && isManager(),
|
||||
items: [
|
||||
{
|
||||
label: 'Plans',
|
||||
icon: UpgradeIcon,
|
||||
component: markRaw(Plans),
|
||||
component: markRaw(h(Plans, { baseAPIPath: 'crm.api.saas_billing' })),
|
||||
},
|
||||
{
|
||||
label: 'Billing',
|
||||
icon: WalletsIcon,
|
||||
component: markRaw(
|
||||
h(Billing, { onChangePlan: () => setActiveTab('Plans') }),
|
||||
h(Billing, {
|
||||
baseAPIPath: 'crm.api.saas_billing',
|
||||
onChangePlan: () => setActiveTab('Plans'),
|
||||
}),
|
||||
),
|
||||
},
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user