Skip to content

Commit

Permalink
adding functionality to buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
iwokonl committed Apr 18, 2024
1 parent e6035bb commit 5dced16
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Payment createPayment(
) throws PayPalRESTException {
Amount amount = new Amount();
amount.setCurrency(currency);
logger.info("Currencyasdasdasdasdasdads: " + currency);
amount.setTotal(String.format(Locale.forLanguageTag(currency), "%.2f", total));

Transaction transaction = new Transaction();
Expand Down Expand Up @@ -195,6 +196,7 @@ public Payment executePayment(
}

public void addAmountToKantorAccount(Payment payment, String userId) {
logger.info("Payment approvedasdasd " + payment.getTransactions().get(0).getAmount().getCurrency()+ " "+ Long.parseLong(userId));
Optional<ForeignCurrencyAccount> account = foreignCurrencyAccountRepo.findByCurrencyCodeAndUserId(payment.getTransactions().get(0).getAmount().getCurrency(), Long.parseLong(userId));
if (account.isPresent()) {
ForeignCurrencyAccount foreignCurrencyAccount = account.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


<!--TODO:Dodać animacje ładowania-->
<div class="container">

<h3 class="nag">Spis kont walutowych</h3>
<div class="row">
<div class="col-md-4" *ngFor="let account of accounts">
Expand All @@ -11,15 +12,17 @@ <h5 class="card-title">
</h5>
<p class="card-text">Balans: {{ account.balance + ' ' + account.curencyCode + ' = ' + (account.balanceInPLN | number : '1.2-2') +' PLN' }}</p>
<button class="btn btn-outline-primary delete" (click)="onDeleteAccount(account)">Usuń konto walutowe</button>
<button class="btn btn-outline-primary">Dodaj fundusze</button>
<button class="btn btn-outline-primary withdraw">Wypłać fundusze</button>
<button class="btn btn-outline-primary" (click)="onAddMoney(account)">Dodaj fundusze</button>
<button class="btn btn-outline-primary withdraw" (click)="createPayout(account)">Wypłać fundusze</button>

<input class="form-control" type="text" placeholder="Wprowadź kwotę do wpłaty/wypłaty" [(ngModel)]="account.amount">

</div>
</div>
</div>
</div>
</div>


</div>


<form class="create-account-form" #createAccountForm="ngForm" (ngSubmit)="createCurrencyAccount(createAccountForm.value)">
Expand All @@ -34,3 +37,4 @@ <h3>Dodawanie konta walutowego</h3>
</div>
<button type="submit" class="btn btn-primary">Create Account</button>
</form>

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
box-shadow: 0 2px 4px 0 rgba(0,0,0,.1);
background-color: #fff;
min-height: 140px;
max-height: 196px;
max-height: 237px;
min-width: 320px;


Expand All @@ -41,7 +41,9 @@

padding: 3px 1px;
}

.form-control{
width: 275px;
}
//zawartość kafelka - tekst
.card-body {
flex-grow: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CurrencyService } from '../currency.service';
})
export class CurrencyAccountComponent implements OnInit {
accounts: any[] = [];

isLoading: boolean = false;
constructor(private axiosService: AxiosService, private currencyService: CurrencyService) { }

getCurrencyAccounts(): void {
Expand Down Expand Up @@ -52,4 +52,38 @@ export class CurrencyAccountComponent implements OnInit {
this.getCurrencyAccounts(); // Refresh the accounts list after creating a new account
});
}

onAddMoney(account: any) {
this.isLoading = true;
this.axiosService.request("POST",
"/api/payment/create",
{
total: account.amount,
currency: account.curencyCode,
method: "paypal",
intent: "sale",
description: "Płatność za pomocą PayPal. Dodanie środków do konta walutowego. Kwota: " + account.amount + " " + account.currencyCode,
cancelUrl: "http://localhost:8082/api/payment/cancel",
successUrl: "http://localhost:8082/api/payment/success"

}).then((response) => {
console.log(response.data);
window.location.href = response.data.url;
this.getCurrencyAccounts();
this.isLoading = false;// Refresh the accounts list after creating a new account
});
}

createPayout(account: any) {
this.axiosService.request("POST",
"/api/payment/createPayout",
{
receiverEmail: "[email protected]", // Dodać kiedyś do db pole paypal email i przypisać do usera podczas rejestracji.
total: account.amount,
currency: account.curencyCode
}).then((response) => {
console.log(response.data);
this.getCurrencyAccounts(); // Refresh the accounts list after creating a new account
});
}
}

0 comments on commit 5dced16

Please sign in to comment.