🔦5. Verify payment information
Verify the payment information for secure payment service implementation.
STEP 01 Server receives payment result
app.use(bodyParser.json());
// "{Merchant endpoint that receives server's payment info}" POST request receiver
app.post("/payments/complete", async (req, res) => {
try {
// Get imp_uid, merchant_uid from req.body
const { imp_uid, merchant_uid } = req.body;
} catch (e) {
res.status(400).send(e);
}
});STEP 02 Get payment details
app.use(bodyParser.json());
...
app.post("/payments/complete", async (req, res) => {
try {
// Get imp_uid, merchant_uid from req.body
const { imp_uid, merchant_uid } = req.body;
...
// Get access token
const getToken = await axios({
url: "https://api.iamport.kr/users/getToken",
method: "post", // POST method
headers: { "Content-Type": "application/json" },
data: {
imp_key: "imp_apikey", // REST API key
imp_secret: "ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f" // REST API Secret
}
});
const { access_token } = getToken.data.response; // access token
...
// Get payment info from i'mport server using imp_uid
const getPaymentData = await axios({
// Pass imp_uid
url: \`https://api.iamport.kr/payments/\${imp_uid}\`,
// GET method
method: "get",
// Add access toke to Authorization header
headers: { "Authorization": access_token }
});
const paymentData = getPaymentData.data.response; // Payment info
...
} catch (e) {
res.status(400).send(e);
}
});STEP 03 Verify payment information
Last updated