Skip to content

Add ejs to better match the v2 advanced integration docs #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions advanced-integration/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Version 2 is the current advanced Checkout integration, and includes hosted card

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

* **3. Adding PayPal buttons and card fields** includes [a full-stack Node.js example](v2/examples/full-stack/).
* **4. Call Orders API for PayPal buttons and card fields** includes [a server-side example](v2/examples/call-orders-api-server-side/)
* **5. Capture order** includes [a server-side example](v2/examples/capture-order-server-side/)
- **3. Adding PayPal buttons and card fields** includes [a full-stack Node.js example](v2/examples/full-stack/).
- **4. Call Orders API for PayPal buttons and card fields** includes [a server-side example](v2/examples/call-orders-api-server-side/)
- **5. Capture order** includes [a server-side example](v2/examples/capture-order-server-side/)
1 change: 1 addition & 0 deletions advanced-integration/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "Apache-2.0",
"dependencies": {
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"express": "^4.18.2",
"node-fetch": "^3.3.2"
},
Expand Down
16 changes: 12 additions & 4 deletions advanced-integration/v2/server/server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import express from "express";
import fetch from "node-fetch";
import "dotenv/config";
import path from "path";

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

app.set("view engine", "ejs");
app.set("views", "./server/views");

// host static files
app.use(express.static("client"));

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

// serve index.html
app.get("/", (req, res) => {
res.sendFile(path.resolve("./client/checkout.html"));
// render checkout page with client id & unique client token
app.get("/", async (req, res) => {
try {
res.render("checkout", {
clientId: PAYPAL_CLIENT_ID,
});
} catch (err) {
res.status(500).send(err.message);
}
});

app.listen(PORT, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
<button id="multi-card-field-button" type="button">Pay now with Card</button>
</div>
<p id="result-message"></p>
<!-- Replace the "test" client-id value with your client-id -->
<script src="https://www.paypal.com/sdk/js?components=buttons,card-fields&client-id=test"></script>
<script src="https://www.paypal.com/sdk/js?components=buttons,card-fields&client-id=<%= clientId %>"></script>
<script src="checkout.js"></script>
</body>
</html>