导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - AddMoneyActivity.java 源代码

正在查看: Clash Legends v0.0.1 应用的 AddMoneyActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.clash.legends.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.clash.legends.models.CurrentUser;
import com.clash.legends.utils.UserLocalStore;
import com.google.gson.Gson;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;

public class AddMoneyActivity extends AppCompatActivity {
    private static final int PAYMENT_WEBVIEW_REQUEST = 1001;
    private Button buttonAddMoney;
    private int currentAmount;
    private String currentOrderId;
    private EditText editTextAmount;
    private OkHttpClient httpClient;
    private RequestQueue mQueue;
    private String minAmount;
    private CurrentUser user;
    private UserLocalStore userLocalStore;
    private final Gson gson = new Gson();
    private volatile boolean isPollingActive = false;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(2131558431);
        this.httpClient = new OkHttpClient();
        this.mQueue = Volley.newRequestQueue(this);
        UserLocalStore userLocalStore = new UserLocalStore(this);
        this.userLocalStore = userLocalStore;
        this.user = userLocalStore.getLoggedInUser();
        ImageView backFromAddCoin = (ImageView) findViewById(2131361971);
        backFromAddCoin.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                AddMoneyActivity.this.m6x4e66ef08(view);
            }
        });
        this.editTextAmount = (EditText) findViewById(2131362273);
        this.buttonAddMoney = (Button) findViewById(2131362072);
        fetchMinAddMoney();
        this.buttonAddMoney.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                AddMoneyActivity.this.m7x40109527(view);
            }
        });
    }

    void m6x4e66ef08(View v) {
        navigateToWallet();
    }

    void m7x40109527(View v) {
        initiatePayment();
    }

    private void initiatePayment() {
        String amountStr = this.editTextAmount.getText().toString();
        if (amountStr.isEmpty()) {
            showToast("Please enter an amount");
            return;
        }
        try {
            int amount = Integer.parseInt(amountStr);
            String str = this.minAmount;
            if (str == null) {
                showToast("Please wait while we load payment details");
            } else if (amount < Integer.parseInt(str)) {
                showToast("Minimum amount should be " + this.minAmount);
            } else {
                createOrder(amount);
            }
        } catch (NumberFormatException e) {
            showToast("Invalid amount entered");
        }
    }

    private String generateServerCompatibleOrderId() {
        StringBuilder sb = new StringBuilder(8);
        for (int i = 0; i < 8; i++) {
            int index = (int) ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".length() * Math.random());
            sb.append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(index));
        }
        return sb.toString();
    }

    private void createOrder(final int amount) {
        this.user = new UserLocalStore(getApplicationContext()).getLoggedInUser();
        String uniqueOrderId = generateServerCompatibleOrderId();
        postDepositDetails(amount, "0", uniqueOrderId);
        Request request = new Request.Builder().url("https://zapupi.com/api/create-order").post(new FormBody.Builder().add("token_key", "0c1f4cdc3b8000c2df4055a02b3b8125").add("secret_key", "2615a07ce9fef80683d211dad896d073").add("amount", String.valueOf(amount)).add("order_id", uniqueOrderId).add("custumer_mobile", "9966339966").add("redirect_url", "https://yourapp.com/payment-callback").add("remark", "Wallet Topup").build()).build();
        this.httpClient.newCall(request).enqueue(new Callback() {
            public void onFailure(Call call, IOException e) {
                AddMoneyActivity.this.handlePaymentError("Payment failed: " + e.getMessage());
            }

            public void onResponse(Call call, Response response) throws IOException {
                try {
                    String responseData = response.body().string();
                    JSONObject jsonResponse = new JSONObject(responseData);
                    if (jsonResponse.getString("status").equals("success")) {
                        String paymentUrl = jsonResponse.getString("payment_url");
                        String serverOrderId = jsonResponse.getString("order_id");
                        AddMoneyActivity.this.openPaymentBrowser(paymentUrl);
                        AddMoneyActivity.this.startPaymentStatusPolling(serverOrderId, amount);
                    } else {
                        String errorMessage = jsonResponse.getString("message");
                        AddMoneyActivity.this.handlePaymentError(errorMessage);
                    }
                } catch (JSONException e) {
                    AddMoneyActivity.this.handlePaymentError("Invalid server response format");
                }
            }
        });
    }

    public void openPaymentBrowser(final String paymentUrl) {
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                AddMoneyActivity.this.m8x212ac075(paymentUrl);
            }
        });
    }

    void m8x212ac075(String paymentUrl) {
        try {
            Intent intent = new Intent((Context) this, (Class<?>) PaymentWebViewActivity.class);
            intent.putExtra("payment_url", paymentUrl);
            intent.putExtra("redirect_url", "https://yourapp.com/payment-callback");
            startActivityForResult(intent, PAYMENT_WEBVIEW_REQUEST);
        } catch (Exception e) {
            handlePaymentError("Payment initialization failed");
        }
    }

    public void startPaymentStatusPolling(final String orderId, final int amount) {
        this.currentOrderId = orderId;
        this.currentAmount = amount;
        this.isPollingActive = true;
        Log.d("PaymentFlow", "Starting 6-minute polling for: " + orderId);
        new Thread(new Runnable() {
            @Override
            public final void run() {
                AddMoneyActivity.this.m9x309da26d(orderId, amount);
            }
        }).start();
    }

    void m9x309da26d(String orderId, int amount) {
        boolean completed;
        int pollAttempts = 0;
        while (this.isPollingActive && pollAttempts < 72) {
            try {
                Log.d("PaymentFlow", "Poll attempt: " + (pollAttempts + 1) + "/72");
                Thread.sleep(5000L);
                completed = checkOrderStatus(orderId, amount);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            if (completed) {
                Log.d("PaymentFlow", "Payment completed successfully");
                break;
            }
            pollAttempts++;
        }
        if (pollAttempts >= 72) {
            handlePaymentError("Payment verification timeout after 6 minutes");
        }
        this.isPollingActive = false;
    }

    private boolean checkOrderStatus(String orderId, int amount) {
        try {
            Request request = new Request.Builder().url("https://zapupi.com/api/order-status").post(new FormBody.Builder().add("token_key", "0c1f4cdc3b8000c2df4055a02b3b8125").add("secret_key", "2615a07ce9fef80683d211dad896d073").add("order_id", orderId).build()).build();
            Response response = this.httpClient.newCall(request).execute();
            try {
                if (response.isSuccessful()) {
                    String responseData = response.body().string();
                    JSONObject jsonResponse = new JSONObject(responseData);
                    if (jsonResponse.getString("status").equals("success")) {
                        JSONObject data = jsonResponse.getJSONObject("data");
                        WebhookData webhookData = (WebhookData) this.gson.fromJson(data.toString(), WebhookData.class);
                        if (webhookData.status.equalsIgnoreCase("Success") || webhookData.status.equalsIgnoreCase("Failed")) {
                            handlePaymentStatus(webhookData, amount);
                            if (response != null) {
                                response.close();
                                return true;
                            }
                            return true;
                        }
                    }
                }
                if (response != null) {
                    response.close();
                    return false;
                }
                return false;
            } finally {
            }
        } catch (Exception e) {
            Log.e("PaymentStatus", "Error checking status", e);
            return false;
        }
    }

    private void handlePaymentStatus(final WebhookData webhookData, final int amount) {
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                AddMoneyActivity.this.m5x94b66fa9(webhookData, amount);
            }
        });
    }

    void m5x94b66fa9(WebhookData webhookData, int amount) {
        char c;
        Log.d("PaymentFlow", "Received status: " + webhookData.status);
        String upperCase = webhookData.status.toUpperCase();
        switch (upperCase.hashCode()) {
            case -1149187101:
                if (upperCase.equals("SUCCESS")) {
                    c = 0;
                    break;
                }
                c = 65535;
                break;
            case 35394935:
                if (upperCase.equals("PENDING")) {
                    c = 2;
                    break;
                }
                c = 65535;
                break;
            case 2066319421:
                if (upperCase.equals("FAILED")) {
                    c = 1;
                    break;
                }
                c = 65535;
                break;
            default:
                c = 65535;
                break;
        }
        switch (c) {
            case 0:
                handlePaymentSuccess(amount, webhookData.order_id);
                break;
            case 1:
                handlePaymentFailure(amount, webhookData.order_id);
                break;
            case 2:
                Log.d("PaymentFlow", "Payment still processing...");
                break;
            default:
                Log.e("PaymentFlow", "Unknown status: " + webhookData.status);
                break;
        }
    }

    private void handlePaymentSuccess(int amount, String orderId) {
        postDepositDetails(amount, "1", orderId);
        postTransaction(amount, orderId);
        updateWalletBalance(amount);
        showToast("Payment successful!");
    }

    private void handlePaymentFailure(int amount, String orderId) {
        postDepositDetails(amount, "2", orderId);
        showToast("Payment failed");
    }

    private void postDepositDetails(double amount, String status, String orderId) {
        String str;
        StringBuilder append = new StringBuilder().append(getResources().getString(2131886167));
        if (status.equals("0")) {
            str = "insert-deposit";
        } else {
            str = "update-deposit-status";
        }
        String url = append.append(str).toString();
        try {
            JSONObject depositDetails = new JSONObject();
            if (status.equals("0")) {
                depositDetails.put("member_id", this.user.getMemberid());
                depositDetails.put("deposit_amount", amount);
                depositDetails.put("deposit_status", status);
                depositDetails.put("deposit_by", "Zapupi");
                depositDetails.put("entry_from", "1");
                depositDetails.put("wallet_address", JSONObject.NULL);
                depositDetails.put("private_key", JSONObject.NULL);
                depositDetails.put("public_key", JSONObject.NULL);
                depositDetails.put("address_hex", JSONObject.NULL);
                depositDetails.put("bank_transection_no", orderId);
                depositDetails.put("reason", JSONObject.NULL);
            } else {
                depositDetails.put("order_id", orderId);
                depositDetails.put("deposit_status", status);
            }
            int method = status.equals("0") ? 1 : 2;
            JsonObjectRequest request = new JsonObjectRequest(method, url, depositDetails, new Response.Listener() {
                public final void onResponse(Object obj) {
                    AddMoneyActivity.lambda$postDepositDetails$5((JSONObject) obj);
                }
            }, new Response.ErrorListener() {
                public final void onErrorResponse(VolleyError volleyError) {
                    AddMoneyActivity.lambda$postDepositDetails$6(volleyError);
                }
            });
            this.mQueue.add(request);
        } catch (JSONException e) {
            Log.e("Deposit", "Error creating JSON");
        }
    }

    static void lambda$postDepositDetails$5(JSONObject response) {
    }

    static void lambda$postDepositDetails$6(VolleyError error) {
    }

    private void postTransaction(double amount, String orderId) {
        String url = getResources().getString(2131886167) + "transactionlat";
        try {
            JSONObject transactionDetails = new JSONObject();
            transactionDetails.put("member_id", this.user.getMemberid());
            transactionDetails.put("deposit", amount);
            transactionDetails.put("note", "Added via Zapupi");
            transactionDetails.put("note_id", "7");
            transactionDetails.put("order_id", JSONObject.NULL);
            transactionDetails.put("entry_from", "1");
            transactionDetails.put("from_mem_id", 0);
            transactionDetails.put("match_id", 0);
            transactionDetails.put("ip_detail", "Android App IP");
            transactionDetails.put("browser", "Android WebView");
            transactionDetails.put("pubg_id", JSONObject.NULL);
            transactionDetails.put("withdraw", 0);
            transactionDetails.put("join_money", 0);
            transactionDetails.put("win_money", 0);
            transactionDetails.put("pyatmnumber", JSONObject.NULL);
            transactionDetails.put("withdraw_method", JSONObject.NULL);
            transactionDetails.put("lottery_id", 0);
            JsonObjectRequest request = new JsonObjectRequest(1, url, transactionDetails, new Response.Listener() {
                public final void onResponse(Object obj) {
                    AddMoneyActivity.lambda$postTransaction$7((JSONObject) obj);
                }
            }, new Response.ErrorListener() {
                public final void onErrorResponse(VolleyError volleyError) {
                    AddMoneyActivity.lambda$postTransaction$8(volleyError);
                }
            });
            this.mQueue.add(request);
        } catch (NumberFormatException | JSONException e) {
            Log.e("Transaction", "Request creation error: " + e.getMessage());
        }
    }

    static void lambda$postTransaction$7(JSONObject response) {
        try {
            JSONObject res = new JSONObject(response.toString());
            if (res.getString("status").equals("success")) {
                Log.d("Transaction", "Transaction recorded");
            } else {
                Log.e("Transaction", "Error: " + res.getString("message"));
            }
        } catch (JSONException e) {
            Log.e("Transaction", "Response parsing error");
        }
    }

    static void lambda$postTransaction$8(VolleyError error) {
        if (error.networkResponse != null) {
            String errorMsg = new String(error.networkResponse.data, StandardCharsets.UTF_8);
            Log.e("Transaction", "Server Error: " + errorMsg);
        } else {
            Log.e("Transaction", "Network Error: " + error.getMessage());
        }
    }

    private void updateWalletBalance(double amount) {
        String url = getResources().getString(2131886167) + "update-wallet-balance";
        try {
            JSONObject balanceUpdate = new JSONObject();
            balanceUpdate.put("member_id", this.user.getMemberid());
            balanceUpdate.put("amount", amount);
            JsonObjectRequest request = new JsonObjectRequest(1, url, balanceUpdate, new Response.Listener() {
                public final void onResponse(Object obj) {
                    AddMoneyActivity.lambda$updateWalletBalance$9((JSONObject) obj);
                }
            }, new Response.ErrorListener() {
                public final void onErrorResponse(VolleyError volleyError) {
                    AddMoneyActivity.lambda$updateWalletBalance$10(volleyError);
                }
            });
            this.mQueue.add(request);
        } catch (JSONException e) {
            Log.e("Balance", "Request creation error: " + e.getMessage());
        }
    }

    static void lambda$updateWalletBalance$9(JSONObject response) {
        try {
            JSONObject res = new JSONObject(response.toString());
            if (res.getString("status").equals("success")) {
                Log.d("Balance", "Wallet updated");
            } else {
                Log.e("Balance", "Error: " + res.getString("message"));
            }
        } catch (JSONException e) {
            Log.e("Balance", "Response parsing error");
        }
    }

    static void lambda$updateWalletBalance$10(VolleyError error) {
        if (error.networkResponse != null) {
            String errorMsg = new String(error.networkResponse.data, StandardCharsets.UTF_8);
            Log.e("Balance", "Server Error: " + errorMsg);
        } else {
            Log.e("Balance", "Network Error: " + error.getMessage());
        }
    }

    private void fetchMinAddMoney() {
        String url = getResources().getString(2131886167) + "min-addmoney";
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(0, url, (JSONObject) null, new Response.Listener() {
            public final void onResponse(Object obj) {
                AddMoneyActivity.this.m2x1d58df7c((JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                AddMoneyActivity.this.m3xf02859b(volleyError);
            }
        });
        this.mQueue.add(jsonObjectRequest);
    }

    void m2x1d58df7c(JSONObject response) {
        try {
            this.minAmount = response.getString("min_addmoney");
        } catch (JSONException e) {
            handlePaymentError("Error parsing server response");
        }
    }

    void m3xf02859b(VolleyError error) {
        handlePaymentError("Network error");
    }

    public void handlePaymentError(final String message) {
        runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                AddMoneyActivity.this.m4x6f20a0ed(message);
            }
        });
    }

    void m4x6f20a0ed(String message) {
        showToast(message);
        Log.e("PaymentError", message);
    }

    private void showToast(String message) {
        Toast.makeText((Context) this, (CharSequence) message, 0).show();
    }

    private void navigateToWallet() {
        startActivity(new Intent((Context) this, (Class<?>) MyWalletActivity.class));
        finish();
    }

    static class WebhookData {
        String amount;
        String create_at;
        String custumer_mobile;
        String order_id;
        String remark;
        String status;
        String txn_id;
        String utr;

        private WebhookData() {
        }
    }
}