-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
61 lines (56 loc) · 1.56 KB
/
example.js
File metadata and controls
61 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
// To include paymongo library in your project, use const paymongo = require('paymongo');
const paymongo = require("./src/paymongo")("<insert secret api key here");
// Create a source
paymongo.sources
.create({
amount: 10000,
currency: "PHP",
type: "gcash",
redirect: {
success: "https://google.com",
failed: "https://google.com",
},
})
.then(function(resource) {
console.log(resource);
})
.catch(function(e) {
if (e.type === "AuthenticationError") {
console.log("auth error");
} else if (e.type === "RouteNotFoundError") {
console.log("route not found");
} else if (e.type === "InvalidRequestError") {
console.log(e.errors);
}
});
// retrieve a source by id
paymongo.sources
.retrieve("insert source id here")
.then(function(resource) {
console.log(resource);
})
.catch(function(e) {
if (e.type === "AuthenticationError") {
console.log("auth error");
} else if (e.type === "ResourceNotFoundError") {
console.log(e.errors);
} else if (e.type === "RouteNotFoundError") {
console.log("route not found");
} else if (e.type === "InvalidRequestError") {
console.log(e.errors);
}
});
// Webhook signing
try {
const event = paymongo.webhooks.constructEvent({
payload: "insert raw data",
signatureHeader: "insert signature header",
webhookSecretKey: "insert webhook secret key",
});
console.log(event);
} catch (e) {
if (e.type === "SignatureVerificationError") {
console.log("handle signature verification error");
}
}