package com.example.paymematedemo2;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.paymematedemo2.R;

import org.json.JSONObject;

import java.util.Iterator;

public class TransactionDetailsActivity extends AppCompatActivity {

    public static boolean isReturn = false;
    TextView tv_txt, tv_status, tv_message;
    Button btn_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transaction_details);
        tv_txt = findViewById(R.id.tv_txt);
        tv_message = findViewById(R.id.tv_message);
        tv_status = findViewById(R.id.tv_status);
        btn_return = findViewById(R.id.btn_return);
        String result = getIntent().getStringExtra("data");
        try {
            JSONObject jsonObject = new JSONObject(result);
            tv_status.setText("STATUS : " + jsonObject.optString("status"));
            if (jsonObject.optString("status").equals("success")) {
                tv_message.setText("The payment request was successful");

                tv_message.setTextColor(Color.parseColor("#359543"));
            } else {
                tv_message.setText("The payment request was unsuccessful");
                tv_message.setTextColor(Color.parseColor("#E21717"));
            }
            Iterator<String> keys = jsonObject.keys();
            while (keys.hasNext()) {
                String key = keys.next();
                tv_txt.setText(tv_txt.getText().toString() + "\n"
                        + key + "\n" + jsonObject.optString(key));
            }

            tv_txt.setText(tv_txt.getText().toString() + "\n\n\n");
        } catch (Exception e) {
            e.printStackTrace();
        }

        btn_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isReturn = true;
                finish();
            }
        });


    }
}
