개발자센터

popup 방식에서의 결과처리

windowType 파라미터에서 popup을 선택한 경우의 결과 처리 방법을 안내합니다.

PortOne.requestIdentityVerification() 함수의 반환 값을 이용해 결제 트랜잭션의 결과를 얻을 수 있습니다.

반환 값의 타입은 Promise 객체이므로 프로젝트 설정에 따라 적절한 방법으로 응답을 처리해주세요.

async function requestIdentityVerificationAndLogResult() {
  const response = await PortOne.requestIdentityVerification({ /* 객체 생략 */ });
  console.log(response); // 응답 객체가 개발자 도구 - 콘솔에 출력됩니다.
}
function requestIdentityVerificationAndLogResult() {
  PortOne.requestIdentityVerification({ /* 객체 생략 */ })
    .then(function (response) {
      console.log(response); // 응답 객체가 개발자 도구 - 콘솔에 출력됩니다.
    });
}

callback Data 전달 예제

아래 코드는 PortOne SDK로부터 전달된 response를 이용해 가맹점 서버 엔드포인트로 인증 결과를 요청하는 예시입니다.

인증 결과를 조회하는 엔드포인트를 서버에서 구현하셔야 하며, 이에 대한 예시는 아래 링크에서 확인하실 수 있습니다.

인증 결과 조회 API 구현하기

async function requestIdentityVerification() {
  const response = await PortOne.requestIdentityVerification({ /* 객체 생략 */ });
  // 프로세스가 제대로 완료되지 않은 경우 에러 코드가 존재합니다
  if (response.code != null) {
    return alert(response.message);
  }
 
  const verificationResult = await axios({
    url: "{서버의 인증 정보를 받는 endpoint}"
    method: "POST",
    body: {
      identityVerificationId: repsonse.identityVerificationId,
    },
  });
 
  // verificationResult 를 이용해 이후 로직을 작성하세요.
}
function requestIdentityVerification() {
  PortOne.requestIdentityVerification({ /* 객체 생략 */ })
    .then(function (response) {
      // 결제가 제대로 완료되지 않은 경우 에러 코드가 존재합니다
      if (response.code != null) {
        return alert(response.message);
      }
 
      axios({
        url: "{서버의 인증 정보를 받는 endpoint}"
        method: "POST",
        body: {
          identityVerificationId: response.identityVerificationId,
        },
      })
        .then(verificationResult => {
          // verificationResult 를 이용해 이후 로직을 작성하세요.
        })
    });
}