PAYONE-GmbH / checkout-demo

New to the PAYONE API? Start here!
MIT License
2 stars 3 forks source link

isCardTypeComplete = False & isCvcComplete = False #14

Open ck88ger opened 1 year ago

ck88ger commented 1 year ago

Hi,

ich see your checkout demo with the iframe solution and it works well if i start your project. If i adapt this to my own project i get this two values as FALSE so the check can not perform.

This is my Code:

TS FILE: `

export class HomeComponent implements AfterViewInit {

iframes: any;

_creditCardCheckResponse: any;

_supportedCardTypes: string[];

constructor() { this._supportedCardTypes = ['V', 'M'] }

ngAfterViewInit() { this.initPayone(); }

initPayone() {

const supportedCardtypes = ["V", "M"];
const config = {
  fields: {
    cardpan: {
      selector: "cardpan",
      style: "font-size: 14px; border: 1px solid #000;",
      type: "input"
    },
    cardcvc2: {
      selector: "cvc",
      type: "password",  // Could be "text" as well.
      style: "font-size: 14px; border: 1px solid #000;",
      size: "4",
      maxlength: "4",
      length: { "V": 3, "M": 3 } // enforce 3 digit CVC für VISA and Mastercard
    },
    cardexpiremonth: {
      selector: "cardexpirymonth",
      type: "text", // select (default), text, <span class="sp-highlight-term underline sp-cursor-pointer" style="background-color: rgb(255, 255, 255);">tel</span>
      size: "2",
      maxlength: "2",
      iframe: {
        width: "40px"
      },
      style: "font-size: 14px; width: 30px; border: solid 1px #000; height: 22px;"
    },
    cardexpireyear: {
      selector: "cardexpiryyear",
      type: "text", // select (default), text, <span class="sp-highlight-term underline sp-cursor-pointer" style="background-color: rgb(255, 255, 255);">tel</span>
      iframe: {
        width: "60px"
      },
      style: "font-size: 14px; width: 50px; border: solid 1px #000; height: 22px;"
    }
  },
  defaultStyle: {
    input: "font-size: 1em; border: 1px solid #000; width: 175px;",
    select: "font-size: 1em; border: 1px solid #000;",
    iframe: {
      height: "22px",
      width: "180px"
    }
  },

  autoCardtypeDetection: {
    supportedCardtypes: supportedCardtypes,
    callback: (detectedCardtype: any) => {

      // For the output container below.
      // @ts-ignore
      document.getElementById('autodetectionResponsePre').innerHTML = detectedCardtype;

      if (detectedCardtype === 'V') {
        // @ts-ignore
        document.getElementById('visa').style.borderColor = '#00F';
        // @ts-ignore
        document.getElementById('mastercard').style.borderColor = '#FFF';
      } else if (detectedCardtype === 'M') {
        // @ts-ignore
        document.getElementById('visa').style.borderColor = '#FFF';
        // @ts-ignore
        document.getElementById('mastercard').style.borderColor = '#00F';
      } else {
        // @ts-ignore
        document.getElementById('visa').style.borderColor = '#FFF';
        // @ts-ignore
        document.getElementById('mastercard').style.borderColor = '#FFF';
      }
    } //,
    // deactivate: true // To turn off automatic card type detection.
  },

  language: 'de', //, // Language to display error-messages (default: Payone.ClientApi.Language.en)
  error: "error" // area to display error-messages (optional)
};

const request = {
  'mid': ID,
  'portalid': ID,
  'aid': ID,
  'hash': this.generateJsHash(),
  'mode': 'test',
  'responsetype': 'JSON',
  'encoding': 'UTF-8',
  'request': 'creditcardcheck',
  'storecarddata': 'yes'
};

this.iframes = new Payone.ClientApi.HostedIFrames(config, request);

const cardTypesLine = document.querySelector('#checkoutCardTypesLine')
// @ts-ignore
cardTypesLine.innerHTML = this._supportedCardTypes.reduce((acc, type) => (
  acc + `<img class="payone-checkout__card ${type === 'V' ? 'payone-checkout__card-visa' : ''}" data-card-type="${type}" src="https://cdn.pay1.de/cc/${type.toLowerCase()}/s/transparent.png" alt="${type} card icon">`
), '')

}

onSubmit() { console.log("isCardTypeComplete", this.iframes.isCardTypeComplete()); console.log("isCardpanComplete", this.iframes.isCardpanComplete()); console.log("isCvcComplete", this.iframes.isCvcComplete()); console.log("isExpireMonthComplete", this.iframes.isExpireMonthComplete()); console.log("isExpireYearComplete", this.iframes.isExpireYearComplete()); console.log("check", this.iframes.isComplete()); if (this.iframes.isComplete()) { // Perform "CreditCardCheck" to create and get a PseudoCardPan; then call your function "payCallback" this.iframes.creditCardCheck('payCallback'); } else { alert("Not complete. Nothing done."); }

}

payCallback(response:any) {

console.debug(response);

}

public generateJsHash(): string { // logic to generate hash }

} `

My Html:

<form (submit)="onSubmit()">

The JSON received from the server

Nothing received yet.

Autodetection callback result

Nothing received yet.

The JSON received from the server

Nothing received yet.

Autodetection callback result

Nothing received yet.
Bildschirm­foto 2023-05-17 um 13 35 08
ck88ger commented 1 year ago

Solved it, the Cardtype field was missing... In your checkout example it was not included.