paypal-v2-sdk
Advanced tools
Comparing version 1.1.9 to 1.1.10
@@ -6,3 +6,3 @@ { | ||
"name": "paypal-v2-sdk", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"description": "Unofficial promise-based PayPal API v2 SDK for node.js", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
@@ -78,3 +78,3 @@ const PayPalClass = require("../../PayPal"); | ||
); | ||
return response.status === 204 ? true : false; | ||
return response.status === 204; | ||
} | ||
@@ -98,3 +98,3 @@ | ||
); | ||
return response.status === 204 ? true : false; | ||
return response.status === 204; | ||
} | ||
@@ -131,4 +131,4 @@ | ||
"Content-Type": "application/json", | ||
data: query, | ||
}, | ||
data: query, | ||
} | ||
@@ -139,2 +139,21 @@ ); | ||
/** | ||
* | ||
* @param {String} id | ||
* @param {Object} query | ||
* @returns | ||
*/ | ||
async recordRefund(id, query) { | ||
const response = await this.PayPal.Axios.post( | ||
`https://api.paypal.com/v2/invoicing/invoices/${id}/refunds`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
data: query, | ||
} | ||
); | ||
return response.data; | ||
} | ||
async deleteExternalPayment(invoiceId, transactionId) { | ||
@@ -151,4 +170,67 @@ const response = await this.PayPal.Axios.delete( | ||
} | ||
async deleteExternalRefund(invoiceId, transactionId) { | ||
const response = await this.PayPal.Axios.delete( | ||
`https://api.paypal.com/v2/invoicing/invoices/${invoiceId}/refunds/${transactionId}`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
return response.status === 204; | ||
} | ||
/** | ||
* | ||
* @param {String} id | ||
* @param {Object} query | ||
*/ | ||
async sendReminder(id, query) { | ||
const response = await this.PayPal.Axios.post( | ||
`https://api.paypal.com/v2/invoicing/invoices/${id}/remind`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
data: query, | ||
} | ||
); | ||
return response.status === 204; | ||
} | ||
async send(id, query) { | ||
const response = await this.PayPal.Axios.post( | ||
`https://api.paypal.com/v2/invoicing/invoices/${id}/send`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
data: query, | ||
} | ||
); | ||
return response.data; | ||
} | ||
async find(query) { | ||
const response = await this.PayPal.Axios.post( | ||
"https://api.paypal.com/v2/invoicing/search-invoices", | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
params: { | ||
page: query.page, | ||
page_size: query.pageSize, | ||
total_required: query.totalRequired, | ||
}, | ||
data: Object.keys(query) | ||
.filter((x) => !["page", "pageSize", "totalRequired"].includes(x)) | ||
.reduce((a, b) => Object.assign(a, { b: query[b] }), {}), | ||
} | ||
); | ||
return response.data; | ||
} | ||
} | ||
module.exports = Invoices; |
@@ -35,7 +35,11 @@ const PayPalClass = require("../../PayPal"); | ||
const ListInvoicesResponse = require("../../Types/Responses/ListInvoices"); | ||
const CancelInvoiceQuery = require("../../Types/Queries/CancelInvoice"); | ||
const QrCodeQuery = require("../../Types/Queries/QRCode"); | ||
const RecordPaymentQuery = require("../../Types/Queries/RecordPayment"); | ||
const RecordPaymentResponse = require("../../Types/Responses/RecordPayment"); | ||
const DeleteExternalPaymentQuery = require("../../Types/Queries/DeleteExternalPayment"); | ||
const DeleteExternalQuery = require("../../Types/Queries/DeleteExternal"); | ||
const RecordRefundResponse = require("../../Types/Responses/RecordRefund"); | ||
const RecordRefundQuery = require("../../Types/Queries/RecordRefund"); | ||
const NotificationQuery = require("../../Types/Queries/NotificationQuery"); | ||
const SendInvoiceResponse = require("../../Types/Responses/SendInvoice"); | ||
const SearchInvoicesQuery = require("../../Types/Queries/SearchInvoices"); | ||
@@ -123,3 +127,3 @@ class Invoices extends InvoicesAPI { | ||
x.phones?.map((y) => | ||
new PhoneDetail() | ||
new PhoneDetail(this.PayPal) | ||
.setCountryCode(y.country_code) | ||
@@ -472,3 +476,3 @@ .setNationalNumber(y.national_number) | ||
* @param {String} id | ||
* @returns {Invoice} | ||
* @returns {Promise<Invoice>} | ||
*/ | ||
@@ -484,11 +488,18 @@ async get(id) { | ||
* @param {ListInvoicesQuery} query | ||
* @returns {ListInvoicesResponse} | ||
* @returns {Promise<ListInvoicesResponse>} | ||
*/ | ||
async list(query) { | ||
const data = await super.list(query.toAttributeObject()); | ||
const listInvoicesResponse = new ListInvoicesResponse(this) | ||
const listInvoicesResponse = new ListInvoicesResponse(this.PayPal) | ||
.setItems(data.items?.map((x) => this.constructInvoice(x))) | ||
.setTotalItems(x.total_items) | ||
.setTotalPages(x.total_pages) | ||
.setLinks(x.links); | ||
.setLinks( | ||
x.links?.map((x) => | ||
new LinkDescription(this.PayPal) | ||
.setHref(x.href) | ||
.setMethod(x.method) | ||
.setRel(x.rel) | ||
) | ||
); | ||
return listInvoicesResponse; | ||
@@ -502,3 +513,3 @@ } | ||
* @param {Invoice|object} invoiceBuilder | ||
* @returns {Invoice} | ||
* @returns {Promise<Invoice>} | ||
*/ | ||
@@ -519,3 +530,3 @@ async create(invoiceBuilder) { | ||
* @param {String} id | ||
* @returns {Boolean} | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
@@ -535,3 +546,3 @@ async delete(id) { | ||
* @param {Invoice|object} invoiceBuilder | ||
* @returns {Invoice} | ||
* @returns {Promise<Invoice>} | ||
*/ | ||
@@ -552,4 +563,4 @@ async fullUpdate(invoiceBuilder) { | ||
* @param {String} id | ||
* @param {CancelInvoiceQuery} body | ||
* @returns | ||
* @param {NotificationQuery} body | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
@@ -576,6 +587,9 @@ async cancel(id, body) { | ||
* @param {RecordPaymentQuery} body | ||
* @returns {Promise<RecordPaymentResponse>} | ||
*/ | ||
async recordPayment(id, body) { | ||
const response = await super.recordPayment(id, body.toAttributeObject()); | ||
return new RecordPaymentResponse(this).setPaymentId(response.payment_id); | ||
return new RecordPaymentResponse(this.PayPal).setPaymentId( | ||
response.payment_id | ||
); | ||
} | ||
@@ -585,3 +599,4 @@ | ||
* | ||
* @param {DeleteExternalPaymentQuery} body | ||
* @param {DeleteExternalQuery} body | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
@@ -595,4 +610,72 @@ async deleteExternalPayment(body) { | ||
} | ||
/** | ||
* | ||
* @param {DeleteExternalQuery} body | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
async deleteExternalRefund(body) { | ||
const response = await super.deleteExternalRefund( | ||
body.invoiceId, | ||
body.transactionId | ||
); | ||
return response; | ||
} | ||
/** | ||
* | ||
* @param {String} id | ||
* @param {RecordRefundQuery} body | ||
* @returns {Promise<RecordPaymentResponse>} | ||
*/ | ||
async recordRefund(id, body) { | ||
const response = await super.recordRefund(id, body.toAttributeObject()); | ||
return new RecordRefundResponse(this.PayPal).setRefundId( | ||
response.refund_id | ||
); | ||
} | ||
/** | ||
* | ||
* @param {String} id | ||
* @param {NotificationQuery} body | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
async sendReminder(id, body) { | ||
const response = await super.sendReminder(id, body.toAttributeObject()); | ||
return response; | ||
} | ||
/** | ||
* | ||
* @param {String} id | ||
* @param {NotificationQuery} body | ||
* @returns {Promise<SendInvoiceResponse>} | ||
*/ | ||
async send(id, body) { | ||
const response = await super.send(id, body.toAttributeObject()); | ||
return new SendInvoiceResponse(this.PayPal).setLinks(response.links); | ||
} | ||
/** | ||
* | ||
* @param {SearchInvoicesQuery} body | ||
*/ | ||
async find(body) { | ||
const response = await super.find(body.toAttributeObject()); | ||
return new ListInvoicesResponse(this.PayPal) | ||
.setTotalPages(response.total_pages) | ||
.setTotalItems(response.total_items) | ||
.setItems(response.items?.map((x) => this.constructInvoice(x))) | ||
.setLinks( | ||
response.links?.map((x) => | ||
new LinkDescription(this.PayPal) | ||
.setHref(x.href) | ||
.setMethod(x.method) | ||
.setRel(x.rel) | ||
) | ||
); | ||
} | ||
} | ||
module.exports = Invoices; |
@@ -35,6 +35,11 @@ const BasePayPal = require("./BasePayPal"); | ||
const ListInvoicesResponse = require("./Types/Responses/ListInvoices"); | ||
const CancelInvoiceQuery = require("./Types/Queries/CancelInvoice"); | ||
const QrCodeQuery = require("./Types/Queries/QRCode"); | ||
const RecordPaymentQuery = require("./Types/Queries/RecordPayment"); | ||
const DeleteExternalPaymentQuery = require("./Types/Queries/DeleteExternalPayment"); | ||
const DeleteExternalQuery = require("./Types/Queries/DeleteExternal"); | ||
const AmountRange = require("./Types/General/AmountRange"); | ||
const DateRange = require("./Types/General/DateRange"); | ||
const Field = require("./Types/General/Field"); | ||
const NotificationQuery = require("./Types/Queries/NotificationQuery"); | ||
const RecordRefundQuery = require("./Types/Queries/RecordRefund"); | ||
const SearchInvoicesQuery = require("./Types/Queries/SearchInvoices"); | ||
@@ -83,2 +88,5 @@ // handlers | ||
Tax: Tax.bind(null, this), | ||
AmountRange: AmountRange.bind(null, this), | ||
DateRange: DateRange.bind(null, this), | ||
Field: Field.bind(null, this), | ||
}, | ||
@@ -93,6 +101,8 @@ invoice: { | ||
ListInvoices: ListInvoicesQuery.bind(null, this), | ||
CancelInvoice: CancelInvoiceQuery.bind(null, this), | ||
QRCode: QrCodeQuery.bind(null, this), | ||
RecordPayment: RecordPaymentQuery.bind(null, this), | ||
DeleteExternalPayment: DeleteExternalPaymentQuery.bind(null, this), | ||
DeleteExternal: DeleteExternalQuery.bind(null, this), | ||
Notification: NotificationQuery.bind(null, this), | ||
RecordRefund: RecordRefundQuery.bind(null, this), | ||
SearchInvoices: SearchInvoicesQuery.bind(null, this), | ||
}, | ||
@@ -99,0 +109,0 @@ }; |
@@ -17,3 +17,3 @@ const PayPalClass = require("../../PayPal"); | ||
const RecordPaymentResponse = require("../Responses/RecordPayment"); | ||
const DeleteExternalPaymentQuery = require("../Queries/DeleteExternalPayment"); | ||
const NotificationQuery = require("../Queries/NotificationQuery"); | ||
@@ -47,4 +47,9 @@ class Invoice { | ||
async cancel() { | ||
const cancelled = await this.PayPal.invoices.invoices.cancel(this.id); | ||
/** | ||
* | ||
* @param {NotificationQuery} body | ||
* @returns | ||
*/ | ||
async cancel(body) { | ||
const cancelled = await this.PayPal.invoices.invoices.cancel(this.id, body); | ||
@@ -82,6 +87,7 @@ return cancelled; | ||
* | ||
* @param {DeleteExternalPaymentQuery} body | ||
* @param {NotificationQuery} body | ||
*/ | ||
async deleteExternalPayment(body) { | ||
const response = await this.PayPal.invoices.invoices.deleteExternalPayment( | ||
async sendReminder(body) { | ||
const response = await this.PayPal.invoices.invoices.sendReminder( | ||
this.id, | ||
body | ||
@@ -92,2 +98,7 @@ ); | ||
async send(body) { | ||
const response = await this.PayPal.invoices.invoices.send(this.id, body); | ||
return response; | ||
} | ||
/* | ||
@@ -94,0 +105,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115766
55
4123