-
Notifications
You must be signed in to change notification settings - Fork 212
@W-19014904 – Adyen Apple Pay PDP #2787
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
mmccullom-sf
merged 26 commits into
SalesforceCommerceCloud:adyenExpressPaymentsDreamForce
from
mmccullom-sf:adyenApplePayPDP
Jul 30, 2025
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
dfe881b
Adyen ApplePay Integration into Shopper Agent
jbisaSF d02f2b5
Apple Pay PDP
965619d
Merge branch 'adyenApplePayBranch3' into adyenApplePayPDP
mmccullom-sf 546f3eb
remove from product page
5d62212
Merge branch 'adyenApplePayPDP' of github.com:mmccullom-sf/pwa-kit in…
f6703c9
remove readme
eb44ff3
pdp work
1d728f4
apple pay pdp
3bdcc25
remove readme
fdf5d7a
remove readme
0663d4c
Merge branch 'adyenApplePayBranch3' into adyenApplePayPDP
mmccullom-sf 3910120
code cleanup
6f74b09
PWA kit PDP
e48b7a0
PWA kit PDP
07f0727
PWA kit PDP
9c98ff7
fix main cart issue
a8b6031
fix shipping issue
cdccb7e
cleanup
6a9560f
quantity fixes
daf9575
small fixes to lint error
5fb1ba2
ssr.js
f871173
Update ssr.js
mmccullom-sf 655fd19
address comment about basket choice
23d0ba0
remove quantity
56ee560
Merge branch 'adyenExpressPaymentsDreamForce' into adyenApplePayPDP
mmccullom-sf 8c4e8d4
merge with Google Pay
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/template-retail-react-app/app/api/adyen/paymentMethods/standalone.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| /** | ||
| * Custom payment methods controller that doesn't require a basket | ||
| * This is specifically for "Buy Now" flows where we need to show Apple Pay | ||
| * before creating a basket | ||
| */ | ||
|
|
||
| // Helper function to get the Adyen PWA library version dynamically | ||
| function getAdyenPwaVersion() { | ||
| try { | ||
| // Try to read the version from the installed package | ||
| const packageJson = require('@adyen/adyen-salesforce-pwa/package.json') | ||
| return packageJson.version | ||
| } catch (error) { | ||
| console.error('Unable to determine Adyen PWA version', error) | ||
| } | ||
| } | ||
|
|
||
| export default async function handler(req, res) { | ||
| if (req.method !== 'GET') { | ||
| return res.status(405).json({error: 'Method not allowed'}) | ||
| } | ||
|
|
||
| try { | ||
| const {siteId, locale} = req.query | ||
|
|
||
| if (!siteId) { | ||
| return res.status(400).json({error: 'siteId is required'}) | ||
| } | ||
|
|
||
| // Get Adyen configuration from environment variables | ||
| // Environment variables are prefixed with the site ID | ||
| const apiKey = process.env[`${siteId}_ADYEN_API_KEY`] | ||
| const merchantAccount = process.env[`${siteId}_ADYEN_MERCHANT_ACCOUNT`] | ||
| const environment = process.env[`${siteId}_ADYEN_ENVIRONMENT`] || 'test' | ||
| const clientKey = process.env[`${siteId}_ADYEN_CLIENT_KEY`] | ||
|
|
||
| if (!apiKey || !merchantAccount || !clientKey) { | ||
| return res.status(500).json({ | ||
| error: 'Missing Adyen configuration', | ||
| details: `Required environment variables: ${siteId}_ADYEN_API_KEY, ${siteId}_ADYEN_MERCHANT_ACCOUNT, ${siteId}_ADYEN_CLIENT_KEY` | ||
| }) | ||
| } | ||
|
|
||
| // Construct Adyen API URL | ||
| const adyenBaseUrl = | ||
| environment === 'live' | ||
| ? 'https://checkout-live.adyen.com/v70' | ||
| : 'https://checkout-test.adyen.com/v70' | ||
|
|
||
| // Call Adyen payment methods API without basket dependency | ||
| const adyenResponse = await fetch(`${adyenBaseUrl}/paymentMethods`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-API-Key': apiKey | ||
| }, | ||
| body: JSON.stringify({ | ||
| merchantAccount, | ||
| countryCode: locale?.split('-')[1] || 'US', | ||
| channel: 'Web' | ||
| }) | ||
| }) | ||
|
|
||
| if (!adyenResponse.ok) { | ||
| const errorBody = await adyenResponse.text() | ||
| console.error('Adyen API error:', errorBody) | ||
| return res.status(adyenResponse.status).json({ | ||
| error: 'Failed to fetch payment methods from Adyen' | ||
| }) | ||
| } | ||
|
|
||
| const paymentMethods = await adyenResponse.json() | ||
|
|
||
| // Return the payment methods with environment configuration and application info | ||
| res.status(200).json({ | ||
| ...paymentMethods, | ||
| environment: { | ||
| ADYEN_ENVIRONMENT: environment, | ||
| ADYEN_CLIENT_KEY: clientKey | ||
| }, | ||
| applicationInfo: { | ||
| adyenLibrary: { | ||
| name: 'adyen-salesforce-pwa', | ||
| version: getAdyenPwaVersion() | ||
| } | ||
| } | ||
| }) | ||
| } catch (error) { | ||
| console.error('Payment methods API error:', error) | ||
| res.status(500).json({ | ||
| error: 'Internal server error', | ||
| message: error.message | ||
| }) | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
...retail-react-app/app/components/apple-pay-express/hooks/use-standalone-payment-methods.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright (c) 2025, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import {useState, useEffect} from 'react' | ||
| import {AdyenPaymentMethodsService} from '@salesforce/retail-react-app/app/components/apple-pay-express/utils/payment-methods' | ||
|
|
||
| /** | ||
| * Hook for fetching payment methods without basket dependency (for "Buy Now" flows) | ||
| * @param {string} authToken - Authentication token | ||
| * @param {object} site - Site configuration | ||
| * @param {object} locale - Locale configuration | ||
| * @param {boolean} enabled - Whether the hook should make API calls (default: true) | ||
| * @returns {object} Payment methods data, loading state, and error | ||
| */ | ||
| export const useStandalonePaymentMethods = (authToken, site, locale, enabled = true) => { | ||
| const [paymentMethods, setPaymentMethods] = useState(null) | ||
| const [loading, setLoading] = useState(false) | ||
| const [error, setError] = useState(null) | ||
|
|
||
| useEffect(() => { | ||
| // Only make API call if enabled and required parameters are available | ||
| if (!enabled || !authToken || !site) { | ||
| return | ||
| } | ||
|
|
||
| const fetchPaymentMethods = async () => { | ||
| try { | ||
| setLoading(true) | ||
| setError(null) | ||
|
|
||
| const service = new AdyenPaymentMethodsService(authToken, site) | ||
| const data = await service.getPaymentMethods() | ||
|
|
||
| setPaymentMethods(data) | ||
| } catch (err) { | ||
| console.error('Error fetching standalone payment methods:', err) | ||
| setError(err) | ||
| } finally { | ||
| setLoading(false) | ||
| } | ||
| } | ||
|
|
||
| fetchPaymentMethods() | ||
| }, [authToken, site, locale, enabled]) | ||
|
|
||
| return { | ||
| paymentMethods, | ||
| loading, | ||
| error | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't shopper facing error messages right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're API error messages, so if for whatever reason someone tried to hit this API with postman or something and had an invalid method they would see these errors.