Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ <h1>One-Time Payment Integrations</h1>
<ul>
<li>
<a href="/recommended/index.html"
>Recommended integration with PayPal, Venmo, PayLater, and PayPal
Credit buttons</a
>Recommended integration with PayPal, PayLater, and PayPal Credit
buttons</a
>
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ async function onPayPalLoaded() {
const clientToken = await getBrowserSafeClientToken();
const sdkInstance = await window.paypal.createInstance({
clientToken,
components: ["paypal-payments", "venmo-payments"],
components: ["paypal-payments"],
pageType: "checkout",
});

Expand All @@ -15,10 +15,6 @@ async function onPayPalLoaded() {
setupPayPalButton(sdkInstance);
}

if (paymentMethods.isEligible("venmo")) {
setupVenmoButton(sdkInstance);
}

if (paymentMethods.isEligible("paylater")) {
const paylaterPaymentMethodDetails =
paymentMethods.getDetails("paylater");
Expand Down Expand Up @@ -71,25 +67,6 @@ async function setupPayPalButton(sdkInstance) {
});
}

async function setupVenmoButton(sdkInstance) {
const venmoPaymentSession = sdkInstance.createVenmoOneTimePaymentSession(
paymentSessionOptions,
);
const venmoButton = document.querySelector("#venmo-button");
venmoButton.removeAttribute("hidden");

venmoButton.addEventListener("click", async () => {
try {
await venmoPaymentSession.start(
{ presentationMode: "auto" },
createOrder(),
);
} catch (error) {
console.error(error);
}
});
}

async function setupPayLaterButton(sdkInstance, paylaterPaymentMethodDetails) {
const paylaterPaymentSession =
sdkInstance.createPayLaterOneTimePaymentSession(paymentSessionOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h1>One-Time Payment Recommended Integration</h1>

<div class="buttons-container">
<paypal-button id="paypal-button" type="pay" hidden></paypal-button>
<venmo-button id="venmo-button" type="pay" hidden></venmo-button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why is the venmo-button removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is under paypalPayments. There's a venmo button example under venmoPayments.

<paypal-pay-later-button
id="paylater-button"
hidden
Expand Down
21 changes: 21 additions & 0 deletions client/components/venmoPayments/oneTimePayment/html/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# One-Time Payments HTML Sample Integration

This HTML sample integration uses HTML, JavaScript, and CSS. It does not require a build process to transpile the source code. It's just static files that can be served up by any web server. [Vite](https://vite.dev/) is used for the local web server to provide the following functionality:

1. Serve up the static HTML and JavaScript files.
2. Proxy the API server so both the client and server are running on port 3000.

## How to Run Locally

```bash
npm install
npm start
```

### Sample Integrations

| Sample Integration | Description |
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Recommended](src/recommended/index.html) | Start with this recommended sample integration. It displays all buttons supported by the v6 SDK and includes eligibility logic. It uses the "auto" presentation mode which attempts to launch a popup window and then automatically falls back to the modal presentation mode when the browser does not support popups. |
| [Custom Payment Handler](src/custom/paymentHandler/index.html) | This custom integration uses the experimental "payment-handler" presentation mode. It teaches how to control the fallback logic for presentation modes based on what the browser supports. |
| [Custom Sandboxed Iframe](src/custom/sandboxedIframe/README.md) | This custom integration demonstrates how a merchant can wrap the v6 SDK integration code into their own iframe and what values need to be passed to the [iframe sandbox attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox). It does require two web servers to demonstrate the use case. Refer to the README in the src/custom/sandboxedIframe directory to learn more. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "v6-web-sdk-sample-integration-client-html",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"preview": "vite preview",
"start": "vite",
"format": "prettier . --write",
"format:check": "prettier . --check",
"lint": "echo \"eslint is not set up\""
},
"license": "Apache-2.0",
"devDependencies": {
"prettier": "^3.5.3",
"vite": "^6.2.0"
}
}
97 changes: 97 additions & 0 deletions client/components/venmoPayments/oneTimePayment/html/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
async function onPayPalLoaded() {
try {
const clientToken = await getBrowserSafeClientToken();
const sdkInstance = await window.paypal.createInstance({
clientToken,
components: ["venmo-payments"],
pageType: "checkout",
});

const paymentMethods = await sdkInstance.findEligibleMethods({
currencyCode: "USD",
});

if (paymentMethods.isEligible("venmo")) {
setupVenmoButton(sdkInstance);
}
} catch (error) {
console.error(error);
}
}

const paymentSessionOptions = {
async onApprove(data) {
console.log("onApprove", data);
const orderData = await captureOrder({
orderId: data.orderId,
});
console.log("Capture result", orderData);
},
onCancel(data) {
console.log("onCancel", data);
},
onError(error) {
console.log("onError", error);
},
};

async function setupVenmoButton(sdkInstance) {
const venmoPaymentSession = sdkInstance.createVenmoOneTimePaymentSession(
paymentSessionOptions,
);
const venmoButton = document.querySelector("#venmo-button");
venmoButton.removeAttribute("hidden");

venmoButton.addEventListener("click", async () => {
try {
await venmoPaymentSession.start(
{ presentationMode: "auto" },
createOrder(),
);
} catch (error) {
console.error(error);
}
});
}

async function getBrowserSafeClientToken() {
const response = await fetch("/paypal-api/auth/browser-safe-client-token", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const { accessToken } = await response.json();

return accessToken;
}

async function createOrder() {
const response = await fetch(
"/paypal-api/checkout/orders/create-with-sample-data",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
);
const { id } = await response.json();

return { orderId: id };
}

async function captureOrder({ orderId }) {
const response = await fetch(
`/paypal-api/checkout/orders/${orderId}/capture`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
},
);
const data = await response.json();

return data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>One-Time Payment - Recommended Integration - PayPal Web SDK</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
.buttons-container {
display: flex;
flex-direction: column;
gap: 12px;
}
</style>
</head>
<body>
<h1>One-Time Payment Recommended Integration</h1>

<div class="buttons-container">
<venmo-button id="venmo-button" type="pay" hidden></venmo-button>
</div>
<script src="app.js"></script>

<script
async
src="https://www.sandbox.paypal.com/web-sdk/v6/core"
onload="onPayPalLoaded()"
></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [],
root: "src",
server: {
port: 3000,
proxy: {
"/paypal-api": {
target: "http://localhost:8080",
changeOrigin: true,
secure: false,
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ v6-web-sdk-sample-integration/server/node
npm install
npm start

v6-web-sdk-sample-integration/client/oneTimePayment/react
v6-web-sdk-sample-integration/client/prebuiltPages/react/oneTimePayment
npm install
npm start
```
Expand Down
20 changes: 0 additions & 20 deletions client/savePayment/html/src/index.html

This file was deleted.