# redirect 결제창 결과처리

{% hint style="warning" %}
**Deprecated**

이 문서는 더 이상 관리되지 않습니다.

[PortOne 개발자센터](https://developers.portone.io/)를 이용해주세요.
{% endhint %}

> 아래 예제 코드는 결제창 형태가 **새로운 페이지로 리디렉션되어** 결제가 진행되는 대부분의 **모바일 환경**에서의 결제요청애 대한 응답을 처리하는 부분입니다.

{% content-ref url="/pages/W3OJ0NVGMRzOSgEaBh84" %}
[리디렉션이란?](/docs/tip/redirect.md)
{% endcontent-ref %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
IMP.request_pay({
  /* 결제 요청 객체를 채워주세요. */
  m_redirect_url: "{리디렉션 될 URL}"
}, /* callback */); // 리디렉션 방식의 경우 callback은 실행되지 않습니다.
```

{% endtab %}
{% endtabs %}

위와 같이 **request\_pay** 함수 파라미터로 **m\_redirect\_url** 을 설정하면 <mark style="color:blue;">**결제 완료**</mark> 이후 해당 URL 주소로 결제 결과를 **쿼리스트링(Query String)** 형태로 전송해 드립니다.

{% hint style="info" %}
**Query String 이란?**

URL 뒤에 데이터를 전달하는 가장 단순한 방법으로 주로 GET 요청과 함께 데이터를 전송할 때 사용합니다.
{% endhint %}

결제 결과를 수신받을 endpoint url 주소를 m\_redirect\_url 에 설정하시면 결제결과 수신이 가능합니다.

아래 파라미터를 설정하신 URL 을 통해 Query String 형태로 수신받을수 있습니다.

아래는 Query String 으로 리디렉션되는 URL 예제입니다.

{% tabs %}
{% tab title="결제완료/가상계좌 발급완료" %}

```url
curl https://myservice.com/payments/complete?imp_uid=결제건을_특정하는_포트원_번호&merchant_uid=가맹점_고유_주문번호&imp_success=true
```

{% endtab %}

{% tab title="결제 실패" %}

```
curl https://myservice.com/payments/complete?imp_uid=결제건을_특정하는_포트원_번호&merchant_uid=가맹점_고유_주문번호&imp_success=false&error_code=에러_코드(현재_정리된_체계는_없음)&error_msg=에러_메시지
```

{% endtab %}
{% endtabs %}

|                    파라미터명                    |      설명     |  비고  |
| :-----------------------------------------: | :---------: | :--: |
|                 **imp\_uid**                | 포트원 결제 고유번호 |  공통  |
|              **merchant\_uid**              |   가맹점 주문번호  |  공통  |
|               **imp\_success**              |   결제 성공 여부  |  공통  |
| <mark style="color:red;">error\_code</mark> |    오류 코드    | 실패 시 |
|  <mark style="color:red;">error\_msg</mark> |    오류 메세지   | 실패 시 |

> <mark style="color:blue;">**결제 완료**</mark>**의 의미**
>
> `결제완료`는 아래의 모든 경우를 포함합니다.
>
> 1. **결제 성공**(결제 상태: `paid`, imp\_success: `true`)
> 2. **결제 실패**(결제 상태: `failed`, imp\_success: `false`)
> 3. PG 모듈 설정이 올바르지 않아, **결제 창이 열리지 않음**
> 4. 사용자가 임의로 X 버튼이나 취소 버튼을 눌러 **결제를 종료**함
> 5. 카드 정보 불일치, 한도 초과, 잔액 부족 등의 사유로 **결제가 중단**됨
> 6. 가상계좌 \*\*발급 완료(\*\*결제 상태: `ready`, imp\_success: `true`)

{% hint style="danger" %}
**결제창이 리디렉션되어 새로운 페이지에서 활성화되는 경우 결제 결과는 callback 으로 받을 수 없습니다.**
{% endhint %}

{% hint style="danger" %}
최종 결제결과 로직처리는 반드시 [<mark style="color:red;">**웹훅**</mark>](/docs/result/webhook.md)을 이용하여 안정적으로 처리해 주셔야 합니다.

웹훅연동을 생략하시는 경우 결제결과를 정상적으로 수신받지 못하는 상황이 발생합니다.
{% endhint %}

{% hint style="warning" %}
**imp\_success 파라미터**

<mark style="color:red;">`imp_success`</mark> 파라미터는 **결제 프로세스 정상 종료 여부**를 의미합니다. 하지만 클라이언트 상에서 자바스크립트 함수를 호출해서 결제창이 열리므로 **결제금액이 위변조 되었을 가능성**이 있기 때문에 **이 값으로 결제의 성공 여부를 판단해서는 안됩니다**. 결제의 성공 여부에 따라 아래와 같이 처리합니다.

* imp\_success = true: 결제 정보(imp\_uid, merchant\_uid)를 서버에 전달해서 결제금액의 위변조 여부를 검증한 후 최종적으로 결제 성공 여부를 판단해야 합니다.
* Imp\_success = false: 결제가 실패했음을 사용자에게 알립니다.

\* 일부 PG사에 한해 `imp_success`가 아닌 `success` 파라미터가 전달되거나 아예 전달되지 않는 경우(예: KG이니시스 - 실시간 계좌이체)도 있으니 주의하셔야 합니다.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://portone.gitbook.io/docs/auth/guide/4./redirect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
