Skip to content

Commit 850d01b

Browse files
committed
fix: acpt create cpt request body structure
1 parent b703e4c commit 850d01b

File tree

19 files changed

+55
-131
lines changed

19 files changed

+55
-131
lines changed

frontend-dev/src/components/AllIntegrations/ACPT/ACPTAuthorization.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default function ACPTAuthorization({
6161
className="btcd-paper-inp w-6 mt-1"
6262
onChange={handleInput}
6363
name="name"
64-
value={acptConf.name}
64+
value={acptConf?.name ?? ''}
6565
type="text"
6666
placeholder={__('Integration Name...', 'bit-integrations')}
6767
disabled={isInfo}
@@ -76,7 +76,7 @@ export default function ACPTAuthorization({
7676
className="btcd-paper-inp w-6 mt-1"
7777
onChange={handleInput}
7878
name="base_url"
79-
value={acptConf.base_url}
79+
value={acptConf?.base_url ?? ''}
8080
type="text"
8181
placeholder={__('Homepage URL...', 'bit-integrations')}
8282
disabled={isInfo}
@@ -91,7 +91,7 @@ export default function ACPTAuthorization({
9191
className="btcd-paper-inp w-6 mt-1"
9292
onChange={handleInput}
9393
name="api_key"
94-
value={acptConf.api_key}
94+
value={acptConf?.api_key ?? ''}
9595
type="text"
9696
placeholder={__('Api Key-Secret:', 'bit-integrations')}
9797
disabled={isInfo}

frontend-dev/src/components/AllIntegrations/IntegInfo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export default function IntegInfo() {
549549
case 'Line':
550550
return <LineAuthorization lineConf={integrationConf} step={1} isInfo />
551551
case 'ACPT':
552-
return <ACPTAuthorization lineConf={integrationConf} step={1} isInfo />
552+
return <ACPTAuthorization acptConf={integrationConf} step={1} isInfo />
553553
default:
554554
return <></>
555555
}

frontend-dev/src/components/AllIntegrations/IntegrationHelpers/ActionProFeatureLabels.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ProFeatureSubtitle = ({ title, subtitle, proVersion }) => {
2424
? subtitle
2525
: sprintf(
2626
__(
27-
'The Bit Integration Pro v(%s) plugin needs to be installed and activated to enable the %s feature',
27+
'The Bit Integrations Pro v(%s) plugin needs to be installed and activated to enable the %s feature',
2828
'bit-integrations'
2929
),
3030
proVersion,

frontend-dev/src/components/AllIntegrations/SendPulse/SendPulseIntegLayout.jsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function SendPulseIntegLayout({
1414
setIsLoading,
1515
setSnackbar
1616
}) {
17-
const handleInput = (e) => {
17+
const handleInput = e => {
1818
const listid = e.target.value
1919
const newConf = { ...sendPulseConf }
2020
if (listid) {
@@ -36,7 +36,7 @@ export default function SendPulseIntegLayout({
3636
onChange={handleInput}>
3737
<option value="">{__('Select List', 'bit-integrations')}</option>
3838
{sendPulseConf?.default?.sendPulseLists &&
39-
Object.keys(sendPulseConf.default.sendPulseLists).map((listName) => (
39+
Object.keys(sendPulseConf.default.sendPulseLists).map(listName => (
4040
<option
4141
key={`${listName + 1}`}
4242
value={sendPulseConf.default.sendPulseLists[listName].listId}>
@@ -45,9 +45,7 @@ export default function SendPulseIntegLayout({
4545
))}
4646
</select>
4747
<button
48-
onClick={() =>
49-
refreshSendPulseList(sendPulseConf, setSendPulseConf, setIsLoading, setSnackbar)
50-
}
48+
onClick={() => refreshSendPulseList(sendPulseConf, setSendPulseConf, setIsLoading, setSnackbar)}
5149
className="icn-btn sh-sm ml-2 mr-2 tooltip"
5250
style={{ '--tooltip-txt': '"Refresh SendPulse list"' }}
5351
type="button"
@@ -118,7 +116,7 @@ export default function SendPulseIntegLayout({
118116
<br />
119117
<Note
120118
note={__(
121-
'Custom Fields are available exclusively in Bit Integration Pro starting from version 2.2.0.',
119+
'Custom Fields are available exclusively in Bit Integrations Pro starting from version 2.2.0.',
122120
'bit-integrations'
123121
)}
124122
/>

includes/Actions/ACPT/ACPTController.php

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -36,88 +36,6 @@ public function authentication($fieldsRequestParams)
3636
wp_send_json_success(__('Authentication successful', 'bit-integrations'), 200);
3737
}
3838

39-
// public function getAllCustomer($fieldsRequestParams)
40-
// {
41-
// $this->checkValidation($fieldsRequestParams);
42-
// $this->setHeaders($fieldsRequestParams->api_key, $fieldsRequestParams->api_secret);
43-
44-
// $customers = get_users(['role' => 'customer', 'number' => -1]);
45-
46-
// wp_send_json_success(array_map(function ($customer) {
47-
// return ['id' => $customer->ID, 'name' => $customer->display_name];
48-
// }, $customers), 200);
49-
// }
50-
51-
// public function getAllProduct($fieldsRequestParams)
52-
// {
53-
// if (!class_exists('WooCommerce')) {
54-
// wp_send_json_success([], 200);
55-
// }
56-
57-
// $this->checkValidation($fieldsRequestParams);
58-
// $this->setHeaders($fieldsRequestParams->api_key, $fieldsRequestParams->api_secret);
59-
60-
// $products = wc_get_products(['status' => 'publish', 'limit' => -1]);
61-
62-
// wp_send_json_success(array_map(function ($product) {
63-
// return ['id' => $product->get_id(), 'name' => $product->get_title()];
64-
// }, $products), 200);
65-
// }
66-
67-
// public function getAllOrder($fieldsRequestParams)
68-
// {
69-
// if (!class_exists('WooCommerce')) {
70-
// wp_send_json_success([], 200);
71-
// }
72-
73-
// $this->checkValidation($fieldsRequestParams);
74-
// $this->setHeaders($fieldsRequestParams->api_key, $fieldsRequestParams->api_secret);
75-
76-
// $orders = wc_get_orders(['limit' => -1, 'orderby' => 'date', 'order' => 'DESC']);
77-
78-
// wp_send_json_success(array_map(function ($order) {
79-
// return ['id' => $order->get_id(), 'name' => '#' . $order->get_id() . ' Order'];
80-
// }, $orders), 200);
81-
// }
82-
83-
// public function getAllLicense($fieldsRequestParams)
84-
// {
85-
// $this->checkValidation($fieldsRequestParams);
86-
// $this->setHeaders($fieldsRequestParams->api_key, $fieldsRequestParams->api_secret);
87-
88-
// $apiEndpoint = $fieldsRequestParams->base_url . '/wp-json/acpt/v2/licenses';
89-
// $response = HttpHelper::get($apiEndpoint, null, $this->_defaultHeader, ['sslverify' => false]);
90-
91-
// if (is_wp_error($response)) {
92-
// wp_send_json_error($response->get_error_message(), HttpHelper::$responseCode);
93-
// }
94-
// if (isset($response->success) && $response->success) {
95-
// wp_send_json_success(array_column($response->data, 'licenseKey'), 200);
96-
// }
97-
98-
// wp_send_json_error(!empty($response->message) ? $response->message : wp_json_encode($response), 400);
99-
// }
100-
101-
// public function getAllGenerator($fieldsRequestParams)
102-
// {
103-
// $this->checkValidation($fieldsRequestParams);
104-
// $this->setHeaders($fieldsRequestParams->api_key, $fieldsRequestParams->api_secret);
105-
106-
// $apiEndpoint = $fieldsRequestParams->base_url . '/wp-json/acpt/v2/generators';
107-
// $response = HttpHelper::get($apiEndpoint, null, $this->_defaultHeader, ['sslverify' => false]);
108-
109-
// if (is_wp_error($response)) {
110-
// wp_send_json_error($response->get_error_message(), HttpHelper::$responseCode);
111-
// }
112-
// if (isset($response->success) && $response->success) {
113-
// wp_send_json_success(array_map(function ($generator) {
114-
// return ['id' => $generator->id, 'name' => $generator->name];
115-
// }, $response->data), 200);
116-
// }
117-
118-
// wp_send_json_error(!empty($response->message) ? $response->message : wp_json_encode($response), 400);
119-
// }
120-
12139
public function execute($integrationData, $fieldValues)
12240
{
12341
$integrationDetails = $integrationData->flow_details;

includes/Actions/ACPT/ACPTHelper.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public static function generateReqDataFromFieldMap($data, $fieldMap)
1414
$triggerValue = $value->formField;
1515
$actionValue = $value->acptFormField;
1616

17+
if (empty($actionValue)) {
18+
continue;
19+
}
20+
1721
$dataFinal[$actionValue] = ($triggerValue === 'custom' && !empty($value->customValue))
1822
? Common::replaceFieldWithValue($value->customValue, $data)
1923
: $data[$triggerValue];
@@ -75,9 +79,11 @@ public static function optionPageValidateRequired($finalData)
7579
return self::validateFields($requiredFields, $finalData);
7680
}
7781

78-
public static function buildLabels($fieldValues, $labelFieldsMap)
82+
public static function buildLabels($fieldValues, $labelFieldsMap, $defaultKey)
7983
{
80-
return self::generateReqDataFromFieldMap($fieldValues, $labelFieldsMap ?? []);
84+
$labels = self::generateReqDataFromFieldMap($fieldValues, $labelFieldsMap ?? []);
85+
86+
return empty($labels) ? [$defaultKey => ''] : $labels;
8187
}
8288

8389
public static function buildSettings(&$finalData, $utilities)
@@ -105,12 +111,14 @@ public static function buildSettings(&$finalData, $utilities)
105111
$settings['capabilities'] = Helper::convertStringToArray($settings['capabilities']);
106112
}
107113

108-
return array_filter($settings);
114+
$settings = array_filter($settings);
115+
116+
return empty($settings) ? ['public' => false] : $settings;
109117
}
110118

111119
public static function prepareCPTData($finalData, $fieldValues, $integrationDetails)
112120
{
113-
$finalData['labels'] = ACPTHelper::buildLabels($fieldValues, $integrationDetails->label_field_map ?? []);
121+
$finalData['labels'] = ACPTHelper::buildLabels($fieldValues, $integrationDetails->label_field_map ?? [], 'menu_name');
114122
$finalData['settings'] = ACPTHelper::buildSettings($finalData, $integrationDetails->utilities ?? []);
115123
$finalData['supports'] = Helper::convertStringToArray($integrationDetails->supports ?? []);
116124

@@ -119,7 +127,7 @@ public static function prepareCPTData($finalData, $fieldValues, $integrationDeta
119127

120128
public static function prepareTaxonomyData($finalData, $fieldValues, $integrationDetails)
121129
{
122-
$finalData['labels'] = ACPTHelper::buildLabels($fieldValues, $integrationDetails->label_field_map ?? []);
130+
$finalData['labels'] = ACPTHelper::buildLabels($fieldValues, $integrationDetails->label_field_map ?? [], 'name');
123131
$finalData['settings'] = ACPTHelper::buildSettings($finalData, $integrationDetails->utilities ?? []);
124132
$finalData['singular'] = $finalData['singular_label'];
125133
$finalData['plural'] = $finalData['plural_label'];

includes/Actions/ACPT/RecordApiHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace BitCode\FI\Actions\ACPT;
88

9-
use BitCode\FI\Log\LogHandler;
109
use BitCode\FI\Core\Util\HttpHelper;
10+
use BitCode\FI\Log\LogHandler;
1111

1212
/**
1313
* Provide functionality for Record insert, upsert

includes/Actions/Bento/RecordApiHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function addEvent($finalData)
8282

8383
$response = apply_filters('btcbi_bento_store_event', false, $reqParams, $finalData);
8484

85-
return empty($response) ? (object) ['error' => wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integration Pro')] : $response;
85+
return empty($response) ? (object) ['error' => wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integrations Pro')] : $response;
8686
}
8787

8888
public function generateReqDataFromFieldMap($data, $fieldMap)

includes/Actions/FluentSupport/RecordApiHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace BitCode\FI\Actions\FluentSupport;
88

9-
use BitCode\FI\Log\LogHandler;
109
use BitCode\FI\Core\Util\Common;
11-
use FluentSupport\App\Models\Ticket;
10+
use BitCode\FI\Core\Util\Helper as BtcbiHelper;
11+
use BitCode\FI\Log\LogHandler;
1212
use FluentSupport\App\Models\Customer;
13+
use FluentSupport\App\Models\Ticket;
1314
use FluentSupport\App\Services\Helper;
14-
use BitCode\FI\Core\Util\Helper as BtcbiHelper;
1515

1616
/**
1717
* Provide functionality for Record insert, upsert
@@ -156,6 +156,6 @@ private static function uploadTicketFiles($finalData, $attachments, $ticket, $cu
156156
do_action('btcbi_fluent_support_upload_ticket_attachments', $finalData, $attachments, $ticket, $customer, $flowId);
157157
}
158158

159-
LogHandler::save($flowId, ['type' => 'Ticket', 'type_name' => 'Upload-Ticket-Attachments'], 'error', wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integration Pro'));
159+
LogHandler::save($flowId, ['type' => 'Ticket', 'type_name' => 'Upload-Ticket-Attachments'], 'error', wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integrations Pro'));
160160
}
161161
}

includes/Actions/FreshSales/RecordApiHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function upsertRecord($module, $finalData)
6969
$response = apply_filters('btcbi_freshsales_upsert_record', $module, $finalData, $this->_integrationDetails, $this->_defaultHeader, $this->baseUrl);
7070

7171
if (\is_string($response) && $response == $module) {
72-
return (object) ['errors' => wp_send_json_error(wp_sprintf(__('%s is not active or not installed', 'bit-integrations'), 'Bit Integration Pro'), 400)];
72+
return (object) ['errors' => wp_send_json_error(wp_sprintf(__('%s is not active or not installed', 'bit-integrations'), 'Bit Integrations Pro'), 400)];
7373
}
7474

7575
return $response;

0 commit comments

Comments
 (0)