Compare commits

..

No commits in common. "main" and "v0.3.0" have entirely different histories.
main ... v0.3.0

4 changed files with 11 additions and 36 deletions

View File

@ -135,13 +135,10 @@ here's the gist of what you need to do:
});
```
4. [Set](https://developer.paypal.com/developer/applications) and Handle the
[`PAYMENT.CAPTURE.COMPLETED`, `PAYMENT.CAPTURE.REVERSED`, and `CUSTOMER.DISPUTE.CREATED`](https://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/)
WebHooks
4. Handle the PAYMENT.CAPTURE.COMPLETED WebHook
```js
// Set webhook at https://developer.paypal.com/developer/applications
// Descriptions at https://developer.paypal.com/docs/api-basics/notifications/webhooks/event-names/
app.get("/api/webhooks/paypal-checkout/:secret", async function (req, res) {
let crypto = require("crypto");
let secret = process.env.PAYPAL_WEBHOOK_SECRET || "";
@ -157,30 +154,13 @@ here's the gist of what you need to do:
let event = req.body;
switch (event.event_type) {
case "PAYMENT.CAPTURE.COMPLETED":
{
let orderId = event.supplementary_data.related_ids.order_id;
let localDbId = event.custom_id;
console.info(
`Confirm that PayPal Order ${orderId} for ${localDbId} has been paid.`
);
}
break;
case "PAYMENT.CAPTURE.REVERSED":
{
// deduct from user's account
}
break;
case "CUSTOMER.DISPUTE.CREATED":
{
// TODO send email to merchant (myself) to check out the dispute
}
break;
case "CUSTOMER.DISPUTE.CREATED":
{
// TODO send email to merchant (myself) to review the dispute status
}
break;
case "PAYMENT.CAPTURE.COMPLETED": {
let orderId = event.supplementary_data.related_ids.order_id;
let localDbId = event.custom_id;
console.info(
`Confirm that PayPal Order ${orderId} for ${localDbId} has been paid.`
);
}
default:
console.log("Ignoring", event.event_type);
res.json({ sucess: true });

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@root/paypal-checkout",
"version": "0.3.1",
"version": "0.3.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@root/paypal-checkout",
"version": "0.3.1",
"version": "0.3.0",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@root/request": "^1.7.0"

View File

@ -1,6 +1,6 @@
{
"name": "@root/paypal-checkout",
"version": "0.3.1",
"version": "0.3.0",
"description": "A more sensible, human-generated wrapper for the PayPal Checkout REST API",
"main": "paypal-checkout.js",
"files": [

View File

@ -441,7 +441,6 @@ Subscription.payee_preferences = {
IMMEDIATE_PAYMENT_REQUIRED: "IMMEDIATE_PAYMENT_REQUIRED",
};
// See https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
Subscription.createRequest = async function _createSubscription({
request_id,
plan_id,
@ -450,8 +449,6 @@ Subscription.createRequest = async function _createSubscription({
shipping_amount,
subscriber,
application_context,
custom_id,
plan,
}) {
return await PayPal.request({
method: "POST",
@ -499,8 +496,6 @@ Subscription.createRequest = async function _createSubscription({
}
*/
application_context: application_context,
custom_id: custom_id,
plan: plan,
},
})
.then(must201or200)