Skip to content

Commit

Permalink
HotFix
Browse files Browse the repository at this point in the history
  • Loading branch information
iwokonl committed May 20, 2024
1 parent 7398956 commit 1e2cf3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public ResponseEntity<PayoutBatch> createPayout(@RequestBody PayoutRequestPaypal
UserDto userDto = userService.getUserInfo().orElseThrow(() -> new AppExeption("User not found", HttpStatus.NOT_FOUND));


logger.error("Currency code: " +payoutRequestPaypalDto.currencyId());
logger.error("Currency code: " +String.valueOf(userDto.getId()));

paypalService.removeAmountToKantorAccount(payoutRequestPaypalDto.currencyId(), String.valueOf(userDto.getId()), payoutRequestPaypalDto.total());
Optional<CurrencyDto> currency = currencyClient.getCurrencyById(Long.valueOf(payoutRequestPaypalDto.currencyId()));

Expand All @@ -118,22 +117,28 @@ public ResponseEntity<PayoutBatch> createPayout(@RequestBody PayoutRequestPaypal
}

CurrencyDto currencyDto = currency.get();

logger.error("asdCurrency total: " +payoutRequestPaypalDto.total());
logger.error("asdCurrency code: " +currencyDto.getCode());
PayoutBatch payoutBatch = paypalService.createPayout(
payoutRequestPaypalDto.receiverEmail(),
payoutRequestPaypalDto.total(),
currencyDto.getCode()
);

ApiService apiService = new ApiService();
String json = apiService.callExternalApi(currencyDto.getCode());
JSONObject jsonObject = new JSONObject(json);
JSONObject ratesObject = jsonObject.getJSONArray("rates").getJSONObject(0);
double mid = ratesObject.getDouble("mid");
AddTransactionDto addTransactionDto = AddTransactionDto.builder()
.typeOfTransaction("PAYOUT")
.amountOfForeginCurrency(String.valueOf(payoutRequestPaypalDto.total()))
.ForeginCurrencyId(63L)
.ForeginCurrencyId(Long.valueOf(payoutRequestPaypalDto.currencyId()))
.targetCurrencyId(63L)
.targetCurrency(String.valueOf(payoutRequestPaypalDto.total()))
.appUserId(String.valueOf(userDto.getId()))

.exchangeRate(String.valueOf(mid))
.build();
logger.error("kkkckc123");
tranactionClient.addTranactionHistory(addTransactionDto);
return ResponseEntity.ok(payoutBatch);
} catch (AppExeption e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,29 @@ private Map<String, String> getPayPalSDKConfig() {
//TODO: Usunąc opłatę za przelew bo 2% ściąga z konta a tak być nie może
public PayoutBatch createPayout(String receiverEmail, Double total, String currency) {
PayoutSenderBatchHeader senderBatchHeader = new PayoutSenderBatchHeader();

logger.error("asdasdasdasdasdasdasdasdasdasdasdd1");
senderBatchHeader.setSenderBatchId(new Random().nextInt(99999) + "").setEmailSubject("You have a payment");
PayoutItem item = new PayoutItem();

item.setRecipientType("EMAIL").setAmount(new Currency(currency, String.format(Locale.US, "%.2f", total))).setReceiver(receiverEmail)
.setSenderItemId("item_" + new Random().nextInt(99999)).setNote("Thank you.");

logger.error("asdasdasdasdasdasdasdasdasdasdasdd2");
List<PayoutItem> items = new ArrayList<PayoutItem>();
items.add(item);

Payout payout = new Payout();

payout.setSenderBatchHeader(senderBatchHeader).setItems(items);
PayoutBatch response = null;

logger.error("asdasdasdasdasdasdasdasdasdasdasdd3");
try {
APIContext context = getAPIContext();
Map<String, String> configMap = new HashMap<>();
configMap.put("mode", mode);

logger.error("asdasdasdasdasdasdasdasdasdasdasdd3");
// Dodaj tutaj dodatkowe parametry konfiguracyjne, jeśli są potrzebne
response = payout.create(context, configMap);
logger.error("asdasdasdasdasdasdasdasdasdasdasdd4");
} catch (Exception e) {
throw new AppExeption("Error occurred while creating payout", HttpStatus.EXPECTATION_FAILED);
}
Expand Down

0 comments on commit 1e2cf3a

Please sign in to comment.