-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EWT-78] Add payment refunds support (#201)
- Loading branch information
1 parent
8aa282f
commit f84b438
Showing
21 changed files
with
637 additions
and
52 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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/truelayer/java/payments/entities/CreatePaymentRefundRequest.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,17 @@ | ||
package com.truelayer.java.payments.entities; | ||
|
||
import java.util.Map; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Builder | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public class CreatePaymentRefundRequest { | ||
private int amountInMinor; | ||
private String reference; | ||
private Map<String, String> metadata; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/truelayer/java/payments/entities/CreatePaymentRefundResponse.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,12 @@ | ||
package com.truelayer.java.payments.entities; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
public class CreatePaymentRefundResponse { | ||
private String id; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/truelayer/java/payments/entities/ListPaymentRefundsResponse.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,10 @@ | ||
package com.truelayer.java.payments.entities; | ||
|
||
import com.truelayer.java.payments.entities.paymentrefund.PaymentRefund; | ||
import java.util.List; | ||
import lombok.Value; | ||
|
||
@Value | ||
public class ListPaymentRefundsResponse { | ||
List<PaymentRefund> items; | ||
} |
10 changes: 10 additions & 0 deletions
10
...main/java/com/truelayer/java/payments/entities/paymentrefund/AuthorizedPaymentRefund.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,10 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class AuthorizedPaymentRefund extends PaymentRefund { | ||
Status status = Status.AUTHORIZED; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/truelayer/java/payments/entities/paymentrefund/ExecutedPaymentRefund.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,12 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import java.time.ZonedDateTime; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class ExecutedPaymentRefund extends PaymentRefund { | ||
Status status = Status.EXECUTED; | ||
ZonedDateTime executedAt; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/truelayer/java/payments/entities/paymentrefund/FailedPaymentRefund.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,13 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import java.time.ZonedDateTime; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class FailedPaymentRefund extends PaymentRefund { | ||
Status status = Status.FAILED; | ||
ZonedDateTime failedAt; | ||
String failureReason; | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/truelayer/java/payments/entities/paymentrefund/PaymentRefund.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,82 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.truelayer.java.TrueLayerException; | ||
import com.truelayer.java.entities.CurrencyCode; | ||
import java.time.ZonedDateTime; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "status", defaultImpl = PendingPaymentRefund.class) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = PendingPaymentRefund.class, name = "pending"), | ||
@JsonSubTypes.Type(value = AuthorizedPaymentRefund.class, name = "authorized"), | ||
@JsonSubTypes.Type(value = ExecutedPaymentRefund.class, name = "executed"), | ||
@JsonSubTypes.Type(value = FailedPaymentRefund.class, name = "failed"), | ||
}) | ||
@Getter | ||
public abstract class PaymentRefund { | ||
private String id; | ||
private int amountInMinor; | ||
private CurrencyCode currency; | ||
private String reference; | ||
private Map<String, String> metadata; | ||
private ZonedDateTime createdAt; | ||
|
||
@JsonIgnore | ||
public abstract Status getStatus(); | ||
|
||
@JsonIgnore | ||
public boolean isPending() { | ||
return this instanceof PendingPaymentRefund; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isAuthorized() { | ||
return this instanceof AuthorizedPaymentRefund; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isExecuted() { | ||
return this instanceof ExecutedPaymentRefund; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isFailed() { | ||
return this instanceof FailedPaymentRefund; | ||
} | ||
|
||
@JsonIgnore | ||
public PendingPaymentRefund asPendingPaymentRefund() { | ||
if (!isPending()) throw new TrueLayerException(buildErrorMessage()); | ||
|
||
return (PendingPaymentRefund) this; | ||
} | ||
|
||
@JsonIgnore | ||
public AuthorizedPaymentRefund asAuthorizedPaymentRefund() { | ||
if (!isAuthorized()) throw new TrueLayerException(buildErrorMessage()); | ||
|
||
return (AuthorizedPaymentRefund) this; | ||
} | ||
|
||
@JsonIgnore | ||
public ExecutedPaymentRefund asExecutedPaymentRefund() { | ||
if (!isExecuted()) throw new TrueLayerException(buildErrorMessage()); | ||
|
||
return (ExecutedPaymentRefund) this; | ||
} | ||
|
||
@JsonIgnore | ||
public FailedPaymentRefund asFailedPaymentRefund() { | ||
if (!isFailed()) throw new TrueLayerException(buildErrorMessage()); | ||
|
||
return (FailedPaymentRefund) this; | ||
} | ||
|
||
private String buildErrorMessage() { | ||
return String.format("Payment refund is of type %s.", this.getClass().getSimpleName()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/truelayer/java/payments/entities/paymentrefund/PendingPaymentRefund.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,10 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
|
||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class PendingPaymentRefund extends PaymentRefund { | ||
Status status = Status.PENDING; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/truelayer/java/payments/entities/paymentrefund/Status.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,17 @@ | ||
package com.truelayer.java.payments.entities.paymentrefund; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum Status { | ||
PENDING("pending"), | ||
AUTHORIZED("authorized"), | ||
EXECUTED("executed"), | ||
FAILED("failed"); | ||
|
||
@JsonValue | ||
private final String 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
Oops, something went wrong.