-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 결제를 확인하는 로직과 결과를 갱신하는 로직을 분리한다.
- Loading branch information
1 parent
31880d8
commit 9433655
Showing
5 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/com/clova/anifriends/domain/payment/repository/PaymentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
package com.clova.anifriends.domain.payment.repository; | ||
|
||
import com.clova.anifriends.domain.payment.Payment; | ||
import com.clova.anifriends.domain.payment.vo.PaymentStatus; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public interface PaymentRepository extends JpaRepository<Payment, Long> { | ||
|
||
Optional<Payment> findByOrderId(String orderId); | ||
|
||
@Modifying | ||
@Transactional | ||
@Query("update Payment p set p.status = :status where p.paymentId = :paymentId") | ||
void updatePaymentStatus( | ||
@Param("paymentId") Long paymentId, | ||
@Param("status") PaymentStatus status | ||
); | ||
|
||
@Modifying | ||
@Transactional | ||
@Query("update Payment p set p.paymentKey = :paymentKey, p.status = :status where p.paymentId = :paymentId") | ||
void updatePaymentKeyAndStatus( | ||
@Param("paymentId") Long paymentId, | ||
@Param("paymentKey") String paymentKey, | ||
@Param("status") PaymentStatus status | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/clova/anifriends/domain/payment/repository/PaymentRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.clova.anifriends.domain.payment.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.clova.anifriends.base.BaseRepositoryTest; | ||
import com.clova.anifriends.domain.donation.Donation; | ||
import com.clova.anifriends.domain.donation.support.fixture.DonationFixture; | ||
import com.clova.anifriends.domain.payment.Payment; | ||
import com.clova.anifriends.domain.payment.vo.PaymentStatus; | ||
import com.clova.anifriends.domain.shelter.Shelter; | ||
import com.clova.anifriends.domain.shelter.support.ShelterFixture; | ||
import com.clova.anifriends.domain.volunteer.Volunteer; | ||
import com.clova.anifriends.domain.volunteer.support.VolunteerFixture; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class PaymentRepositoryTest extends BaseRepositoryTest { | ||
|
||
@Nested | ||
@DisplayName("updatePaymentStatus 실행 시") | ||
class UpdatePaymentStatusTest { | ||
|
||
@Test | ||
@DisplayName("성공") | ||
void updatePaymentStatus() { | ||
// given | ||
Shelter shelter = ShelterFixture.shelter(); | ||
Volunteer volunteer = VolunteerFixture.volunteer(); | ||
Donation donation = DonationFixture.donation(shelter, volunteer); | ||
Payment payment = new Payment(donation); | ||
|
||
shelterRepository.save(shelter); | ||
volunteerRepository.save(volunteer); | ||
paymentRepository.save(payment); | ||
|
||
// when | ||
paymentRepository.updatePaymentStatus(payment.getPaymentId(), PaymentStatus.ABORTED); | ||
|
||
// then | ||
entityManager.flush(); | ||
entityManager.clear(); | ||
|
||
Payment updatedPayment = paymentRepository.findById(payment.getPaymentId()).get(); | ||
assertThat(updatedPayment.getStatus()).isEqualTo(PaymentStatus.ABORTED); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters