Skip to content

Conversation

gregjopa
Copy link
Contributor

This PR updates the SavePayment flow to add logic to the onApprove() callback to upgrade the vaultSetupToken to a paymentToken that can be used for future transactions. Now our Save Payment demo aligns with this v5 doc: https://developer.paypal.com/docs/checkout/save-payment-methods/purchase-later/js-sdk/paypal/

@gregjopa gregjopa requested a review from a team as a code owner May 23, 2025 15:10
@gregjopa gregjopa force-pushed the feature/vault-enhancements-v2 branch from 1767bc3 to ea1c939 Compare May 23, 2025 15:11
@gregjopa gregjopa requested review from imbrian and mchoun May 23, 2025 15:12

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

Choose a reason for hiding this comment

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

I don't think the "Pay with" button label makes sense for saving a payment so removing it.

const paymentTokenResponse = jsonResponse as PaymentTokenResponse;

if (paymentTokenResponse.id) {
await savePaymentTokenToDatabase(paymentTokenResponse);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its important that we teach developers NOT to return this paymentToken value to the front-end. This is a long-lived value that can be used for making payments where the buyer is not present or doing a one-shot transaction.

We want to teach developers to save this payment token in their database instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have a lot of comments in this repo, but I think this type of callout would be good to have in a comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point. I just added a code comment about not returning this payment token id back to the browser.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I really like this comment!

Copy link

@mchoun mchoun left a comment

Choose a reason for hiding this comment

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

Looks good to me! 🚀

Copy link
Contributor

@hamzanasir hamzanasir left a comment

Choose a reason for hiding this comment

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

Nice work @gregjopa!

const createPaymentTokenResponse = await createPaymentToken(
data.vaultSetupToken,
);
console.log(createPaymentTokenResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe we can preface this log with a string if we want to keep it like:

console.log("Create payment token response: ", createPaymentTokenResponse);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion. I added this label.

const paymentTokenResponse = jsonResponse as PaymentTokenResponse;

if (paymentTokenResponse.id) {
await savePaymentTokenToDatabase(paymentTokenResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I really like this comment!

echo "::group:: $directory"
cd "$directory" && npm install && cd -
cd "$directory"
npm install || exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the exit 1 needed? My assumption would be that npm install returns with a non-zero status code if it fails 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Best I can tell, I think this explicit "exit 1" is needed. I noticed on this PR that originally CI was passing even though the prettier check was erroring. You can see it in this GitHub Actions run: https://github.com/paypal-examples/v6-web-sdk-sample-integration/actions/runs/15213524563/job/42793351279
Screenshot 2025-05-27 at 9 39 47 PM

I am open to other ways of solving this.

@gregjopa gregjopa merged commit 95301a3 into main May 28, 2025
1 check passed
@gregjopa gregjopa deleted the feature/vault-enhancements-v2 branch May 28, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants