mirror of
https://github.com/therootcompany/paypal-checkout.js.git
synced 2025-12-24 06:18:46 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f47523f56d | |||
| 70da150599 | |||
| 3d18aa00de |
36
README.md
36
README.md
@ -135,10 +135,13 @@ here's the gist of what you need to do:
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Handle the PAYMENT.CAPTURE.COMPLETED WebHook
|
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
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Set webhook at https://developer.paypal.com/developer/applications
|
// 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) {
|
app.get("/api/webhooks/paypal-checkout/:secret", async function (req, res) {
|
||||||
let crypto = require("crypto");
|
let crypto = require("crypto");
|
||||||
let secret = process.env.PAYPAL_WEBHOOK_SECRET || "";
|
let secret = process.env.PAYPAL_WEBHOOK_SECRET || "";
|
||||||
@ -154,13 +157,30 @@ here's the gist of what you need to do:
|
|||||||
|
|
||||||
let event = req.body;
|
let event = req.body;
|
||||||
switch (event.event_type) {
|
switch (event.event_type) {
|
||||||
case "PAYMENT.CAPTURE.COMPLETED": {
|
case "PAYMENT.CAPTURE.COMPLETED":
|
||||||
let orderId = event.supplementary_data.related_ids.order_id;
|
{
|
||||||
let localDbId = event.custom_id;
|
let orderId = event.supplementary_data.related_ids.order_id;
|
||||||
console.info(
|
let localDbId = event.custom_id;
|
||||||
`Confirm that PayPal Order ${orderId} for ${localDbId} has been paid.`
|
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;
|
||||||
default:
|
default:
|
||||||
console.log("Ignoring", event.event_type);
|
console.log("Ignoring", event.event_type);
|
||||||
res.json({ sucess: true });
|
res.json({ sucess: true });
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@root/paypal-checkout",
|
"name": "@root/paypal-checkout",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@root/paypal-checkout",
|
"name": "@root/paypal-checkout",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@root/request": "^1.7.0"
|
"@root/request": "^1.7.0"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@root/paypal-checkout",
|
"name": "@root/paypal-checkout",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"description": "A more sensible, human-generated wrapper for the PayPal Checkout REST API",
|
"description": "A more sensible, human-generated wrapper for the PayPal Checkout REST API",
|
||||||
"main": "paypal-checkout.js",
|
"main": "paypal-checkout.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -441,6 +441,7 @@ Subscription.payee_preferences = {
|
|||||||
IMMEDIATE_PAYMENT_REQUIRED: "IMMEDIATE_PAYMENT_REQUIRED",
|
IMMEDIATE_PAYMENT_REQUIRED: "IMMEDIATE_PAYMENT_REQUIRED",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// See https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
|
||||||
Subscription.createRequest = async function _createSubscription({
|
Subscription.createRequest = async function _createSubscription({
|
||||||
request_id,
|
request_id,
|
||||||
plan_id,
|
plan_id,
|
||||||
@ -449,6 +450,8 @@ Subscription.createRequest = async function _createSubscription({
|
|||||||
shipping_amount,
|
shipping_amount,
|
||||||
subscriber,
|
subscriber,
|
||||||
application_context,
|
application_context,
|
||||||
|
custom_id,
|
||||||
|
plan,
|
||||||
}) {
|
}) {
|
||||||
return await PayPal.request({
|
return await PayPal.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -496,6 +499,8 @@ Subscription.createRequest = async function _createSubscription({
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
application_context: application_context,
|
application_context: application_context,
|
||||||
|
custom_id: custom_id,
|
||||||
|
plan: plan,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(must201or200)
|
.then(must201or200)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user