title | description |
---|---|
Redirect method |
Process the payment result in a typical mobile environment using page redirection. |
import ContentRef from "/components/gitbook/ContentRef.astro";
import Swagger from "/components/gitbook/swagger/Swagger.astro";
import SwaggerDescription from "/components/gitbook/swagger/SwaggerDescription.astro";
import SwaggerParameter from "/components/gitbook/swagger/SwaggerParameter.astro";
import Tab from "/components/gitbook/tabs/Tab.astro";
import Tabs from "/components/gitbook/tabs/Tabs.astro";
import Hint from "~/components/Hint.astro";
```ts title="client-side" IMP.request_pay( { /* ...Omitted... */ m_redirect_url: "{redirect URL}", } /* callback */, ); // callback is not called ``` ```ts title="client-side" IMP.request_pay( { /* ...Omitted... */ m_redirect_url: "{redirect URL}", } /* callback */, ); // callback is not called ```The following sample code processes the response to a payment request in a typical mobile environment where the payment window is redirected to a new page to process the payment result.
If m_redirect_url is specified as the request_pay function parameter as above, the payment result is sent to the URL address in the form of a query string after payment is completed.
**What is a query string?**This is the simplest way to pass data by attaching it to the end of a URL, and it is mainly used when sending data in the GET method.
You can receive the following parameters through the specified URL as a query string. i'mport payment ID Merchant order ID Error code (upon payment failure only) Error message (upon payment failure only)The following is an example of a redirecting URL based on the query string.
```sh curl https://myservice.com/payments/complete?imp_uid=unique_iamport_paymentID&merchant_uid=unique_merchant_orderID&imp_success=true ``` ```sh curl https://myservice.com/payments/complete?imp_uid=unique_iamport_paymentID&merchant_uid=unique_merchant_orderID&imp_success=false&error_code=error_code(none_defined_currently)&error_msg=error_message ``` **If the payment window is redirected to a new page, you cannot receive the payment result via callback.** The final payment result logic processing must be handled stably by using a [**webhook**](../../../result/webhook). If you don't set up a webhook, you may fail to receive the payment result.**Note - imp\_success parameter**What does completion of the payment process mean?
The
payment process is complete
when:
Payment is successful (Status:
paid
, imp_success:true
)Payment fails (Status:
failed
, imp_success:false
)Payment window fails to open due to PG module setting error
User terminates the payment process by clicking the X or Cancel button
Payment is suspended due to invalid card information, limit exceeded, insufficient balance, etc.
Virtual account is issued (status:
ready
, imp_success:true
)
The imp_success
parameter indicates whether or not the payment process completed successfully.
However, since the payment page is opened by calling a JavaScript function from the client-side,
the payment amount can be forged by a malicious user.
Hence, this value should not be used to determine the success of the payment.
Depending on the value of imp_success
, determine the payment success as follows:
- imp_success = true: First send payment information (imp_uid, merchant_uid) to the server to verify the payment amount, and then finalize payment success.
- imp_success = false: Alert the user that the payment failed.
* Note that some PGs return a success
parameter instead of imp_success
, or return neither. (Example: KG INICIS - instant bank transfer)