Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add challenges to payout model #281

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import java.time.LocalDate;

import lombok.Data;
import lombok.EqualsAndHashCode;

import com.mx.path.model.mdx.model.MdxBase;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.challenges.Challenge;

@Data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lombok makes java POJOs so much cleaner!

@EqualsAndHashCode(callSuper = true)
public final class Payout extends MdxBase<Payout> {

private String accountId;
private Double amount;
private MdxList<Challenge> challenges;
private String confirmationId;
private LocalDate expiresOn;
private Double fee;
Expand All @@ -29,188 +36,4 @@ public final class Payout extends MdxBase<Payout> {
private String type;
private String challengeQuestion;
private String challengeAnswer;

public String getAccountId() {
return accountId;
}

public void setAccountId(String newAccountId) {
this.accountId = newAccountId;
}

public Double getAmount() {
return amount;
}

public void setAmount(Double newAmount) {
this.amount = newAmount;
}

public String getConfirmationId() {
return confirmationId;
}

public void setConfirmationId(String newConfirmationId) {
this.confirmationId = newConfirmationId;
}

public LocalDate getExpiresOn() {
return expiresOn;
}

public void setExpiresOn(LocalDate newExpiresOn) {
this.expiresOn = newExpiresOn;
}

public Double getFee() {
return fee;
}

public void setFee(Double newFee) {
this.fee = newFee;
}

public String getId() {
return id;
}

public void setId(String newId) {
this.id = newId;
}

public String getMemo() {
return memo;
}

public void setMemo(String newMemo) {
this.memo = newMemo;
}

public String getNameCheckWarningTitle() {
return nameCheckWarningTitle;
}

public void setNameCheckWarningTitle(String newNameCheckWarningTitle) {
this.nameCheckWarningTitle = newNameCheckWarningTitle;
}

public String getNameCheckWarningText() {
return nameCheckWarningText;
}

public void setNameCheckWarningText(String newNameCheckWarningText) {
this.nameCheckWarningText = newNameCheckWarningText;
}

public String getPayoutMethodId() {
return payoutMethodId;
}

public void setPayoutMethodId(String payoutMethodId) {
this.payoutMethodId = payoutMethodId;
}

public String getPayoutRequestId() {
return payoutRequestId;
}

public void setPayoutRequestId(String newPayoutrequestId) {
this.payoutRequestId = newPayoutrequestId;
}

public String getRecipientId() {
return recipientId;
}

public void setRecipientId(String recipientId) {
this.recipientId = recipientId;
}

public String getRecurringPayoutId() {
return recurringPayoutId;
}

public void setRecurringPayoutId(String newRecurringPayoutId) {
this.recurringPayoutId = newRecurringPayoutId;
}

public String getStatus() {
return status;
}

public void setStatus(String newStatus) {
this.status = newStatus;
}

public String getSenderName() {
return senderName;
}

public void setSenderName(String newSenderName) {
this.senderName = newSenderName;
}

public LocalDate getSendOn() {
return sendOn;
}

public void setSendOn(LocalDate newSentOnAt) {
this.sendOn = newSentOnAt;
}

public Long getSentAt() {
return sentAt;
}

public void setSentAt(Long newSentAt) {
this.sentAt = newSentAt;
}

public LocalDate getSentOn() {
return sentOn;
}

public void setSentOn(LocalDate newSentOn) {
this.sentOn = newSentOn;
}

public String getSpeedText() {
return speedText;
}

public void setSpeedText(String newSpeedText) {
this.speedText = newSpeedText;
}

public String getToken() {
return token;
}

public void setToken(String newToken) {
this.token = newToken;
}

public String getType() {
return type;
}

public void setType(String newType) {
this.type = newType;
}

public String getChallengeQuestion() {
return challengeQuestion;
}

public void setChallengeQuestion(String challengeQuestion) {
this.challengeQuestion = challengeQuestion;
}

public String getChallengeAnswer() {
return challengeAnswer;
}

public void setChallengeAnswer(String challengeAnswer) {
this.challengeAnswer = challengeAnswer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public final ResponseEntity<MdxList<Account>> listPayoutFromAccounts() {
@RequestMapping(value = "/payouts", method = RequestMethod.POST, consumes = BaseController.MDX_MEDIA)
public final ResponseEntity<Payout> createPayout(@RequestBody Payout payoutRequest) {
AccessorResponse<Payout> response = gateway().payouts().create(payoutRequest);
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);

// Return 202 returning challenge questions
Payout result = response.getResult();
HttpStatus status = HttpStatus.OK;
if (result.getChallenges() != null && !result.getChallenges().isEmpty()) {
status = HttpStatus.ACCEPTED;
}
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
}

@RequestMapping(value = "/payouts/{id}/cancel", method = RequestMethod.PUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mx.path.gateway.api.payout.PayoutMethodGateway
import com.mx.path.gateway.api.payout.RecipientGateway
import com.mx.path.model.mdx.model.MdxList
import com.mx.path.model.mdx.model.account.Account
import com.mx.path.model.mdx.model.challenges.Challenge
import com.mx.path.model.mdx.model.payout.Payout
import com.mx.path.model.mdx.model.payout.PayoutMethod
import com.mx.path.model.mdx.model.payout.Recipient
Expand Down Expand Up @@ -74,6 +75,27 @@ class PayoutsControllerTest extends Specification implements WithMockery {
response.getBody() == payout
}

def "CreatePayout with challenges"() {
given:
BaseController.setGateway(gateway)

def payout = new Payout().tap {
setChallenges(new MdxList<Challenge>().tap {
add(new Challenge())
})
}

Mockito.doReturn(new AccessorResponse<Payout>().withResult(payout)).when(payoutGateway).create(payout)

when:
def response = subject.createPayout(payout)

then:
verify(payoutGateway).create(payout) || true
response.statusCode == HttpStatus.ACCEPTED
response.body == payout
}

def "CancelPayout interacts with gateway"() {
given:
BaseController.setGateway(gateway)
Expand Down