package com.example.fund_restart;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Payement extends AppCompatActivity implements View.OnClickListener {
    Button don_pay;
    String money = String.valueOf(10);
    String url;
    private static final int TEZ_REQUEST_CODE = 123;
    private static final String GOOGLE_TEZ_PACKAGE_NAME = "com.google.android.apps.nbu.paisa.user";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_payement);
        Bundle b = getIntent().getExtras();
        String url = b.getString("url");
        don_pay = findViewById(R.id.don_pay);
        don_pay.setOnClickListener(this);
        String he = url;

        /*       Uri uri =
                    new Uri.Builder()
                            .scheme("upi")
                            .authority("pay")
                            .appendQueryParameter("pa", "cmrfbihar@idbi")
                            .appendQueryParameter("pn", "Test Merchant")
                            .appendQueryParameter("mc", "1234")
                            .appendQueryParameter("tr", "123456789")
                            .appendQueryParameter("tn", "Little help")
                            .appendQueryParameter("am", "1.01")
                            .appendQueryParameter("cu", "INR")
                            .appendQueryParameter("url", "https://gpay.app.goo.gl/31gzbM")
                            .build();
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
            intent.setPackage(GOOGLE_TEZ_PACKAGE_NAME);
            startActivityForResult(intent, TEZ_REQUEST_CODE);


            Uri uri =
                    new Uri.Builder()
                            .scheme("upi")
                            .authority("pay")
                            .appendQueryParameter("pa", "dhanushg100@okhdfcbank")
                            .appendQueryParameter("pn", "Test Merchant")
                            .appendQueryParameter("mc", "1234")
                            .appendQueryParameter("tr", "123456789")
                            .appendQueryParameter("tn", "Little Help")
                            .appendQueryParameter("am", "1.01")
                            .appendQueryParameter("cu", "INR")
                            .appendQueryParameter("url", "https://gpay.app.goo.gl/ypFRwR")
                            .build();
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);
             intent.setPackage(GOOGLE_TEZ_PACKAGE_NAME);
            startActivityForResult(intent, TEZ_REQUEST_CODE);*/
    }

    @Override
    public void onClick(View v) {
        if (v == don_pay) {
            if (url == "bihar") {
                Uri uri =
                        new Uri.Builder()
                                .scheme("upi")
                                .authority("pay")
                                .appendQueryParameter("pa", "cmrfbihar@idbi")
                                .appendQueryParameter("pn", "Test Merchant")
                                .appendQueryParameter("mc", "1234")
                                .appendQueryParameter("tr", "123456789")
                                .appendQueryParameter("tn", "Little help")
                                .appendQueryParameter("am", money)
                                .appendQueryParameter("cu", "INR")
                                .appendQueryParameter("url", "https://gpay.app.goo.gl/31gzbM")
                                .build();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(uri);
                intent.setPackage(GOOGLE_TEZ_PACKAGE_NAME);
                startActivityForResult(intent, TEZ_REQUEST_CODE);
            }


        }
    }
}