class PaymentLedger (View source)

결제 레코드의 배타 접근과 저장을 전담하는 저장소.

결제 상태 계산은 하지 않으며, PaymentLifecycle이 계산한 값을 그대로 쓴다.

Methods

MorphMany
payments(Model $billable)

이 모델의 결제 목록 관계(최신순)를 반환한다.

Payment|null
find(Model $billable, string $paymentId)

Billable 범위 안에서 결제 1건을 찾는다.

withExclusiveAccess(Model $billable, string $paymentId, Closure $operation)

레코드를 잠그고 콜백을 실행한다. 범위를 벗어나면 예외가 발생한다.

withExclusiveAccessByPaymentId(string $paymentId, Closure $operation)

결제 ID만으로 레코드를 잠그고 콜백을 실행한다. 레코드가 없으면 예외가 발생한다.

void
withExclusiveAccessByReference(string $billableType, string $billableId, string $paymentId, Closure $operation)

Billable 참조(타입·키)로 범위를 정해 레코드를 잠그고 콜백을 실행한다.

Collection
stalePending(Carbon $createdBefore)

기준 시각보다 먼저 만들어진 PENDING 결제를 모든 Billable에 걸쳐 고른다.

update(Payment $payment, array $values)

미리 계산된 결과 값을 레코드에 그대로 쓴다. 증가분이 아닌 절대값이다.

createPending(Model $billable, string $customerId, int $amount, string $orderName)

PENDING 결제 레코드를 새로 만든다. payment_id 충돌 시 다시 시도한다.

Details

MorphMany payments(Model $billable)

이 모델의 결제 목록 관계(최신순)를 반환한다.

Parameters

Model $billable

조회할 Billable 모델

Return Value

MorphMany

생성일 내림차순 결제 관계

Payment|null find(Model $billable, string $paymentId)

Billable 범위 안에서 결제 1건을 찾는다.

Parameters

Model $billable

소유 Billable 모델

string $paymentId

PortOne 결제 식별자

Return Value

Payment|null

결제 레코드, 없으면 null

Payment withExclusiveAccess(Model $billable, string $paymentId, Closure $operation)

레코드를 잠그고 콜백을 실행한다. 범위를 벗어나면 예외가 발생한다.

Parameters

Model $billable

소유 Billable 모델

string $paymentId

PortOne 결제 식별자

Closure $operation

잠금 안에서 실행할 연산

Return Value

Payment

콜백이 반환한 결제 레코드

Exceptions

PaymentNotFoundException

Payment withExclusiveAccessByPaymentId(string $paymentId, Closure $operation)

결제 ID만으로 레코드를 잠그고 콜백을 실행한다. 레코드가 없으면 예외가 발생한다.

웹훅처럼 결제 ID만 아는 결제 완료(completeByPaymentId) 전용이다. 소유 Billable은 따지지 않는다.

Parameters

string $paymentId

PortOne 결제 식별자

Closure $operation

잠금 안에서 실행할 연산

Return Value

Payment

콜백이 반환한 결제 레코드

Exceptions

PaymentNotFoundException

void withExclusiveAccessByReference(string $billableType, string $billableId, string $paymentId, Closure $operation)

Billable 참조(타입·키)로 범위를 정해 레코드를 잠그고 콜백을 실행한다.

만료 잡 전용이다. 레코드가 없으면(이미 삭제됐거나 범위 밖) 아무것도 하지 않는다.

Parameters

string $billableType

소유 Billable 모델의 morph 타입

string $billableId

소유 Billable 모델의 키

string $paymentId

PortOne 결제 식별자

Closure $operation

잠금 안에서 실행할 연산

Return Value

void

Collection stalePending(Carbon $createdBefore)

기준 시각보다 먼저 만들어진 PENDING 결제를 모든 Billable에 걸쳐 고른다.

만료 명령 전용인 유일한 범위 밖 조회이며, 각 레코드의 Billable 참조와 결제 ID만 돌려준다.

Parameters

Carbon $createdBefore

이 시각보다 먼저 만들어진 레코드만 고른다

Return Value

Collection

billable_type·billable_id·payment_id만 채운 결제 레코드

Payment update(Payment $payment, array $values)

미리 계산된 결과 값을 레코드에 그대로 쓴다. 증가분이 아닌 절대값이다.

Parameters

Payment $payment

갱신할 결제 레코드

array $values

저장할 절대값

Return Value

Payment

갱신된 결제 레코드

Payment createPending(Model $billable, string $customerId, int $amount, string $orderName)

PENDING 결제 레코드를 새로 만든다. payment_id 충돌 시 다시 시도한다.

Parameters

Model $billable

결제를 소유할 Billable 모델

string $customerId

PortOne 고객 ID

int $amount

결제 금액(원)

string $orderName 주문명

Return Value

Payment

생성된 PENDING 결제 레코드