curl --request POST \
--url https://meterengine.com/v1/payment-attempts/{id}/cancellations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"reason": "<string>",
"amount": 123
}
'const url = 'https://meterengine.com/v1/payment-attempts/{id}/cancellations';
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({reason: '<string>', amount: 123})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));{
"amount": 123,
"completed_at": "2023-11-07T05:31:56Z",
"failure_code": "<string>",
"failure_message": "<string>",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"mode": "test",
"payment_attempt_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"reason": "<string>",
"requested_at": "2023-11-07T05:31:56Z",
"status": "pending"
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}결제 취소 요청
done인 결제 시도의 금액 전부나 일부를 토스페이먼츠에 취소 요청한다. amount를 빼면 남은 결제 금액 전부를 취소한다. 남은 결제 금액은 시도 금액에서 done인 취소의 합을 뺀 값이다. 시도의 결제 모드 키로 토스페이먼츠를 부른다. 취소되면 status=done, 거절되면 status=failed와 failure_code, failure_message가 남고 둘 다 201이다. 토스페이먼츠 응답으로 결과를 확인하지 못하면 status=pending인 취소를 201로 돌려준다. 시도 하나에 pending인 취소는 하나뿐이다. 있으면 409다. API 키의 모드가 취소 대상과 다르면 409다. Idempotency-Key를 주면 같은 도입사와 환경의 같은 요청을 다시 보내도 그 취소를 지금 상태로 201로 돌려준다. 같은 키로 다른 시도, 금액, 사유를 보내면 409다. 이 키는 고객과 미터 등록의 Idempotency-Key와 계약이 다르다. UUID만 받고, 충돌 code는 payment_cancellation_idempotency_conflict이며, 다시 돌려준 응답에 Idempotency-Replayed 헤더를 붙이지 않는다. requested_at과 completed_at은 KST(+09:00)로 나온다.
curl --request POST \
--url https://meterengine.com/v1/payment-attempts/{id}/cancellations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"reason": "<string>",
"amount": 123
}
'const url = 'https://meterengine.com/v1/payment-attempts/{id}/cancellations';
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({reason: '<string>', amount: 123})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error(err));{
"amount": 123,
"completed_at": "2023-11-07T05:31:56Z",
"failure_code": "<string>",
"failure_message": "<string>",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"mode": "test",
"payment_attempt_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"reason": "<string>",
"requested_at": "2023-11-07T05:31:56Z",
"status": "pending"
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}{
"code": "validation_error",
"message": "서버 내부 오류입니다",
"errors": [
{
"field": "event_type",
"message": "공백일 수 없습니다"
}
]
}인증
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
헤더
취소 요청마다 발급한 UUID. 응답을 받지 못해 다시 요청할 때는 같은 값을 보낸다.
경로 매개변수
취소할 결제 시도의 id.
본문
응답
결제 취소. status는 done, failed, pending 중 하나
취소한 금액. 원 단위 정수
failed일 때만 있다. 토스페이먼츠가 준 값: 취소 거절 코드(예: NOT_CANCELABLE_AMOUNT). MeterEngine이 정한 값: HTTP_<상태>(토스페이먼츠 거절 응답에 코드가 없을 때 그 HTTP 상태), NOT_FOUND_CANCELLATION(취소를 요청하고 payment.not-found-failure-delay(기본 10분)가 지나도 토스페이먼츠 결제 조회에 이 취소에 맞는 취소 거래가 없을 때. 토스페이먼츠 코드가 아니다), toss_payments_credential_missing(토스페이먼츠를 부르기 전에 결제 모드의 키가 없었다).
failed일 때만 있다. 토스페이먼츠가 준 거절 문구이거나, failure_code가 MeterEngine 코드면 그 오류 문구다
취소한 결제 시도의 결제 모드. test 또는 live
test, live 취소 사유
pending은 토스페이먼츠 결과를 아직 확인하지 못한 취소다
pending, done, failed