File

integration-libs/digital-payments/src/checkout/cms-components/dp-payment-method/dp-payment-callback/dp-payment-callback.component.ts

Implements

OnInit

Metadata

selector cx-dp-payment-callback
templateUrl ./dp-payment-callback.component.html

Index

Properties
Methods
Outputs

Constructor

constructor(dpPaymentService: DpCheckoutPaymentService, dpStorageService: DpLocalStorageService, globalMsgService: GlobalMessageService, route: ActivatedRoute)
Parameters :
Name Type Optional
dpPaymentService DpCheckoutPaymentService No
dpStorageService DpLocalStorageService No
globalMsgService GlobalMessageService No
route ActivatedRoute No

Outputs

closeCallback
Type : EventEmitter
paymentDetailsAdded
Type : EventEmitter

Methods

Private fetchPaymentDetails
fetchPaymentDetails()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

closeCallback
Default value : new EventEmitter<any>()
Decorators :
@Output()
paymentDetailsAdded
Default value : new EventEmitter<any>()
Decorators :
@Output()
import { DpLocalStorageService } from './../../../facade/dp-local-storage.service';
import { DP_CARD_REGISTRATION_STATUS } from '../../../../utils/dp-constants';
import { ActivatedRoute } from '@angular/router';
import { GlobalMessageService, GlobalMessageType } from '@spartacus/core';
import { DpCheckoutPaymentService } from '../../../facade';
import { Component, OnInit, EventEmitter, Output } from '@angular/core';

@Component({
  selector: 'cx-dp-payment-callback',
  templateUrl: './dp-payment-callback.component.html',
})
export class DpPaymentCallbackComponent implements OnInit {
  @Output()
  closeCallback = new EventEmitter<any>();
  @Output()
  paymentDetailsAdded = new EventEmitter<any>();

  constructor(
    protected dpPaymentService: DpCheckoutPaymentService,
    protected dpStorageService: DpLocalStorageService,
    protected globalMsgService: GlobalMessageService,
    protected route: ActivatedRoute
  ) {}

  ngOnInit(): void {
    const dpResponse = this.route.snapshot.queryParamMap.get(
      DP_CARD_REGISTRATION_STATUS
    );
    if (dpResponse?.toLowerCase() === 'successful') {
      this.fetchPaymentDetails();
    } else {
      this.globalMsgService.add(
        { key: 'dpPaymentForm.cancelledOrFailed' },
        GlobalMessageType.MSG_TYPE_WARNING
      );
      this.closeCallback.emit();
    }
  }

  private fetchPaymentDetails() {
    const paymentRequest = this.dpStorageService.readCardRegistrationState();

    if (paymentRequest?.sessionId && paymentRequest?.signature) {
      this.dpPaymentService
        .createPaymentDetails(
          paymentRequest.sessionId,
          paymentRequest.signature
        )
        .subscribe((details) => {
          if (details?.id) {
            this.paymentDetailsAdded.emit(details);
          } else if (details) {
            this.globalMsgService.add(
              { key: 'dpPaymentForm.error.paymentFetch' },
              GlobalMessageType.MSG_TYPE_ERROR
            );
            this.closeCallback.emit();
          }
        });
    } else {
      this.globalMsgService.add(
        { key: 'dpPaymentForm.error.unknown' },
        GlobalMessageType.MSG_TYPE_ERROR
      );
      this.closeCallback.emit();
    }
  }
}
<div class="text-center">{{ 'dpPaymentForm.callback' | cxTranslate }}</div>
<div class="cx-spinner"><cx-spinner></cx-spinner></div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""