Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve payment method #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow was added by CodeSee. Learn more at https://codesee.io/
# This is v2.0 of this workflow file
on:
push:
branches:
- master
pull_request_target:
types: [opened, synchronize, reopened]

name: CodeSee

permissions: read-all

jobs:
codesee:
runs-on: ubuntu-latest
continue-on-error: true
name: Analyze the repo with CodeSee
steps:
- uses: Codesee-io/codesee-action@v2
with:
codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
codesee-url: https://app.codesee.io
57 changes: 22 additions & 35 deletions src/com/shashi/service/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,43 @@ public class OrderServiceImpl implements OrderService {
@Override
public String paymentSuccess(String userName, double paidAmount) {
String status = "Order Placement Failed!";
List<CartBean> cartItems = new CartServiceImpl().getAllCartItems(userName);

List<CartBean> cartItems = new ArrayList<CartBean>();
cartItems = new CartServiceImpl().getAllCartItems(userName);

if (cartItems.size() == 0)
if (cartItems.isEmpty()) {
return status;
}

TransactionBean transaction = new TransactionBean(userName, paidAmount);
boolean ordered = false;

String transactionId = transaction.getTransactionId();

// System.out.println("Transaction: "+transaction.getTransactionId()+"
// "+transaction.getTransAmount()+" "+transaction.getUserName()+"
// "+transaction.getTransDateTime());
boolean ordered = true;

for (CartBean item : cartItems) {

double amount = new ProductServiceImpl().getProductPrice(item.getProdId()) * item.getQuantity();

OrderBean order = new OrderBean(transactionId, item.getProdId(), item.getQuantity(), amount);

ordered = addOrder(order);
if (!ordered)
ordered = ordered && processOrder(order, item);
if (!ordered) {
break;
else {
ordered = new CartServiceImpl().removeAProduct(item.getUserId(), item.getProdId());
}

if (!ordered)
break;
else
ordered = new ProductServiceImpl().sellNProduct(item.getProdId(), item.getQuantity());

if (!ordered)
break;
}
if (ordered && addTransactionAndNotify(transaction, userName)) {
status = "Order Placed Successfully!";
}
return status;
}

if (ordered) {
ordered = new OrderServiceImpl().addTransaction(transaction);
if (ordered) {

MailMessage.transactionSuccess(userName, new UserServiceImpl().getFName(userName),
transaction.getTransactionId(), transaction.getTransAmount());
private boolean processOrder(OrderBean order, CartBean item) {
return addOrder(order) &&
new CartServiceImpl().removeAProduct(item.getUserId(), item.getProdId()) &&
new ProductServiceImpl().sellNProduct(item.getProdId(), item.getQuantity());
}

status = "Order Placed Successfully!";
}
private boolean addTransactionAndNotify(TransactionBean transaction, String userName) {
boolean added = new OrderServiceImpl().addTransaction(transaction);
if (added) {
MailMessage.transactionSuccess(userName, new UserServiceImpl().getFName(userName),
transaction.getTransactionId(), transaction.getTransAmount());
}

return status;
return added;
}

@Override
Expand Down