Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support payone iDeal payment method (#974)
Co-authored-by: Silke <s.grueber@intershop.de>
- Loading branch information
Showing
6 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,60 @@ | ||
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, map } from 'rxjs'; | ||
|
||
import { PaymentMethodBaseData, PaymentMethodData } from 'ish-core/models/payment-method/payment-method.interface'; | ||
|
||
@Injectable() | ||
export class PaymentPayoneInterceptor implements HttpInterceptor { | ||
/** | ||
* Map eligible payment method data for specified payone payment methods | ||
* | ||
* @param body : The response body | ||
* @returns The mapped response body | ||
*/ | ||
private mapEligiblePaymentMethods(body: PaymentMethodData): PaymentMethodData { | ||
if (body.data?.length) { | ||
return { | ||
...body, | ||
data: body.data.map(paymentMethod => | ||
paymentMethod.serviceID === 'Payone_IDeal' ? this.mapPayoneIDealParameters(paymentMethod) : paymentMethod | ||
), | ||
}; | ||
} | ||
|
||
return body; | ||
} | ||
|
||
/** | ||
* Map Payone Ideal Bank group options, provide an error message key for the required validator | ||
* This workaround will be obsolete if the REST api comply with the correct data format | ||
* | ||
* @param paymentMethod The iDeal payment method data | ||
* @returns The mapped payment method data | ||
*/ | ||
private mapPayoneIDealParameters(paymentMethod: PaymentMethodBaseData): PaymentMethodBaseData { | ||
const options = paymentMethod.hostedPaymentPageParameters?.map(param => { | ||
return { displayName: param.value, id: param.name }; | ||
}); | ||
|
||
const parameterDefinitions = paymentMethod.parameterDefinitions?.map(data => { | ||
const constraints = data.constraints.required | ||
? { ...data.constraints, required: { message: 'checkout.bankGroup.error.required' } } | ||
: data.constraints; | ||
return data.name === 'bankGroupCode' ? { ...data, constraints, options } : data; | ||
}); | ||
|
||
return { ...paymentMethod, parameterDefinitions }; | ||
} | ||
|
||
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { | ||
return next.handle(req).pipe( | ||
map(event => { | ||
if (event instanceof HttpResponse && event.url.includes('/eligible-payment-methods')) { | ||
return event.clone({ body: this.mapEligiblePaymentMethods(event.body) }); | ||
} | ||
return event; | ||
}) | ||
); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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