diff --git a/src/chat/functions/sendOrderMessage.ts b/src/chat/functions/sendOrderMessage.ts index 3690dd7073..4924d11582 100644 --- a/src/chat/functions/sendOrderMessage.ts +++ b/src/chat/functions/sendOrderMessage.ts @@ -101,7 +101,6 @@ export async function sendOrderMessage( undefined, true ); - console.log(data); if (typeof data === 'undefined') throw new WPPError( 'product_not_found', diff --git a/src/eventEmitter/eventTypes.ts b/src/eventEmitter/eventTypes.ts index 69645d4617..c142355e4e 100644 --- a/src/eventEmitter/eventTypes.ts +++ b/src/eventEmitter/eventTypes.ts @@ -20,6 +20,7 @@ import { ChatEventTypes } from '../chat/events/eventTypes'; import { ConfigEventTypes } from '../config/eventTypes'; import { ConnEventTypes } from '../conn/events/eventTypes'; import { GroupEventTypes } from '../group/events/eventTypes'; +import { OrderEventTypes } from '../order/events/eventTypes'; import { StatusEventTypes } from '../status/events/eventTypes'; import { WebpackEvents } from '../webpack/eventTypes'; @@ -29,6 +30,7 @@ export { ChatEventTypes } from '../chat/events/eventTypes'; export { ConfigEventTypes } from '../config/eventTypes'; export { ConnEventTypes } from '../conn/events/eventTypes'; export { GroupEventTypes } from '../group/events/eventTypes'; +export { OrderEventTypes } from '../order/events/eventTypes'; export { StatusEventTypes } from '../status/events/eventTypes'; export { WebpackEvents } from '../webpack/eventTypes'; @@ -38,5 +40,6 @@ export type EventTypes = BlocklistEventTypes & ConfigEventTypes & ConnEventTypes & GroupEventTypes & + OrderEventTypes & StatusEventTypes & WebpackEvents; diff --git a/src/order/events/eventTypes.ts b/src/order/events/eventTypes.ts new file mode 100644 index 0000000000..cb1abd875d --- /dev/null +++ b/src/order/events/eventTypes.ts @@ -0,0 +1,36 @@ +/*! + * Copyright 2023 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { MsgKey } from '../../whatsapp'; + +export interface OrderEventTypes { + /** + * Triggered when change the active chat + * + * @example + * ```javascript + * WPP.on('order.payment_status', (order) => { + * // Your code + * }); + * ``` + */ + 'order.payment_status': { + method: string; + timestamp: number; + reference_id: string; + msgId: MsgKey; + }; +} diff --git a/src/order/events/index.ts b/src/order/events/index.ts new file mode 100644 index 0000000000..28b95dca23 --- /dev/null +++ b/src/order/events/index.ts @@ -0,0 +1,17 @@ +/*! + * Copyright 2021 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import './registerUpdateOrderEvent'; diff --git a/src/order/events/registerUpdateOrderEvent.ts b/src/order/events/registerUpdateOrderEvent.ts new file mode 100644 index 0000000000..b7aa24a865 --- /dev/null +++ b/src/order/events/registerUpdateOrderEvent.ts @@ -0,0 +1,45 @@ +/*! + * Copyright 2021 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { internalEv } from '../../eventEmitter'; +import * as webpack from '../../webpack'; +import { MsgModel, MsgStore } from '../../whatsapp'; + +webpack.onInjected(() => registerUpdateOrderEvent()); + +function registerUpdateOrderEvent() { + MsgStore.on('add', (msg: MsgModel) => { + if ( + msg.type !== 'interactive' || + msg.interactivePayload?.buttons[0].name !== 'payment_method' || + !msg.isNewMsg + ) { + return; + } + const payload = JSON.parse( + msg.interactivePayload?.buttons[0].buttonParamsJson + ); + + queueMicrotask(() => { + internalEv.emit('order.payment_status', { + method: payload.payment_method, + timestamp: payload.payment_timestamp, + reference_id: payload.reference_id, + msgId: msg.id, + }); + }); + }); +} diff --git a/src/order/index.ts b/src/order/index.ts index 15b554f601..a7c5b70c52 100644 --- a/src/order/index.ts +++ b/src/order/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ +export * from './events'; export * from './functions'; diff --git a/src/whatsapp/models/MsgModel.ts b/src/whatsapp/models/MsgModel.ts index c2f75cbbf8..c769e878d2 100644 --- a/src/whatsapp/models/MsgModel.ts +++ b/src/whatsapp/models/MsgModel.ts @@ -334,6 +334,8 @@ interface Derived { pollOptions?: any; pollSelectableOptionsCount?: number; pollUpdateParentKey?: any; + nativeFlowName?: string; + interactivePayload?: any; } /** @whatsapp 17304 */