Skip to content
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/payment-iframe-shop-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-admin-sdk": patch
---

Changed `addPaymentIframe` to add `shopId` parameter to iframe url.
17 changes: 15 additions & 2 deletions packages/admin-sdk/src/_private/payment/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('Private Service Payment', () => {
let mockModalClose: jest.Mock;
let mockLocationStartAutoResizer: jest.Mock;
let mockGetAppInformation: jest.Mock;
let mockGetShopId: jest.Mock;
let eventListeners: Map<string, Set<EventListener>>;
let mockModalOpen: jest.Mock;

Expand Down Expand Up @@ -84,6 +85,10 @@ describe('Private Service Payment', () => {
});
(context.getAppInformation as jest.Mock) = mockGetAppInformation;

// Mock context.getShopId
mockGetShopId = jest.fn().mockResolvedValue('shop-id-123');
(context.getShopId as jest.Mock) = mockGetShopId;

// Clear all mocks
jest.clearAllMocks();
mockBroadcastChannelInstance.addEventListener.mockClear();
Expand Down Expand Up @@ -126,7 +131,7 @@ describe('Private Service Payment', () => {
expect(mockGetAppInformation).toHaveBeenCalledTimes(1);
expect(result.iframeEl).toBeInstanceOf(HTMLIFrameElement);
expect(result.iframeEl.src).toBe(
'https://example.com/payment?service-name=test-app&service-version=1.0.0&shop-url=https://shop.example.com&sw-version=6.5.0&sw-user-language=en-GB&shop-plan=beyond'
'https://example.com/payment?service-name=test-app&service-version=1.0.0&shop-url=https://shop.example.com&sw-version=6.5.0&sw-user-language=en-GB&shop-plan=beyond&shop-id=shop-id-123'
);
expect(container.contains(result.iframeEl)).toBe(true);
});
Expand All @@ -153,10 +158,18 @@ describe('Private Service Payment', () => {
const result = await addPaymentIframe(container, baseUrl, options);

expect(result.iframeEl.src).toBe(
'https://example.com/payment?service-name=test-app&service-version=1.0.0&shop-url=https://license-aud.shop.example.com&sw-version=6.5.0&sw-user-language=en-GB&shop-plan=premium'
'https://example.com/payment?service-name=test-app&service-version=1.0.0&shop-url=https://license-aud.shop.example.com&sw-version=6.5.0&sw-user-language=en-GB&shop-plan=premium&shop-id=shop-id-123'
);
});

it('should default shop-id to an empty value when getShopId returns null', async () => {
mockGetShopId.mockResolvedValue(null);
const result = await addPaymentIframe(container, baseUrl, options);

expect(mockGetShopId).toHaveBeenCalledTimes(1);
expect(result.iframeEl.src.endsWith('&shop-id=')).toBe(true);
});

it('should append iframe to the provided element', async () => {
const result = await addPaymentIframe(container, baseUrl, options);

Expand Down
4 changes: 3 additions & 1 deletion packages/admin-sdk/src/_private/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export const addPaymentIframe = async (
shopUrl = options.shopUrl || '';
shopPlan = options.shopPlan || '';
}
const link = `${baseUrl}/payment?service-name=${name}&service-version=${version}&shop-url=${shopUrl}&sw-version=${options.swVersion}&sw-user-language=${options.swUserLanguage}&shop-plan=${shopPlan}`;

const shopId = await context.getShopId();
const link = `${baseUrl}/payment?service-name=${name}&service-version=${version}&shop-url=${shopUrl}&sw-version=${options.swVersion}&sw-user-language=${options.swUserLanguage}&shop-plan=${shopPlan}&shop-id=${shopId ?? ''}`;
const iframeEl = document.createElement('iframe');
iframeEl.width = '100%';
iframeEl.height = '100%';
Expand Down
Loading