Skip to content

Commit

Permalink
Merge pull request #556 from commercelayer/fix/adyen-shopper-ip
Browse files Browse the repository at this point in the history
Add shopper ip on adyen payment
  • Loading branch information
acasazza authored Jul 29, 2024
2 parents fa551af + d43e913 commit 6478900
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PlaceOrderContext from '#context/PlaceOrderContext'
import OrderContext from '#context/OrderContext'
import omit from '#utils/omit'
import type UIElement from '@adyen/adyen-web/dist/types/components/UIElement'
import { getPublicIP } from '#utils/getPublicIp'

type Styles = Partial<{
base: CSSProperties
Expand Down Expand Up @@ -124,6 +125,7 @@ export function AdyenPayment({
setPaymentRef({ ref })
}
const browserInfo = getBrowserInfo()
const shopperIp = await getPublicIP()
const attributes: any = {
payment_request_data: {
payment_method: state.data.paymentMethod,
Expand All @@ -132,6 +134,7 @@ export function AdyenPayment({
origin: window.location.origin,
return_url: window.location.href,
redirect_from_issuer_method: 'GET',
shopper_ip: shopperIp,
browser_info: {
acceptHeader:
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
Expand Down
13 changes: 13 additions & 0 deletions packages/react-components/src/utils/getPublicIp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export async function getPublicIP(): Promise<string> {
try {
const response = await fetch('https://api.ipify.org?format=json');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
return data.ip;
} catch (error) {
console.error('Error fetching public IP address:', error);
throw error;
}
}

0 comments on commit 6478900

Please sign in to comment.