feat: new payment gateway creation from settings
This commit is contained in:
@@ -141,9 +141,6 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
show: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const evaluators = createListResource({
|
const evaluators = createListResource({
|
||||||
|
|||||||
@@ -156,9 +156,6 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
show: {
|
|
||||||
type: Boolean,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const members = createResource({
|
const members = createResource({
|
||||||
@@ -185,7 +182,6 @@ const openProfile = (username: string) => {
|
|||||||
username: username,
|
username: username,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
console.log(show.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMember = createResource({
|
const newMember = createResource({
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
>
|
>
|
||||||
<template #body-content>
|
<template #body-content>
|
||||||
<SettingFields
|
<SettingFields
|
||||||
v-if="gatewayID != 'new'"
|
v-if="gatewayID != 'new' && paymentGateway.data"
|
||||||
:fields="paymentGateway.data.fields"
|
:fields="paymentGateway.data.fields"
|
||||||
:data="paymentGateway.data.data"
|
:data="paymentGateway.data.data"
|
||||||
class="pt-5 my-0"
|
class="pt-5 my-0"
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<SettingFields
|
<SettingFields
|
||||||
v-if="newGateway"
|
v-if="newGateway"
|
||||||
:fields="newGatewayFields"
|
:fields="newGatewayFields"
|
||||||
:data="null"
|
:data="newGatewayData"
|
||||||
class="pt-5 my-0"
|
class="pt-5 my-0"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -53,9 +53,11 @@ import {
|
|||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import SettingFields from '@/components/Settings/SettingFields.vue'
|
import SettingFields from '@/components/Settings/SettingFields.vue'
|
||||||
|
|
||||||
const show = defineModel()
|
const show = defineModel<boolean>({ required: true, default: false })
|
||||||
const paymentGateways = defineModel<any>('paymentGateways')
|
const paymentGateways = defineModel<any>('paymentGateways')
|
||||||
const newGateway = ref(null)
|
const newGateway = ref(null)
|
||||||
|
const newGatewayFields = ref([])
|
||||||
|
const newGatewayData = ref<Record<string, any>>({})
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
gatewayID: string | null
|
gatewayID: string | null
|
||||||
@@ -79,7 +81,16 @@ const allGateways = createListResource({
|
|||||||
filters: {
|
filters: {
|
||||||
module: 'Payment Gateways',
|
module: 'Payment Gateways',
|
||||||
},
|
},
|
||||||
fields: ['name', 'issingle', 'fields'],
|
fields: ['name', 'issingle'],
|
||||||
|
})
|
||||||
|
|
||||||
|
const gatewayFields = createResource({
|
||||||
|
url: 'lms.lms.api.get_new_gateway_fields',
|
||||||
|
makeParams(values: any) {
|
||||||
|
return {
|
||||||
|
doctype: values.doctype,
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const arrangeFields = (fields: any[]) => {
|
const arrangeFields = (fields: any[]) => {
|
||||||
@@ -104,40 +115,100 @@ watch(
|
|||||||
paymentGateway.reload()
|
paymentGateway.reload()
|
||||||
} else if (props.gatewayID == 'new') {
|
} else if (props.gatewayID == 'new') {
|
||||||
allGateways.reload()
|
allGateways.reload()
|
||||||
console.log(allGateways.data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const getNewGateway = () => {
|
||||||
|
return allGateways.data?.find((gateway: any) =>
|
||||||
|
gateway.name.includes(newGateway.value)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(newGateway, () => {
|
||||||
|
let gatewayDoc = getNewGateway()
|
||||||
|
gatewayFields.reload({ doctype: gatewayDoc.name }).then(() => {
|
||||||
|
let fields = gatewayFields.data || []
|
||||||
|
arrangeFields(fields)
|
||||||
|
newGatewayFields.value = fields
|
||||||
|
prepareGatewayData()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const saveSettings = (close: () => void) => {
|
const saveSettings = (close: () => void) => {
|
||||||
call('frappe.client.set_value', {
|
if (props.gatewayID === 'new') {
|
||||||
doctype: paymentGateway.data.doctype,
|
saveNewGateway(close)
|
||||||
name: paymentGateway.data.docname,
|
} else {
|
||||||
fieldname: Object.keys(paymentGateway.data.data).reduce(
|
saveExistingGateway(
|
||||||
(fields: any, key: string) => {
|
paymentGateway.data.doctype,
|
||||||
if (
|
paymentGateway.data.docname,
|
||||||
paymentGateway.data.data[key] &&
|
close
|
||||||
typeof paymentGateway.data.data[key] === 'object'
|
)
|
||||||
) {
|
}
|
||||||
fields[key] = paymentGateway.data.data[key].file_url
|
}
|
||||||
} else {
|
|
||||||
fields[key] = paymentGateway.data.data[key]
|
const saveNewGateway = (close: () => void) => {
|
||||||
}
|
let gatewayDoc = getNewGateway()
|
||||||
return fields
|
if (gatewayDoc.issingle) {
|
||||||
|
saveExistingGateway(gatewayDoc.name, gatewayDoc.name, close)
|
||||||
|
} else {
|
||||||
|
call('frappe.client.insert', {
|
||||||
|
doc: {
|
||||||
|
doctype: gatewayDoc.name,
|
||||||
|
...newGatewayData.value,
|
||||||
},
|
},
|
||||||
{}
|
}).then((data: any) => {
|
||||||
),
|
paymentGateways.value.reload()
|
||||||
|
close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveExistingGateway = (
|
||||||
|
doctype: string,
|
||||||
|
docname: string,
|
||||||
|
close: () => void
|
||||||
|
) => {
|
||||||
|
call('frappe.client.set_value', {
|
||||||
|
doctype: doctype,
|
||||||
|
name: docname,
|
||||||
|
fieldname: getGatewayFields(),
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
paymentGateway.reload()
|
paymentGateways.value?.reload()
|
||||||
close()
|
close()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getGatewayFields = () => {
|
||||||
|
let data =
|
||||||
|
props.gatewayID == 'new' ? newGatewayData.value : paymentGateway.data.data
|
||||||
|
return Object.keys(data).reduce((fields: any, key: string) => {
|
||||||
|
if (data[key] && typeof data[key] === 'object') {
|
||||||
|
fields[key] = data[key].file_url
|
||||||
|
} else {
|
||||||
|
fields[key] = data[key]
|
||||||
|
}
|
||||||
|
return fields
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
const createGatewayRecord = (gatewayDoc: any, data: any = {}) => {
|
||||||
|
call('frappe.client.insert', {
|
||||||
|
doc: {
|
||||||
|
doctype: 'Payment Gateway',
|
||||||
|
gateway: newGateway.value,
|
||||||
|
gateway_controller: gatewayDoc.issingle ? '' : gatewayDoc.name,
|
||||||
|
gateway_settings: gatewayDoc.issingle ? '' : data.name,
|
||||||
|
},
|
||||||
|
}).then(() => {
|
||||||
|
paymentGateways.value?.reload()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const allGatewayOptions = computed(() => {
|
const allGatewayOptions = computed(() => {
|
||||||
let options: string[] = []
|
let options: string[] = []
|
||||||
let gatewayList = allGateways.data?.map((gateway: any) => gateway.name) || []
|
let gatewayList = allGateways.data?.map((gateway: any) => gateway.name) || []
|
||||||
gatewayList.forEach((gateway: any) => {
|
gatewayList.forEach((gateway: any) => {
|
||||||
console.log(gateway)
|
|
||||||
let gatewayName = gateway.split(' ')[0]
|
let gatewayName = gateway.split(' ')[0]
|
||||||
let existingGateways =
|
let existingGateways =
|
||||||
paymentGateways.value?.data?.map((pg: any) => pg.name) || []
|
paymentGateways.value?.data?.map((pg: any) => pg.name) || []
|
||||||
@@ -150,4 +221,13 @@ const allGatewayOptions = computed(() => {
|
|||||||
})
|
})
|
||||||
return options.map((gateway: string) => ({ label: gateway, value: gateway }))
|
return options.map((gateway: string) => ({ label: gateway, value: gateway }))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const prepareGatewayData = () => {
|
||||||
|
newGatewayData.value = {}
|
||||||
|
if (newGatewayFields.value.length) {
|
||||||
|
newGatewayFields.value.forEach((field: any) => {
|
||||||
|
newGatewayData.value[field.fieldname] = field.default || ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -37,13 +37,16 @@
|
|||||||
<component
|
<component
|
||||||
v-if="activeTab.template"
|
v-if="activeTab.template"
|
||||||
:is="activeTab.template"
|
:is="activeTab.template"
|
||||||
v-model:show="show"
|
|
||||||
v-bind="{
|
v-bind="{
|
||||||
label: activeTab.label,
|
label: activeTab.label,
|
||||||
description: activeTab.description,
|
description: activeTab.description,
|
||||||
...(activeTab.label == 'Branding'
|
...(activeTab.label == 'Branding'
|
||||||
? { fields: activeTab.fields }
|
? { fields: activeTab.fields }
|
||||||
: {}),
|
: {}),
|
||||||
|
...(activeTab.label == 'Evaluators' ||
|
||||||
|
activeTab.label == 'Members'
|
||||||
|
? { 'onUpdate:show': (val) => (show = val), show }
|
||||||
|
: {}),
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<!-- <PaymentSettings
|
<!-- <PaymentSettings
|
||||||
|
|||||||
+31
-9
@@ -6,6 +6,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import zipfile
|
import zipfile
|
||||||
|
from dataclasses import fields
|
||||||
from xml.dom.minidom import parseString
|
from xml.dom.minidom import parseString
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
@@ -823,7 +824,6 @@ def get_count(doctype, filters):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_payment_gateway_details(payment_gateway):
|
def get_payment_gateway_details(payment_gateway):
|
||||||
fields = []
|
|
||||||
gateway = frappe.get_doc("Payment Gateway", payment_gateway)
|
gateway = frappe.get_doc("Payment Gateway", payment_gateway)
|
||||||
|
|
||||||
if gateway.gateway_controller is None:
|
if gateway.gateway_controller is None:
|
||||||
@@ -843,15 +843,30 @@ def get_payment_gateway_details(payment_gateway):
|
|||||||
except Exception:
|
except Exception:
|
||||||
frappe.throw(_("{0} Settings not found").format(payment_gateway))
|
frappe.throw(_("{0} Settings not found").format(payment_gateway))
|
||||||
|
|
||||||
|
gateway_fields = get_transformed_fields(meta, data)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"fields": gateway_fields,
|
||||||
|
"data": data,
|
||||||
|
"doctype": doctype,
|
||||||
|
"docname": docname,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_transformed_fields(meta, data=None):
|
||||||
|
transformed_fields = []
|
||||||
for row in meta:
|
for row in meta:
|
||||||
if row.fieldtype not in ["Column Break", "Section Break"]:
|
if row.fieldtype not in ["Column Break", "Section Break"]:
|
||||||
if row.fieldtype in ["Attach", "Attach Image"]:
|
if row.fieldtype in ["Attach", "Attach Image"]:
|
||||||
fieldtype = "Upload"
|
fieldtype = "Upload"
|
||||||
data[row.fieldname] = get_file_info(data.get(row.fieldname))
|
if data and data.get(row.fieldname):
|
||||||
|
data[row.fieldname] = get_file_info(data.get(row.fieldname))
|
||||||
|
elif row.fieldtype == "Check":
|
||||||
|
fieldtype = "checkbox"
|
||||||
else:
|
else:
|
||||||
fieldtype = row.fieldtype
|
fieldtype = row.fieldtype
|
||||||
|
|
||||||
fields.append(
|
transformed_fields.append(
|
||||||
{
|
{
|
||||||
"label": row.label,
|
"label": row.label,
|
||||||
"name": row.fieldname,
|
"name": row.fieldname,
|
||||||
@@ -859,12 +874,19 @@ def get_payment_gateway_details(payment_gateway):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return transformed_fields
|
||||||
"fields": fields,
|
|
||||||
"data": data,
|
|
||||||
"doctype": doctype,
|
@frappe.whitelist()
|
||||||
"docname": docname,
|
def get_new_gateway_fields(doctype):
|
||||||
}
|
try:
|
||||||
|
meta = frappe.get_meta(doctype).fields
|
||||||
|
except Exception:
|
||||||
|
frappe.throw(_("{0} not found").format(doctype))
|
||||||
|
|
||||||
|
transformed_fields = get_transformed_fields(meta)
|
||||||
|
|
||||||
|
return transformed_fields
|
||||||
|
|
||||||
|
|
||||||
def update_course_statistics():
|
def update_course_statistics():
|
||||||
|
|||||||
Reference in New Issue
Block a user