forked from pedroslopez/whatsapp-web.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Get Orders and Products (pedroslopez#612)
* - Get products and orders * - Get products and orders * - Eslint fixes * - Eslint fixes * allow downloading media for products * products and orders work on normal accounts Co-authored-by: Renato Jop <renato.jop@consystec-corp.com> Co-authored-by: Pedro Lopez <pedroslopez@me.com> Co-authored-by: Pedro S. Lopez <pslamoros@hotmail.com>
- Loading branch information
1 parent
f506c17
commit 5177a25
Showing
9 changed files
with
314 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
const Product = require('./Product'); | ||
|
||
/** | ||
* Represents a Order on WhatsApp | ||
* @extends {Base} | ||
*/ | ||
class Order extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
|
||
if (data) this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* List of products | ||
* @type {Array<Product>} | ||
*/ | ||
if (data.products) { | ||
this.products = data.products.map(product => new Product(this.client, product)); | ||
} | ||
/** | ||
* Order Subtotal | ||
* @type {string} | ||
*/ | ||
this.subtotal = data.subtotal; | ||
/** | ||
* Order Total | ||
* @type {string} | ||
*/ | ||
this.total = data.total; | ||
/** | ||
* Order Currency | ||
* @type {string} | ||
*/ | ||
this.currency = data.currency; | ||
/** | ||
* Order Created At | ||
* @type {number} | ||
*/ | ||
this.createdAt = data.createdAt; | ||
|
||
return super._patch(data); | ||
} | ||
|
||
|
||
} | ||
|
||
module.exports = Order; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
const ProductMetadata = require('./ProductMetadata'); | ||
|
||
/** | ||
* Represents a Product on WhatsAppBusiness | ||
* @extends {Base} | ||
*/ | ||
class Product extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
|
||
if (data) this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** | ||
* Product ID | ||
* @type {string} | ||
*/ | ||
this.id = data.id; | ||
/** | ||
* Price | ||
* @type {string} | ||
*/ | ||
this.price = data.price ? data.price : ''; | ||
/** | ||
* Product Thumbnail | ||
* @type {string} | ||
*/ | ||
this.thumbnailUrl = data.thumbnailUrl; | ||
/** | ||
* Currency | ||
* @type {string} | ||
*/ | ||
this.currency = data.currency; | ||
/** | ||
* Product Name | ||
* @type {string} | ||
*/ | ||
this.name = data.name; | ||
/** | ||
* Product Quantity | ||
* @type {number} | ||
*/ | ||
this.quantity = data.quantity; | ||
/** Product metadata */ | ||
this.data = null; | ||
return super._patch(data); | ||
} | ||
|
||
async getData() { | ||
if (this.data === null) { | ||
let result = await this.client.pupPage.evaluate((productId) => { | ||
return window.WWebJS.getProductMetadata(productId); | ||
}, this.id); | ||
if (!result) { | ||
this.data = undefined; | ||
} else { | ||
this.data = new ProductMetadata(this.client, result); | ||
} | ||
} | ||
return this.data; | ||
} | ||
} | ||
|
||
module.exports = Product; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Base = require('./Base'); | ||
|
||
class ProductMetadata extends Base { | ||
constructor(client, data) { | ||
super(client); | ||
|
||
if (data) this._patch(data); | ||
} | ||
|
||
_patch(data) { | ||
/** Product ID */ | ||
this.id = data.id; | ||
/** Retailer ID */ | ||
this.retailer_id = data.retailer_id; | ||
/** Product Name */ | ||
this.name = data.name; | ||
/** Product Description */ | ||
this.description = data.description; | ||
|
||
return super._patch(data); | ||
} | ||
|
||
} | ||
|
||
module.exports = ProductMetadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.