Skip to content

Commit

Permalink
feat: Support payment provider icons
Browse files Browse the repository at this point in the history
Closes: CXSPA-6402
  • Loading branch information
Matejk00 authored Nov 4, 2024
1 parent b0a5081 commit 4c84bc1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration-libs/opf/base/root/model/opf-base.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ActiveConfiguration {
providerType?: OpfPaymentProviderType;
displayName?: string;
acquirerCountryCode?: string;
logoUrl?: string;
}

export interface OpfDynamicScript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ <h3>
>
<div class="cx-payment-type">
{{ configuration.displayName }}
<img
*ngIf="configuration?.logoUrl"
[src]="configuration.logoUrl"
[alt]="configuration.displayName"
class="cx-payment-logo"
/>
</div>
</label>
<cx-opf-checkout-payment-wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
OpfPaymentProviderType,
} from '@spartacus/opf/base/root';

import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { OpfCheckoutTermsAndConditionsAlertModule } from '../opf-checkout-terms-and-conditions-alert';
import { OpfCheckoutPaymentsComponent } from './opf-checkout-payments.component';
Expand All @@ -29,6 +31,7 @@ const mockActiveConfigurations: ActiveConfiguration[] = [
id: 2,
providerType: OpfPaymentProviderType.PAYMENT_GATEWAY,
displayName: 'Test2',
logoUrl: 'logoUrl',
},
{
id: 3,
Expand Down Expand Up @@ -73,6 +76,7 @@ describe('OpfCheckoutPaymentsComponent', () => {
let fixture: ComponentFixture<OpfCheckoutPaymentsComponent>;
let globalMessageService: GlobalMessageService;
let opfMetadataStoreServiceMock: jasmine.SpyObj<OpfMetadataStoreService>;
let el: DebugElement;

beforeEach(async () => {
opfMetadataStoreServiceMock = jasmine.createSpyObj(
Expand Down Expand Up @@ -101,6 +105,7 @@ describe('OpfCheckoutPaymentsComponent', () => {

fixture = TestBed.createComponent(OpfCheckoutPaymentsComponent);
component = fixture.componentInstance;
el = fixture.debugElement;
});
beforeEach(() => {
globalMessageService = TestBed.inject(GlobalMessageService);
Expand Down Expand Up @@ -172,4 +177,34 @@ describe('OpfCheckoutPaymentsComponent', () => {

expect(component.selectedPaymentId).toBe(defaultSelectedPaymentOptionId);
});

it('should render payment provider logo', () => {
activeConfigurationsState$.next({
loading: false,
error: false,
data: mockActiveConfigurations,
});

fixture.detectChanges();

mockActiveConfigurations.forEach((configuration) => {
const logoElement = el.query(
By.css(
'label[for=paymentId-' + configuration.id + '] .cx-payment-logo'
)
);

if (configuration?.logoUrl) {
expect(logoElement).toBeTruthy();
expect(logoElement.nativeElement.attributes['alt'].value).toBe(
configuration.displayName
);
expect(logoElement.nativeElement.attributes['src'].value).toBe(
configuration.logoUrl
);
} else {
expect(logoElement).toBeFalsy();
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

input:disabled + .form-check-label {
color: var(--cx-color-medium);

.cx-payment-logo {
opacity: 0.3;
}
}

input[type='radio'] {
Expand All @@ -31,5 +35,10 @@
display: none;
}
}

.cx-payment-logo {
max-height: 30px;
margin: -2px 0 0 4px;
}
}
}

0 comments on commit 4c84bc1

Please sign in to comment.