-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1eddd14
commit e4bcb5b
Showing
7 changed files
with
255 additions
and
33 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.checkout.payments; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReverseRequest { | ||
|
||
private String reference; | ||
|
||
private Map<String, String> metadata; | ||
|
||
} |
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,19 @@ | ||
package com.checkout.payments; | ||
|
||
import com.checkout.common.Resource; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
@Data | ||
@EqualsAndHashCode(callSuper = true) | ||
@ToString(callSuper = true) | ||
public class ReverseResponse extends Resource { | ||
|
||
@SerializedName("action_id") | ||
private String actionId; | ||
|
||
private String reference; | ||
|
||
} |
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
80 changes: 80 additions & 0 deletions
80
src/test/java/com/checkout/payments/ReversePaymentsTestIT.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,80 @@ | ||
package com.checkout.payments; | ||
|
||
import com.checkout.payments.request.PaymentRequest; | ||
import com.checkout.payments.request.source.RequestCardSource; | ||
import com.checkout.payments.response.PaymentResponse; | ||
import com.checkout.payments.sender.PaymentCorporateSender; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.checkout.CardSourceHelper.getCardSourcePayment; | ||
import static com.checkout.CardSourceHelper.getCorporateSender; | ||
import static com.checkout.CardSourceHelper.getRequestCardSource; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class ReversePaymentsTestIT extends AbstractPaymentsTestIT { | ||
|
||
@Test | ||
void shouldReversePayment() { | ||
|
||
final RequestCardSource source = getRequestCardSource(); | ||
final PaymentCorporateSender sender = getCorporateSender(); | ||
final PaymentRequest request = getCardSourcePayment(source, sender, false); | ||
|
||
// payment | ||
final PaymentResponse paymentResponse = makeCardPayment(request); | ||
assertNotNull(paymentResponse.getLink("capture")); | ||
|
||
final String reference = UUID.randomUUID().toString(); | ||
|
||
// reverse | ||
final ReverseRequest reverseRequest = ReverseRequest.builder() | ||
.reference(reference) | ||
.build(); | ||
|
||
final ReverseResponse reverseResponse = blocking(() -> paymentsClient.reversePayment(paymentResponse.getId(), reverseRequest)); | ||
|
||
assertNotNull(reverseResponse); | ||
assertNotNull(reverseResponse.getReference()); | ||
assertEquals(reference, reverseResponse.getReference()); | ||
|
||
} | ||
|
||
@Test | ||
void shouldReversePayment_idempotencyKey() { | ||
|
||
final RequestCardSource source = getRequestCardSource(); | ||
final PaymentCorporateSender sender = getCorporateSender(); | ||
final PaymentRequest request = getCardSourcePayment(source, sender, false); | ||
|
||
// payment | ||
final PaymentResponse paymentResponse = makeCardPayment(request); | ||
assertNotNull(paymentResponse.getLink("capture")); | ||
|
||
final String reference = UUID.randomUUID().toString(); | ||
final String idempotencyKey = UUID.randomUUID().toString(); | ||
|
||
// reverse | ||
final ReverseRequest reverseRequest = ReverseRequest.builder() | ||
.reference(reference) | ||
.build(); | ||
|
||
final ReverseResponse reverseResponse = blocking(() -> paymentsClient.reversePayment(paymentResponse.getId(), reverseRequest, idempotencyKey)); | ||
|
||
assertNotNull(reverseResponse); | ||
assertNotNull(reverseResponse.getReference()); | ||
assertEquals(reference, reverseResponse.getReference()); | ||
|
||
final ReverseResponse reverseResponse_2 = blocking(() -> paymentsClient.reversePayment(paymentResponse.getId(), reverseRequest, idempotencyKey)); | ||
|
||
assertNotNull(reverseResponse_2); | ||
assertNotNull(reverseResponse_2.getReference()); | ||
assertEquals(reference, reverseResponse_2.getReference()); | ||
|
||
assertEquals(reverseResponse.getActionId(), reverseResponse_2.getActionId()); | ||
|
||
} | ||
|
||
} |