Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
paypal-v2-sdk
Advanced tools
Unofficial promise-based object-oriented PayPal API v2 SDK for node.js
npm install paypal-v2-sdk
To write an app using this unofficial PayPal SDK (for v2 api)
client_id
and client_secret
from the PayPal Developer Portalpaypal-v2-sdk
(ensure dependency is in your package.json)paypal-v2-sdk
in your fileimport { PayPal } from "paypal-v2-sdk";
PayPal.configure("YOUR CLIENT ID", "YOUR CLIENT SECRET", true);
try {
await PayPal.authenticate();
} catch (e) {
console.error(e); // error while authenticating
}
Using types is completely optional as all methods return the correct type and wherever a type is required as an argument, you can use the callback method which will return the correct type.
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
const invoice: Invoice = await PayPal.getInvoicing().get("id of invoice");
import { PayPal, Invoicing } from "paypal-v2-sdk";
const invoice: Invoicing.Invoice = await PayPal.getInvoicing().get("id of invoice");
import { PayPal } from "paypal-v2-sdk";
const invoice = await PayPal.getInvoicing().get("id of invoice");
// ^^^^^^^^^
// The #get() method returns Invoice as a type
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
const draftInvoice = new Invoice().setPayPal(PayPal).<methods>;
const returnedInvoice = draftInvoice.createDraft();
import { PayPal, Invoicing } from "paypal-v2-sdk";
const draftInvoice = new Invoicing.Invoice().<methods>;
const returnedInvoice = await PayPal.getInvoicing().createDraft(draftInvoice);
import { PayPal } from "paypal-v2-sdk";
const returnedInvoice = await PayPal.getInvoicing().createDraft((invoice) => invoice.<methods>);
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
// Specifying Invoice as the type is not necessary as #get() returns Invoice as the type, it
// is displayed here for information purposes only, but this is how to import types
const invoice: Invoice = await PayPal.getInvoicing().get("id of invoice");
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
const invoice: Invoice = await PayPal.getInvoicing().get("id of invoice");
const deleted = await invoice.delete();
console.log(deleted); // true if deleted, false if not
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
let invoice: Invoice = new Invoice(PayPal)
.setAdditionalRecipients(
(recipient) => recipient.setEmailAddress("some@email.com"),
(recipient) => recipient.setEmailAddress("another@website.com")
)
.setConfiguration((configuration) =>
configuration
.setAllowTip(true)
.setPartialPayment((partialPayment) =>
partialPayment
.setAllowPartialPayment(true)
.setMinimumAmountDue((money) => money.setCurrencyCode("USD").setValue("10.00"))
)
.setTaxCalculatedAfterDiscount(false)
)
.setDetail((invoiceDetail) =>
invoiceDetail
.setCurrencyCode("USD")
.setMemo("some memo")
.setNote("some note")
.setPaymentTerm((paymentTerm) => paymentTerm.setTermType("NET_45"))
)
.setInvoicer((invoicer) =>
invoicer
.setEmailAddress("company@some.com")
.setAdditionalNotes("some additional notes")
.setLogoUrl("https://logo.com/image.png")
.setPhones(
(phone) => phone.setCountryCode("44").setNationalNumber("123456"),
(phone) => phone.setCountryCode("44").setNationalNumber("345678")
)
.setTaxId("123456789")
.setWebsite("https://website.com/")
)
.setItems(
(item) =>
item
.setItemDescription("some description")
.setItemName("some name")
.setItemUnitAmount((money) => money.setCurrencyCode("USD").setValue("20.00"))
.setItemTax((tax) => tax.setPercent("10").setName("Processing Fee"))
.setItemUnitOfMeasure((unitOfMeasure) => unitOfMeasure.QUANTITY),
(item) =>
item
.setItemDescription("another description")
.setItemName("another name")
.setItemUnitAmount((money) => money.setCurrencyCode("USD").setValue("10.00"))
.setItemTax((tax) => tax.setPercent("10").setName("Processing Fee"))
.setItemUnitOfMeasure((unitOfMeasure) => unitOfMeasure.QUANTITY)
)
.setPrimaryRecipients((recipient) =>
recipient
.setBillingInfo((billingInfo) => billingInfo.setEmailAddress("customer@some.com").setLanguage("en_US"))
.setShippingInfo((contactInfo) =>
contactInfo
.setAddress((address) =>
address
.setAddressDetails((addressDetails) =>
addressDetails
.setBuildingName("some building")
.setStreetName("some street")
.setStreetNumber("123")
.setStreetType("some street type")
.setSubBuilding("some sub building")
)
.setAddressLine1("some address line 1")
.setAddressLine2("some address line 2")
.setAddressLine3("some address line 3")
.setAdminArea1("some area 1")
.setCountryCode("GB")
.setPostalCode("12345")
)
.setBusinessName("some business name")
.setName((name) =>
name
.setFullName("some full name")
.setGivenName("some given name")
.setSurname("some surname")
.setMiddleName("some middle name")
.setPrefix("some prefix")
.setSuffix("some suffix")
.setSurname("some surname")
)
)
);
invoice = await invoice.createDraft(/* Generate Next Invoice Number */ true);
try {
invoice = await invoice.send(
/*Additional Recipients*/ undefined,
/*Note*/ undefined,
/*Send to Invoicer*/ true,
/*Send to Recipient*/ true,
/*Subject*/ undefined
);
} catch (e) {
console.error(e);
return;
}
console.log(invoice.toJson()); // the updated invoice
import { PayPal, Invoicing } from "paypal-v2-sdk";
import Invoice = Invoicing.Invoice;
let invoice: Invoice = Invoice.fromObject({
detail: {
invoice_number: "123",
reference: "deal-ref",
invoice_date: "2018-11-12",
currency_code: "USD",
note: "Thank you for your busin.0ess.",
term: "No refunds after 30 days.",
memo: "This is a long contract",
payment_term: {
term_type: "NET_10",
due_date: "2018-11-22",
},
},
invoicer: {
name: {
given_name: "David",
surname: "Larusso",
},
address: {
address_line_1: "1234 First Street",
address_line_2: "337673 Hillside Court",
admin_area_2: "Anytown",
admin_area_1: "CA",
postal_code: "98765",
country_code: "US",
},
email_address: "merchant@example.com",
phones: [
{
country_code: "001",
national_number: "4085551234",
phone_type: "MOBILE",
},
],
website: "www.test.com",
tax_id: "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy- Jb5SeuGj185MNNw6g",
logo_url: "https://example.com/logo.PNG",
additional_notes: "2-4",
},
primary_recipients: [
{
billing_info: {
name: {
given_name: "Stephanie",
surname: "Meyers",
},
address: {
address_line_1: "1234 Main Street",
admin_area_2: "Anytown",
admin_area_1: "CA",
postal_code: "98765",
country_code: "US",
},
email_address: "bill-me@example.com",
phones: [
{
country_code: "001",
national_number: "4884551234",
phone_type: "HOME",
},
],
additional_info_value: "add-info",
},
shipping_info: {
name: {
given_name: "Stephanie",
surname: "Meyers",
},
address: {
address_line_1: "1234 Main Street",
admin_area_2: "Anytown",
admin_area_1: "CA",
postal_code: "98765",
country_code: "US",
},
},
},
],
items: [
{
name: "Yoga Mat",
description: "Elastic mat to practice yoga.",
quantity: "1",
unit_amount: {
currency_code: "USD",
value: "50.00",
},
tax: {
name: "Sales Tax",
percent: "7.25",
},
discount: {
percent: "5",
},
unit_of_measure: "QUANTITY",
},
{
name: "Yoga t-shirt",
quantity: "1",
unit_amount: {
currency_code: "USD",
value: "10.00",
},
tax: {
name: "Sales Tax",
percent: "7.25",
},
discount: {
amount: {
currency_code: "USD",
value: "5.00",
},
},
unit_of_measure: "QUANTITY",
},
],
configuration: {
partial_payment: {
allow_partial_payment: true,
minimum_amount_due: {
currency_code: "USD",
value: "20.00",
},
},
allow_tip: true,
tax_calculated_after_discount: true,
tax_inclusive: false,
template_id: "TEMP-19V05281TU309413B",
},
amount: {
breakdown: {
custom: {
label: "Packing Charges",
amount: {
currency_code: "USD",
value: "10.00",
},
},
shipping: {
amount: {
currency_code: "USD",
value: "10.00",
},
tax: {
name: "Sales Tax",
percent: "7.25",
},
},
discount: {
invoice_discount: {
percent: "5",
},
},
},
},
}).setPayPal(PayPal);
invoice = await invoice.createDraft(
/*Generate Next Invoice Number*/ true
);
try {
// Re-assign invoice as #send() updates the Invoice object from PayPal
invoice = await invoice.send(
/*Additional Recipients*/ undefined,
/*Note*/ undefined,
/*Send to Invoicer*/ true,
/*Send to Recipient*/ true,
/*Subject*/ undefined
);
} catch (e) {
// invoice failed to send, outputs statusText from API
console.error(e);
}
console.log(invoice); // contains all updated details for the invoice
paypal-v2-sdk
has a built-in Event Emitter.
You can output debug messages:
PayPal.on("debug", (str) => { console.debug(str) } );
FAQs
Unofficial promise-based object-oriented PayPal API v2 SDK for node.js
We found that paypal-v2-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.