Skip to content

Commit 8b9ba5d

Browse files
committed
Link to return buyer experience
1 parent dcffe7f commit 8b9ba5d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

save-payment-method/client/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ window.paypal
7070
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
7171
resultMessage(
7272
`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details.<br>
73-
<a href='/?${orderData.payment_source.paypal.attributes.vault.customer.id}'>See the return buyer experience</a>
73+
<a href='/?customerID=${orderData.payment_source.paypal.attributes.vault.customer.id}'>See the return buyer experience</a>
7474
`,
7575
);
7676

save-payment-method/server/server.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const authenticate = async (bodyParams) => {
2323
const params = {
2424
grant_type: "client_credentials",
2525
response_type: "id_token",
26-
...bodyParams
26+
...bodyParams,
2727
};
28-
28+
2929
// pass the url encoded value as the body of the post call
3030
const urlEncodedParams = new URLSearchParams(params).toString();
3131
try {
@@ -36,14 +36,9 @@ const authenticate = async (bodyParams) => {
3636
PAYPAL_CLIENT_ID + ":" + PAYPAL_CLIENT_SECRET,
3737
).toString("base64");
3838

39-
let body = "grant_type=client_credentials&response_type=id_token";
40-
if (targetCustomerId) {
41-
body += `&target_customer_id=${targetCustomerId}`;
42-
}
43-
4439
const response = await fetch(`${base}/v1/oauth2/token`, {
4540
method: "POST",
46-
body,
41+
body: urlEncodedParams,
4742
headers: {
4843
Authorization: `Basic ${auth}`,
4944
},
@@ -94,6 +89,7 @@ const createOrder = async (cart) => {
9489
experience_context: {
9590
return_url: "http://example.com",
9691
cancel_url: "http://example.com",
92+
shipping_preference: "NO_SHIPPING",
9793
},
9894
},
9995
},
@@ -180,7 +176,9 @@ app.post("/api/orders/:orderID/capture", async (req, res) => {
180176
// render checkout page with client id & user id token
181177
app.get("/", async (req, res) => {
182178
try {
183-
const { jsonResponse } = await authenticate(req.query.customerID);
179+
const { jsonResponse } = await authenticate({
180+
target_customer_id: req.query.customerID,
181+
});
184182
res.render("checkout", {
185183
clientId: PAYPAL_CLIENT_ID,
186184
userIdToken: jsonResponse.id_token,

0 commit comments

Comments
 (0)