Skip to content

Commit

Permalink
Merge pull request #105 from uphold/feature/add-transaction-commit-re…
Browse files Browse the repository at this point in the history
…quest-security-code

Add support for transaction commit request security code
  • Loading branch information
SandroMachado authored Feb 20, 2018
2 parents 3556030 + 667b28a commit 73f4f77
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,49 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
Assert.assertEquals(bodyOutput.toString(), "{\"beneficiary\":{\"address\":{\"city\":\"faz\",\"country\":\"fez\",\"line1\":\"fiz\",\"line2\":\"foz\",\"state\":\"fuz\",\"zipCode\":\"foobiz\"},\"name\":\"buz\",\"relationship\":\"fez\"},\"message\":\"foobar\"}");
}

@Test
public void commitWithMessageAndSecurityCodeShouldReturnTheTransaction() throws Exception {
ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream();
String responseString = "{ \"id\": \"foobar\" }";

MockRestAdapter<Transaction> adapter = new MockRestAdapter<>(responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
public Promise<Transaction> call(UpholdRestAdapter adapter) {
Transaction transaction = Fixtures.loadTransaction(new HashMap<String, String>() {{
put("transactionStatus", "pending");
put("originCardId", "foo");
put("transactionId", "bar");
}});

transaction.setUpholdRestAdapter(adapter);

return transaction.commit(new TransactionCommitRequest("foobar", "foo"));
}
});

Header otpHeader = null;
Request request = adapter.getRequest();
Transaction transaction = adapter.getResult();

for (Header header : request.getHeaders()) {
if ("OTP-Token".equalsIgnoreCase(header.getName())) {
otpHeader = header;

break;
}
}

request.getBody().writeTo(bodyOutput);

Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/cards/foo/transactions/bar/commit", BuildConfig.API_SERVER_URL));
Assert.assertEquals(request.getMethod(), "POST");
Assert.assertNull(otpHeader);
Assert.assertEquals(transaction.getId(), "foobar");
Assert.assertEquals(bodyOutput.toString(), "{\"message\":\"foobar\",\"securityCode\":\"foo\"}");
}

@Test
public void commitWithOTPShouldReturnTheTransaction() throws Exception {
ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Promise<Transaction> call(UpholdRestAdapter upholdRestAdapter) {
UserCardService userCardService = adapter.getRestAdapter().create(UserCardService.class);
RetrofitPromise<Transaction> promise = new RetrofitPromise<>();

userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message"), "otp", promise);
userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message", "securityCode"), "otp", promise);

return promise;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public Promise<Transaction> commit(String otp, TransactionCommitRequest transact
}

if (transactionCommitRequest == null) {
transactionCommitRequest = new TransactionCommitRequest(null, null);
transactionCommitRequest = new TransactionCommitRequest((String) null);
}

userCardService.confirmTransaction(getCardIdPath(), this.getId(), transactionCommitRequest, otp, promise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class TransactionCommitRequest implements Serializable {

private final Beneficiary beneficiary;
private final String message;
private final String securityCode;

/**
* Constructor.
Expand All @@ -20,6 +21,7 @@ public class TransactionCommitRequest implements Serializable {
public TransactionCommitRequest(Beneficiary beneficiary) {
this.beneficiary = beneficiary;
this.message = null;
this.securityCode = null;
}

/**
Expand All @@ -31,6 +33,7 @@ public TransactionCommitRequest(Beneficiary beneficiary) {
public TransactionCommitRequest(String message) {
this.beneficiary = null;
this.message = message;
this.securityCode = null;
}

/**
Expand All @@ -43,6 +46,20 @@ public TransactionCommitRequest(String message) {
public TransactionCommitRequest(Beneficiary beneficiary, String message) {
this.beneficiary = beneficiary;
this.message = message;
this.securityCode = null;
}

/**
* Constructor.
*
* @param message The transaction message.
* @param securityCode The transaction security code.
*/

public TransactionCommitRequest(String message, String securityCode) {
this.beneficiary = null;
this.message = message;
this.securityCode = securityCode;
}

/**
Expand All @@ -65,4 +82,14 @@ public String getMessage() {
return message;
}

/**
* Gets the transaction security code.
*
* @return the transaction security code.
*/

public String getSecurityCode() {
return securityCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public void shouldBeSerializableTransactionCommitRequestWithBeneficiaryAndMessag
Assert.assertEquals(transactionCommitRequest.getBeneficiary().getRelationship(), deserializedTransactionCommitRequestTest.getBeneficiary().getRelationship());
}

@Test
public void shouldBeSerializableTransactionCommitRequestWithMessageAndSecurityCode() {
TransactionCommitRequest transactionCommitRequest = new TransactionCommitRequest("foo", "bar");
byte[] serializedTransactionCommitRequestTest = SerializationUtils.serialize(transactionCommitRequest);
TransactionCommitRequest deserializedTransactionCommitRequestTest = SerializationUtils.deserialize(serializedTransactionCommitRequestTest);

Assert.assertEquals(transactionCommitRequest.getMessage(), deserializedTransactionCommitRequestTest.getMessage());
Assert.assertEquals(transactionCommitRequest.getSecurityCode(), deserializedTransactionCommitRequestTest.getSecurityCode());
}

}

0 comments on commit 73f4f77

Please sign in to comment.