Skip to content
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

Fix/redirect component to pass browser info #2469

Merged
merged 4 commits into from
Dec 4, 2023
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
5 changes: 5 additions & 0 deletions .changeset/swift-rice-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---

Pass the `browserInfo` in the `state.data` for the Redirect payments, in order to fix the mobile web integration for some redirect payments.
11 changes: 0 additions & 11 deletions packages/lib/src/components/Giropay/Giropay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ class GiropayElement extends RedirectElement {
};
}

/**
* Formats the component data output
*/
formatData() {
return {
paymentMethod: {
type: GiropayElement.type
}
};
}

get displayName() {
return this.props.name || this.constructor['type'];
}
Expand Down
10 changes: 10 additions & 0 deletions packages/lib/src/components/Redirect/Redirect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mount } from 'enzyme';
import { h } from 'preact';
import Redirect from './Redirect';
import RedirectShopper from './components/RedirectShopper';
import RedirectElement from './Redirect';

jest.mock('../../utils/detectInIframe', () => {
return jest.fn().mockImplementation(() => {
Expand All @@ -21,6 +22,7 @@ describe('Redirect', () => {
test('Accepts a POST redirect status', () => {
window.HTMLFormElement.prototype.submit = jest.fn();

// @ts-ignore ignore
const wrapper = mount(<RedirectShopper url="http://www.adyen.com" method="POST" data={{}} />);

expect(wrapper.find('form')).toHaveLength(1);
Expand All @@ -32,11 +34,19 @@ describe('Redirect', () => {
test('Accepts a POST redirect status, setting target to _top, when the config prop tells it to', () => {
window.HTMLFormElement.prototype.submit = jest.fn();

// @ts-ignore ignore
const wrapper = mount(<RedirectShopper url="http://www.adyen.com" method="POST" data={{}} redirectFromTopWhenInIframe={true} />);

expect(wrapper.find('form')).toHaveLength(1);
expect(wrapper.find('form').prop('target')).toBe('_top');
setTimeout(() => expect(window.HTMLFormElement.prototype.submit).toHaveBeenCalled(), 0);
});
});

describe('Redirect formatData', () => {
test('should send browserInfo in the data', () => {
const redirectElement = new RedirectElement({});
expect(redirectElement.formatData().browserInfo).not.toBeNull();
});
});
});
8 changes: 7 additions & 1 deletion packages/lib/src/components/Redirect/Redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIElement from '../UIElement';
import CoreProvider from '../../core/Context/CoreProvider';
import RedirectShopper from './components/RedirectShopper';
import RedirectButton from '../internal/RedirectButton';
import collectBrowserInfo from '../../utils/browserInfo';

/**
* RedirectElement
Expand All @@ -30,7 +31,8 @@ class RedirectElement extends UIElement {
return {
paymentMethod: {
type: this.props.type
}
},
browserInfo: this.browserInfo
};
}

Expand All @@ -45,6 +47,10 @@ class RedirectElement extends UIElement {
return this.resources.getImage()(this.props.type);
}

get browserInfo() {
return collectBrowserInfo();
}

render() {
if (this.props.url && this.props.method) {
return <RedirectShopper {...this.props} />;
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/config/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const amount = {

export const useSession = urlParams.session !== 'manual';

export const returnUrl = 'http://localhost:3020/result';
export const returnUrl = `${window.location.protocol}//localhost:3020/result`;

export default {
amount,
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/pages/Dropin/manual.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AdyenCheckout from '@adyen/adyen-web';
import '@adyen/adyen-web/dist/es/adyen.css';
import { getPaymentMethods, makePayment, checkBalance, createOrder, cancelOrder, makeDetailsCall } from '../../services';
import { amount, shopperLocale, countryCode, returnUrl } from '../../config/commonConfig';
import { amount, shopperLocale, countryCode } from '../../config/commonConfig';
import { getSearchParameters } from '../../utils';

export async function initManual() {
Expand Down
Loading