mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
feat: Include payment info (#684)
This commit is contained in:
52
index.d.ts
vendored
52
index.d.ts
vendored
@@ -428,6 +428,7 @@ declare namespace WAWebJS {
|
|||||||
REVOKED = 'revoked',
|
REVOKED = 'revoked',
|
||||||
ORDER = 'order',
|
ORDER = 'order',
|
||||||
PRODUCT = 'product',
|
PRODUCT = 'product',
|
||||||
|
PAYMENT = 'payment',
|
||||||
UNKNOWN = 'unknown',
|
UNKNOWN = 'unknown',
|
||||||
GROUP_INVITE = 'groups_v4_invite',
|
GROUP_INVITE = 'groups_v4_invite',
|
||||||
}
|
}
|
||||||
@@ -600,6 +601,10 @@ declare namespace WAWebJS {
|
|||||||
* Gets the order associated with a given message
|
* Gets the order associated with a given message
|
||||||
*/
|
*/
|
||||||
getOrder: () => Order,
|
getOrder: () => Order,
|
||||||
|
/**
|
||||||
|
* Gets the payment details associated with a given message
|
||||||
|
*/
|
||||||
|
getPayment: () => Payment,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ID that represents a message */
|
/** ID that represents a message */
|
||||||
@@ -1061,6 +1066,53 @@ declare namespace WAWebJS {
|
|||||||
createdAt: number;
|
createdAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Payment on WhatsApp
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* {
|
||||||
|
* id: {
|
||||||
|
* fromMe: true,
|
||||||
|
* remote: {
|
||||||
|
* server: 'c.us',
|
||||||
|
* user: '5511999999999',
|
||||||
|
* _serialized: '5511999999999@c.us'
|
||||||
|
* },
|
||||||
|
* id: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||||
|
* _serialized: 'true_5511999999999@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
||||||
|
* },
|
||||||
|
* paymentCurrency: 'BRL',
|
||||||
|
* paymentAmount1000: 1000,
|
||||||
|
* paymentMessageReceiverJid: {
|
||||||
|
* server: 'c.us',
|
||||||
|
* user: '5511999999999',
|
||||||
|
* _serialized: '5511999999999@c.us'
|
||||||
|
* },
|
||||||
|
* paymentTransactionTimestamp: 1623463058,
|
||||||
|
* paymentStatus: 4,
|
||||||
|
* paymentTxnStatus: 4,
|
||||||
|
* paymentNote: 'note'
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export interface Payment {
|
||||||
|
/** Payment Id*/
|
||||||
|
id: object,
|
||||||
|
/** Payment currency */
|
||||||
|
paymentCurrency: string,
|
||||||
|
/** Payment ammount */
|
||||||
|
paymentAmount1000 : number,
|
||||||
|
/** Payment receiver */
|
||||||
|
paymentMessageReceiverJid : object,
|
||||||
|
/** Payment transaction timestamp */
|
||||||
|
paymentTransactionTimestamp : number,
|
||||||
|
/** Payment paymentStatus */
|
||||||
|
paymentStatus : number,
|
||||||
|
/** Integer that represents the payment Text */
|
||||||
|
paymentTxnStatus : number,
|
||||||
|
/** The note sent with the payment */
|
||||||
|
paymentNote : string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Call on WhatsApp
|
* Represents a Call on WhatsApp
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const Base = require('./Base');
|
|||||||
const MessageMedia = require('./MessageMedia');
|
const MessageMedia = require('./MessageMedia');
|
||||||
const Location = require('./Location');
|
const Location = require('./Location');
|
||||||
const Order = require('./Order');
|
const Order = require('./Order');
|
||||||
|
const Payment = require('./Payment');
|
||||||
const { MessageTypes } = require('../util/Constants');
|
const { MessageTypes } = require('../util/Constants');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -438,6 +439,21 @@ class Message extends Base {
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Gets the payment details associated with a given message
|
||||||
|
* @return {Promise<Payment>}
|
||||||
|
*/
|
||||||
|
async getPayment() {
|
||||||
|
if (this.type === MessageTypes.PAYMENT) {
|
||||||
|
const msg = await this.client.pupPage.evaluate(async (msgId) => {
|
||||||
|
const msg = window.Store.Msg.get(msgId);
|
||||||
|
if(!msg) return null;
|
||||||
|
return msg.serialize();
|
||||||
|
}, this.id._serialized);
|
||||||
|
return new Payment(this.client, msg);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Message;
|
module.exports = Message;
|
||||||
|
|||||||
78
src/structures/Payment.js
Normal file
78
src/structures/Payment.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
const Base = require('./Base');
|
||||||
|
|
||||||
|
class Payment extends Base {
|
||||||
|
constructor(client, data) {
|
||||||
|
super(client);
|
||||||
|
|
||||||
|
if (data) this._patch(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
_patch(data) {
|
||||||
|
/**
|
||||||
|
* The payment Id
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
this.id = data.id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payment currency
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.paymentCurrency = data.paymentCurrency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payment ammount ( R$ 1.00 = 1000 )
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.paymentAmount1000 = data.paymentAmount1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payment receiver
|
||||||
|
* @type {object}
|
||||||
|
*/
|
||||||
|
this.paymentMessageReceiverJid = data.paymentMessageReceiverJid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payment transaction timestamp
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.paymentTransactionTimestamp = data.paymentTransactionTimestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The paymentStatus
|
||||||
|
* @type {number}
|
||||||
|
*
|
||||||
|
* Possible Status
|
||||||
|
* 0:UNKNOWN_STATUS
|
||||||
|
* 1:PROCESSING
|
||||||
|
* 2:SENT
|
||||||
|
* 3:NEED_TO_ACCEPT
|
||||||
|
* 4:COMPLETE
|
||||||
|
* 5:COULD_NOT_COMPLETE
|
||||||
|
* 6:REFUNDED
|
||||||
|
* 7:EXPIRED
|
||||||
|
* 8:REJECTED
|
||||||
|
* 9:CANCELLED
|
||||||
|
* 10:WAITING_FOR_PAYER
|
||||||
|
* 11:WAITING
|
||||||
|
*/
|
||||||
|
this.paymentStatus = data.paymentStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integer that represents the payment Text
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.paymentTxnStatus = data.paymentTxnStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The note sent with the payment
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.paymentNote = !data.paymentNoteMsg ? undefined : data.paymentNoteMsg.body ? data.paymentNoteMsg.body : undefined ;
|
||||||
|
|
||||||
|
return super._patch(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Payment;
|
||||||
@@ -14,5 +14,6 @@ module.exports = {
|
|||||||
Label: require('./Label.js'),
|
Label: require('./Label.js'),
|
||||||
Order: require('./Order'),
|
Order: require('./Order'),
|
||||||
Product: require('./Product'),
|
Product: require('./Product'),
|
||||||
Call: require('./Call')
|
Call: require('./Call'),
|
||||||
|
Payment: require('./Payment')
|
||||||
};
|
};
|
||||||
@@ -74,7 +74,8 @@ exports.MessageTypes = {
|
|||||||
REVOKED: 'revoked',
|
REVOKED: 'revoked',
|
||||||
PRODUCT: 'product',
|
PRODUCT: 'product',
|
||||||
UNKNOWN: 'unknown',
|
UNKNOWN: 'unknown',
|
||||||
GROUP_INVITE: 'groups_v4_invite'
|
GROUP_INVITE: 'groups_v4_invite',
|
||||||
|
PAYMENT: 'payment'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user