curl --request POST \
--url https://meterengine.com/v1/invoices/{id}/payment-attempts \
--header 'Authorization: Bearer <token>'const url = 'https://meterengine.com/v1/invoices/{id}/payment-attempts';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
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",
"invoice_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"mode": "test",
"payment_key": "<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": "공백일 수 없습니다"
}
]
}인보이스 결제 요청
인보이스의 total_amount를 그 고객의 등록 카드로 토스페이먼츠 자동결제 승인을 요청한다. 본문은 받지 않는다. 도입사의 현재 결제 모드(test 또는 live)의 토스페이먼츠 키와 그 모드로 등록한 카드를 쓴다. 승인되면 status=done과 payment_key, 거절되면 status=failed와 failure_code, failure_message가 남고 둘 다 201이다. 토스페이먼츠 응답으로 결과를 확인하지 못하면 status=pending인 시도를 201로 돌려준다. 결제 모드마다 인보이스 하나에 결제 중이거나 결제된 시도는 하나뿐이다. 이미 있으면 409다. requested_at과 completed_at은 KST(+09:00)로 나온다.
curl --request POST \
--url https://meterengine.com/v1/invoices/{id}/payment-attempts \
--header 'Authorization: Bearer <token>'const url = 'https://meterengine.com/v1/invoices/{id}/payment-attempts';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
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",
"invoice_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"mode": "test",
"payment_key": "<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.
헤더
test 모드에서만 받는다. 값을 그대로 토스페이먼츠에 넘겨 실패 응답을 재현한다. 빈 값은 보내지 않은 것으로 본다.
경로 매개변수
결제할 인보이스의 id.
응답
결제 시도. status는 done, failed, pending 중 하나
failed일 때만 있다. 토스페이먼츠가 준 값: 승인 거절 코드(예: REJECT_CARD_COMPANY), 또는 주문 조회로 확인한 결제 상태 ABORTED, EXPIRED. MeterEngine이 정한 값: HTTP_<상태>(토스페이먼츠 거절 응답에 코드가 없을 때 그 HTTP 상태), NOT_FOUND_PAYMENT(결제를 요청하고 payment.not-found-failure-delay(기본 10분)가 지나도 토스페이먼츠 주문 조회가 404 NOT_FOUND_PAYMENT일 때. 토스페이먼츠 조회 오류 코드와 이름이 같지만 결제 거절이 아니라 MeterEngine의 판정이다), toss_payments_credential_missing(토스페이먼츠를 부르기 전에 결제 모드의 키가 없었다), payment_method_missing(토스페이먼츠를 부르기 전에 결제 모드의 카드가 없었다).
failed일 때만 있다. 토스페이먼츠가 준 거절 문구이거나, failure_code가 MeterEngine 코드면 그 오류 문구다
결제한 결제 모드. test 또는 live
test, live 토스페이먼츠가 승인한 결제의 키. done일 때만 있다
pending은 토스페이먼츠 결과를 아직 확인하지 못한 시도다
pending, done, failed