Skip to content

Commit e646a8f

Browse files
authored
Merge pull request #19 from akreisman-epam/master
Added transfers and paypal accounts endpoints
2 parents f37d284 + f4da864 commit e646a8f

26 files changed

+1942
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
0.3.0 (in progress)
55
-------------------
66

7+
- Added PayPal endpoint
8+
- Added Transfer endpoint
79
- Added Payment Status Transitions endpoint
810
- Added Update Prepaid Card endpoint
911
- Added Paper Checks endpoint

src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,178 @@ public HyperwalletList<HyperwalletStatusTransition> listPaperCheckStatusTransiti
813813
});
814814
}
815815

816+
//--------------------------------------
817+
// Transfers
818+
//--------------------------------------
819+
820+
/**
821+
* Create Transfer Request
822+
*
823+
* @param transfer HyperwalletTransfer object to create
824+
* @return HyperwalletTransfer Transfer object created
825+
*/
826+
public HyperwalletTransfer createTransfer(HyperwalletTransfer transfer) {
827+
if (transfer == null) {
828+
throw new HyperwalletException("Transfer is required");
829+
}
830+
if (StringUtils.isEmpty(transfer.getSourceToken())) {
831+
throw new HyperwalletException("Source token is required");
832+
}
833+
if (StringUtils.isEmpty(transfer.getDestinationToken())) {
834+
throw new HyperwalletException("Destination token is required");
835+
}
836+
if (StringUtils.isEmpty(transfer.getClientTransferId())) {
837+
throw new HyperwalletException("ClientTransferId is required");
838+
}
839+
transfer = copy(transfer);
840+
transfer.setStatus(null);
841+
transfer.setCreatedOn(null);
842+
transfer.setExpiresOn(null);
843+
return apiClient.post(url + "/transfers", transfer, HyperwalletTransfer.class);
844+
}
845+
846+
/**
847+
* Get Transfer Request
848+
*
849+
* @param transferToken Transfer token assigned
850+
* @return HyperwalletTransfer Transfer
851+
*/
852+
public HyperwalletTransfer getTransfer(String transferToken) {
853+
if (StringUtils.isEmpty(transferToken)) {
854+
throw new HyperwalletException("Transfer token is required");
855+
}
856+
return apiClient.get(url + "/transfers/" + transferToken, HyperwalletTransfer.class);
857+
}
858+
859+
/**
860+
* List Transfer Requests
861+
*
862+
* @param options List filter option
863+
* @return HyperwalletList of HyperwalletTransfer
864+
*/
865+
public HyperwalletList<HyperwalletTransfer> listTransfers(HyperwalletTransferListOptions options) {
866+
String url = paginate(this.url + "/transfers", options);
867+
if (options != null) {
868+
url = addParameter(url, "sourceToken", options.getSourceToken());
869+
url = addParameter(url, "destinationToken", options.getDestinationToken());
870+
}
871+
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletTransfer>>() {
872+
});
873+
}
874+
875+
/**
876+
* List Transfer Requests
877+
*
878+
* @return HyperwalletList of HyperwalletTransfer
879+
*/
880+
public HyperwalletList<HyperwalletTransfer> listTransfers() {
881+
return listTransfers(null);
882+
}
883+
884+
/**
885+
* Create Transfer Status Transition
886+
*
887+
* @param transferToken Transfer token assigned
888+
* @return HyperwalletStatusTransition new status for Transfer Request
889+
*/
890+
public HyperwalletStatusTransition createTransferStatusTransition(String transferToken, HyperwalletStatusTransition transition) {
891+
if (transition == null) {
892+
throw new HyperwalletException("Transition is required");
893+
}
894+
if (StringUtils.isEmpty(transferToken)) {
895+
throw new HyperwalletException("Transfer token is required");
896+
}
897+
if (!StringUtils.isEmpty(transition.getToken())) {
898+
throw new HyperwalletException("Status Transition token may not be present");
899+
}
900+
transition = copy(transition);
901+
transition.setCreatedOn(null);
902+
transition.setFromStatus(null);
903+
transition.setToStatus(null);
904+
return apiClient.post(url + "/transfers/" + transferToken + "/status-transitions", transition, HyperwalletStatusTransition.class);
905+
}
906+
907+
//--------------------------------------
908+
// PayPal Accounts
909+
//--------------------------------------
910+
911+
/**
912+
* Create PayPal Account Request
913+
*
914+
* @param payPalAccount HyperwalletPayPalAccount object to create
915+
* @return HyperwalletPayPalAccount created PayPal account for the specified user
916+
*/
917+
public HyperwalletPayPalAccount createPayPalAccount(HyperwalletPayPalAccount payPalAccount) {
918+
if (payPalAccount == null) {
919+
throw new HyperwalletException("PayPal Account is required");
920+
}
921+
if (StringUtils.isEmpty(payPalAccount.getUserToken())) {
922+
throw new HyperwalletException("User token is required");
923+
}
924+
if (StringUtils.isEmpty(payPalAccount.getTransferMethodCountry())) {
925+
throw new HyperwalletException("Transfer Method Country is required");
926+
}
927+
if (StringUtils.isEmpty(payPalAccount.getTransferMethodCurrency())) {
928+
throw new HyperwalletException("Transfer Method Currency is required");
929+
}
930+
if (StringUtils.isEmpty(payPalAccount.getEmail())) {
931+
throw new HyperwalletException("Email is required");
932+
}
933+
if (!StringUtils.isEmpty(payPalAccount.getToken())) {
934+
throw new HyperwalletException("PayPal Account token may not be present");
935+
}
936+
if (payPalAccount.getType() == null) {
937+
payPalAccount.setType(HyperwalletTransferMethod.Type.PAYPAL_ACCOUNT);
938+
}
939+
payPalAccount = copy(payPalAccount);
940+
payPalAccount.setStatus(null);
941+
payPalAccount.setCreatedOn(null);
942+
return apiClient.post(url + "/users/" + payPalAccount.getUserToken() + "/paypal-accounts", payPalAccount, HyperwalletPayPalAccount.class);
943+
}
944+
945+
/**
946+
* Get PayPal Account Request
947+
*
948+
* @param userToken User token assigned
949+
* @param payPalAccountToken PayPal Account token assigned
950+
* @return HyperwalletPayPalAccount PayPal Account
951+
*/
952+
public HyperwalletPayPalAccount getPayPalAccount(String userToken, String payPalAccountToken) {
953+
if (StringUtils.isEmpty(userToken)) {
954+
throw new HyperwalletException("User token is required");
955+
}
956+
if (StringUtils.isEmpty(payPalAccountToken)) {
957+
throw new HyperwalletException("PayPal Account token is required");
958+
}
959+
return apiClient.get(url + "/users/" + userToken + "/paypal-accounts/" + payPalAccountToken, HyperwalletPayPalAccount.class);
960+
}
961+
962+
/**
963+
* List PayPal Accounts
964+
*
965+
* @param userToken User token assigned
966+
* @param options List filter option
967+
* @return HyperwalletList of HyperwalletPayPalAccount
968+
*/
969+
public HyperwalletList<HyperwalletPayPalAccount> listPayPalAccounts(String userToken, HyperwalletPaginationOptions options) {
970+
if (StringUtils.isEmpty(userToken)) {
971+
throw new HyperwalletException("User token is required");
972+
}
973+
String url = paginate(this.url + "/users/" + userToken + "/paypal-accounts", options);
974+
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletPayPalAccount>>() {
975+
});
976+
}
977+
978+
/**
979+
* List PayPal Accounts
980+
*
981+
* @param userToken User token assigned
982+
* @return HyperwalletList of HyperwalletPayPalAccount
983+
*/
984+
public HyperwalletList<HyperwalletPayPalAccount> listPayPalAccounts(String userToken) {
985+
return listPayPalAccounts(userToken, null);
986+
}
987+
816988
//--------------------------------------
817989
// Bank Accounts
818990
//--------------------------------------
@@ -1595,4 +1767,14 @@ private HyperwalletTransferMethod copy(HyperwalletTransferMethod transferMethod)
15951767
return transferMethod;
15961768
}
15971769

1770+
private HyperwalletTransfer copy(HyperwalletTransfer transfer) {
1771+
transfer = HyperwalletJsonUtil.fromJson(HyperwalletJsonUtil.toJson(transfer), HyperwalletTransfer.class);
1772+
return transfer;
1773+
}
1774+
1775+
private HyperwalletPayPalAccount copy(HyperwalletPayPalAccount payPalAccount) {
1776+
payPalAccount = HyperwalletJsonUtil.fromJson(HyperwalletJsonUtil.toJson(payPalAccount), HyperwalletPayPalAccount.class);
1777+
return payPalAccount;
1778+
}
1779+
15981780
}

0 commit comments

Comments
 (0)