Skip to content

Commit c4ee30f

Browse files
authored
Add ejs to better match the v2 advanced integration docs (#93)
1 parent e453180 commit c4ee30f

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

advanced-integration/v2/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Version 2 is the current advanced Checkout integration, and includes hosted card
1818

1919
The documentation for advanced Checkout integration using JavaScript SDK includes additional sample code in the following sections:
2020

21-
* **3. Adding PayPal buttons and card fields** includes [a full-stack Node.js example](v2/examples/full-stack/).
22-
* **4. Call Orders API for PayPal buttons and card fields** includes [a server-side example](v2/examples/call-orders-api-server-side/)
23-
* **5. Capture order** includes [a server-side example](v2/examples/capture-order-server-side/)
21+
- **3. Adding PayPal buttons and card fields** includes [a full-stack Node.js example](v2/examples/full-stack/).
22+
- **4. Call Orders API for PayPal buttons and card fields** includes [a server-side example](v2/examples/call-orders-api-server-side/)
23+
- **5. Capture order** includes [a server-side example](v2/examples/capture-order-server-side/)

advanced-integration/v2/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"license": "Apache-2.0",
1515
"dependencies": {
1616
"dotenv": "^16.3.1",
17+
"ejs": "^3.1.9",
1718
"express": "^4.18.2",
1819
"node-fetch": "^3.3.2"
1920
},

advanced-integration/v2/server/server.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import express from "express";
22
import fetch from "node-fetch";
33
import "dotenv/config";
4-
import path from "path";
54

65
const { PAYPAL_CLIENT_ID, PAYPAL_CLIENT_SECRET, PORT = 8888 } = process.env;
76
const base = "https://api-m.sandbox.paypal.com";
87
const app = express();
98

9+
app.set("view engine", "ejs");
10+
app.set("views", "./server/views");
11+
1012
// host static files
1113
app.use(express.static("client"));
1214

@@ -142,9 +144,15 @@ app.post("/api/orders/:orderID/capture", async (req, res) => {
142144
}
143145
});
144146

145-
// serve index.html
146-
app.get("/", (req, res) => {
147-
res.sendFile(path.resolve("./client/checkout.html"));
147+
// render checkout page with client id & unique client token
148+
app.get("/", async (req, res) => {
149+
try {
150+
res.render("checkout", {
151+
clientId: PAYPAL_CLIENT_ID,
152+
});
153+
} catch (err) {
154+
res.status(500).send(err.message);
155+
}
148156
});
149157

150158
app.listen(PORT, () => {

advanced-integration/v2/client/checkout.html renamed to advanced-integration/v2/server/views/checkout.ejs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<button id="multi-card-field-button" type="button">Pay now with Card</button>
1818
</div>
1919
<p id="result-message"></p>
20-
<!-- Replace the "test" client-id value with your client-id -->
21-
<script src="https://www.paypal.com/sdk/js?components=buttons,card-fields&client-id=test"></script>
20+
<script src="https://www.paypal.com/sdk/js?components=buttons,card-fields&client-id=<%= clientId %>"></script>
2221
<script src="checkout.js"></script>
2322
</body>
2423
</html>

0 commit comments

Comments
 (0)