paypal-v2-sdk
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -6,3 +6,3 @@ { | ||
"name": "paypal-v2-sdk", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Unofficial SDK for PayPal API v2", | ||
@@ -9,0 +9,0 @@ "main": "index.js", |
182
README.md
@@ -9,1 +9,183 @@ Installation | ||
=== | ||
To write an app using this unofficial PayPal SDK (for v2 api) | ||
- Register for a Developer account and get your `client_id` and `client_secret` from the [PayPal Developer Portal](https://developer.paypal.com/) | ||
- Install `paypal-v2-sdk` (ensure dependency is in your package.json) | ||
- Require `paypal-v2-sdk` in your file (or import for ES6) | ||
```js | ||
const PayPal = require("paypal-v2-sdk"); | ||
``` | ||
- Configure your PayPal instance | ||
```js | ||
PayPal.configure("YOUR CLIENT ID", "YOUR CLIENT SECRET"); | ||
``` | ||
- Authenticate your connection (you only need to do this once) | ||
```js | ||
try { | ||
await PayPal.authenticate(); | ||
} catch (e) { | ||
// handle your error | ||
} | ||
``` | ||
Samples | ||
=== | ||
Invoices | ||
--- | ||
- Getting an invoice | ||
- Returns Invoice object | ||
```js | ||
const Invoice = PayPal.invoices.invoices.get("id of invoice"); | ||
``` | ||
- Getting an invoice and then deleting it | ||
```js | ||
const Invoice = PayPal.invoices.invoices.get("id of invoice"); | ||
const deleted = await Invoice.delete(); | ||
console.log(deleted); // true | ||
``` | ||
- Getting the next invoice number & then creating an invoice **using the builder** (EXAMPLE) | ||
```js | ||
const nextNumber = await PayPal.invoices.invoiceNumber.generate() | ||
const Invoice = new PayPal.types.invoice.Invoice() | ||
.setDetail( | ||
new PayPal.types.invoice.Detail() | ||
.setCurrencyCode("USD") | ||
.setNote("Creating an invoice!") | ||
.setTermsAndConditions("url here") | ||
.setInvoiceNumber(nextNumber) | ||
) | ||
.setInvoicer( | ||
new PayPal.types.invoice.InvoicerInfo() | ||
.setEmailAddress("test@test.com") | ||
.setPhones( | ||
[ | ||
new PayPal.types.general.PhoneDetail() | ||
.setCountryCode("44") | ||
.setNationalNumber("123456") | ||
] | ||
) | ||
.setWebsite("https://mystore.com/") | ||
.setTaxId("your tax id") | ||
.setLogoUrl("url") | ||
) | ||
.setPrimaryRecipients( | ||
[ | ||
new PayPal.types.general.RecipientInfo() | ||
.setBillingInfo( | ||
new PayPal.types.general.BillingInfo() | ||
.setEmailAddress("test@test.com") | ||
.setAdditionalInfo("additional info") | ||
) | ||
.setShippingInfo( | ||
new PayPal.types.general.ContactInfo() | ||
.setBusinessName("My Cool Business") | ||
.setName( | ||
new PayPal.types.general.Name() | ||
.setPrefix("Mr") | ||
.setGivenName("Thomas") | ||
.setSurname("Whoever") | ||
) | ||
.setAddress( | ||
new PayPal.types.general.AddressPortable() | ||
.setAddressLines(["12 London Way"]) | ||
.setAdminArea(["Admin area 4", "Some neighborhood", "Leeds", "East Yorkshire"]) | ||
.setPostalCode("LE12 AH7") | ||
.setCountryCode("GB") | ||
) | ||
) | ||
], | ||
[ // another one? ] | ||
) | ||
.setItems( | ||
[ | ||
new PayPal.types.general.Item() | ||
.setName("T-Shirt") | ||
.setDescription("A very cool T-Shirt") | ||
.setQuantity("1") | ||
.setUnitAmount( | ||
new PayPal.types.general.Money() | ||
.setCurrencyCode("USD") | ||
.setValue("25") | ||
) | ||
.setTax( | ||
new PayPal.types.general.Tax() | ||
.setName("VAT") | ||
.setPercent("20") | ||
) | ||
.setDiscount( | ||
new PayPal.types.general.Discount() | ||
.setPercent("5") | ||
) | ||
], | ||
[ | ||
new PayPal.types.general.Item() | ||
.setName("Hoodie") | ||
.setDescription("A very very cool Hoodie") | ||
.setQuantity("3") | ||
.setUnitAmount( | ||
new PayPal.types.general.Money() | ||
.setCurrencyCode("USD") | ||
.setValue("40") | ||
) | ||
.setTax( | ||
new PayPal.types.general.Tax() | ||
.setName("VAT") | ||
.setPercent("20") | ||
) | ||
.setDiscount( | ||
new PayPal.types.general.Discount() | ||
.setPercent("15") | ||
) | ||
] | ||
) | ||
.setConfiguration( | ||
new PayPal.types.general.Configuration() | ||
.setTaxCalculatedAfterDiscount(true) | ||
.setTaxInclusive(false) | ||
.setAllowTip(true) | ||
.setPartialPayment( | ||
new PayPal.types.general.PartialPayment() | ||
.setAllowPartialPayment(true) | ||
.setMinimumAmountDue( | ||
new PayPal.types.general.Money() | ||
.setCurrencyCode("USD") | ||
.setValue("72.5") | ||
) | ||
) | ||
) | ||
.setAmount( | ||
new PayPal.types.general.AmountSummaryDetail() | ||
.setBreakdown( | ||
new PayPal.types.general.AmountWithBreakdown() | ||
.setShipping( | ||
new PayPal.types.general.ShippingCost() | ||
.setTax( | ||
new PayPal.types.general.Tax() | ||
.setName("Shipping Fee") | ||
.setAmount( | ||
new PayPal.types.general.Money() | ||
.setCurrencyCode("USD") | ||
.setValue("5.99") | ||
) | ||
) | ||
) | ||
.setDiscount( | ||
new PayPal.types.general.AggregatedDiscount() | ||
.setInvoiceDiscount( | ||
new PayPal.types.general.Discount() | ||
.setPercent("10") | ||
) | ||
) | ||
) | ||
) | ||
``` | ||
Debugging | ||
=== | ||
`paypal-v2-sdk` has a built-in Event Emitter. | ||
You can output debug messages: | ||
```js | ||
PayPal.on("debug", (str) => console.debug(str)); | ||
``` |
const BasePayPal = require("./BasePayPal"); | ||
const Token = require("./API/Authentication/Token"); | ||
const AddressDetails = require("./Types/General/AddressDetails"); | ||
const AddressPortable = require("./Types/General/AddressPortable"); | ||
const AggregatedDiscount = require("./Types/General/AggregatedDiscount"); | ||
const AmountSummaryDetail = require("./Types/General/AmountSummaryDetail"); | ||
const AmountWithBreakdown = require("./Types/General/AmountWithBreakdown"); | ||
const BillingInfo = require("./Types/General/BillingInfo"); | ||
const Configuration = require("./Types/General/Configuration"); | ||
const ContactInfo = require("./Types/General/ContactInfo"); | ||
const CustomAmount = require("./Types/General/CustomAmount"); | ||
const Discount = require("./Types/General/Discount"); | ||
const FileReference = require("./Types/General/FileReference"); | ||
const Item = require("./Types/General/Item"); | ||
const LinkDescription = require("./Types/General/LinkDescription"); | ||
const Metadata = require("./Types/General/Metadata"); | ||
const Money = require("./Types/General/Money"); | ||
const Name = require("./Types/General/Name"); | ||
const PartialPayment = require("./Types/General/PartialPayment"); | ||
const PaymentDetail = require("./Types/General/PaymentDetail"); | ||
const Payments = require("./Types/General/Payments"); | ||
const PhoneDetail = require("./Types/General/PhoneDetail"); | ||
const RecipientInfo = require("./Types/General/RecipientInfo"); | ||
const RefundDetail = require("./Types/General/RefundDetail"); | ||
const Refunds = require("./Types/General/Refunds"); | ||
const ShippingCost = require("./Types/General/ShippingCost"); | ||
const Tax = require("./Types/General/Tax"); | ||
const Invoice = require("./Types/Invoices/Invoice"); | ||
const InvoiceDetail = require("./Types/Invoices/InvoiceDetail"); | ||
const InvoiceInvoicerInfo = require("./Types/Invoices/InvoiceInvoicerInfo"); | ||
const InvoicePaymentTerm = require("./Types/Invoices/InvoicePaymentTerm"); | ||
@@ -19,2 +48,38 @@ // handlers | ||
}; | ||
this.types = { | ||
general: { | ||
AddressDetails: AddressDetails.bind(null, this), | ||
AddressPortable: AddressPortable.bind(null, this), | ||
AggregatedDiscount: AggregatedDiscount.bind(null, this), | ||
AmountSummaryDetail: AmountSummaryDetail.bind(null, this), | ||
AmountWithBreakDown: AmountWithBreakdown.bind(null, this), | ||
BillingInfo: BillingInfo.bind(null, this), | ||
Configuration: Configuration.bind(null, this), | ||
ContactInfo: ContactInfo.bind(null, this), | ||
CustomAmount: CustomAmount.bind(null, this), | ||
Discount: Discount.bind(null, this), | ||
FileReference: FileReference.bind(null, this), | ||
Item: Item.bind(null, this), | ||
LinkDescription: LinkDescription.bind(null, this), | ||
Metadata: Metadata.bind(null, this), | ||
Money: Money.bind(null, this), | ||
Name: Name.bind(null, this), | ||
PartialPayment: PartialPayment.bind(null, this), | ||
PaymentDetail: PaymentDetail.bind(null, this), | ||
Payments: Payments.bind(null, this), | ||
PhoneDetail: PhoneDetail.bind(null, this), | ||
RecipientInfo: RecipientInfo.bind(null, this), | ||
RefundDetail: RefundDetail.bind(null, this), | ||
Refunds: Refunds.bind(null, this), | ||
ShippingCost: ShippingCost.bind(null, this), | ||
Tax: Tax.bind(null, this), | ||
}, | ||
invoice: { | ||
Invoice: Invoice.bind(null, this), | ||
Detail: InvoiceDetail.bind(null, this), | ||
InvoicerInfo: InvoiceInvoicerInfo.bind(null, this), | ||
PaymentTerm: InvoicePaymentTerm.bind(null, this), | ||
}, | ||
}; | ||
} | ||
@@ -21,0 +86,0 @@ |
@@ -6,5 +6,5 @@ const PayPalClass = require("../../PayPal"); | ||
* | ||
* @param {PayPalClass} PayPal | ||
* @param {PayPalClass|null} PayPal | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -9,3 +9,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -12,0 +12,0 @@ } |
@@ -12,3 +12,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -15,0 +15,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -9,3 +9,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -12,0 +12,0 @@ } |
@@ -11,3 +11,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -14,0 +14,0 @@ } |
@@ -9,3 +9,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -12,0 +12,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -12,3 +12,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -15,0 +15,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -9,3 +9,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -12,0 +12,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -8,3 +8,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -11,0 +11,0 @@ } |
@@ -11,3 +11,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -14,0 +14,0 @@ } |
@@ -9,3 +9,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -12,0 +12,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -21,3 +21,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -24,0 +24,0 @@ } |
@@ -12,3 +12,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -15,0 +15,0 @@ } |
@@ -10,3 +10,3 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
@@ -13,0 +13,0 @@ } |
@@ -8,6 +8,5 @@ const PayPalClass = require("../../PayPal"); | ||
*/ | ||
constructor(PayPal) { | ||
constructor(PayPal = null) { | ||
this.PayPal = PayPal; | ||
} | ||
toJson() { | ||
@@ -14,0 +13,0 @@ return JSON.stringify(this.toAttributeObject()); |
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
78808
2814
190