Skip to content

Commit

Permalink
File change
Browse files Browse the repository at this point in the history
  • Loading branch information
sentry-autofix[bot] authored Oct 31, 2024
1 parent 5f216d6 commit e985e89
Showing 1 changed file with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ private String getProductInfoUrl(int index) {
public void checkout() {
Log.i("checkout", "checkout >>>");
selectedStoreItems = this.adapter.getSelectedStoreItems();

if (selectedStoreItems == null || selectedStoreItems.isEmpty()) {
Log.w("checkout", "Attempted checkout with empty cart");
Sentry.captureMessage("Attempted checkout with empty cart", SentryLevel.WARNING);
return;
}

ITransaction checkoutTransaction = Sentry.startTransaction("checkout [android]", "http.client");
checkoutTransaction.setOperation("http");
Sentry.configureScope(scope -> scope.setTransaction(checkoutTransaction));
Expand Down Expand Up @@ -350,20 +357,36 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();

processDeliveryItem(checkoutTransaction);

checkoutTransaction.finish(SpanStatus.INTERNAL_ERROR);
}
});
}
}
try {
if (!response.isSuccessful()) {
String errorBody = response.body() != null ? response.body().string() : "Unknown error";
Log.e("checkout", "Checkout failed with status: " + response.code() + ", error: " + errorBody);

Sentry.configureScope(scope -> {
scope.setExtra("response_code", response.code());
scope.setExtra("error_body", errorBody);
scope.setTag("error.type", "checkout_failed");
});

getActivity().runOnUiThread(() -> {

@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
progressDialog.dismiss();
Sentry.captureException(e);
});
} else {
String successBody = response.body() != null ? response.body().string() : "";
Log.d("checkout", "Checkout successful: " + successBody);

getActivity().runOnUiThread(() -> {
checkoutTransaction.finish(SpanStatus.OK);
// Reset cart
mCartItemCount = 0;
((EmpowerPlantActivity) getActivity()).textCartItemCount.setText("0");
selectedStoreItems.clear();
adapter.notifyDataSetChanged();
});
}
} finally {
response.close();

processDeliveryItem(checkoutTransaction);
checkoutTransaction.finish(SpanStatus.INTERNAL_ERROR);
Expand Down Expand Up @@ -401,30 +424,49 @@ private JSONObject buildJSONPostData(HashMap<String, StoreItem> selectedStoreIte
} catch (JSONException e) {
ISpan span = Sentry.getSpan();
if (span != null) {
JSONObject form = new JSONObject();
span.setThrowable(e);
span.finish(SpanStatus.INTERNAL_ERROR);
span.finish();
}
Sentry.captureException(e);
}
return postBody;
}

private void processDeliveryItem(ITransaction checkoutTransaction) {
Log.i("processDeliveryItem", "processDeliveryItem >>>");
ISpan processDeliverySpan = checkoutTransaction.startChild("task", "process delivery");

try {
throw new MainFragment.BackendAPIException("Failed to init delivery item workflow");
} catch (Exception e) {
Log.e("processDeliveryItem", e.getMessage());
processDeliverySpan.setThrowable(e);

// Add required form fields with proper structure
form.put("email", "someone@gmail.com");
form.put("shipping", new JSONObject()
.put("address", "123 Street")
.put("city", "San Francisco")
.put("state", "CA")
.put("zip", "94105")
.put("country", "US"));
form.put("billing", new JSONObject()
.put("address", "123 Street")
.put("city", "San Francisco")
.put("state", "CA")
.put("zip", "94105")
.put("country", "US"));
form.put("payment", new JSONObject()
.put("method", "credit_card")
.put("card_token", "tok_visa"));

postBody.put("form", form);
processDeliverySpan.setStatus(SpanStatus.INTERNAL_ERROR);
Sentry.captureException(e);
}

if (processDeliverySpan.getStatus() != SpanStatus.INTERNAL_ERROR) {
processDeliverySpan.setStatus(SpanStatus.OK);
span.setTag("error.type", "json_construction");
span.setTag("error.details", e.getMessage());
}
processDeliverySpan.finish();
Log.i("processDeliveryItem", "<<< processDeliveryItem");
Expand Down

0 comments on commit e985e89

Please sign in to comment.